2 * Copyright (c) 2015 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
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
21 * DEALINGS IN THE SOFTWARE.
25 * A rudimentary test to check whether the correct values are being written
26 * to gl_SampleMaskIn when ARB_post_depth_coverage is enabled.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_compat_version
= 43;
33 config
.supports_gl_core_version
= 43;
34 config
.window_width
= 160;
35 config
.window_height
= 160;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_DOUBLE
;
37 PIGLIT_GL_TEST_CONFIG_END
39 static GLuint prog1
, prog2
, vao
, ssbo
;
40 static GLint
*sample_mask
;
42 static const char *vs_text
=
47 " gl_Position = pos_in;\n"
50 static const char *fs_text1
=
55 " gl_FragDepth = 0.5f;\n"
56 " color = vec4(0.0, 1.0, 0.0, 1.0);\n"
59 static const char *fs_text2
=
61 "#extension GL_ARB_post_depth_coverage: enable\n"
63 "layout(early_fragment_tests) in;\n"
64 "layout(post_depth_coverage) in;\n"
65 "layout(location = 2) uniform int width;"
66 "layout(std430, binding = 3) buffer MaskOutput {"
71 " int index = int(gl_FragCoord.y) * width + int(gl_FragCoord.x);\n"
72 " mask_output.data[index] = int(gl_SampleMaskIn[0]);\n"
73 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
77 make_shader_program1(void)
81 prog
= piglit_build_simple_program(vs_text
, fs_text1
);
84 glBindAttribLocation(prog
, 0, "pos_in");
88 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
89 piglit_report_result(PIGLIT_FAIL
);
96 make_shader_program2(void)
100 prog
= piglit_build_simple_program(vs_text
, fs_text2
);
103 glBindAttribLocation(prog
, 0, "pos_in");
107 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
108 piglit_report_result(PIGLIT_FAIL
);
119 glGenBuffers(1, &ssbo
);
120 glBindBuffer(GL_SHADER_STORAGE_BUFFER
, ssbo
);
122 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
123 piglit_report_result(PIGLIT_FAIL
);
132 static const float pos_tc
[12][2] = {
146 const int stride
= sizeof(pos_tc
[0]);
149 glGenVertexArrays(1, &vao
);
150 glBindVertexArray(vao
);
152 glGenBuffers(1, &vbo
);
153 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
154 glBufferData(GL_ARRAY_BUFFER
, sizeof(pos_tc
), pos_tc
, GL_STATIC_DRAW
);
155 piglit_check_gl_error(GL_NO_ERROR
);
157 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, stride
, (void *) 0);
159 glEnableVertexAttribArray(0);
161 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
162 piglit_report_result(PIGLIT_FAIL
);
170 piglit_init(int argc
, char **argv
)
172 piglit_require_extension("GL_ARB_post_depth_coverage");
173 prog1
= make_shader_program1();
174 prog2
= make_shader_program2();
183 float green
[4] = {0.0, 1.0, 0.0, 1.0};
184 float red
[4] = {1.0, 0.0, 0.0, 1.0};
188 glEnable(GL_DEPTH_TEST
);
189 glViewport(0, 0, piglit_width
, piglit_height
);
190 sample_mask
= (GLint
*) malloc (sizeof(GLint
) * (piglit_width
* piglit_height
));
191 for (i
= 0; i
< piglit_width
* piglit_height
; i
++) {
194 glBufferData(GL_SHADER_STORAGE_BUFFER
, sizeof(GLint
) * (piglit_width
*
195 piglit_height
), &sample_mask
[0], GL_DYNAMIC_COPY
);
196 glBindBufferBase(GL_SHADER_STORAGE_BUFFER
, 3, ssbo
);
198 glClearColor(0.0, 0.0, 0.0, 1.0);
199 glEnable(GL_DEPTH_TEST
);
200 glEnable(GL_STENCIL_TEST
);
201 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
203 glStencilFunc(GL_ALWAYS
, 1, 0xFF);
204 glStencilOp(GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
205 glDrawArrays(GL_TRIANGLES
, 0, 6);
207 glStencilFunc(GL_NOTEQUAL
, 1, 0xFF);
208 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
209 glUniform1i(2, piglit_width
);
210 glDrawArrays(GL_TRIANGLES
, 6, 6);
212 glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT
);
214 glGetBufferSubData(GL_SHADER_STORAGE_BUFFER
, 0, sizeof(GLint
) *
215 piglit_width
* piglit_height
, &sample_mask
[0]);
217 for (i
= 0; i
< piglit_width
; i
++) {
218 for (j
= 0; j
< piglit_height
; j
++) {
219 if (i
>= piglit_width
/ 2) {
220 if (sample_mask
[piglit_width
* j
+ i
] != 1) {
225 if (sample_mask
[piglit_width
* j
+ i
] != 0) {
233 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
/ 2, piglit_height
,
235 pass
= piglit_probe_rect_rgba(piglit_width
/ 2, 0, piglit_width
/ 2,
236 piglit_height
, red
) && pass
;
237 piglit_present_results();
239 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
242 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;