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
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
30 /* Note: meaningful test cases (with non-zero values) for the following are
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
} },
62 return ARRAY_SIZE(query_types
);
66 get_query_values(const struct query_type_desc
*desc
, bool *exact
, uint32_t *expected
)
71 case GL_ANY_SAMPLES_PASSED
:
72 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE
:
75 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
76 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
80 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
84 case GL_PRIMITIVES_GENERATED
:
85 case GL_PRIMITIVES_SUBMITTED_ARB
:
89 case GL_SAMPLES_PASSED_ARB
:
90 *expected
= piglit_width
* piglit_height
;
97 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
100 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
101 case GL_VERTICES_SUBMITTED_ARB
:
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
:
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
])
124 if (!piglit_is_extension_supported(desc
->extensions
[i
]))
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");
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
);
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
);
165 glQueryCounter(query
, query_type
);
171 static const char vsCode
[] =
175 " gl_Position = pos_in;\n"
178 static const char fsCode
[] =
182 " color = vec4(0.0, 0.0, 1.0, 1.0);\n"
185 prog
= piglit_build_simple_program(vsCode
, fsCode
);