ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / arb_query_buffer_object / common.c
blob5e0705b0f9de5358ebad99bf9db7f2c656fb53cb
1 /*
2 * Copyright © 2015 Glenn Kennard
3 * Copyright (c) 2017 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
26 #include "common.h"
28 static int prog;
30 /* Note: meaningful test cases (with non-zero values) for the following are
31 * missing:
32 * - GL_COMPUTE_SHADER_INVOCATIONS_ARB
33 * - GL_GEOMETRY_SHADER_INVOCATIONS
34 * - GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
35 * - GL_TESS_CONTROL_SHADER_PATCHES_ARB
36 * - GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
37 * - GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
39 const struct query_type_desc query_types[] = {
40 { GL_ANY_SAMPLES_PASSED, { "GL_ARB_occlusion_query2", NULL } },
41 { GL_ANY_SAMPLES_PASSED_CONSERVATIVE, { "GL_ARB_ES3_compatibility", NULL } },
42 { GL_CLIPPING_INPUT_PRIMITIVES_ARB, { "GL_ARB_pipeline_statistics_query", NULL } },
43 { GL_CLIPPING_OUTPUT_PRIMITIVES_ARB, { "GL_ARB_pipeline_statistics_query", NULL } },
44 { GL_COMPUTE_SHADER_INVOCATIONS_ARB, { "GL_ARB_pipeline_statistics_query", "GL_ARB_compute_shader" } },
45 { GL_FRAGMENT_SHADER_INVOCATIONS_ARB, { "GL_ARB_pipeline_statistics_query", NULL } },
46 { GL_GEOMETRY_SHADER_INVOCATIONS, { "GL_ARB_pipeline_statistics_query", NULL } },
47 { GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB, { "GL_ARB_pipeline_statistics_query", NULL } },
48 { GL_PRIMITIVES_GENERATED, { NULL, } },
49 { GL_PRIMITIVES_SUBMITTED_ARB, { "GL_ARB_pipeline_statistics_query", NULL } },
50 { GL_SAMPLES_PASSED_ARB, { NULL, } },
51 { GL_TESS_CONTROL_SHADER_PATCHES_ARB, { "GL_ARB_pipeline_statistics_query", "GL_ARB_tessellation_shader" } },
52 { GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB, { "GL_ARB_pipeline_statistics_query", "GL_ARB_tessellation_shader" } },
53 { GL_TIMESTAMP, { "GL_ARB_timer_query", NULL } },
54 { GL_TIME_ELAPSED, { "GL_ARB_timer_query", NULL } },
55 { GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, { NULL, } },
56 { GL_VERTEX_SHADER_INVOCATIONS_ARB, { "GL_ARB_pipeline_statistics_query", NULL } },
57 { GL_VERTICES_SUBMITTED_ARB, { "GL_ARB_pipeline_statistics_query", NULL } },
60 unsigned
61 num_query_types() {
62 return ARRAY_SIZE(query_types);
65 void
66 get_query_values(const struct query_type_desc *desc, bool *exact, uint32_t *expected)
68 *exact = true;
70 switch (desc->type) {
71 case GL_ANY_SAMPLES_PASSED:
72 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
73 *expected = 1;
74 break;
75 case GL_CLIPPING_INPUT_PRIMITIVES_ARB:
76 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB:
77 *exact = false;
78 *expected = 1;
79 break;
80 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB:
81 *exact = false;
82 *expected = 1;
83 break;
84 case GL_PRIMITIVES_GENERATED:
85 case GL_PRIMITIVES_SUBMITTED_ARB:
86 *exact = false;
87 *expected = 1;
88 break;
89 case GL_SAMPLES_PASSED_ARB:
90 *expected = piglit_width * piglit_height;
91 break;
92 case GL_TIMESTAMP:
93 case GL_TIME_ELAPSED:
94 *exact = false;
95 *expected = 1;
96 break;
97 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
98 *expected = 0;
99 break;
100 case GL_VERTEX_SHADER_INVOCATIONS_ARB:
101 case GL_VERTICES_SUBMITTED_ARB:
102 *exact = false;
103 *expected = 1;
104 break;
105 case GL_COMPUTE_SHADER_INVOCATIONS_ARB:
106 case GL_GEOMETRY_SHADER_INVOCATIONS:
107 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB:
108 case GL_TESS_CONTROL_SHADER_PATCHES_ARB:
109 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB:
110 *expected = 0;
111 break;
112 default:
113 abort();
117 bool
118 is_query_supported(const struct query_type_desc *desc)
120 for (unsigned i = 0; i < ARRAY_SIZE(desc->extensions); ++i) {
121 if (!desc->extensions[i])
122 break;
124 if (!piglit_is_extension_supported(desc->extensions[i]))
125 return false;
128 return true;
131 bool
132 is_gs_valid(const struct query_type_desc *desc, uint32_t expected, uint64_t cpu_result)
134 switch (desc->type) {
135 case GL_GEOMETRY_SHADER_INVOCATIONS:
136 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB:
137 if (!expected && cpu_result) {
138 fprintf(stderr, "WARNING: GEOMETRY_SHADER statistics query returned nonzero when no GS bound\n");
139 return true;
141 return false;
142 default:
143 break;
145 return true;
148 void
149 run_query(unsigned query, const struct query_type_desc *desc)
151 GLenum query_type = desc->type;
153 glClearColor(0.5, 0.5, 0.5, 1.0);
154 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
156 /* Enable query, draw something that should pass */
157 glEnable(GL_DEPTH_TEST);
158 glUseProgram(prog);
159 if (query_type != GL_TIMESTAMP)
160 glBeginQuery(query_type, query);
161 piglit_draw_rect_z(0.5, -1, -1, 2, 2);
162 if (query_type != GL_TIMESTAMP)
163 glEndQuery(query_type);
164 else
165 glQueryCounter(query, query_type);
168 void
169 query_common_init()
171 static const char vsCode[] =
172 "#version 150\n"
173 "in vec4 pos_in;\n"
174 "void main() {\n"
175 " gl_Position = pos_in;\n"
176 "}\n";
178 static const char fsCode[] =
179 "#version 150\n"
180 "out vec4 color;\n"
181 "void main() {\n"
182 " color = vec4(0.0, 0.0, 1.0, 1.0);\n"
183 "}\n";
185 prog = piglit_build_simple_program(vsCode, fsCode);