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_two_buff_text
[] =
35 "#extension GL_ARB_enhanced_layouts: require\n"
37 "layout(xfb_buffer = 1) out;\n"
38 "layout(xfb_offset = 0) out float x1_out;\n"
39 "layout(xfb_offset = 4) out float x2_out[2];\n"
40 "layout(xfb_offset = 12) out vec3 x3_out;\n"
41 "layout(xfb_buffer = 3) out;\n"
42 "layout(xfb_offset = 0, xfb_buffer = 3) out float y1_out;\n"
43 "layout(xfb_offset = 4) out vec4 y2_out;\n"
45 " gl_Position = vec4(0.0);\n"
49 " x3_out = vec3(4.0, 5.0, 6.0);\n"
51 " y2_out = vec4(8.0, 9.0, 10.0, 11.0);\n"
54 static const char *varying_names
[2][3] = {
55 {"x1_out", "x2_out", "x3_out"},
56 {"y1_out", "y2_out", ""} };
60 build_and_use_program(const char *vs_text
)
62 GLuint prog
= piglit_build_simple_program_multiple_shaders(
63 GL_VERTEX_SHADER
, vs_text
, 0);
66 if (!piglit_link_check_status(prog
))
67 piglit_report_result(PIGLIT_FAIL
);
68 if (!piglit_check_gl_error(GL_NO_ERROR
))
69 piglit_report_result(PIGLIT_FAIL
);
77 check_varyings_match(GLuint prog
, GLint
*values
, unsigned num_values
,
82 for (unsigned i
= 0; i
< num_values
; i
++) {
84 glGetProgramResourceName(prog
, GL_TRANSFORM_FEEDBACK_VARYING
,
85 values
[i
], 10, NULL
, name
);
87 bool match_found
= false;
88 for (unsigned i
= 0; i
< num_values
; i
++) {
89 if (strcmp(name
, varying_names
[buffer
][i
]) == 0) {
96 printf("ACTIVE_VARIABLES did no return an index for "
97 "%s\n", varying_names
[buffer
][i
]);
106 piglit_init(int argc
, char **argv
)
109 bool active_res
= true;
110 bool max_active
= true;
111 bool buff_bind
[2] = { true, true };
112 bool num_active
[2] = { false, false };
113 bool varying_idx
[2] = { false, false };
116 piglit_require_extension("GL_ARB_transform_feedback3");
117 piglit_require_extension("GL_ARB_enhanced_layouts");
119 prog
= build_and_use_program(vs_two_buff_text
);
123 glGetProgramInterfaceiv(prog
, GL_TRANSFORM_FEEDBACK_BUFFER
,
124 GL_ACTIVE_RESOURCES
, &value
);
126 printf("Expected 2 ACTIVE_RESOURCES found %d\n", value
);
130 piglit_report_subtest_result(active_res
? PIGLIT_PASS
: PIGLIT_FAIL
,
131 "Query ACTIVE_RESOURCES");
133 glGetProgramInterfaceiv(prog
, GL_TRANSFORM_FEEDBACK_BUFFER
,
134 GL_MAX_NUM_ACTIVE_VARIABLES
, &value
);
136 printf("Expected MAX_NUM_ACTIVE_VARIABLES to be 3 found %d\n",
141 piglit_report_subtest_result(max_active
? PIGLIT_PASS
: PIGLIT_FAIL
,
142 "Query MAX_NUM_ACTIVE_VARIABLES");
144 GLenum props
[] = {GL_BUFFER_BINDING
, GL_NUM_ACTIVE_VARIABLES
,
145 GL_ACTIVE_VARIABLES
};
146 for (unsigned i
= 0; i
< 2; i
++) {
147 glGetProgramResourceiv(prog
, GL_TRANSFORM_FEEDBACK_BUFFER
, i
,
148 3, props
, 5, NULL
, values
);
150 if (values
[0] != 1 && values
[0] != 3)
151 buff_bind
[i
] = false;
152 if (values
[0] == 1) {
154 num_active
[i
] = true;
156 printf("Expected 3 NUM_ACTIVE_VARIABLES "
157 "found %d\n", values
[1]);
161 check_varyings_match(prog
, &values
[2], 3, 0);
162 } else if (values
[0] == 3) {
163 if (values
[1] == 2) {
164 num_active
[i
] = true;
166 printf("Expected 2 NUM_ACTIVE_VARIABLES "
167 "found %d\n", values
[1]);
171 check_varyings_match(prog
, &values
[2], 2, 1);
175 piglit_report_subtest_result(buff_bind
[0] && buff_bind
[1] ?
176 PIGLIT_PASS
: PIGLIT_FAIL
,
177 "Query BUFFER_BINDING");
179 piglit_report_subtest_result(num_active
[0] && num_active
[1] ?
180 PIGLIT_PASS
: PIGLIT_FAIL
,
181 "Query NUM_ACTIVE_VARIABLES");
183 piglit_report_subtest_result(varying_idx
[0] && varying_idx
[1] ?
184 PIGLIT_PASS
: PIGLIT_FAIL
,
185 "Query ACTIVE_VARIABLES");
187 if (!piglit_check_gl_error(GL_NO_ERROR
))
188 piglit_report_result(PIGLIT_FAIL
);
190 pass
= active_res
&& max_active
&& buff_bind
[0] && buff_bind
[1] &&
191 num_active
[0] && num_active
[1] && varying_idx
[0] &&
194 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
200 /* Should never be reached */