ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / intel_conservative_rasterization / innercoverage.c
blob8524fb9a4b3f601228261958dea82a1ce4805552
1 /*
2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
25 /** @file innercoverage.c
27 * Verifies that the inner_coverage layout qualifier works when
28 * GL_INTEL_conservative_rasterization is enabled.
31 #include "piglit-util-gl.h"
32 #include "piglit-matrix.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 #if defined(PIGLIT_USE_OPENGL)
37 config.supports_gl_core_version = 42;
38 #elif defined(PIGLIT_USE_OPENGL_ES3)
39 config.supports_gl_es_version = 31;
40 #endif
42 config.window_width = 400;
43 config.window_height = 400;
44 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
46 PIGLIT_GL_TEST_CONFIG_END
48 enum piglit_result
49 piglit_display(void)
51 enum piglit_result result = PIGLIT_PASS;
53 /* The following fragment programs render the opaque red color
54 * only when dispatched with a gl_SampleMaskIn empty. It
55 * should therefore expose the effect of the inner_coverage
56 * (i.e. no color with this qualifier and a triangle outline
57 * without it). */
58 GLuint inner_prog = piglit_build_simple_program(
59 #if defined(PIGLIT_USE_OPENGL)
60 "#version 420\n"
61 #elif defined(PIGLIT_USE_OPENGL_ES3)
62 "#version 310 es\n"
63 #endif
64 "in vec4 piglit_vertex;\n"
65 "void main()\n"
66 "{\n"
67 " gl_Position = piglit_vertex;\n"
68 "}\n",
69 #if defined(PIGLIT_USE_OPENGL)
70 "#version 420\n"
71 "#extension GL_INTEL_conservative_rasterization: enable\n"
72 #elif defined(PIGLIT_USE_OPENGL_ES3)
73 "#version 310 es\n"
74 "#extension GL_OES_sample_variables: enable\n"
75 "#extension GL_INTEL_conservative_rasterization: enable\n"
76 "precision highp float;\n"
77 #endif
78 "layout(inner_coverage) in;\n"
79 "out vec4 color;\n"
80 "void main()\n"
81 "{\n"
82 " float one = 1.0 - float(gl_SampleMaskIn[0]);\n"
83 " color = vec4(one, 0.0, 0.0, one);\n"
84 "}\n");
85 if (!inner_prog)
86 piglit_report_result(PIGLIT_FAIL);
88 GLuint conservative_prog = piglit_build_simple_program(
89 #if defined(PIGLIT_USE_OPENGL)
90 "#version 420\n"
91 #elif defined(PIGLIT_USE_OPENGL_ES3)
92 "#version 310 es\n"
93 #endif
94 "in vec4 piglit_vertex;\n"
95 "void main()\n"
96 "{\n"
97 " gl_Position = piglit_vertex;\n"
98 "}\n",
99 #if defined(PIGLIT_USE_OPENGL)
100 "#version 420\n"
101 "#extension GL_INTEL_conservative_rasterization: enable\n"
102 #elif defined(PIGLIT_USE_OPENGL_ES3)
103 "#version 310 es\n"
104 "#extension GL_OES_sample_variables: enable\n"
105 "#extension GL_INTEL_conservative_rasterization: enable\n"
106 "precision highp float;\n"
107 #endif
108 "out vec4 color;\n"
109 "void main()\n"
110 "{\n"
111 " float one = 1.0 - float(gl_SampleMaskIn[0]);\n"
112 " color = vec4(one, 0.0, 0.0, one);\n"
113 "}\n");
114 if (!conservative_prog)
115 piglit_report_result(PIGLIT_FAIL);
117 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
118 glViewport(0, 0, piglit_width, piglit_height);
120 glClearColor(0.0, 0.0, 0.0, 0.0);
122 GLuint vao;
123 glGenVertexArrays(1, &vao);
124 glBindVertexArray(vao);
126 GLuint vbo;
127 float delta = 1.01 / piglit_width;
128 float vertices[3][2] = {
129 { -0.5, -1 + delta, },
130 { 0, 0.8, },
131 { 0.5, -1 + delta, },
133 glGenBuffers(1, &vbo);
134 glBindBuffer(GL_ARRAY_BUFFER, vbo);
135 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
136 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL);
137 glEnableVertexAttribArray(0);
139 glEnable(GL_CONSERVATIVE_RASTERIZATION_INTEL);
141 glUseProgram(conservative_prog);
142 glClear(GL_COLOR_BUFFER_BIT);
143 glDrawArrays(GL_TRIANGLES, 0, 3);
145 if(!piglit_check_gl_error(GL_NO_ERROR))
146 return PIGLIT_FAIL;
148 piglit_present_results();
150 const float conservative_expected[] = { 0.0, 0.0, 0.0, 0.0 };
151 if (!piglit_probe_pixel_rgba(piglit_width / 2, 0, conservative_expected))
152 result = PIGLIT_FAIL;
154 glUseProgram(inner_prog);
155 glClear(GL_COLOR_BUFFER_BIT);
156 glDrawArrays(GL_TRIANGLES, 0, 3);
158 if(!piglit_check_gl_error(GL_NO_ERROR))
159 result = PIGLIT_FAIL;
161 piglit_present_results();
163 const float inner_expected[] = { 1.0, 0.0, 0.0, 1.0 };
164 if (!piglit_probe_pixel_rgba(piglit_width / 2, 0, inner_expected))
165 result = PIGLIT_FAIL;
167 return result;
170 void piglit_init(int argc, char **argv)
172 piglit_require_extension("GL_INTEL_conservative_rasterization");