xref: /aosp_15_r20/external/deqp/external/openglcts/modules/gl/gl3cCullDistanceTests.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _GL3CCULLDISTANCETESTS_HPP
2*35238bceSAndroid Build Coastguard Worker #define _GL3CCULLDISTANCETESTS_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * OpenGL Conformance Test Suite
5*35238bceSAndroid Build Coastguard Worker  * -----------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright (c) 2015-2016 The Khronos Group Inc.
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  */ /*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief
24*35238bceSAndroid Build Coastguard Worker  */ /*-------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker /**
27*35238bceSAndroid Build Coastguard Worker  */ /*!
28*35238bceSAndroid Build Coastguard Worker  * \file  gl3cCullDistanceTests.hpp
29*35238bceSAndroid Build Coastguard Worker  * \brief  Cull Distance Test Suite Interface
30*35238bceSAndroid Build Coastguard Worker  */ /*-------------------------------------------------------------------*/
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker #include "glcTestCase.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "glwDefs.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuDefs.hpp"
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker namespace glcts
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker namespace CullDistance
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker /** @brief Cull Distance Test utility class
41*35238bceSAndroid Build Coastguard Worker  *
42*35238bceSAndroid Build Coastguard Worker  *  This class contains utility static function members
43*35238bceSAndroid Build Coastguard Worker  *  helpful to OpenGL shader template based construction
44*35238bceSAndroid Build Coastguard Worker  *  and building process.
45*35238bceSAndroid Build Coastguard Worker  */
46*35238bceSAndroid Build Coastguard Worker class Utilities
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker public:
49*35238bceSAndroid Build Coastguard Worker     /* Public static methods */
50*35238bceSAndroid Build Coastguard Worker     static void buildProgram(const glw::Functions &gl, tcu::TestContext &testCtx, const glw::GLchar *cs_body,
51*35238bceSAndroid Build Coastguard Worker                              const glw::GLchar *fs_body, const glw::GLchar *gs_body, const glw::GLchar *tc_body,
52*35238bceSAndroid Build Coastguard Worker                              const glw::GLchar *te_body, const glw::GLchar *vs_body, const glw::GLuint &n_tf_varyings,
53*35238bceSAndroid Build Coastguard Worker                              const glw::GLchar **tf_varyings, glw::GLuint *out_program);
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker     static void replaceAll(std::string &str, const std::string &from, const std::string &to);
56*35238bceSAndroid Build Coastguard Worker 
57*35238bceSAndroid Build Coastguard Worker     static std::string intToString(glw::GLint integer);
58*35238bceSAndroid Build Coastguard Worker };
59*35238bceSAndroid Build Coastguard Worker 
60*35238bceSAndroid Build Coastguard Worker /** @brief Cull Distance API Coverage Test class
61*35238bceSAndroid Build Coastguard Worker  *
62*35238bceSAndroid Build Coastguard Worker  *  This class contains basic API coverage test,
63*35238bceSAndroid Build Coastguard Worker  *  which check if the implementation provides
64*35238bceSAndroid Build Coastguard Worker  *  basic cull distance structures:
65*35238bceSAndroid Build Coastguard Worker  *
66*35238bceSAndroid Build Coastguard Worker  *   * Checks that calling GetIntegerv with MAX_CULL_DISTANCES doesn't generate
67*35238bceSAndroid Build Coastguard Worker  *    any errors and returns a value at least 8.
68*35238bceSAndroid Build Coastguard Worker  *
69*35238bceSAndroid Build Coastguard Worker  *   * Checks that calling GetIntegerv with MAX_COMBINED_CLIP_AND_CULL_DISTANCES
70*35238bceSAndroid Build Coastguard Worker  *     doesn't generate any errors and returns a value at least 8.
71*35238bceSAndroid Build Coastguard Worker  *
72*35238bceSAndroid Build Coastguard Worker  *   * Checks that using the GLSL built-in constant gl_MaxCullDistance in any
73*35238bceSAndroid Build Coastguard Worker  *     shader stage (including compute shader) compiles and links successfully
74*35238bceSAndroid Build Coastguard Worker  *     and that the value of the built-in constant is at least 8.
75*35238bceSAndroid Build Coastguard Worker  *
76*35238bceSAndroid Build Coastguard Worker  *   * Checks that using the GLSL built-in constant gl_MaxCombinedClipAndCull-
77*35238bceSAndroid Build Coastguard Worker  *     Distances in any shader stage (including compute shader) compiles and
78*35238bceSAndroid Build Coastguard Worker  *     links successfully and that the value of the built-in constant is at
79*35238bceSAndroid Build Coastguard Worker  *     least 8.
80*35238bceSAndroid Build Coastguard Worker  */
81*35238bceSAndroid Build Coastguard Worker class APICoverageTest : public deqp::TestCase
82*35238bceSAndroid Build Coastguard Worker {
83*35238bceSAndroid Build Coastguard Worker public:
84*35238bceSAndroid Build Coastguard Worker     /* Public methods */
85*35238bceSAndroid Build Coastguard Worker     APICoverageTest(deqp::Context &context);
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker protected:
88*35238bceSAndroid Build Coastguard Worker     /* Protected methods */
89*35238bceSAndroid Build Coastguard Worker     void deinit();
90*35238bceSAndroid Build Coastguard Worker     tcu::TestNode::IterateResult iterate();
91*35238bceSAndroid Build Coastguard Worker 
92*35238bceSAndroid Build Coastguard Worker private:
93*35238bceSAndroid Build Coastguard Worker     /* Private fields */
94*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_bo_id;
95*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_cs_id;
96*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_cs_to_id;
97*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_fbo_draw_id;
98*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_fbo_draw_to_id;
99*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_fbo_read_id;
100*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_fs_id;
101*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_gs_id;
102*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_po_id;
103*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_tc_id;
104*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_te_id;
105*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vao_id;
106*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vs_id;
107*35238bceSAndroid Build Coastguard Worker };
108*35238bceSAndroid Build Coastguard Worker 
109*35238bceSAndroid Build Coastguard Worker /** @brief Cull Distance Functional Test class
110*35238bceSAndroid Build Coastguard Worker  *
111*35238bceSAndroid Build Coastguard Worker  *  This class contains functional test cases,
112*35238bceSAndroid Build Coastguard Worker  *  which check if the implementation works
113*35238bceSAndroid Build Coastguard Worker  *  in specified way. For each functional test:
114*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline to test the basic functionality of cull distances.
115*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but don't redeclare gl_ClipDistance with a size.
116*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but don't redeclare gl_CullDistance with a size.
117*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but don't redeclare either gl_ClipDistance or
118*35238bceSAndroid Build Coastguard Worker  *      gl_CullDistance with a size.
119*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but use dynamic indexing when writing the elements
120*35238bceSAndroid Build Coastguard Worker  *      of the gl_ClipDistance and gl_CullDistance arrays.
121*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but add a geometry shader to the program that
122*35238bceSAndroid Build Coastguard Worker  *      simply passes through all written clip and cull distances.
123*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but add a tessellation control and tessellation
124*35238bceSAndroid Build Coastguard Worker  *      evaluation shader to the program which simply pass through all written
125*35238bceSAndroid Build Coastguard Worker  *      clip and cull distances.
126*35238bceSAndroid Build Coastguard Worker  *    * Test that using #extension with GL_ARB_cull_distance allows using the
127*35238bceSAndroid Build Coastguard Worker  *      feature even with an earlier version of GLSL. Also test that the
128*35238bceSAndroid Build Coastguard Worker  *      extension name is available as preprocessor #define.
129*35238bceSAndroid Build Coastguard Worker  *  a basic outline is used to check the implementation:
130*35238bceSAndroid Build Coastguard Worker  *    * Enable disjunct cull distances using Enable with CLIP_DISTANCE<i>.
131*35238bceSAndroid Build Coastguard Worker  *    * Use a program that has only a vertex shader and a fragment shader.
132*35238bceSAndroid Build Coastguard Worker  *      The vertex shader should redeclare gl_ClipDistance with a size that
133*35238bceSAndroid Build Coastguard Worker  *      fits all enabled cull distances. Also redeclare gl_CullDistance with a
134*35238bceSAndroid Build Coastguard Worker  *      size. The sum of the two sizes should not be more than MAX_COMBINED_-
135*35238bceSAndroid Build Coastguard Worker  *      CLIP_AND_CULL_DISTANCES. The fragment shader should output the cull
136*35238bceSAndroid Build Coastguard Worker  *      distances written by the vertex shader by reading them from the built-in
137*35238bceSAndroid Build Coastguard Worker  *      array gl_CullDistance.
138*35238bceSAndroid Build Coastguard Worker  *    * Write different positive and negative values for all the enabled clip
139*35238bceSAndroid Build Coastguard Worker  *      distances to gl_ClipDistance in the vertex shader. Also write different
140*35238bceSAndroid Build Coastguard Worker  *      positive and negative values for all the elements of gl_CullDistance.
141*35238bceSAndroid Build Coastguard Worker  *      Use constant indices when writing to gl_ClipDistance and gl_CullDistance.
142*35238bceSAndroid Build Coastguard Worker  *    * Render point, line and triangle primitives. Expect primitives that for
143*35238bceSAndroid Build Coastguard Worker  *      a given index <i> all of their vertices have a negative value set for
144*35238bceSAndroid Build Coastguard Worker  *      gl_CullDistance[i] to be discarded. Otherwise, they should be clipped
145*35238bceSAndroid Build Coastguard Worker  *      according to the enabled clip distances as without this extension.
146*35238bceSAndroid Build Coastguard Worker  *      Check the output image to make sure that the color output for each
147*35238bceSAndroid Build Coastguard Worker  *      fragment matches the expected interpolated values of the written cull
148*35238bceSAndroid Build Coastguard Worker  *      distances.
149*35238bceSAndroid Build Coastguard Worker  * */
150*35238bceSAndroid Build Coastguard Worker class FunctionalTest : public deqp::TestCase
151*35238bceSAndroid Build Coastguard Worker {
152*35238bceSAndroid Build Coastguard Worker public:
153*35238bceSAndroid Build Coastguard Worker     /* Public methods */
154*35238bceSAndroid Build Coastguard Worker     FunctionalTest(deqp::Context &context);
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker protected:
157*35238bceSAndroid Build Coastguard Worker     /* Protected methods */
158*35238bceSAndroid Build Coastguard Worker     void deinit();
159*35238bceSAndroid Build Coastguard Worker     tcu::TestNode::IterateResult iterate();
160*35238bceSAndroid Build Coastguard Worker 
161*35238bceSAndroid Build Coastguard Worker private:
162*35238bceSAndroid Build Coastguard Worker     /* Private type definitions */
163*35238bceSAndroid Build Coastguard Worker     enum _primitive_mode
164*35238bceSAndroid Build Coastguard Worker     {
165*35238bceSAndroid Build Coastguard Worker         PRIMITIVE_MODE_LINES,
166*35238bceSAndroid Build Coastguard Worker         PRIMITIVE_MODE_POINTS,
167*35238bceSAndroid Build Coastguard Worker         PRIMITIVE_MODE_TRIANGLES,
168*35238bceSAndroid Build Coastguard Worker 
169*35238bceSAndroid Build Coastguard Worker         PRIMITIVE_MODE_COUNT
170*35238bceSAndroid Build Coastguard Worker     };
171*35238bceSAndroid Build Coastguard Worker 
172*35238bceSAndroid Build Coastguard Worker     /* Private methods */
173*35238bceSAndroid Build Coastguard Worker     void buildPO(glw::GLuint clipdistances_array_size, glw::GLuint culldistances_array_size, bool dynamic_index_writes,
174*35238bceSAndroid Build Coastguard Worker                  _primitive_mode primitive_mode, bool redeclare_clipdistances, bool redeclare_culldistances,
175*35238bceSAndroid Build Coastguard Worker                  bool use_core_functionality, bool use_gs, bool use_ts, bool fetch_culldistance_from_fs);
176*35238bceSAndroid Build Coastguard Worker 
177*35238bceSAndroid Build Coastguard Worker     void configureVAO(glw::GLuint clipdistances_array_size, glw::GLuint culldistances_array_size,
178*35238bceSAndroid Build Coastguard Worker                       _primitive_mode primitive_mode);
179*35238bceSAndroid Build Coastguard Worker 
180*35238bceSAndroid Build Coastguard Worker     void deinitPO();
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker     void executeRenderTest(glw::GLuint clipdistances_array_size, glw::GLuint culldistances_array_size,
183*35238bceSAndroid Build Coastguard Worker                            _primitive_mode primitive_mode, bool use_tesselation, bool fetch_culldistance_from_fs);
184*35238bceSAndroid Build Coastguard Worker 
185*35238bceSAndroid Build Coastguard Worker     glw::GLint readRedPixelValue(glw::GLint x, glw::GLint y);
186*35238bceSAndroid Build Coastguard Worker 
187*35238bceSAndroid Build Coastguard Worker     void readTexturePixels();
188*35238bceSAndroid Build Coastguard Worker 
189*35238bceSAndroid Build Coastguard Worker     /* Private fields */
190*35238bceSAndroid Build Coastguard Worker     std::vector<glw::GLfloat> m_bo_data;
191*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_bo_id;
192*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_fbo_id;
193*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_po_id;
194*35238bceSAndroid Build Coastguard Worker     glw::GLsizei m_render_primitives;
195*35238bceSAndroid Build Coastguard Worker     glw::GLsizei m_render_vertices;
196*35238bceSAndroid Build Coastguard Worker     glw::GLint m_sub_grid_cell_size;
197*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_to_id;
198*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vao_id;
199*35238bceSAndroid Build Coastguard Worker 
200*35238bceSAndroid Build Coastguard Worker     const glw::GLuint m_to_height;
201*35238bceSAndroid Build Coastguard Worker     const glw::GLuint m_to_width;
202*35238bceSAndroid Build Coastguard Worker     static const glw::GLuint m_to_pixel_data_cache_color_components = 4;
203*35238bceSAndroid Build Coastguard Worker     std::vector<glw::GLushort> m_to_pixel_data_cache;
204*35238bceSAndroid Build Coastguard Worker };
205*35238bceSAndroid Build Coastguard Worker 
206*35238bceSAndroid Build Coastguard Worker /** @brief Cull Distance Negative Test class
207*35238bceSAndroid Build Coastguard Worker  *
208*35238bceSAndroid Build Coastguard Worker  *  This class contains negative test cases,
209*35238bceSAndroid Build Coastguard Worker  *  which check if the implementation returns
210*35238bceSAndroid Build Coastguard Worker  *  properly in case of unsupport state
211*35238bceSAndroid Build Coastguard Worker  *  configuration. Following cases are checked:
212*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but redeclare gl_ClipDistance and gl_CullDistance
213*35238bceSAndroid Build Coastguard Worker  *      with sizes whose sum is more than MAX_COMBINED_CLIP_AND_CULL_DISTANCES.
214*35238bceSAndroid Build Coastguard Worker  *      Expect a compile-time or link-time error.
215*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but don't redeclare gl_ClipDistance and/or
216*35238bceSAndroid Build Coastguard Worker  *      gl_CullDistance with a size and statically write values to such elements
217*35238bceSAndroid Build Coastguard Worker  *      of gl_ClipDistance and gl_CullDistance that the sum of these element
218*35238bceSAndroid Build Coastguard Worker  *      indices is greater than MAX_COMBINED_CLIP_AND_CULL_DISTANCES minus two
219*35238bceSAndroid Build Coastguard Worker  *      (the "minus two" part is needed because the indices are zero-based).
220*35238bceSAndroid Build Coastguard Worker  *      Expect a compile-time or link-time error.
221*35238bceSAndroid Build Coastguard Worker  *    * Use the basic outline but don't redeclare gl_ClipDistance and/or
222*35238bceSAndroid Build Coastguard Worker  *      gl_CullDistance with a size and use dynamic indexing when writing their
223*35238bceSAndroid Build Coastguard Worker  *      elements. Expect a compile-time or link-time error.
224*35238bceSAndroid Build Coastguard Worker  */
225*35238bceSAndroid Build Coastguard Worker class NegativeTest : public deqp::TestCase
226*35238bceSAndroid Build Coastguard Worker {
227*35238bceSAndroid Build Coastguard Worker public:
228*35238bceSAndroid Build Coastguard Worker     /* Public methods */
229*35238bceSAndroid Build Coastguard Worker     NegativeTest(deqp::Context &context);
230*35238bceSAndroid Build Coastguard Worker 
231*35238bceSAndroid Build Coastguard Worker protected:
232*35238bceSAndroid Build Coastguard Worker     /* Protected methods */
233*35238bceSAndroid Build Coastguard Worker     void deinit();
234*35238bceSAndroid Build Coastguard Worker     tcu::TestNode::IterateResult iterate();
235*35238bceSAndroid Build Coastguard Worker 
236*35238bceSAndroid Build Coastguard Worker private:
237*35238bceSAndroid Build Coastguard Worker     /* Private methods */
238*35238bceSAndroid Build Coastguard Worker     std::string getTestDescription(glw::GLint n_test_iteration, bool should_redeclare_output_variables,
239*35238bceSAndroid Build Coastguard Worker                                    bool use_dynamic_index_based_writes);
240*35238bceSAndroid Build Coastguard Worker 
241*35238bceSAndroid Build Coastguard Worker     /* Private fields */
242*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_fs_id;
243*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_po_id;
244*35238bceSAndroid Build Coastguard Worker     glw::GLchar *m_temp_buffer;
245*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vs_id;
246*35238bceSAndroid Build Coastguard Worker };
247*35238bceSAndroid Build Coastguard Worker 
248*35238bceSAndroid Build Coastguard Worker /** @brief Grouping class for Cull Distance Tests */
249*35238bceSAndroid Build Coastguard Worker class Tests : public deqp::TestCaseGroup
250*35238bceSAndroid Build Coastguard Worker {
251*35238bceSAndroid Build Coastguard Worker public:
252*35238bceSAndroid Build Coastguard Worker     /* Public methods */
253*35238bceSAndroid Build Coastguard Worker     Tests(deqp::Context &context);
254*35238bceSAndroid Build Coastguard Worker 
255*35238bceSAndroid Build Coastguard Worker     void init(void);
256*35238bceSAndroid Build Coastguard Worker 
257*35238bceSAndroid Build Coastguard Worker private:
258*35238bceSAndroid Build Coastguard Worker     Tests(const CullDistance::Tests &other);
259*35238bceSAndroid Build Coastguard Worker     Tests &operator=(const CullDistance::Tests &other);
260*35238bceSAndroid Build Coastguard Worker };
261*35238bceSAndroid Build Coastguard Worker } // namespace CullDistance
262*35238bceSAndroid Build Coastguard Worker /* CullDistance namespace */
263*35238bceSAndroid Build Coastguard Worker } // namespace glcts
264*35238bceSAndroid Build Coastguard Worker 
265*35238bceSAndroid Build Coastguard Worker #endif // _GL3CCULLDISTANCETESTS_HPP
266