xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fSSBOLayoutCase.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _ES31FSSBOLAYOUTCASE_HPP
2 #define _ES31FSSBOLAYOUTCASE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES 3.1 Module
5  * -------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
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 SSBO layout tests.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 #include "gluShaderUtil.hpp"
29 #include "gluVarType.hpp"
30 
31 namespace glu
32 {
33 class RenderContext;
34 }
35 
36 namespace deqp
37 {
38 namespace gles31
39 {
40 
41 // Buffer block details.
42 namespace bb
43 {
44 
45 enum BufferVarFlags
46 {
47     LAYOUT_SHARED       = (1 << 0),
48     LAYOUT_PACKED       = (1 << 1),
49     LAYOUT_STD140       = (1 << 2),
50     LAYOUT_STD430       = (1 << 3),
51     LAYOUT_ROW_MAJOR    = (1 << 4),
52     LAYOUT_COLUMN_MAJOR = (1 << 5), //!< \note Lack of both flags means column-major matrix.
53     LAYOUT_MASK =
54         LAYOUT_SHARED | LAYOUT_PACKED | LAYOUT_STD140 | LAYOUT_STD430 | LAYOUT_ROW_MAJOR | LAYOUT_COLUMN_MAJOR,
55 
56     // \todo [2013-10-14 pyry] Investigate adding these.
57     /*    QUALIFIER_COHERENT = (1<<6),
58         QUALIFIER_VOLATILE = (1<<7),
59         QUALIFIER_RESTRICT = (1<<8),
60         QUALIFIER_READONLY = (1<<9),
61         QUALIFIER_WRITEONLY = (1<<10),*/
62 
63     ACCESS_READ  = (1 << 11), //!< Buffer variable is read in the shader.
64     ACCESS_WRITE = (1 << 12), //!< Buffer variable is written in the shader.
65 };
66 
67 class BufferVar
68 {
69 public:
70     BufferVar(const char *name, const glu::VarType &type, uint32_t flags);
71 
getName(void) const72     const char *getName(void) const
73     {
74         return m_name.c_str();
75     }
getType(void) const76     const glu::VarType &getType(void) const
77     {
78         return m_type;
79     }
getFlags(void) const80     uint32_t getFlags(void) const
81     {
82         return m_flags;
83     }
84 
85 private:
86     std::string m_name;
87     glu::VarType m_type;
88     uint32_t m_flags;
89 };
90 
91 class BufferBlock
92 {
93 public:
94     typedef std::vector<BufferVar>::iterator iterator;
95     typedef std::vector<BufferVar>::const_iterator const_iterator;
96 
97     BufferBlock(const char *blockName);
98 
getBlockName(void) const99     const char *getBlockName(void) const
100     {
101         return m_blockName.c_str();
102     }
getInstanceName(void) const103     const char *getInstanceName(void) const
104     {
105         return m_instanceName.empty() ? DE_NULL : m_instanceName.c_str();
106     }
isArray(void) const107     bool isArray(void) const
108     {
109         return m_arraySize > 0;
110     }
getArraySize(void) const111     int getArraySize(void) const
112     {
113         return m_arraySize;
114     }
getFlags(void) const115     uint32_t getFlags(void) const
116     {
117         return m_flags;
118     }
119 
setInstanceName(const char * name)120     void setInstanceName(const char *name)
121     {
122         m_instanceName = name;
123     }
setFlags(uint32_t flags)124     void setFlags(uint32_t flags)
125     {
126         m_flags = flags;
127     }
addMember(const BufferVar & var)128     void addMember(const BufferVar &var)
129     {
130         m_variables.push_back(var);
131     }
132     void setArraySize(int arraySize);
133 
getLastUnsizedArraySize(int instanceNdx) const134     int getLastUnsizedArraySize(int instanceNdx) const
135     {
136         return m_lastUnsizedArraySizes[instanceNdx];
137     }
setLastUnsizedArraySize(int instanceNdx,int size)138     void setLastUnsizedArraySize(int instanceNdx, int size)
139     {
140         m_lastUnsizedArraySizes[instanceNdx] = size;
141     }
142 
begin(void)143     inline iterator begin(void)
144     {
145         return m_variables.begin();
146     }
begin(void) const147     inline const_iterator begin(void) const
148     {
149         return m_variables.begin();
150     }
end(void)151     inline iterator end(void)
152     {
153         return m_variables.end();
154     }
end(void) const155     inline const_iterator end(void) const
156     {
157         return m_variables.end();
158     }
159 
160 private:
161     std::string m_blockName;
162     std::string m_instanceName;
163     std::vector<BufferVar> m_variables;
164     int m_arraySize;                          //!< Array size or 0 if not interface block array.
165     std::vector<int> m_lastUnsizedArraySizes; //!< Sizes of last unsized array element, can be different per instance.
166     uint32_t m_flags;
167 };
168 
169 class ShaderInterface
170 {
171 public:
172     ShaderInterface(void);
173     ~ShaderInterface(void);
174 
175     glu::StructType &allocStruct(const char *name);
176     const glu::StructType *findStruct(const char *name) const;
177     void getNamedStructs(std::vector<const glu::StructType *> &structs) const;
178 
179     BufferBlock &allocBlock(const char *name);
180 
getNumBlocks(void) const181     int getNumBlocks(void) const
182     {
183         return (int)m_bufferBlocks.size();
184     }
getBlock(int ndx) const185     const BufferBlock &getBlock(int ndx) const
186     {
187         return *m_bufferBlocks[ndx];
188     }
189 
190 private:
191     ShaderInterface(const ShaderInterface &);
192     ShaderInterface &operator=(const ShaderInterface &);
193 
194     std::vector<glu::StructType *> m_structs;
195     std::vector<BufferBlock *> m_bufferBlocks;
196 };
197 
198 class BufferLayout;
199 
200 } // namespace bb
201 
202 class SSBOLayoutCase : public tcu::TestCase
203 {
204 public:
205     enum BufferMode
206     {
207         BUFFERMODE_SINGLE = 0, //!< Single buffer shared between uniform blocks.
208         BUFFERMODE_PER_BLOCK,  //!< Per-block buffers
209 
210         BUFFERMODE_LAST
211     };
212 
213     SSBOLayoutCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name, const char *description,
214                    glu::GLSLVersion glslVersion, BufferMode bufferMode);
215     ~SSBOLayoutCase(void);
216 
217     IterateResult iterate(void);
218 
219 protected:
220     bool compareStdBlocks(const bb::BufferLayout &refLayout, const bb::BufferLayout &cmpLayout) const;
221     bool compareSharedBlocks(const bb::BufferLayout &refLayout, const bb::BufferLayout &cmpLayout) const;
222     bool compareTypes(const bb::BufferLayout &refLayout, const bb::BufferLayout &cmpLayout) const;
223     bool checkLayoutIndices(const bb::BufferLayout &layout) const;
224     bool checkLayoutBounds(const bb::BufferLayout &layout) const;
225     bool checkIndexQueries(uint32_t program, const bb::BufferLayout &layout) const;
226 
227     bool execute(uint32_t program);
228 
229     glu::RenderContext &m_renderCtx;
230     glu::GLSLVersion m_glslVersion;
231     BufferMode m_bufferMode;
232     bb::ShaderInterface m_interface;
233 
234 private:
235     SSBOLayoutCase(const SSBOLayoutCase &);
236     SSBOLayoutCase &operator=(const SSBOLayoutCase &);
237 };
238 
239 } // namespace gles31
240 } // namespace deqp
241 
242 #endif // _ES31FSSBOLAYOUTCASE_HPP
243