Extended CTS_ARB_sparse_texture2 MS34
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / gl / gl4cSparseTexture2Tests.hpp
1 #ifndef _GL4CSPARSETEXTURE2TESTS_HPP
2 #define _GL4CSPARSETEXTURE2TESTS_HPP
3 /*-------------------------------------------------------------------------
4  * OpenGL Conformance Test Suite
5  * -----------------------------
6  *
7  * Copyright (c) 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  */ /*!
28  * \file  gl4cSparseTexture2Tests.hpp
29  * \brief Conformance tests for the GL_ARB_sparse_texture2 functionality.
30  */ /*-------------------------------------------------------------------*/
31
32 #include "glcTestCase.hpp"
33 #include "glwDefs.hpp"
34 #include "glwEnums.hpp"
35 #include "tcuDefs.hpp"
36 #include <map>
37 #include <set>
38 #include <vector>
39
40 #include "gl4cSparseTextureTests.hpp"
41 #include "gluDrawUtil.hpp"
42 #include "gluShaderProgram.hpp"
43 #include "gluTextureUtil.hpp"
44 #include "tcuTextureUtil.hpp"
45
46 using namespace glw;
47 using namespace glu;
48
49 namespace gl4cts
50 {
51
52 struct PageSizeStruct
53 {
54         GLint xSize;
55         GLint ySize;
56         GLint zSize;
57
58         PageSizeStruct() : xSize(0), ySize(0), zSize(0)
59         {
60         }
61         PageSizeStruct(GLint x, GLint y, GLint z) : xSize(x), ySize(y), zSize(z)
62         {
63         }
64 };
65
66 typedef std::pair<GLint, PageSizeStruct> PageSizePair;
67
68 /** Test verifies if GL_ARB_sparse_texture2 extension is available for GLSL
69  **/
70 class ShaderExtensionTestCase : public deqp::TestCase
71 {
72 public:
73         /* Public methods */
74         ShaderExtensionTestCase(deqp::Context& context);
75
76         tcu::TestNode::IterateResult iterate();
77
78 private:
79         /* Private members */
80 };
81
82 /** Test verifies if values returned by GetInternalFormat* query matches Standard Virtual Page Sizes for <pname>:
83  *   - VIRTUAL_PAGE_SIZE_X_ARB,
84  *   - VIRTUAL_PAGE_SIZE_Y_ARB,
85  *   - VIRTUAL_PAGE_SIZE_Z_ARB.
86  **/
87 class StandardPageSizesTestCase : public deqp::TestCase
88 {
89 public:
90         /* Public methods */
91         StandardPageSizesTestCase(deqp::Context& context);
92
93         void                                             init();
94         tcu::TestNode::IterateResult iterate();
95
96 private:
97         /* Private methods */
98         std::vector<GLint> mSupportedTargets;
99         std::map<GLint, PageSizeStruct> mStandardVirtualPageSizesTable;
100
101         /* Private members */
102 };
103
104 /** Test verifies glTexStorage* functionality added by ARB_sparse_texture2 extension
105  **/
106 class SparseTexture2AllocationTestCase : public SparseTextureAllocationTestCase
107 {
108 public:
109         /* Public methods */
110         SparseTexture2AllocationTestCase(deqp::Context& context);
111
112         virtual void                                             init();
113         virtual tcu::TestNode::IterateResult iterate();
114
115 private:
116         /* Private methods */
117 };
118
119 /** Test verifies glTexPageCommitmentARB functionality added by ARB_sparse_texture2 extension
120  **/
121 class SparseTexture2CommitmentTestCase : public SparseTextureCommitmentTestCase
122 {
123 public:
124         /* Public methods */
125         SparseTexture2CommitmentTestCase(deqp::Context& context);
126
127         SparseTexture2CommitmentTestCase(deqp::Context& context, const char* name, const char* description);
128
129         virtual void                                             init();
130         virtual tcu::TestNode::IterateResult iterate();
131
132 protected:
133         /* Protected members */
134         struct TokenStrings
135         {
136                 std::string format;
137                 std::string pointType;
138                 std::string pointDef;
139                 std::string outputType;
140                 std::string inputType;
141                 std::string returnType;
142                 std::string resultExpected;
143                 std::string resultDefault;
144                 std::string epsilon;
145                 std::string sampleDef;
146         };
147
148         /* Protected methods */
149         TokenStrings createShaderTokens(GLint target, GLint format, GLint sample, const std::string outputBase = "image",
150                                                                         const std::string inputBase = "image");
151
152         virtual bool caseAllowed(GLint target, GLint format);
153
154         virtual bool sparseAllocateTexture(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint levels);
155         virtual bool allocateTexture(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint levels);
156         virtual bool writeDataToTexture(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level);
157         virtual bool verifyTextureData(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level);
158 };
159
160 /** Test verifies if access to uncommitted regions of sparse texture works as expected
161  **/
162 class UncommittedRegionsAccessTestCase : public SparseTexture2CommitmentTestCase
163 {
164 public:
165         /* Public methods */
166         UncommittedRegionsAccessTestCase(deqp::Context& context);
167
168         virtual void                                             init();
169         virtual tcu::TestNode::IterateResult iterate();
170
171 private:
172         /* Private members */
173         GLuint mFramebuffer;
174         GLuint mRenderbuffer;
175
176         /* Private methods */
177         bool readsAllowed(GLint target, GLint format, bool shaderOnly = false);
178         bool atomicAllowed(GLint target, GLint format);
179         bool depthStencilAllowed(GLint target, GLint format);
180
181         bool UncommittedReads(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level);
182         bool UncommittedAtomicOperations(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level);
183         bool UncommittedDepthStencil(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level);
184
185         void prepareDepthStencilFramebuffer(const Functions& gl, GLint width, GLint height);
186         void cleanupDepthStencilFramebuffer(const Functions& gl);
187         bool verifyTextureDataExtended(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level,
188                                                                    bool shaderOnly = false);
189         bool verifyAtomicOperations(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level);
190         bool verifyStencilTest(const Functions& gl, ShaderProgram& program, GLint width, GLint height,
191                                                    GLint widthCommitted);
192         bool verifyDepthTest(const Functions& gl, ShaderProgram& program, GLint width, GLint height, GLint widthCommitted);
193         bool verifyDepthBoundsTest(const Functions& gl, ShaderProgram& program, GLint width, GLint height,
194                                                            GLint widthCommitted);
195 };
196
197 /** Test verifies if sparse texture lookup functions for GLSL works as expected
198  **/
199 class SparseTexture2LookupTestCase : public SparseTexture2CommitmentTestCase
200 {
201 public:
202         /* Public methods */
203         SparseTexture2LookupTestCase(deqp::Context& context);
204
205         void                                             init();
206         tcu::TestNode::IterateResult iterate();
207
208 private:
209         /* Private types */
210         struct FunctionToken
211         {
212                 std::string name;
213                 std::string arguments;
214
215                 std::set<GLint> allowedTargets;
216
217                 FunctionToken()
218                 {
219                 }
220
221                 FunctionToken(std::string fname, std::string fargs) : name(fname), arguments(fargs)
222                 {
223                 }
224         };
225
226         struct TokenStringsExt : public TokenStrings
227         {
228                 std::string formatDef;
229                 std::string sizeDef;
230                 std::string lodDef;
231                 std::string coordType;
232                 std::string coordDef;
233                 std::string cubeMapCoordDef;
234                 std::string refZDef;
235                 std::string offsetDim;
236                 std::string componentDef;
237                 std::string offsetArrayDef;
238                 std::string pointCoord;
239         };
240
241         /* Private members */
242         std::vector<FunctionToken> mFunctions;
243
244         /* Private methods */
245         TokenStringsExt createLookupShaderTokens(GLint target, GLint format, GLint level, GLint sample,
246                                                                                          FunctionToken& funcToken);
247
248         virtual bool caseAllowed(GLint target, GLint format);
249         virtual bool funcAllowed(GLint target, GLint format, FunctionToken& funcToken);
250
251         virtual bool writeDataToTexture(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level);
252
253         virtual void setupDepthMode(const Functions& gl, GLint target, GLuint& texture);
254         virtual bool verifyLookupTextureData(const Functions& gl, GLint target, GLint format, GLuint& texture, GLint level,
255                                                                                  FunctionToken& funcToken);
256 };
257
258 /** Test group which encapsulates all sparse texture conformance tests */
259 class SparseTexture2Tests : public deqp::TestCaseGroup
260 {
261 public:
262         /* Public methods */
263         SparseTexture2Tests(deqp::Context& context);
264
265         void init();
266
267 private:
268         SparseTexture2Tests(const SparseTexture2Tests& other);
269         SparseTexture2Tests& operator=(const SparseTexture2Tests& other);
270 };
271
272 } /* glcts namespace */
273
274 #endif // _GL4CSPARSETEXTURE2TESTS_HPP