xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fTextureLevelStateQueryTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.1 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Texture level state query tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es31fTextureLevelStateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "tcuTestLog.hpp"
27 #include "gluRenderContext.hpp"
28 #include "gluCallLogWrapper.hpp"
29 #include "gluTextureUtil.hpp"
30 #include "gluStrUtil.hpp"
31 #include "gluContextInfo.hpp"
32 #include "glwFunctions.hpp"
33 #include "glwEnums.hpp"
34 #include "tcuTextureUtil.hpp"
35 #include "tcuFormatUtil.hpp"
36 #include "deStringUtil.hpp"
37 #include "deUniquePtr.hpp"
38 
39 namespace deqp
40 {
41 namespace gles31
42 {
43 namespace Functional
44 {
45 namespace
46 {
47 
48 using namespace gls::StateQueryUtil;
49 
textureTypeHasDepth(glw::GLenum textureBindTarget)50 static bool textureTypeHasDepth(glw::GLenum textureBindTarget)
51 {
52     switch (textureBindTarget)
53     {
54     case GL_TEXTURE_2D:
55         return false;
56     case GL_TEXTURE_3D:
57         return true;
58     case GL_TEXTURE_2D_ARRAY:
59         return true;
60     case GL_TEXTURE_CUBE_MAP:
61         return false;
62     case GL_TEXTURE_2D_MULTISAMPLE:
63         return false;
64     case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
65         return true;
66     case GL_TEXTURE_BUFFER:
67         return false;
68     case GL_TEXTURE_CUBE_MAP_ARRAY:
69         return true;
70     default:
71         DE_ASSERT(false);
72         return false;
73     }
74 }
75 
textureTypeHasHeight(glw::GLenum textureBindTarget)76 static bool textureTypeHasHeight(glw::GLenum textureBindTarget)
77 {
78     switch (textureBindTarget)
79     {
80     case GL_TEXTURE_2D:
81         return true;
82     case GL_TEXTURE_3D:
83         return true;
84     case GL_TEXTURE_2D_ARRAY:
85         return true;
86     case GL_TEXTURE_CUBE_MAP:
87         return true;
88     case GL_TEXTURE_2D_MULTISAMPLE:
89         return true;
90     case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
91         return true;
92     case GL_TEXTURE_BUFFER:
93         return false;
94     case GL_TEXTURE_CUBE_MAP_ARRAY:
95         return true;
96     default:
97         DE_ASSERT(false);
98         return false;
99     }
100 }
101 
getTextureTargetExtension(glw::GLenum target)102 static const char *getTextureTargetExtension(glw::GLenum target)
103 {
104     switch (target)
105     {
106     case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
107         return "GL_OES_texture_storage_multisample_2d_array";
108     case GL_TEXTURE_BUFFER:
109         return "GL_EXT_texture_buffer";
110     case GL_TEXTURE_CUBE_MAP_ARRAY:
111         return "GL_EXT_texture_cube_map_array";
112     default:
113         DE_ASSERT(false);
114         return DE_NULL;
115     }
116 }
117 
isCoreTextureTarget(glw::GLenum target,const glu::ContextType & contextType)118 static bool isCoreTextureTarget(glw::GLenum target, const glu::ContextType &contextType)
119 {
120     switch (target)
121     {
122     case GL_TEXTURE_2D:
123     case GL_TEXTURE_3D:
124     case GL_TEXTURE_2D_ARRAY:
125     case GL_TEXTURE_CUBE_MAP:
126     case GL_TEXTURE_2D_MULTISAMPLE:
127         return true;
128 
129     case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
130     case GL_TEXTURE_BUFFER:
131     case GL_TEXTURE_CUBE_MAP_ARRAY:
132         return glu::contextSupports(contextType, glu::ApiType::es(3, 2)) ||
133                glu::contextSupports(contextType, glu::ApiType::core(4, 5));
134 
135     default:
136         return false;
137     }
138 }
139 
140 struct TextureGenerationSpec
141 {
142     struct TextureLevelSpec
143     {
144         int width;
145         int height;
146         int depth;
147         int level;
148         glw::GLenum internalFormat;
149         bool compressed;
150 
TextureLevelSpecdeqp::gles31::Functional::__anone157aa4e0111::TextureGenerationSpec::TextureLevelSpec151         TextureLevelSpec(void) : width(0), height(0), depth(0), level(0), internalFormat(GL_RGBA), compressed(false)
152         {
153         }
154     };
155 
156     glw::GLenum bindTarget;
157     glw::GLenum queryTarget;
158     bool immutable;
159     bool fixedSamplePos; // !< fixed sample pos argument for multisample textures
160     int sampleCount;
161     int texBufferDataOffset;
162     int texBufferDataSize;
163     bool bindWholeArray;
164     std::vector<TextureLevelSpec> levels;
165     std::string description;
166 
TextureGenerationSpecdeqp::gles31::Functional::__anone157aa4e0111::TextureGenerationSpec167     TextureGenerationSpec(void)
168         : bindTarget(0)
169         , queryTarget(0)
170         , immutable(true)
171         , fixedSamplePos(true)
172         , sampleCount(0)
173         , texBufferDataOffset(0)
174         , texBufferDataSize(256)
175         , bindWholeArray(false)
176     {
177     }
178 };
179 struct IntegerPrinter
180 {
getIntegerNamedeqp::gles31::Functional::__anone157aa4e0111::IntegerPrinter181     static std::string getIntegerName(int v)
182     {
183         return de::toString(v);
184     }
getFloatNamedeqp::gles31::Functional::__anone157aa4e0111::IntegerPrinter185     static std::string getFloatName(float v)
186     {
187         return de::toString(v);
188     }
189 };
190 
191 struct PixelFormatPrinter
192 {
getIntegerNamedeqp::gles31::Functional::__anone157aa4e0111::PixelFormatPrinter193     static std::string getIntegerName(int v)
194     {
195         return de::toString(glu::getTextureFormatStr(v));
196     }
getFloatNamedeqp::gles31::Functional::__anone157aa4e0111::PixelFormatPrinter197     static std::string getFloatName(float v)
198     {
199         return de::toString(glu::getTextureFormatStr((int)v));
200     }
201 };
202 
203 template <typename Printer>
verifyTextureLevelParameterEqualWithPrinter(glu::CallLogWrapper & gl,glw::GLenum target,int level,glw::GLenum pname,int refValue,QueryType type)204 static bool verifyTextureLevelParameterEqualWithPrinter(glu::CallLogWrapper &gl, glw::GLenum target, int level,
205                                                         glw::GLenum pname, int refValue, QueryType type)
206 {
207     QueriedState state;
208     tcu::ResultCollector result(gl.getLog(), " // ERROR: ");
209 
210     gl.getLog() << tcu::TestLog::Message << "Verifying " << glu::getTextureLevelParameterStr(pname) << ", expecting "
211                 << Printer::getIntegerName(refValue) << tcu::TestLog::EndMessage;
212     queryTextureLevelState(result, gl, type, target, level, pname, state);
213 
214     if (state.isUndefined())
215         return false;
216 
217     verifyInteger(result, state, refValue);
218 
219     return result.getResult() == QP_TEST_RESULT_PASS;
220 }
221 
verifyTextureLevelParameterEqual(glu::CallLogWrapper & gl,glw::GLenum target,int level,glw::GLenum pname,int refValue,QueryType type)222 static bool verifyTextureLevelParameterEqual(glu::CallLogWrapper &gl, glw::GLenum target, int level, glw::GLenum pname,
223                                              int refValue, QueryType type)
224 {
225     return verifyTextureLevelParameterEqualWithPrinter<IntegerPrinter>(gl, target, level, pname, refValue, type);
226 }
227 
verifyTextureLevelParameterInternalFormatEqual(glu::CallLogWrapper & gl,glw::GLenum target,int level,glw::GLenum pname,int refValue,QueryType type)228 static bool verifyTextureLevelParameterInternalFormatEqual(glu::CallLogWrapper &gl, glw::GLenum target, int level,
229                                                            glw::GLenum pname, int refValue, QueryType type)
230 {
231     return verifyTextureLevelParameterEqualWithPrinter<PixelFormatPrinter>(gl, target, level, pname, refValue, type);
232 }
233 
verifyTextureLevelParameterGreaterOrEqual(glu::CallLogWrapper & gl,glw::GLenum target,int level,glw::GLenum pname,int refValue,QueryType type)234 static bool verifyTextureLevelParameterGreaterOrEqual(glu::CallLogWrapper &gl, glw::GLenum target, int level,
235                                                       glw::GLenum pname, int refValue, QueryType type)
236 {
237     QueriedState state;
238     tcu::ResultCollector result(gl.getLog(), " // ERROR: ");
239 
240     gl.getLog() << tcu::TestLog::Message << "Verifying " << glu::getTextureLevelParameterStr(pname) << ", expecting "
241                 << refValue << " or greater" << tcu::TestLog::EndMessage;
242     queryTextureLevelState(result, gl, type, target, level, pname, state);
243 
244     if (state.isUndefined())
245         return false;
246 
247     verifyIntegerMin(result, state, refValue);
248 
249     return result.getResult() == QP_TEST_RESULT_PASS;
250 }
251 
verifyTextureLevelParameterInternalFormatAnyOf(glu::CallLogWrapper & gl,glw::GLenum target,int level,glw::GLenum pname,const int * refValues,int numRefValues,QueryType type)252 static bool verifyTextureLevelParameterInternalFormatAnyOf(glu::CallLogWrapper &gl, glw::GLenum target, int level,
253                                                            glw::GLenum pname, const int *refValues, int numRefValues,
254                                                            QueryType type)
255 {
256     QueriedState state;
257     tcu::ResultCollector result(gl.getLog(), " // ERROR: ");
258 
259     // Log what we try to do
260     {
261         tcu::MessageBuilder msg(&gl.getLog());
262 
263         msg << "Verifying " << glu::getTextureLevelParameterStr(pname) << ", expecting any of {";
264         for (int ndx = 0; ndx < numRefValues; ++ndx)
265         {
266             if (ndx != 0)
267                 msg << ", ";
268             msg << glu::getTextureFormatStr(refValues[ndx]);
269         }
270         msg << "}";
271         msg << tcu::TestLog::EndMessage;
272     }
273 
274     queryTextureLevelState(result, gl, type, target, level, pname, state);
275     if (state.isUndefined())
276         return false;
277 
278     // verify
279     switch (state.getType())
280     {
281     case DATATYPE_INTEGER:
282     {
283         for (int ndx = 0; ndx < numRefValues; ++ndx)
284             if (state.getIntAccess() == refValues[ndx])
285                 return true;
286 
287         gl.getLog() << tcu::TestLog::Message << "Error: got " << state.getIntAccess() << ", ("
288                     << glu::getTextureFormatStr(state.getIntAccess()) << ")" << tcu::TestLog::EndMessage;
289         return false;
290     }
291     case DATATYPE_FLOAT:
292     {
293         for (int ndx = 0; ndx < numRefValues; ++ndx)
294             if (state.getFloatAccess() == (float)refValues[ndx])
295                 return true;
296 
297         gl.getLog() << tcu::TestLog::Message << "Error: got " << state.getFloatAccess() << ", ("
298                     << glu::getTextureFormatStr((int)state.getFloatAccess()) << ")" << tcu::TestLog::EndMessage;
299         return false;
300     }
301     default:
302         DE_ASSERT(false);
303         return false;
304     }
305 }
306 
isDepthFormat(const tcu::TextureFormat & fmt)307 static bool isDepthFormat(const tcu::TextureFormat &fmt)
308 {
309     return fmt.order == tcu::TextureFormat::D || fmt.order == tcu::TextureFormat::DS;
310 }
311 
isColorRenderableFormat(glw::GLenum internalFormat)312 static bool isColorRenderableFormat(glw::GLenum internalFormat)
313 {
314     return internalFormat == GL_RGB565 || internalFormat == GL_RGBA4 || internalFormat == GL_RGB5_A1 ||
315            internalFormat == GL_RGB10_A2 || internalFormat == GL_RGB10_A2UI || internalFormat == GL_SRGB8_ALPHA8 ||
316            internalFormat == GL_R8 || internalFormat == GL_RG8 || internalFormat == GL_RGB8 ||
317            internalFormat == GL_RGBA8 || internalFormat == GL_R8I || internalFormat == GL_RG8I ||
318            internalFormat == GL_RGBA8I || internalFormat == GL_R8UI || internalFormat == GL_RG8UI ||
319            internalFormat == GL_RGBA8UI || internalFormat == GL_R16I || internalFormat == GL_RG16I ||
320            internalFormat == GL_RGBA16I || internalFormat == GL_R16UI || internalFormat == GL_RG16UI ||
321            internalFormat == GL_RGBA16UI || internalFormat == GL_R32I || internalFormat == GL_RG32I ||
322            internalFormat == GL_RGBA32I || internalFormat == GL_R32UI || internalFormat == GL_RG32UI ||
323            internalFormat == GL_RGBA32UI;
324 }
325 
isRenderableFormat(glw::GLenum internalFormat)326 static bool isRenderableFormat(glw::GLenum internalFormat)
327 {
328     return isColorRenderableFormat(internalFormat) || internalFormat == GL_DEPTH_COMPONENT16 ||
329            internalFormat == GL_DEPTH_COMPONENT24 || internalFormat == GL_DEPTH_COMPONENT32F ||
330            internalFormat == GL_DEPTH24_STENCIL8 || internalFormat == GL_DEPTH32F_STENCIL8;
331 }
332 
isTextureBufferFormat(glw::GLenum internalFormat)333 static bool isTextureBufferFormat(glw::GLenum internalFormat)
334 {
335     return internalFormat == GL_R8 || internalFormat == GL_R16F || internalFormat == GL_R32F ||
336            internalFormat == GL_R8I || internalFormat == GL_R16I || internalFormat == GL_R32I ||
337            internalFormat == GL_R8UI || internalFormat == GL_R16UI || internalFormat == GL_R32UI ||
338            internalFormat == GL_RG8 || internalFormat == GL_RG16F || internalFormat == GL_RG32F ||
339            internalFormat == GL_RG8I || internalFormat == GL_RG16I || internalFormat == GL_RG32I ||
340            internalFormat == GL_RG8UI || internalFormat == GL_RG16UI || internalFormat == GL_RG32UI ||
341            internalFormat == GL_RGB32F || internalFormat == GL_RGB32I || internalFormat == GL_RGB32UI ||
342            internalFormat == GL_RGBA8 || internalFormat == GL_RGBA16F || internalFormat == GL_RGBA32F ||
343            internalFormat == GL_RGBA8I || internalFormat == GL_RGBA16I || internalFormat == GL_RGBA32I ||
344            internalFormat == GL_RGBA8UI || internalFormat == GL_RGBA16UI || internalFormat == GL_RGBA32UI;
345 }
346 
isLegalFormatForTarget(glw::GLenum target,glw::GLenum format)347 static bool isLegalFormatForTarget(glw::GLenum target, glw::GLenum format)
348 {
349     const tcu::TextureFormat fmt = glu::mapGLInternalFormat(format);
350 
351     if (target == GL_TEXTURE_3D && isDepthFormat(fmt))
352         return false;
353     if ((target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) &&
354         !isRenderableFormat(format))
355         return false;
356     if (target == GL_TEXTURE_BUFFER || !isTextureBufferFormat(format))
357         return false;
358     return true;
359 }
360 
isCompressionSupportedForTarget(glw::GLenum target)361 static bool isCompressionSupportedForTarget(glw::GLenum target)
362 {
363     return target == GL_TEXTURE_2D || target == GL_TEXTURE_2D_ARRAY;
364 }
365 
isMultisampleTarget(glw::GLenum target)366 static bool isMultisampleTarget(glw::GLenum target)
367 {
368     return target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
369 }
370 
targetSupportsMipLevels(glw::GLenum target)371 static bool targetSupportsMipLevels(glw::GLenum target)
372 {
373     return target != GL_TEXTURE_2D_MULTISAMPLE && target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY &&
374            target != GL_TEXTURE_BUFFER;
375 }
376 
getPixelSize(glw::GLenum internalFormat)377 static int getPixelSize(glw::GLenum internalFormat)
378 {
379     const tcu::TextureFormat fmt = glu::mapGLInternalFormat(internalFormat);
380     return fmt.getPixelSize();
381 }
382 
generateColorTextureGenerationGroup(std::vector<TextureGenerationSpec> & group,glw::GLenum target,int maxSamples,glw::GLenum internalFormat)383 static void generateColorTextureGenerationGroup(std::vector<TextureGenerationSpec> &group, glw::GLenum target,
384                                                 int maxSamples, glw::GLenum internalFormat)
385 {
386     const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
387 
388     // initial
389     {
390         TextureGenerationSpec texGen;
391         texGen.bindTarget  = target;
392         texGen.queryTarget = queryTarget;
393         texGen.immutable   = true;
394         texGen.sampleCount = 0;
395         texGen.description = glu::getTextureTargetStr(target).toString() + ", initial values";
396 
397         group.push_back(texGen);
398     }
399 
400     // ms targets
401     if (isMultisampleTarget(target))
402     {
403         {
404             TextureGenerationSpec texGen;
405             TextureGenerationSpec::TextureLevelSpec level;
406 
407             texGen.bindTarget     = target;
408             texGen.queryTarget    = queryTarget;
409             texGen.immutable      = true;
410             texGen.sampleCount    = 1;
411             texGen.fixedSamplePos = false;
412             texGen.description    = glu::getTextureTargetStr(target).toString() + ", low sample count";
413 
414             level.width          = 16;
415             level.height         = 16;
416             level.depth          = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (1);
417             level.level          = 0;
418             level.internalFormat = internalFormat;
419             level.compressed     = false;
420 
421             texGen.levels.push_back(level);
422             group.push_back(texGen);
423         }
424         {
425             TextureGenerationSpec texGen;
426             TextureGenerationSpec::TextureLevelSpec level;
427 
428             texGen.bindTarget     = target;
429             texGen.queryTarget    = queryTarget;
430             texGen.immutable      = true;
431             texGen.sampleCount    = maxSamples;
432             texGen.fixedSamplePos = false;
433             texGen.description    = glu::getTextureTargetStr(target).toString() + ", high sample count";
434 
435             level.width          = 32;
436             level.height         = 32;
437             level.depth          = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (1);
438             level.level          = 0;
439             level.internalFormat = internalFormat;
440             level.compressed     = false;
441 
442             texGen.levels.push_back(level);
443             group.push_back(texGen);
444         }
445         {
446             TextureGenerationSpec texGen;
447             TextureGenerationSpec::TextureLevelSpec level;
448 
449             texGen.bindTarget     = target;
450             texGen.queryTarget    = queryTarget;
451             texGen.immutable      = true;
452             texGen.sampleCount    = maxSamples;
453             texGen.fixedSamplePos = true;
454             texGen.description    = glu::getTextureTargetStr(target).toString() + ", fixed sample positions";
455 
456             level.width          = 32;
457             level.height         = 32;
458             level.depth          = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (1);
459             level.level          = 0;
460             level.internalFormat = internalFormat;
461             level.compressed     = false;
462 
463             texGen.levels.push_back(level);
464             group.push_back(texGen);
465         }
466     }
467     else if (target == GL_TEXTURE_BUFFER)
468     {
469         // whole buffer
470         {
471             TextureGenerationSpec texGen;
472             TextureGenerationSpec::TextureLevelSpec level;
473             const int baseSize = getPixelSize(internalFormat);
474 
475             texGen.bindTarget          = target;
476             texGen.queryTarget         = queryTarget;
477             texGen.immutable           = true;
478             texGen.description         = glu::getTextureTargetStr(target).toString() + ", whole buffer";
479             texGen.texBufferDataOffset = 0;
480             texGen.texBufferDataSize   = 32 * baseSize + (baseSize - 1);
481             texGen.bindWholeArray      = true;
482 
483             level.width          = 32;
484             level.height         = 1;
485             level.depth          = 1;
486             level.level          = 0;
487             level.internalFormat = internalFormat;
488             level.compressed     = false;
489 
490             texGen.levels.push_back(level);
491             group.push_back(texGen);
492         }
493         // partial buffer
494         {
495             TextureGenerationSpec texGen;
496             TextureGenerationSpec::TextureLevelSpec level;
497             const int baseSize = getPixelSize(internalFormat);
498 
499             texGen.bindTarget          = target;
500             texGen.queryTarget         = queryTarget;
501             texGen.immutable           = true;
502             texGen.description         = glu::getTextureTargetStr(target).toString() + ", partial buffer";
503             texGen.texBufferDataOffset = 256;
504             texGen.texBufferDataSize   = 16 * baseSize + (baseSize - 1);
505             texGen.bindWholeArray      = false;
506 
507             level.width          = 16;
508             level.height         = 1;
509             level.depth          = 1;
510             level.level          = 0;
511             level.internalFormat = internalFormat;
512             level.compressed     = false;
513 
514             texGen.levels.push_back(level);
515             group.push_back(texGen);
516         }
517     }
518     else
519     {
520         // immutable
521         {
522             TextureGenerationSpec texGen;
523             TextureGenerationSpec::TextureLevelSpec level;
524 
525             texGen.bindTarget  = target;
526             texGen.queryTarget = queryTarget;
527             texGen.immutable   = true;
528             texGen.description = glu::getTextureTargetStr(target).toString() + ", immutable";
529 
530             level.width          = 32;
531             level.height         = 32;
532             level.depth          = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (1);
533             level.level          = 0;
534             level.internalFormat = internalFormat;
535             level.compressed     = false;
536 
537             texGen.levels.push_back(level);
538             group.push_back(texGen);
539         }
540         // mutable
541         {
542             TextureGenerationSpec texGen;
543             TextureGenerationSpec::TextureLevelSpec level;
544 
545             texGen.bindTarget  = target;
546             texGen.queryTarget = queryTarget;
547             texGen.immutable   = false;
548             texGen.description = glu::getTextureTargetStr(target).toString() + ", mutable";
549 
550             level.width          = 16;
551             level.height         = (target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) ? (16) : (64);
552             level.depth          = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (1);
553             level.level          = 0;
554             level.internalFormat = internalFormat;
555             level.compressed     = false;
556 
557             texGen.levels.push_back(level);
558             group.push_back(texGen);
559         }
560         // mip3
561         {
562             TextureGenerationSpec texGen;
563             TextureGenerationSpec::TextureLevelSpec level;
564 
565             texGen.bindTarget  = target;
566             texGen.queryTarget = queryTarget;
567             texGen.immutable   = false;
568             texGen.description = glu::getTextureTargetStr(target).toString() + ", mip level 3";
569 
570             level.width          = 4;
571             level.height         = (target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) ? (4) : (8);
572             level.depth          = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (1);
573             level.level          = 3;
574             level.internalFormat = internalFormat;
575             level.compressed     = false;
576 
577             texGen.levels.push_back(level);
578             group.push_back(texGen);
579         }
580     }
581 }
582 
generateInternalFormatTextureGenerationGroup(std::vector<TextureGenerationSpec> & group,glw::GLenum target)583 static void generateInternalFormatTextureGenerationGroup(std::vector<TextureGenerationSpec> &group, glw::GLenum target)
584 {
585     const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
586 
587     // Internal formats
588     static const glw::GLenum internalFormats[] = {GL_R8,
589                                                   GL_R8_SNORM,
590                                                   GL_RG8,
591                                                   GL_RG8_SNORM,
592                                                   GL_RGB8,
593                                                   GL_RGB8_SNORM,
594                                                   GL_RGB565,
595                                                   GL_RGBA4,
596                                                   GL_RGB5_A1,
597                                                   GL_RGBA8,
598                                                   GL_RGBA8_SNORM,
599                                                   GL_RGB10_A2,
600                                                   GL_RGB10_A2UI,
601                                                   GL_SRGB8,
602                                                   GL_SRGB8_ALPHA8,
603                                                   GL_R16F,
604                                                   GL_RG16F,
605                                                   GL_RGB16F,
606                                                   GL_RGBA16F,
607                                                   GL_R32F,
608                                                   GL_RG32F,
609                                                   GL_RGB32F,
610                                                   GL_RGBA32F,
611                                                   GL_R11F_G11F_B10F,
612                                                   GL_RGB9_E5,
613                                                   GL_R8I,
614                                                   GL_R8UI,
615                                                   GL_R16I,
616                                                   GL_R16UI,
617                                                   GL_R32I,
618                                                   GL_R32UI,
619                                                   GL_RG8I,
620                                                   GL_RG8UI,
621                                                   GL_RG16I,
622                                                   GL_RG16UI,
623                                                   GL_RG32I,
624                                                   GL_RG32UI,
625                                                   GL_RGB8I,
626                                                   GL_RGB8UI,
627                                                   GL_RGB16I,
628                                                   GL_RGB16UI,
629                                                   GL_RGB32I,
630                                                   GL_RGB32UI,
631                                                   GL_RGBA8I,
632                                                   GL_RGBA8UI,
633                                                   GL_RGBA16I,
634                                                   GL_RGBA16UI,
635                                                   GL_RGBA32I,
636                                                   GL_RGBA32UI,
637 
638                                                   GL_DEPTH_COMPONENT32F,
639                                                   GL_DEPTH_COMPONENT24,
640                                                   GL_DEPTH_COMPONENT16,
641                                                   GL_DEPTH32F_STENCIL8,
642                                                   GL_DEPTH24_STENCIL8};
643 
644     // initial
645     {
646         TextureGenerationSpec texGen;
647         texGen.bindTarget     = target;
648         texGen.queryTarget    = queryTarget;
649         texGen.immutable      = true;
650         texGen.sampleCount    = 0;
651         texGen.fixedSamplePos = true;
652         texGen.description    = glu::getTextureTargetStr(target).toString() + ", initial values";
653 
654         group.push_back(texGen);
655     }
656 
657     // test all formats
658     for (int internalFormatNdx = 0; internalFormatNdx < DE_LENGTH_OF_ARRAY(internalFormats); ++internalFormatNdx)
659     {
660         if (!isLegalFormatForTarget(target, internalFormats[internalFormatNdx]))
661             continue;
662 
663         const int baseSize = getPixelSize(internalFormats[internalFormatNdx]);
664         TextureGenerationSpec texGen;
665         TextureGenerationSpec::TextureLevelSpec level;
666 
667         texGen.bindTarget  = target;
668         texGen.queryTarget = queryTarget;
669         texGen.immutable   = true;
670         texGen.sampleCount = (isMultisampleTarget(target) ? (1) : (0));
671         texGen.description = glu::getTextureTargetStr(target).toString() + ", internal format " +
672                              glu::getTextureFormatName(internalFormats[internalFormatNdx]);
673 
674         if (target == GL_TEXTURE_BUFFER)
675         {
676             texGen.texBufferDataOffset = 0;
677             texGen.texBufferDataSize   = 32 * baseSize + (baseSize - 1);
678             texGen.bindWholeArray      = true;
679         }
680 
681         level.width          = 32;
682         level.height         = (textureTypeHasHeight(target)) ? (32) : (1);
683         level.depth          = (textureTypeHasDepth(target)) ? (6) : (1);
684         level.level          = 0;
685         level.internalFormat = internalFormats[internalFormatNdx];
686         level.compressed     = false;
687 
688         texGen.levels.push_back(level);
689         group.push_back(texGen);
690     }
691 
692     // test mutable rgba8 with mip level 3
693     if (targetSupportsMipLevels(target))
694     {
695         TextureGenerationSpec texGen;
696         TextureGenerationSpec::TextureLevelSpec level;
697 
698         texGen.bindTarget  = target;
699         texGen.queryTarget = queryTarget;
700         texGen.immutable   = false;
701         texGen.description = glu::getTextureTargetStr(target).toString() + ", internal format GL_RGBA8, mip level 3";
702 
703         level.width          = 32;
704         level.height         = 32;
705         level.depth          = (textureTypeHasDepth(target)) ? (6) : (1);
706         level.level          = 3;
707         level.internalFormat = GL_RGBA8;
708         level.compressed     = false;
709 
710         texGen.levels.push_back(level);
711         group.push_back(texGen);
712     }
713 }
714 
generateCompressedTextureGenerationGroup(std::vector<TextureGenerationSpec> & group,glw::GLenum target)715 static void generateCompressedTextureGenerationGroup(std::vector<TextureGenerationSpec> &group, glw::GLenum target)
716 {
717     const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
718 
719     // initial
720     {
721         TextureGenerationSpec texGen;
722         texGen.bindTarget  = target;
723         texGen.queryTarget = queryTarget;
724         texGen.immutable   = true;
725         texGen.description = glu::getTextureTargetStr(target).toString() + ", initial values";
726 
727         group.push_back(texGen);
728     }
729 
730     // compressed
731     if (isCompressionSupportedForTarget(target))
732     {
733         TextureGenerationSpec texGen;
734         TextureGenerationSpec::TextureLevelSpec level;
735 
736         texGen.bindTarget  = target;
737         texGen.queryTarget = queryTarget;
738         texGen.immutable   = false;
739         texGen.description = glu::getTextureTargetStr(target).toString() + ", compressed";
740 
741         level.width          = 32;
742         level.height         = 32;
743         level.depth          = (target == GL_TEXTURE_2D_ARRAY) ? (2) : (1);
744         level.level          = 0;
745         level.internalFormat = GL_COMPRESSED_RGB8_ETC2;
746         level.compressed     = true;
747 
748         texGen.levels.push_back(level);
749         group.push_back(texGen);
750     }
751 }
752 
generateTextureBufferGenerationGroup(std::vector<TextureGenerationSpec> & group,glw::GLenum target)753 static void generateTextureBufferGenerationGroup(std::vector<TextureGenerationSpec> &group, glw::GLenum target)
754 {
755     const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
756 
757     // initial
758     {
759         TextureGenerationSpec texGen;
760         texGen.bindTarget  = target;
761         texGen.queryTarget = queryTarget;
762         texGen.immutable   = true;
763         texGen.sampleCount = 0;
764         texGen.description = glu::getTextureTargetStr(target).toString() + ", initial values";
765 
766         group.push_back(texGen);
767     }
768 
769     // actual specification tests are in texture_buffer tests, no need to do them here too
770 }
771 
applyTextureGenerationSpec(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec,glw::GLuint & texBuffer)772 bool applyTextureGenerationSpec(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec, glw::GLuint &texBuffer)
773 {
774     bool allOk = true;
775 
776     DE_ASSERT(!(spec.immutable && spec.levels.size() > 1)); // !< immutable textures have only one level
777 
778     for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
779     {
780         const glu::TransferFormat transferFormat =
781             (spec.levels[levelNdx].compressed) ?
782                 (glu::TransferFormat()) :
783                 (glu::getTransferFormat(glu::mapGLInternalFormat(spec.levels[levelNdx].internalFormat)));
784 
785         if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D)
786             gl.glTexStorage2D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width,
787                               spec.levels[levelNdx].height);
788         else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_3D)
789             gl.glTexStorage3D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width,
790                               spec.levels[levelNdx].height, spec.levels[levelNdx].depth);
791         else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_ARRAY)
792             gl.glTexStorage3D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width,
793                               spec.levels[levelNdx].height, spec.levels[levelNdx].depth);
794         else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP)
795             gl.glTexStorage2D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width,
796                               spec.levels[levelNdx].height);
797         else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_MULTISAMPLE)
798             gl.glTexStorage2DMultisample(spec.bindTarget, spec.sampleCount, spec.levels[levelNdx].internalFormat,
799                                          spec.levels[levelNdx].width, spec.levels[levelNdx].height,
800                                          (spec.fixedSamplePos) ? (GL_TRUE) : (GL_FALSE));
801         else if (spec.immutable && !spec.levels[levelNdx].compressed &&
802                  spec.bindTarget == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
803             gl.glTexStorage3DMultisample(spec.bindTarget, spec.sampleCount, spec.levels[levelNdx].internalFormat,
804                                          spec.levels[levelNdx].width, spec.levels[levelNdx].height,
805                                          spec.levels[levelNdx].depth, (spec.fixedSamplePos) ? (GL_TRUE) : (GL_FALSE));
806         else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
807             gl.glTexStorage3D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width,
808                               spec.levels[levelNdx].height, spec.levels[levelNdx].depth);
809         else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D)
810             gl.glTexImage2D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat,
811                             spec.levels[levelNdx].width, spec.levels[levelNdx].height, 0, transferFormat.format,
812                             transferFormat.dataType, DE_NULL);
813         else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_3D)
814             gl.glTexImage3D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat,
815                             spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0,
816                             transferFormat.format, transferFormat.dataType, DE_NULL);
817         else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_ARRAY)
818             gl.glTexImage3D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat,
819                             spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0,
820                             transferFormat.format, transferFormat.dataType, DE_NULL);
821         else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP)
822             gl.glTexImage2D(spec.queryTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat,
823                             spec.levels[levelNdx].width, spec.levels[levelNdx].height, 0, transferFormat.format,
824                             transferFormat.dataType, DE_NULL);
825         else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
826             gl.glTexImage3D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat,
827                             spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0,
828                             transferFormat.format, transferFormat.dataType, DE_NULL);
829         else if (!spec.immutable && spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D)
830         {
831             DE_ASSERT(spec.levels[levelNdx].width == 32);
832             DE_ASSERT(spec.levels[levelNdx].height == 32);
833             DE_ASSERT(spec.levels[levelNdx].internalFormat == GL_COMPRESSED_RGB8_ETC2);
834 
835             static const uint8_t buffer[64 * 8] = {0};
836             gl.glCompressedTexImage2D(spec.bindTarget, spec.levels[levelNdx].level,
837                                       spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width,
838                                       spec.levels[levelNdx].height, 0, sizeof(buffer), buffer);
839         }
840         else if (!spec.immutable && spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_ARRAY)
841         {
842             DE_ASSERT(spec.levels[levelNdx].width == 32);
843             DE_ASSERT(spec.levels[levelNdx].height == 32);
844             DE_ASSERT(spec.levels[levelNdx].depth == 2);
845             DE_ASSERT(spec.levels[levelNdx].internalFormat == GL_COMPRESSED_RGB8_ETC2);
846 
847             static const uint8_t buffer[64 * 8 * 2] = {0};
848             gl.glCompressedTexImage3D(spec.bindTarget, spec.levels[levelNdx].level,
849                                       spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width,
850                                       spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0, sizeof(buffer),
851                                       buffer);
852         }
853         else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_BUFFER)
854         {
855             gl.glGenBuffers(1, &texBuffer);
856             gl.glBindBuffer(GL_TEXTURE_BUFFER, texBuffer);
857 
858             if (spec.bindWholeArray)
859             {
860                 gl.glBufferData(GL_TEXTURE_BUFFER, spec.texBufferDataSize, DE_NULL, GL_STATIC_DRAW);
861                 gl.glTexBuffer(GL_TEXTURE_BUFFER, spec.levels[levelNdx].internalFormat, texBuffer);
862             }
863             else
864             {
865                 gl.glBufferData(GL_TEXTURE_BUFFER, spec.texBufferDataOffset + spec.texBufferDataSize, DE_NULL,
866                                 GL_STATIC_DRAW);
867                 gl.glTexBufferRange(GL_TEXTURE_BUFFER, spec.levels[levelNdx].internalFormat, texBuffer,
868                                     spec.texBufferDataOffset, spec.texBufferDataSize);
869             }
870         }
871         else
872             DE_ASSERT(false);
873 
874         {
875             const glw::GLenum err = gl.glGetError();
876             if (err != GL_NO_ERROR)
877             {
878                 gl.getLog() << tcu::TestLog::Message
879                             << "Texture specification failed, got " + glu::getErrorStr(err).toString()
880                             << tcu::TestLog::EndMessage;
881                 allOk = false;
882             }
883         }
884     }
885 
886     return allOk;
887 }
888 
889 class TextureLevelCase : public TestCase
890 {
891 public:
892     TextureLevelCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type);
893     ~TextureLevelCase(void);
894 
895     void init(void);
896     void deinit(void);
897     IterateResult iterate(void);
898 
899 protected:
900     void getFormatSamples(glw::GLenum internalFormat, std::vector<int> &samples);
901     bool testConfig(const TextureGenerationSpec &spec);
902     virtual bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec) = 0;
903     virtual void generateTestIterations(std::vector<TextureGenerationSpec> &iterations)        = 0;
904 
905     const QueryType m_type;
906     const glw::GLenum m_target;
907     glw::GLuint m_texture;
908     glw::GLuint m_texBuffer;
909 
910 private:
911     int m_iteration;
912     std::vector<TextureGenerationSpec> m_iterations;
913     bool m_allIterationsOk;
914     std::vector<int> m_failedIterations;
915 };
916 
TextureLevelCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)917 TextureLevelCase::TextureLevelCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
918     : TestCase(ctx, name, desc)
919     , m_type(type)
920     , m_target(target)
921     , m_texture(0)
922     , m_texBuffer(0)
923     , m_iteration(0)
924     , m_allIterationsOk(true)
925 {
926 }
927 
~TextureLevelCase(void)928 TextureLevelCase::~TextureLevelCase(void)
929 {
930     deinit();
931 }
932 
init(void)933 void TextureLevelCase::init(void)
934 {
935     if (!isCoreTextureTarget(m_target, m_context.getRenderContext().getType()))
936     {
937         const char *const targetExtension = getTextureTargetExtension(m_target);
938 
939         if (!m_context.getContextInfo().isExtensionSupported(targetExtension))
940             throw tcu::NotSupportedError("Test requires " + std::string(targetExtension) + " extension");
941     }
942 
943     generateTestIterations(m_iterations);
944 
945     for (int iterationNdx = 0; iterationNdx < (int)m_iterations.size(); ++iterationNdx)
946         DE_ASSERT(m_iterations[iterationNdx].bindTarget == m_target);
947 }
948 
deinit(void)949 void TextureLevelCase::deinit(void)
950 {
951     if (m_texture)
952     {
953         m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texture);
954         m_texture = 0;
955     }
956     if (m_texBuffer)
957     {
958         m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texBuffer);
959         m_texBuffer = 0;
960     }
961 }
962 
getFormatSamples(glw::GLenum internalFormat,std::vector<int> & samples)963 void TextureLevelCase::getFormatSamples(glw::GLenum internalFormat, std::vector<int> &samples)
964 {
965     const glw::Functions gl = m_context.getRenderContext().getFunctions();
966     int sampleCount         = -1;
967 
968     if (!isMultisampleTarget(m_target))
969         return;
970 
971     gl.getInternalformativ(m_target, internalFormat, GL_NUM_SAMPLE_COUNTS, 1, &sampleCount);
972 
973     if (sampleCount < 0)
974         throw tcu::TestError("internal format query failed");
975 
976     samples.resize(sampleCount);
977 
978     if (sampleCount > 0)
979     {
980         gl.getInternalformativ(m_target, internalFormat, GL_SAMPLES, sampleCount, &samples[0]);
981         GLU_EXPECT_NO_ERROR(gl.getError(), "get max samples");
982     }
983 }
984 
iterate(void)985 TextureLevelCase::IterateResult TextureLevelCase::iterate(void)
986 {
987     const bool result = testConfig(m_iterations[m_iteration]);
988 
989     if (!result)
990     {
991         m_failedIterations.push_back(m_iteration);
992         m_allIterationsOk = false;
993     }
994 
995     if (++m_iteration < (int)m_iterations.size())
996         return CONTINUE;
997 
998     if (m_allIterationsOk)
999         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1000     else
1001     {
1002         tcu::MessageBuilder msg(&m_testCtx.getLog());
1003 
1004         msg << "Following iteration(s) failed: ";
1005         for (int ndx = 0; ndx < (int)m_failedIterations.size(); ++ndx)
1006         {
1007             if (ndx)
1008                 msg << ", ";
1009             msg << (m_failedIterations[ndx] + 1);
1010         }
1011         msg << tcu::TestLog::EndMessage;
1012 
1013         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "One or more iterations failed");
1014     }
1015     return STOP;
1016 }
1017 
testConfig(const TextureGenerationSpec & spec)1018 bool TextureLevelCase::testConfig(const TextureGenerationSpec &spec)
1019 {
1020     const tcu::ScopedLogSection section(m_testCtx.getLog(), "Iteration",
1021                                         std::string() + "Iteration " + de::toString(m_iteration + 1) + "/" +
1022                                             de::toString((int)m_iterations.size()) + " - " + spec.description);
1023     glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
1024     bool result;
1025 
1026     gl.enableLogging(true);
1027 
1028     gl.glGenTextures(1, &m_texture);
1029     gl.glBindTexture(spec.bindTarget, m_texture);
1030     GLU_EXPECT_NO_ERROR(gl.glGetError(), "gen tex");
1031 
1032     // Set the state
1033     applyTextureGenerationSpec(gl, spec, m_texBuffer);
1034 
1035     // Verify the state
1036     result = checkTextureState(gl, spec);
1037 
1038     gl.glDeleteTextures(1, &m_texture);
1039     m_texture = 0;
1040 
1041     if (m_texBuffer)
1042     {
1043         gl.glDeleteBuffers(1, &m_texBuffer);
1044         m_texture = 0;
1045     }
1046 
1047     return result;
1048 }
1049 
1050 /*--------------------------------------------------------------------*//*!
1051  * \brief Test texture target
1052  *//*--------------------------------------------------------------------*/
1053 class TextureLevelCommonCase : public TextureLevelCase
1054 {
1055 public:
1056     TextureLevelCommonCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type);
1057 
1058 protected:
1059     virtual void generateTestIterations(std::vector<TextureGenerationSpec> &iterations);
1060 };
1061 
TextureLevelCommonCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1062 TextureLevelCommonCase::TextureLevelCommonCase(Context &ctx, const char *name, const char *desc, glw::GLenum target,
1063                                                QueryType type)
1064     : TextureLevelCase(ctx, name, desc, target, type)
1065 {
1066 }
1067 
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1068 void TextureLevelCommonCase::generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1069 {
1070     const glw::GLenum internalFormat = GL_RGBA8;
1071     int maxSamples;
1072     std::vector<int> samples;
1073 
1074     getFormatSamples(internalFormat, samples);
1075     if (samples.empty())
1076         maxSamples = -1;
1077     else
1078         maxSamples = samples[0];
1079 
1080     generateColorTextureGenerationGroup(iterations, m_target, maxSamples, internalFormat);
1081 }
1082 
1083 class TextureLevelSampleCase : public TextureLevelCommonCase
1084 {
1085 public:
TextureLevelSampleCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1086     TextureLevelSampleCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1087         : TextureLevelCommonCase(ctx, name, desc, target, type)
1088     {
1089     }
1090 
1091 private:
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1092     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1093     {
1094         const int queryLevel = (spec.levels.empty()) ? (0) : (spec.levels[0].level);
1095         const int refValue   = (spec.levels.empty()) ? (0) : (spec.sampleCount);
1096 
1097         return verifyTextureLevelParameterGreaterOrEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_SAMPLES, refValue,
1098                                                          m_type);
1099     }
1100 };
1101 
1102 class TextureLevelFixedSamplesCase : public TextureLevelCommonCase
1103 {
1104 public:
TextureLevelFixedSamplesCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1105     TextureLevelFixedSamplesCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1106         : TextureLevelCommonCase(ctx, name, desc, target, type)
1107     {
1108     }
1109 
1110 private:
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1111     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1112     {
1113         const int queryLevel = (spec.levels.empty()) ? (0) : (spec.levels[0].level);
1114         const int refValue   = (spec.levels.empty()) ? (1) : ((spec.fixedSamplePos) ? (1) : (0));
1115 
1116         return verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_FIXED_SAMPLE_LOCATIONS,
1117                                                 refValue, m_type);
1118     }
1119 };
1120 
1121 class TextureLevelWidthCase : public TextureLevelCommonCase
1122 {
1123 public:
TextureLevelWidthCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1124     TextureLevelWidthCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1125         : TextureLevelCommonCase(ctx, name, desc, target, type)
1126     {
1127     }
1128 
1129 private:
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1130     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1131     {
1132         const int initialValue = 0;
1133         bool allOk             = true;
1134 
1135         if (spec.levels.empty())
1136         {
1137             const int queryLevel = 0;
1138             const int refValue   = initialValue;
1139 
1140             allOk &=
1141                 verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_WIDTH, refValue, m_type);
1142         }
1143         else
1144         {
1145             for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1146             {
1147                 const int queryLevel = spec.levels[levelNdx].level;
1148                 const int refValue   = spec.levels[levelNdx].width;
1149 
1150                 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_WIDTH, refValue,
1151                                                           m_type);
1152             }
1153         }
1154 
1155         return allOk;
1156     }
1157 };
1158 
1159 class TextureLevelHeightCase : public TextureLevelCommonCase
1160 {
1161 public:
TextureLevelHeightCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1162     TextureLevelHeightCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1163         : TextureLevelCommonCase(ctx, name, desc, target, type)
1164     {
1165     }
1166 
1167 private:
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1168     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1169     {
1170         const int initialValue = 0;
1171         bool allOk             = true;
1172 
1173         if (spec.levels.empty())
1174         {
1175             const int queryLevel = 0;
1176             const int refValue   = initialValue;
1177 
1178             allOk &=
1179                 verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_HEIGHT, refValue, m_type);
1180         }
1181         else
1182         {
1183             for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1184             {
1185                 const int queryLevel = spec.levels[levelNdx].level;
1186                 const int refValue   = spec.levels[levelNdx].height;
1187 
1188                 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_HEIGHT, refValue,
1189                                                           m_type);
1190             }
1191         }
1192 
1193         return allOk;
1194     }
1195 };
1196 
1197 class TextureLevelDepthCase : public TextureLevelCommonCase
1198 {
1199 public:
TextureLevelDepthCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1200     TextureLevelDepthCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1201         : TextureLevelCommonCase(ctx, name, desc, target, type)
1202     {
1203     }
1204 
1205 private:
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1206     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1207     {
1208         const int initialValue = 0;
1209         bool allOk             = true;
1210 
1211         if (spec.levels.empty())
1212         {
1213             const int queryLevel = 0;
1214             const int refValue   = initialValue;
1215 
1216             allOk &=
1217                 verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_DEPTH, refValue, m_type);
1218         }
1219         else
1220         {
1221             for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1222             {
1223                 const int queryLevel = spec.levels[levelNdx].level;
1224                 const int refValue   = spec.levels[levelNdx].depth;
1225 
1226                 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_DEPTH, refValue,
1227                                                           m_type);
1228             }
1229         }
1230 
1231         return allOk;
1232     }
1233 };
1234 
1235 class TextureLevelInternalFormatCase : public TextureLevelCase
1236 {
1237 public:
TextureLevelInternalFormatCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1238     TextureLevelInternalFormatCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1239         : TextureLevelCase(ctx, name, desc, target, type)
1240     {
1241     }
1242 
1243 private:
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1244     void generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1245     {
1246         generateInternalFormatTextureGenerationGroup(iterations, m_target);
1247     }
1248 
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1249     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1250     {
1251         bool allOk = true;
1252 
1253         if (spec.levels.empty())
1254         {
1255             const int queryLevel       = 0;
1256             const int initialValues[2] = {GL_RGBA, GL_R8};
1257 
1258             allOk &= verifyTextureLevelParameterInternalFormatAnyOf(gl, spec.queryTarget, queryLevel,
1259                                                                     GL_TEXTURE_INTERNAL_FORMAT, initialValues,
1260                                                                     DE_LENGTH_OF_ARRAY(initialValues), m_type);
1261         }
1262         else
1263         {
1264             for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1265             {
1266                 const int queryLevel = spec.levels[levelNdx].level;
1267                 const int refValue   = spec.levels[levelNdx].internalFormat;
1268 
1269                 allOk &= verifyTextureLevelParameterInternalFormatEqual(gl, spec.queryTarget, queryLevel,
1270                                                                         GL_TEXTURE_INTERNAL_FORMAT, refValue, m_type);
1271             }
1272         }
1273 
1274         return allOk;
1275     }
1276 };
1277 
1278 class TextureLevelSizeCase : public TextureLevelCase
1279 {
1280 public:
1281     TextureLevelSizeCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type,
1282                          glw::GLenum pname);
1283 
1284 private:
1285     void generateTestIterations(std::vector<TextureGenerationSpec> &iterations);
1286     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec);
1287     int getMinimumComponentResolution(glw::GLenum internalFormat);
1288 
1289     const glw::GLenum m_pname;
1290 };
1291 
TextureLevelSizeCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type,glw::GLenum pname)1292 TextureLevelSizeCase::TextureLevelSizeCase(Context &ctx, const char *name, const char *desc, glw::GLenum target,
1293                                            QueryType type, glw::GLenum pname)
1294     : TextureLevelCase(ctx, name, desc, target, type)
1295     , m_pname(pname)
1296 {
1297 }
1298 
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1299 void TextureLevelSizeCase::generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1300 {
1301     generateInternalFormatTextureGenerationGroup(iterations, m_target);
1302 }
1303 
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1304 bool TextureLevelSizeCase::checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1305 {
1306     bool allOk = true;
1307 
1308     if (spec.levels.empty())
1309     {
1310         allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, m_pname, 0, m_type);
1311     }
1312     else
1313     {
1314         for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1315         {
1316             const int queryLevel = spec.levels[levelNdx].level;
1317             const int refValue   = getMinimumComponentResolution(spec.levels[levelNdx].internalFormat);
1318 
1319             allOk &=
1320                 verifyTextureLevelParameterGreaterOrEqual(gl, spec.queryTarget, queryLevel, m_pname, refValue, m_type);
1321         }
1322     }
1323 
1324     return allOk;
1325 }
1326 
getMinimumComponentResolution(glw::GLenum internalFormat)1327 int TextureLevelSizeCase::getMinimumComponentResolution(glw::GLenum internalFormat)
1328 {
1329     const tcu::TextureFormat format  = glu::mapGLInternalFormat(internalFormat);
1330     const tcu::IVec4 channelBitDepth = tcu::getTextureFormatBitDepth(format);
1331 
1332     switch (m_pname)
1333     {
1334     case GL_TEXTURE_RED_SIZE:
1335         if (format.order == tcu::TextureFormat::R || format.order == tcu::TextureFormat::RG ||
1336             format.order == tcu::TextureFormat::RGB || format.order == tcu::TextureFormat::RGBA ||
1337             format.order == tcu::TextureFormat::BGRA || format.order == tcu::TextureFormat::ARGB ||
1338             format.order == tcu::TextureFormat::sRGB || format.order == tcu::TextureFormat::sRGBA)
1339             return channelBitDepth[0];
1340         else
1341             return 0;
1342 
1343     case GL_TEXTURE_GREEN_SIZE:
1344         if (format.order == tcu::TextureFormat::RG || format.order == tcu::TextureFormat::RGB ||
1345             format.order == tcu::TextureFormat::RGBA || format.order == tcu::TextureFormat::BGRA ||
1346             format.order == tcu::TextureFormat::ARGB || format.order == tcu::TextureFormat::sRGB ||
1347             format.order == tcu::TextureFormat::sRGBA)
1348             return channelBitDepth[1];
1349         else
1350             return 0;
1351 
1352     case GL_TEXTURE_BLUE_SIZE:
1353         if (format.order == tcu::TextureFormat::RGB || format.order == tcu::TextureFormat::RGBA ||
1354             format.order == tcu::TextureFormat::BGRA || format.order == tcu::TextureFormat::ARGB ||
1355             format.order == tcu::TextureFormat::sRGB || format.order == tcu::TextureFormat::sRGBA)
1356             return channelBitDepth[2];
1357         else
1358             return 0;
1359 
1360     case GL_TEXTURE_ALPHA_SIZE:
1361         if (format.order == tcu::TextureFormat::RGBA || format.order == tcu::TextureFormat::BGRA ||
1362             format.order == tcu::TextureFormat::ARGB || format.order == tcu::TextureFormat::sRGBA)
1363             return channelBitDepth[3];
1364         else
1365             return 0;
1366 
1367     case GL_TEXTURE_DEPTH_SIZE:
1368         if (format.order == tcu::TextureFormat::D || format.order == tcu::TextureFormat::DS)
1369             return channelBitDepth[0];
1370         else
1371             return 0;
1372 
1373     case GL_TEXTURE_STENCIL_SIZE:
1374         if (format.order == tcu::TextureFormat::DS)
1375             return channelBitDepth[3];
1376         else
1377             return 0;
1378 
1379     case GL_TEXTURE_SHARED_SIZE:
1380         if (internalFormat == GL_RGB9_E5)
1381             return 5;
1382         else
1383             return 0;
1384     default:
1385         DE_ASSERT(false);
1386         return 0;
1387     }
1388 }
1389 
1390 class TextureLevelTypeCase : public TextureLevelCase
1391 {
1392 public:
1393     TextureLevelTypeCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type,
1394                          glw::GLenum pname);
1395 
1396 private:
1397     void generateTestIterations(std::vector<TextureGenerationSpec> &iterations);
1398     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec);
1399     int getComponentType(glw::GLenum internalFormat);
1400 
1401     const glw::GLenum m_pname;
1402 };
1403 
TextureLevelTypeCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type,glw::GLenum pname)1404 TextureLevelTypeCase::TextureLevelTypeCase(Context &ctx, const char *name, const char *desc, glw::GLenum target,
1405                                            QueryType type, glw::GLenum pname)
1406     : TextureLevelCase(ctx, name, desc, target, type)
1407     , m_pname(pname)
1408 {
1409 }
1410 
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1411 void TextureLevelTypeCase::generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1412 {
1413     generateInternalFormatTextureGenerationGroup(iterations, m_target);
1414 }
1415 
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1416 bool TextureLevelTypeCase::checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1417 {
1418     bool allOk = true;
1419 
1420     if (spec.levels.empty())
1421     {
1422         allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, m_pname, GL_NONE, m_type);
1423     }
1424     else
1425     {
1426         for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1427         {
1428             const int queryLevel = spec.levels[levelNdx].level;
1429             const int refValue   = getComponentType(spec.levels[levelNdx].internalFormat);
1430 
1431             allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, m_pname, refValue, m_type);
1432         }
1433     }
1434 
1435     return allOk;
1436 }
1437 
getComponentType(glw::GLenum internalFormat)1438 int TextureLevelTypeCase::getComponentType(glw::GLenum internalFormat)
1439 {
1440     const tcu::TextureFormat format             = glu::mapGLInternalFormat(internalFormat);
1441     const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
1442     glw::GLenum channelType                     = GL_NONE;
1443 
1444     // depth-stencil special cases
1445     if (format.type == tcu::TextureFormat::UNSIGNED_INT_24_8)
1446     {
1447         if (m_pname == GL_TEXTURE_DEPTH_TYPE)
1448             return GL_UNSIGNED_NORMALIZED;
1449         else
1450             return GL_NONE;
1451     }
1452     else if (format.type == tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV)
1453     {
1454         if (m_pname == GL_TEXTURE_DEPTH_TYPE)
1455             return GL_FLOAT;
1456         else
1457             return GL_NONE;
1458     }
1459     else
1460     {
1461         switch (channelClass)
1462         {
1463         case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1464             channelType = GL_SIGNED_NORMALIZED;
1465             break;
1466         case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1467             channelType = GL_UNSIGNED_NORMALIZED;
1468             break;
1469         case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1470             channelType = GL_INT;
1471             break;
1472         case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1473             channelType = GL_UNSIGNED_INT;
1474             break;
1475         case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1476             channelType = GL_FLOAT;
1477             break;
1478         default:
1479             DE_ASSERT(false);
1480         }
1481     }
1482 
1483     switch (m_pname)
1484     {
1485     case GL_TEXTURE_RED_TYPE:
1486         if (format.order == tcu::TextureFormat::R || format.order == tcu::TextureFormat::RG ||
1487             format.order == tcu::TextureFormat::RGB || format.order == tcu::TextureFormat::RGBA ||
1488             format.order == tcu::TextureFormat::BGRA || format.order == tcu::TextureFormat::ARGB ||
1489             format.order == tcu::TextureFormat::sRGB || format.order == tcu::TextureFormat::sRGBA)
1490             return channelType;
1491         else
1492             return GL_NONE;
1493 
1494     case GL_TEXTURE_GREEN_TYPE:
1495         if (format.order == tcu::TextureFormat::RG || format.order == tcu::TextureFormat::RGB ||
1496             format.order == tcu::TextureFormat::RGBA || format.order == tcu::TextureFormat::BGRA ||
1497             format.order == tcu::TextureFormat::ARGB || format.order == tcu::TextureFormat::sRGB ||
1498             format.order == tcu::TextureFormat::sRGBA)
1499             return channelType;
1500         else
1501             return GL_NONE;
1502 
1503     case GL_TEXTURE_BLUE_TYPE:
1504         if (format.order == tcu::TextureFormat::RGB || format.order == tcu::TextureFormat::RGBA ||
1505             format.order == tcu::TextureFormat::BGRA || format.order == tcu::TextureFormat::ARGB ||
1506             format.order == tcu::TextureFormat::sRGB || format.order == tcu::TextureFormat::sRGBA)
1507             return channelType;
1508         else
1509             return GL_NONE;
1510 
1511     case GL_TEXTURE_ALPHA_TYPE:
1512         if (format.order == tcu::TextureFormat::RGBA || format.order == tcu::TextureFormat::BGRA ||
1513             format.order == tcu::TextureFormat::ARGB || format.order == tcu::TextureFormat::sRGBA)
1514             return channelType;
1515         else
1516             return GL_NONE;
1517 
1518     case GL_TEXTURE_DEPTH_TYPE:
1519         if (format.order == tcu::TextureFormat::D || format.order == tcu::TextureFormat::DS)
1520             return channelType;
1521         else
1522             return GL_NONE;
1523 
1524     default:
1525         DE_ASSERT(false);
1526         return 0;
1527     }
1528 }
1529 
1530 class TextureLevelCompressedCase : public TextureLevelCase
1531 {
1532 public:
TextureLevelCompressedCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1533     TextureLevelCompressedCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1534         : TextureLevelCase(ctx, name, desc, target, type)
1535     {
1536     }
1537 
1538 private:
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1539     void generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1540     {
1541         generateCompressedTextureGenerationGroup(iterations, m_target);
1542     }
1543 
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1544     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1545     {
1546         bool allOk = true;
1547 
1548         if (spec.levels.empty())
1549         {
1550             allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_COMPRESSED, 0, m_type);
1551         }
1552         else
1553         {
1554             for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1555             {
1556                 const int queryLevel = spec.levels[levelNdx].level;
1557                 const int refValue   = (spec.levels[levelNdx].compressed) ? (1) : (0);
1558 
1559                 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_COMPRESSED,
1560                                                           refValue, m_type);
1561             }
1562         }
1563 
1564         return allOk;
1565     }
1566 };
1567 
checkSupport(Context & ctx)1568 static bool checkSupport(Context &ctx)
1569 {
1570     auto ctxType = ctx.getRenderContext().getType();
1571     return contextSupports(ctxType, glu::ApiType::es(3, 2)) || contextSupports(ctxType, glu::ApiType::core(4, 5)) ||
1572            ctx.getContextInfo().isExtensionSupported("GL_EXT_texture_buffer");
1573 }
1574 
1575 class TextureLevelBufferDataStoreCase : public TextureLevelCase
1576 {
1577 public:
TextureLevelBufferDataStoreCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1578     TextureLevelBufferDataStoreCase(Context &ctx, const char *name, const char *desc, glw::GLenum target,
1579                                     QueryType type)
1580         : TextureLevelCase(ctx, name, desc, target, type)
1581     {
1582     }
1583 
1584 private:
init(void)1585     void init(void)
1586     {
1587         if (!checkSupport(m_context))
1588             throw tcu::NotSupportedError("Test requires GL_EXT_texture_buffer extension");
1589         TextureLevelCase::init();
1590     }
1591 
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1592     void generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1593     {
1594         generateTextureBufferGenerationGroup(iterations, m_target);
1595     }
1596 
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1597     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1598     {
1599         bool allOk = true;
1600 
1601         if (spec.levels.empty())
1602         {
1603             allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_DATA_STORE_BINDING, 0,
1604                                                       m_type);
1605         }
1606         else
1607         {
1608             allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_DATA_STORE_BINDING,
1609                                                       m_texBuffer, m_type);
1610         }
1611 
1612         return allOk;
1613     }
1614 };
1615 
1616 class TextureLevelBufferDataOffsetCase : public TextureLevelCase
1617 {
1618 public:
TextureLevelBufferDataOffsetCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1619     TextureLevelBufferDataOffsetCase(Context &ctx, const char *name, const char *desc, glw::GLenum target,
1620                                      QueryType type)
1621         : TextureLevelCase(ctx, name, desc, target, type)
1622     {
1623     }
1624 
1625 private:
init(void)1626     void init(void)
1627     {
1628         if (!checkSupport(m_context))
1629             throw tcu::NotSupportedError("Test requires GL_EXT_texture_buffer extension");
1630         TextureLevelCase::init();
1631     }
1632 
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1633     void generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1634     {
1635         generateTextureBufferGenerationGroup(iterations, m_target);
1636     }
1637 
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1638     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1639     {
1640         bool allOk = true;
1641 
1642         if (spec.levels.empty())
1643         {
1644             allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_OFFSET, 0, m_type);
1645         }
1646         else
1647         {
1648             const int refValue = spec.texBufferDataOffset;
1649 
1650             allOk &=
1651                 verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_OFFSET, refValue, m_type);
1652         }
1653 
1654         return allOk;
1655     }
1656 };
1657 
1658 class TextureLevelBufferDataSizeCase : public TextureLevelCase
1659 {
1660 public:
TextureLevelBufferDataSizeCase(Context & ctx,const char * name,const char * desc,glw::GLenum target,QueryType type)1661     TextureLevelBufferDataSizeCase(Context &ctx, const char *name, const char *desc, glw::GLenum target, QueryType type)
1662         : TextureLevelCase(ctx, name, desc, target, type)
1663     {
1664     }
1665 
1666 private:
init(void)1667     void init(void)
1668     {
1669         if (!checkSupport(m_context))
1670             throw tcu::NotSupportedError("Test requires GL_EXT_texture_buffer extension");
1671         TextureLevelCase::init();
1672     }
1673 
generateTestIterations(std::vector<TextureGenerationSpec> & iterations)1674     void generateTestIterations(std::vector<TextureGenerationSpec> &iterations)
1675     {
1676         generateTextureBufferGenerationGroup(iterations, m_target);
1677     }
1678 
checkTextureState(glu::CallLogWrapper & gl,const TextureGenerationSpec & spec)1679     bool checkTextureState(glu::CallLogWrapper &gl, const TextureGenerationSpec &spec)
1680     {
1681         bool allOk = true;
1682 
1683         if (spec.levels.empty())
1684         {
1685             allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_SIZE, 0, m_type);
1686         }
1687         else
1688         {
1689             const int refValue = spec.texBufferDataSize;
1690 
1691             allOk &=
1692                 verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_SIZE, refValue, m_type);
1693         }
1694 
1695         return allOk;
1696     }
1697 };
1698 
1699 } // namespace
1700 
getVerifierSuffix(QueryType type)1701 static const char *getVerifierSuffix(QueryType type)
1702 {
1703     switch (type)
1704     {
1705     case QUERY_TEXTURE_LEVEL_FLOAT:
1706         return "_float";
1707     case QUERY_TEXTURE_LEVEL_INTEGER:
1708         return "_integer";
1709     default:
1710         DE_ASSERT(false);
1711         return DE_NULL;
1712     }
1713 }
1714 
TextureLevelStateQueryTests(Context & context)1715 TextureLevelStateQueryTests::TextureLevelStateQueryTests(Context &context)
1716     : TestCaseGroup(context, "texture_level", "GetTexLevelParameter tests")
1717 {
1718 }
1719 
~TextureLevelStateQueryTests(void)1720 TextureLevelStateQueryTests::~TextureLevelStateQueryTests(void)
1721 {
1722 }
1723 
init(void)1724 void TextureLevelStateQueryTests::init(void)
1725 {
1726     static const QueryType verifiers[] = {
1727         QUERY_TEXTURE_LEVEL_INTEGER,
1728         QUERY_TEXTURE_LEVEL_FLOAT,
1729     };
1730 
1731 #define FOR_EACH_VERIFIER(X)                                                                  \
1732     do                                                                                        \
1733     {                                                                                         \
1734         for (int verifierNdx = 0; verifierNdx < DE_LENGTH_OF_ARRAY(verifiers); ++verifierNdx) \
1735         {                                                                                     \
1736             const std::string verifierSuffix = getVerifierSuffix(verifiers[verifierNdx]);     \
1737             const QueryType verifier         = verifiers[verifierNdx];                        \
1738             targetGroup->addChild(X);                                                         \
1739         }                                                                                     \
1740     } while (0)
1741 
1742     static const struct
1743     {
1744         const char *name;
1745         glw::GLenum target;
1746     } textureTargets[] = {
1747         {
1748             "texture_2d",
1749             GL_TEXTURE_2D,
1750         },
1751         {
1752             "texture_3d",
1753             GL_TEXTURE_3D,
1754         },
1755         {
1756             "texture_2d_array",
1757             GL_TEXTURE_2D_ARRAY,
1758         },
1759         {
1760             "texture_cube_map",
1761             GL_TEXTURE_CUBE_MAP,
1762         },
1763         {
1764             "texture_2d_multisample",
1765             GL_TEXTURE_2D_MULTISAMPLE,
1766         },
1767         {
1768             "texture_2d_multisample_array",
1769             GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
1770         }, // GL_OES_texture_storage_multisample_2d_array
1771         {
1772             "texture_buffer",
1773             GL_TEXTURE_BUFFER,
1774         }, // GL_EXT_texture_buffer
1775         {
1776             "texture_cube_array",
1777             GL_TEXTURE_CUBE_MAP_ARRAY,
1778         }, // GL_EXT_texture_cube_map_array
1779     };
1780 
1781     for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(textureTargets); ++targetNdx)
1782     {
1783         tcu::TestCaseGroup *const targetGroup =
1784             new tcu::TestCaseGroup(m_testCtx, textureTargets[targetNdx].name, textureTargets[targetNdx].name);
1785         addChild(targetGroup);
1786 
1787         FOR_EACH_VERIFIER(new TextureLevelSampleCase(m_context, ("samples" + verifierSuffix).c_str(),
1788                                                      "Verify TEXTURE_SAMPLES", textureTargets[targetNdx].target,
1789                                                      verifier));
1790         FOR_EACH_VERIFIER(new TextureLevelFixedSamplesCase(
1791             m_context, ("fixed_sample_locations" + verifierSuffix).c_str(), "Verify TEXTURE_FIXED_SAMPLE_LOCATIONS",
1792             textureTargets[targetNdx].target, verifier));
1793         FOR_EACH_VERIFIER(new TextureLevelWidthCase(m_context, ("width" + verifierSuffix).c_str(),
1794                                                     "Verify TEXTURE_WIDTH", textureTargets[targetNdx].target,
1795                                                     verifier));
1796         FOR_EACH_VERIFIER(new TextureLevelHeightCase(m_context, ("height" + verifierSuffix).c_str(),
1797                                                      "Verify TEXTURE_HEIGHT", textureTargets[targetNdx].target,
1798                                                      verifier));
1799         FOR_EACH_VERIFIER(new TextureLevelDepthCase(m_context, ("depth" + verifierSuffix).c_str(),
1800                                                     "Verify TEXTURE_DEPTH", textureTargets[targetNdx].target,
1801                                                     verifier));
1802         FOR_EACH_VERIFIER(new TextureLevelInternalFormatCase(m_context, ("internal_format" + verifierSuffix).c_str(),
1803                                                              "Verify TEXTURE_INTERNAL_FORMAT",
1804                                                              textureTargets[targetNdx].target, verifier));
1805         FOR_EACH_VERIFIER(new TextureLevelSizeCase(m_context, ("red_size" + verifierSuffix).c_str(),
1806                                                    "Verify TEXTURE_RED_SIZE", textureTargets[targetNdx].target,
1807                                                    verifier, GL_TEXTURE_RED_SIZE));
1808         FOR_EACH_VERIFIER(new TextureLevelSizeCase(m_context, ("green_size" + verifierSuffix).c_str(),
1809                                                    "Verify TEXTURE_GREEN_SIZE", textureTargets[targetNdx].target,
1810                                                    verifier, GL_TEXTURE_GREEN_SIZE));
1811         FOR_EACH_VERIFIER(new TextureLevelSizeCase(m_context, ("blue_size" + verifierSuffix).c_str(),
1812                                                    "Verify TEXTURE_BLUE_SIZE", textureTargets[targetNdx].target,
1813                                                    verifier, GL_TEXTURE_BLUE_SIZE));
1814         FOR_EACH_VERIFIER(new TextureLevelSizeCase(m_context, ("alpha_size" + verifierSuffix).c_str(),
1815                                                    "Verify TEXTURE_ALPHA_SIZE", textureTargets[targetNdx].target,
1816                                                    verifier, GL_TEXTURE_ALPHA_SIZE));
1817         FOR_EACH_VERIFIER(new TextureLevelSizeCase(m_context, ("depth_size" + verifierSuffix).c_str(),
1818                                                    "Verify TEXTURE_DEPTH_SIZE", textureTargets[targetNdx].target,
1819                                                    verifier, GL_TEXTURE_DEPTH_SIZE));
1820         FOR_EACH_VERIFIER(new TextureLevelSizeCase(m_context, ("stencil_size" + verifierSuffix).c_str(),
1821                                                    "Verify TEXTURE_STENCIL_SIZE", textureTargets[targetNdx].target,
1822                                                    verifier, GL_TEXTURE_STENCIL_SIZE));
1823         FOR_EACH_VERIFIER(new TextureLevelSizeCase(m_context, ("shared_size" + verifierSuffix).c_str(),
1824                                                    "Verify TEXTURE_SHARED_SIZE", textureTargets[targetNdx].target,
1825                                                    verifier, GL_TEXTURE_SHARED_SIZE));
1826         FOR_EACH_VERIFIER(new TextureLevelTypeCase(m_context, ("red_type" + verifierSuffix).c_str(),
1827                                                    "Verify TEXTURE_RED_TYPE", textureTargets[targetNdx].target,
1828                                                    verifier, GL_TEXTURE_RED_TYPE));
1829         FOR_EACH_VERIFIER(new TextureLevelTypeCase(m_context, ("green_type" + verifierSuffix).c_str(),
1830                                                    "Verify TEXTURE_GREEN_TYPE", textureTargets[targetNdx].target,
1831                                                    verifier, GL_TEXTURE_GREEN_TYPE));
1832         FOR_EACH_VERIFIER(new TextureLevelTypeCase(m_context, ("blue_type" + verifierSuffix).c_str(),
1833                                                    "Verify TEXTURE_BLUE_TYPE", textureTargets[targetNdx].target,
1834                                                    verifier, GL_TEXTURE_BLUE_TYPE));
1835         FOR_EACH_VERIFIER(new TextureLevelTypeCase(m_context, ("alpha_type" + verifierSuffix).c_str(),
1836                                                    "Verify TEXTURE_ALPHA_TYPE", textureTargets[targetNdx].target,
1837                                                    verifier, GL_TEXTURE_ALPHA_TYPE));
1838         FOR_EACH_VERIFIER(new TextureLevelTypeCase(m_context, ("depth_type" + verifierSuffix).c_str(),
1839                                                    "Verify TEXTURE_DEPTH_TYPE", textureTargets[targetNdx].target,
1840                                                    verifier, GL_TEXTURE_DEPTH_TYPE));
1841         FOR_EACH_VERIFIER(new TextureLevelCompressedCase(m_context, ("compressed" + verifierSuffix).c_str(),
1842                                                          "Verify TEXTURE_COMPRESSED", textureTargets[targetNdx].target,
1843                                                          verifier));
1844         FOR_EACH_VERIFIER(new TextureLevelBufferDataStoreCase(
1845             m_context, ("buffer_data_store_binding" + verifierSuffix).c_str(),
1846             "Verify TEXTURE_BUFFER_DATA_STORE_BINDING", textureTargets[targetNdx].target, verifier));
1847         FOR_EACH_VERIFIER(new TextureLevelBufferDataOffsetCase(m_context, ("buffer_offset" + verifierSuffix).c_str(),
1848                                                                "Verify TEXTURE_BUFFER_OFFSET",
1849                                                                textureTargets[targetNdx].target, verifier));
1850         FOR_EACH_VERIFIER(new TextureLevelBufferDataSizeCase(m_context, ("buffer_size" + verifierSuffix).c_str(),
1851                                                              "Verify TEXTURE_BUFFER_SIZE",
1852                                                              textureTargets[targetNdx].target, verifier));
1853     }
1854 
1855 #undef FOR_EACH_VERIFIER
1856 }
1857 
1858 } // namespace Functional
1859 } // namespace gles31
1860 } // namespace deqp
1861