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
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
24 #include "piglit-util-gl.h"
26 PIGLIT_GL_TEST_CONFIG_BEGIN
28 config
.supports_gl_compat_version
= 32;
29 config
.supports_gl_core_version
= 32;
31 PIGLIT_GL_TEST_CONFIG_END
33 static const char vs_pass_thru_text
[] =
36 " gl_Position = vec4(0.0);\n"
39 static const char vs_two_sets_text
[] =
41 "#extension GL_ARB_enhanced_layouts: require\n"
43 "layout(xfb_offset = 0) out float x1_out;\n"
44 "layout(xfb_offset = 4) out float x2_out[2];\n"
45 "layout(xfb_offset = 12) out vec3 x3_out;\n"
46 "layout(xfb_buffer = 2) out;\n"
47 "layout(xfb_offset = 0, xfb_buffer = 2) out float y1_out;\n"
48 "layout(xfb_offset = 4) out vec4 y2_out;\n"
50 " gl_Position = vec4(0.0);\n"
54 " x3_out = vec3(4.0, 5.0, 6.0);\n"
56 " y2_out = vec4(8.0, 9.0, 10.0, 11.0);\n"
59 static const char vs_two_sets_ifc_text
[] =
61 "#extension GL_ARB_enhanced_layouts: require\n"
64 " layout(xfb_offset = 12) out float x1_out;\n"
65 " layout(xfb_offset = 16) out vec2 x2_out;\n"
66 " layout(xfb_buffer = 0) out vec3 not_captured;\n"
67 " layout(xfb_offset = 0) out vec3 x3_out;\n"
69 "layout(xfb_buffer = 2) out;\n"
70 "layout(xfb_offset = 0) out block2 {\n"
75 " gl_Position = vec4(0.0);\n"
77 " x2_out = vec2(5.0, 6.0);\n"
78 " x3_out = vec3(1.0, 2.0, 3.0);\n"
80 " y2_out = vec4(8.0, 9.0, 10.0, 11.0);\n"
83 static const char vs_two_sets_named_ifc_text
[] =
85 "#extension GL_ARB_enhanced_layouts: require\n"
88 " layout(xfb_offset = 0) out float x1_out;\n"
89 " layout(xfb_offset = 4) out vec2 x2_out;\n"
90 " layout(xfb_buffer = 0) out vec3 not_captured;\n"
91 " layout(xfb_offset = 12) out vec3 x3_out;\n"
93 "layout(xfb_buffer = 2) out;\n"
94 "layout(xfb_offset = 0) out block2 {\n"
99 " gl_Position = vec4(0.0);\n"
101 " x.x2_out = vec2(2.0, 3.0);\n"
102 " x.x3_out = vec3(4.0, 5.0, 6.0);\n"
104 " y.y2_out = vec4(8.0, 9.0, 10.0, 11.0);\n"
107 static const char vs_two_sets_struct_text
[] =
109 "#extension GL_ARB_enhanced_layouts: require\n"
115 " Array x2_Array[2];\n"
122 "layout(xfb_offset = 0) out S s1;\n"
123 "layout(xfb_offset = 0, xfb_buffer = 2) out struct S2 {\n"
128 " gl_Position = vec4(0.0);\n"
129 " s1.x1_out = 1.0;\n"
130 " s1.x2_AoA[0].x2_Array[0].x2_out = 2.0;\n"
131 " s1.x2_AoA[0].x2_Array[1].x2_out = 3.0;\n"
132 " s1.x2_AoA[1].x2_Array[0].x2_out = 4.0;\n"
133 " s1.x2_AoA[1].x2_Array[1].x2_out = 5.0;\n"
134 " s1.x3_out = 6.0;\n"
135 " s2.y1_out = 7.0;\n"
136 " s2.y2_out = vec4(8.0, 9.0, 10.0, 11.0);\n"
139 static const char gs_text_two_sets_tmpl
[] =
141 "#extension GL_ARB_enhanced_layouts: require\n"
142 "#extension GL_ARB_gpu_shader5 : enable\n"
143 "#define INVOCATION_MAX_N %u\n"
144 "layout(points, invocations = INVOCATION_MAX_N) in;\n"
145 "layout(points, max_vertices = 1) out;\n"
147 "layout(xfb_offset = 0) out float x1_out;\n"
148 "layout(xfb_offset = 4) out vec2 x2_out;\n"
149 "layout(xfb_offset = 12) out vec3 x3_out;\n"
150 "out vec3 not_captured1;\n"
151 "layout(xfb_buffer = 2) out;\n"
152 "layout(xfb_offset = 0) out float y1_out;\n"
153 "layout(xfb_offset = 4) out vec4 y2_out;\n"
154 "layout(xfb_buffer = 2) out vec3 not_captured2;\n"
156 " gl_Position = gl_in[0].gl_Position;\n"
157 " x1_out = 1.0 + gl_InvocationID;\n"
158 " x2_out = vec2(2.0 + gl_InvocationID, 3.0 + gl_InvocationID);\n"
159 " x3_out = vec3(4.0 + gl_InvocationID, 5.0 + gl_InvocationID,\n"
160 " 6.0 + gl_InvocationID);\n"
161 " y1_out = 7.0 + gl_InvocationID;\n"
162 " y2_out = vec4(8.0 + gl_InvocationID, 9.0 + gl_InvocationID,\n"
163 " 10.0 + gl_InvocationID, 11.0 + gl_InvocationID);\n"
164 " not_captured1 = vec3(1.0);"
165 " not_captured2 = vec3(1.0);"
170 #define BUF_1_FLOAT_N 6
171 #define BUF_2_FLOAT_N 5
174 print_usage_and_exit(const char *prog_name
)
176 printf("Usage: %s <subtest>\n"
177 " where <subtest> is one of the following:\n"
178 " vs (vertex shader only)\n"
179 " vs_ifc (vertex shader only, with interface block)\n"
180 " vs_named_ifc (vertex shader only, with named interface block)\n"
181 " vs_struct (vertex shader only, with structs)\n"
182 " gs (with geometry shader invoked once per stage)\n"
183 " gs_max (with geometry shader invoked max times per "
184 "stage)\n", prog_name
);
185 piglit_report_result(PIGLIT_FAIL
);
189 build_and_use_program(unsigned gs_invocation_n
, const char *vs_text
)
193 if (gs_invocation_n
== 0) {
194 prog
= piglit_build_simple_program_multiple_shaders(
195 GL_VERTEX_SHADER
, vs_text
, 0);
199 (void)!asprintf(&gs_text
, gs_text_two_sets_tmpl
, gs_invocation_n
);
200 prog
= piglit_build_simple_program_multiple_shaders(
201 GL_VERTEX_SHADER
, vs_pass_thru_text
,
202 GL_GEOMETRY_SHADER
, gs_text
, 0);
207 if (!piglit_link_check_status(prog
))
208 piglit_report_result(PIGLIT_FAIL
);
209 if (!piglit_check_gl_error(GL_NO_ERROR
))
210 piglit_report_result(PIGLIT_FAIL
);
216 probe_buffers(const GLuint
*xfb
, const GLuint
*queries
, unsigned primitive_n
)
224 const unsigned first_n
= primitive_n
* BUF_1_FLOAT_N
;
225 const unsigned second_n
= primitive_n
* BUF_2_FLOAT_N
;
227 glGetQueryObjectuiv(queries
[0], GL_QUERY_RESULT
, &query_result
);
228 if (query_result
!= primitive_n
) {
229 printf("Expected %u primitives written, got %u\n",
230 primitive_n
, query_result
);
231 piglit_report_result(PIGLIT_FAIL
);
234 glGetQueryObjectuiv(queries
[1], GL_QUERY_RESULT
, &query_result
);
235 if (query_result
!= primitive_n
) {
236 printf("Expected %u primitives generated, got %u\n",
237 primitive_n
, query_result
);
238 piglit_report_result(PIGLIT_FAIL
);
241 first
= malloc(first_n
* sizeof(float));
242 second
= malloc(second_n
* sizeof(float));
244 for (i
= 0; i
< primitive_n
; ++i
) {
245 first
[i
* BUF_1_FLOAT_N
+ 0] = i
+ 1.0; /* x1 */
246 first
[i
* BUF_1_FLOAT_N
+ 1] = i
+ 2.0; /* x2[0] */
247 first
[i
* BUF_1_FLOAT_N
+ 2] = i
+ 3.0; /* x2[1] */
248 first
[i
* BUF_1_FLOAT_N
+ 3] = i
+ 4.0; /* x3[0] */
249 first
[i
* BUF_1_FLOAT_N
+ 4] = i
+ 5.0; /* x3[1] */
250 first
[i
* BUF_1_FLOAT_N
+ 5] = i
+ 6.0; /* x3[2] */
252 second
[i
* BUF_2_FLOAT_N
+ 0] = i
+ 7.0; /* y1 */
253 second
[i
* BUF_2_FLOAT_N
+ 1] = i
+ 8.0; /* y2[0] */
254 second
[i
* BUF_2_FLOAT_N
+ 2] = i
+ 9.0; /* y2[1] */
255 second
[i
* BUF_2_FLOAT_N
+ 3] = i
+ 10.0; /* y2[2] */
256 second
[i
* BUF_2_FLOAT_N
+ 4] = i
+ 11.0; /* y2u3] */
259 pass
= piglit_probe_buffer(xfb
[0], GL_TRANSFORM_FEEDBACK_BUFFER
,
260 "first", 1, first_n
, first
);
261 pass
= piglit_probe_buffer(xfb
[1], GL_TRANSFORM_FEEDBACK_BUFFER
,
262 "second", 1, second_n
, second
) &&
272 parse_args(int argc
, char **argv
, const char **vs_text
)
274 GLint gs_invocation_n
;
277 print_usage_and_exit(argv
[0]);
279 if (strcmp(argv
[1], "vs") == 0) {
280 *vs_text
= vs_two_sets_text
;
284 if (strcmp(argv
[1], "vs_ifc") == 0) {
285 *vs_text
= vs_two_sets_ifc_text
;
289 if (strcmp(argv
[1], "vs_named_ifc") == 0) {
290 *vs_text
= vs_two_sets_named_ifc_text
;
294 if (strcmp(argv
[1], "vs_struct") == 0) {
295 *vs_text
= vs_two_sets_struct_text
;
299 piglit_require_extension("GL_ARB_gpu_shader5");
301 if (strcmp(argv
[1], "gs") == 0)
304 if (strcmp(argv
[1], "gs_max") != 0)
305 print_usage_and_exit(argv
[0]);
307 glGetIntegerv(GL_MAX_GEOMETRY_SHADER_INVOCATIONS
, &gs_invocation_n
);
308 if (gs_invocation_n
<= 0) {
309 printf("Maximum amount of geometry shader invocations "
310 "needs to be positive (%u).\n", gs_invocation_n
);
311 piglit_report_result(PIGLIT_FAIL
);
314 return gs_invocation_n
;
318 piglit_init(int argc
, char **argv
)
321 unsigned primitive_n
, gs_invocation_n
;
327 piglit_require_extension("GL_ARB_transform_feedback3");
328 piglit_require_extension("GL_ARB_enhanced_layouts");
330 gs_invocation_n
= parse_args(argc
, argv
, &vs_text
);
332 /* Zero invocations means the feedback is produced by vertex shader */
333 primitive_n
= gs_invocation_n
? gs_invocation_n
: 1;
335 build_and_use_program(gs_invocation_n
, vs_text
);
337 /* Set up the transform feedback buffers. */
338 glGenBuffers(ARRAY_SIZE(xfb
), xfb
);
339 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER
, 0, xfb
[0]);
340 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER
,
341 primitive_n
* BUF_1_FLOAT_N
* sizeof(float), NULL
,
343 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER
, 2, xfb
[1]);
344 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER
,
345 primitive_n
* BUF_2_FLOAT_N
* sizeof(float), NULL
,
348 /* Test only records using transform feedback. */
349 glEnable(GL_RASTERIZER_DISCARD
);
351 if (!piglit_check_gl_error(GL_NO_ERROR
))
352 piglit_report_result(PIGLIT_FAIL
);
354 glGenQueries(2, queries
);
355 glBeginQuery(GL_PRIMITIVES_GENERATED
, queries
[0]);
356 glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, queries
[1]);
358 /* Test is run under desktop OpenGL 3.2 -> use of VAOs is required */
359 glGenVertexArrays(1, &vao
);
360 glBindVertexArray(vao
);
362 /* Draw and record */
363 glBeginTransformFeedback(GL_POINTS
);
364 glDrawArrays(GL_POINTS
, 0, 1);
365 glEndQuery(GL_PRIMITIVES_GENERATED
);
366 glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
);
367 glEndTransformFeedback();
368 glDeleteVertexArrays(1, &vao
);
370 if (!piglit_check_gl_error(GL_NO_ERROR
))
371 piglit_report_result(PIGLIT_FAIL
);
373 pass
= probe_buffers(xfb
, queries
, primitive_n
);
375 glDeleteBuffers(2, xfb
);
376 glDeleteQueries(2, queries
);
378 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
384 /* Should never be reached */