1 #ifndef _ESEXTCGPUSHADER5SSBOARRAYINDEXING_HPP
2 #define _ESEXTCGPUSHADER5SSBOARRAYINDEXING_HPP
3 /*-------------------------------------------------------------------------
4  * OpenGL Conformance Test Suite
5  * -----------------------------
6  *
7  * Copyright (c) 2014-2016 The Khronos Group Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */ /*!
22  * \file
23  * \brief
24  */ /*-------------------------------------------------------------------*/
25 
26 /*!
27  * \file esextcGPUShader5SSBOArrayIndexing.hpp
28  * \brief GPUShader5 SSBO Array Indexing (Test 5)
29  */ /*-------------------------------------------------------------------*/
30 
31 #include "../esextcTestCaseBase.hpp"
32 
33 namespace glcts
34 {
35 /**  Implementation of Test 5 from CTS_EXT_gpu_shader5. Description follows
36  *
37  *   Test whether indexing into an array of SSBOs using dynamically uniform
38  *   integer expressions works as expected.
39  *
40  *   Category:   API,
41  *               Functional Test,
42  *
43  *   Write a compute shader with an array of four SSBOs.
44  *   The work group size should be 3x3
45  *
46  *   shared Buffer ComputeSSBO {
47  *       uint value;
48  *   } computeSSBO[4];
49  *
50  *   Initialize a set of buffer objects to be assigned as SSBO data sources.
51  *   Set the buffer objects' data to zeros.
52  *
53  *   Add a uniform variable:
54  *
55  *   uniform uint index;
56  *
57  *   In the compute shader perform operations:
58  *
59  *   uint id = gl_LocalInvocationID.x * local_size_y + gl_LocalInvocationID.y;
60  *
61  *   for(uint i = 0; i < local_size_x * local_size_y; ++i)
62  *   {
63  *       if(id == i)
64  *       {
65  *           computeSSBO[index].value += id;
66  *       }
67  *       memoryBarrier();
68  *   }
69  *
70  *   Create a program from the above compute shader and use it.
71  *
72  *   Execute:
73  *
74  *   glUniform1ui( indexLocation, 1);
75  *   glDispatchCompute(1, 1, 1);
76  *   glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
77  *
78  *   glUniform1ui( indexLocation, 3);
79  *   glDispatchCompute(1, 1, 1);
80  *   glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
81  *
82  *   Map the buffer object's data storage to program memory using glMapBuffer
83  *   for all four buffer objects.
84  *
85  *   The test is successful if the values read from mapped buffers
86  *   corresponding to computeSSBO[1].value and computeSSBO[3].value and equal
87  *   to 36 and the values corresponding to computeSSBO[0].value and
88  *   computeSSBO[2].value are equal to 0.
89  */
90 class GPUShader5SSBOArrayIndexing : public TestCaseBase
91 {
92 public:
93     /* Public functions */
94     GPUShader5SSBOArrayIndexing(Context &context, const ExtParameters &extParams, const char *name,
95                                 const char *description);
96 
~GPUShader5SSBOArrayIndexing()97     virtual ~GPUShader5SSBOArrayIndexing()
98     {
99     }
100 
101     virtual IterateResult iterate(void);
102     virtual void deinit(void);
103 
104 private:
105     /* Private variables */
106     static const char *m_compute_shader_code;
107     static const glw::GLuint m_n_arrays;
108 
109     glw::GLuint m_compute_shader_id;
110     glw::GLuint m_program_id;
111     glw::GLuint *m_ssbo_buffer_ids;
112 
113     /* Private functions */
114     void initTest(void);
115 };
116 
117 } // namespace glcts
118 
119 #endif // _ESEXTCGPUSHADER5SSBOARRAYINDEXING_HPP
120