ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_query_buffer_object / common.c
blobcd6bd478739ad6dc5781be96f3b5ad8817658ca0
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 void
132 run_query(unsigned query, const struct query_type_desc *desc)
134 GLenum query_type = desc->type;
136 glClearColor(0.5, 0.5, 0.5, 1.0);
137 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
139 /* Enable query, draw something that should pass */
140 glEnable(GL_DEPTH_TEST);
141 glUseProgram(prog);
142 if (query_type != GL_TIMESTAMP)
143 glBeginQuery(query_type, query);
144 piglit_draw_rect_z(0.5, -1, -1, 2, 2);
145 if (query_type != GL_TIMESTAMP)
146 glEndQuery(query_type);
147 else
148 glQueryCounter(query, query_type);
151 void
152 query_common_init()
154 static const char vsCode[] =
155 "#version 150\n"
156 "in vec4 pos_in;\n"
157 "void main() {\n"
158 " gl_Position = pos_in;\n"
159 "}\n";
161 static const char fsCode[] =
162 "#version 150\n"
163 "out vec4 color;\n"
164 "void main() {\n"
165 " color = vec4(0.0, 0.0, 1.0, 1.0);\n"
166 "}\n";
168 prog = piglit_build_simple_program(vsCode, fsCode);