1 #ifndef _ES31FSSBOLAYOUTCASE_HPP
2 #define _ES31FSSBOLAYOUTCASE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES 3.1 Module
5 * -------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief SSBO layout tests.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 #include "gluShaderUtil.hpp"
29 #include "gluVarType.hpp"
41 // Buffer block details.
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 = LAYOUT_SHARED|LAYOUT_PACKED|LAYOUT_STD140|LAYOUT_STD430|LAYOUT_ROW_MAJOR|LAYOUT_COLUMN_MAJOR,
55 // \todo [2013-10-14 pyry] Investigate adding these.
56 /* QUALIFIER_COHERENT = (1<<6),
57 QUALIFIER_VOLATILE = (1<<7),
58 QUALIFIER_RESTRICT = (1<<8),
59 QUALIFIER_READONLY = (1<<9),
60 QUALIFIER_WRITEONLY = (1<<10),*/
62 ACCESS_READ = (1<<11), //!< Buffer variable is read in the shader.
63 ACCESS_WRITE = (1<<12), //!< Buffer variable is written in the shader.
69 BufferVar (const char* name, const glu::VarType& type, deUint32 flags);
71 const char* getName (void) const { return m_name.c_str(); }
72 const glu::VarType& getType (void) const { return m_type; }
73 deUint32 getFlags (void) const { return m_flags; }
84 typedef std::vector<BufferVar>::iterator iterator;
85 typedef std::vector<BufferVar>::const_iterator const_iterator;
87 BufferBlock (const char* blockName);
89 const char* getBlockName (void) const { return m_blockName.c_str(); }
90 const char* getInstanceName (void) const { return m_instanceName.empty() ? DE_NULL : m_instanceName.c_str(); }
91 bool isArray (void) const { return m_arraySize > 0; }
92 int getArraySize (void) const { return m_arraySize; }
93 deUint32 getFlags (void) const { return m_flags; }
95 void setInstanceName (const char* name) { m_instanceName = name; }
96 void setFlags (deUint32 flags) { m_flags = flags; }
97 void addMember (const BufferVar& var) { m_variables.push_back(var); }
98 void setArraySize (int arraySize);
100 int getLastUnsizedArraySize (int instanceNdx) const { return m_lastUnsizedArraySizes[instanceNdx]; }
101 void setLastUnsizedArraySize (int instanceNdx, int size) { m_lastUnsizedArraySizes[instanceNdx] = size; }
103 inline iterator begin (void) { return m_variables.begin(); }
104 inline const_iterator begin (void) const { return m_variables.begin(); }
105 inline iterator end (void) { return m_variables.end(); }
106 inline const_iterator end (void) const { return m_variables.end(); }
109 std::string m_blockName;
110 std::string m_instanceName;
111 std::vector<BufferVar> m_variables;
112 int m_arraySize; //!< Array size or 0 if not interface block array.
113 std::vector<int> m_lastUnsizedArraySizes; //!< Sizes of last unsized array element, can be different per instance.
117 class ShaderInterface
120 ShaderInterface (void);
121 ~ShaderInterface (void);
123 glu::StructType& allocStruct (const char* name);
124 const glu::StructType* findStruct (const char* name) const;
125 void getNamedStructs (std::vector<const glu::StructType*>& structs) const;
127 BufferBlock& allocBlock (const char* name);
129 int getNumBlocks (void) const { return (int)m_bufferBlocks.size(); }
130 const BufferBlock& getBlock (int ndx) const { return *m_bufferBlocks[ndx]; }
133 ShaderInterface (const ShaderInterface&);
134 ShaderInterface& operator= (const ShaderInterface&);
136 std::vector<glu::StructType*> m_structs;
137 std::vector<BufferBlock*> m_bufferBlocks;
144 class SSBOLayoutCase : public tcu::TestCase
149 BUFFERMODE_SINGLE = 0, //!< Single buffer shared between uniform blocks.
150 BUFFERMODE_PER_BLOCK, //!< Per-block buffers
155 SSBOLayoutCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, glu::GLSLVersion glslVersion, BufferMode bufferMode);
156 ~SSBOLayoutCase (void);
158 IterateResult iterate (void);
161 bool compareStdBlocks (const bb::BufferLayout& refLayout, const bb::BufferLayout& cmpLayout) const;
162 bool compareSharedBlocks (const bb::BufferLayout& refLayout, const bb::BufferLayout& cmpLayout) const;
163 bool compareTypes (const bb::BufferLayout& refLayout, const bb::BufferLayout& cmpLayout) const;
164 bool checkLayoutIndices (const bb::BufferLayout& layout) const;
165 bool checkLayoutBounds (const bb::BufferLayout& layout) const;
166 bool checkIndexQueries (deUint32 program, const bb::BufferLayout& layout) const;
168 bool execute (deUint32 program);
170 glu::RenderContext& m_renderCtx;
171 glu::GLSLVersion m_glslVersion;
172 BufferMode m_bufferMode;
173 bb::ShaderInterface m_interface;
176 SSBOLayoutCase (const SSBOLayoutCase&);
177 SSBOLayoutCase& operator= (const SSBOLayoutCase&);
183 #endif // _ES31FSSBOLAYOUTCASE_HPP