Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / shaderrender / vktShaderRender.hpp
1 #ifndef _VKTSHADERRENDER_HPP
2 #define _VKTSHADERRENDER_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Vulkan ShaderRenderCase
25  *//*--------------------------------------------------------------------*/
26
27 #include "tcuTexture.hpp"
28 #include "tcuSurface.hpp"
29 #include "tcuMaybe.hpp"
30
31 #include "deMemory.h"
32 #include "deSharedPtr.hpp"
33 #include "deUniquePtr.hpp"
34
35 #include "vkDefs.hpp"
36 #include "vkRefUtil.hpp"
37 #include "vkPrograms.hpp"
38 #include "vkRef.hpp"
39 #include "vkMemUtil.hpp"
40 #include "vkBuilderUtil.hpp"
41 #include "vkTypeUtil.hpp"
42 #include "vkPlatform.hpp"
43
44 #include "vktTestCaseUtil.hpp"
45
46 namespace vkt
47 {
48 namespace sr
49 {
50
51 class LineStream
52 {
53 public:
54                                                 LineStream              (int indent = 0)        { m_indent = indent; }
55                                                 ~LineStream             (void)                          {}
56
57         const char*                     str                             (void) const            { m_string = m_stream.str(); return m_string.c_str(); }
58         LineStream&                     operator<<              (const char* line)      { for (int i = 0; i < m_indent; i++) { m_stream << "\t"; } m_stream << line << "\n"; return *this; }
59
60 private:
61         int                                     m_indent;
62         std::ostringstream      m_stream;
63         mutable std::string     m_string;
64 };
65
66 class QuadGrid;
67 class ShaderRenderCaseInstance;
68
69 class TextureBinding
70 {
71 public:
72         enum Type
73         {
74                 TYPE_NONE = 0,
75                 TYPE_1D,
76                 TYPE_2D,
77                 TYPE_3D,
78                 TYPE_CUBE_MAP,
79                 TYPE_1D_ARRAY,
80                 TYPE_2D_ARRAY,
81                 TYPE_CUBE_ARRAY,
82
83                 TYPE_LAST
84         };
85
86         enum Init
87         {
88                 INIT_UPLOAD_DATA,
89                 INIT_CLEAR,
90
91                 INIT_LAST
92         };
93
94         struct MinMaxLod
95         {
96                 float minLod;
97                 float maxLod;
98
99                 MinMaxLod (float min, float max) : minLod(min), maxLod(max) {}
100         };
101
102         struct Parameters
103         {
104                 deUint32                                        baseMipLevel;
105                 vk::VkComponentMapping          componentMapping;
106                 vk::VkSampleCountFlagBits       samples;
107                 Init                                            initialization;
108                 tcu::Maybe<MinMaxLod>           minMaxLod;
109
110                 Parameters (deUint32                                            baseMipLevel_           = 0,
111                                         vk::VkComponentMapping                  componentMapping_       = vk::makeComponentMappingRGBA(),
112                                         vk::VkSampleCountFlagBits               samples_                        = vk::VK_SAMPLE_COUNT_1_BIT,
113                                         Init                                                    initialization_         = INIT_UPLOAD_DATA,
114                                         const tcu::Maybe<MinMaxLod>&    minMaxLod_                      = tcu::Nothing)
115                         : baseMipLevel          (baseMipLevel_)
116                         , componentMapping      (componentMapping_)
117                         , samples                       (samples_)
118                         , initialization        (initialization_)
119                         , minMaxLod                     (minMaxLod_)
120                 {
121                 }
122         };
123
124                                                                                 TextureBinding          (const tcu::Archive&    archive,
125                                                                                                                         const char*                             filename,
126                                                                                                                         const Type                              type,
127                                                                                                                         const tcu::Sampler&             sampler);
128
129                                                                                 TextureBinding          (const tcu::Texture1D* tex1D, const tcu::Sampler& sampler);
130                                                                                 TextureBinding          (const tcu::Texture2D* tex2D, const tcu::Sampler& sampler);
131                                                                                 TextureBinding          (const tcu::Texture3D* tex3D, const tcu::Sampler& sampler);
132                                                                                 TextureBinding          (const tcu::TextureCube* texCube, const tcu::Sampler& sampler);
133                                                                                 TextureBinding          (const tcu::Texture1DArray* tex1DArray, const tcu::Sampler& sampler);
134                                                                                 TextureBinding          (const tcu::Texture2DArray* tex2DArray, const tcu::Sampler& sampler);
135                                                                                 TextureBinding          (const tcu::TextureCubeArray* texCubeArray, const tcu::Sampler& sampler);
136
137                                                                                 ~TextureBinding         (void);
138
139         Type                                                            getType                         (void) const { return m_type;           }
140         const tcu::Sampler&                                     getSampler                      (void) const { return m_sampler;        }
141
142         const tcu::Texture1D&                           get1D                           (void) const { DE_ASSERT(getType() == TYPE_1D && m_binding.tex1D != NULL);                                      return *m_binding.tex1D;                }
143         const tcu::Texture2D&                           get2D                           (void) const { DE_ASSERT(getType() == TYPE_2D && m_binding.tex2D != NULL);                                      return *m_binding.tex2D;                }
144         const tcu::Texture3D&                           get3D                           (void) const { DE_ASSERT(getType() == TYPE_3D && m_binding.tex3D != NULL);                                      return *m_binding.tex3D;                }
145         const tcu::TextureCube&                         getCube                         (void) const { DE_ASSERT(getType() == TYPE_CUBE_MAP && m_binding.texCube != NULL);                      return *m_binding.texCube;              }
146         const tcu::Texture1DArray&                      get1DArray                      (void) const { DE_ASSERT(getType() == TYPE_1D_ARRAY && m_binding.tex1DArray != NULL);           return *m_binding.tex1DArray;   }
147         const tcu::Texture2DArray&                      get2DArray                      (void) const { DE_ASSERT(getType() == TYPE_2D_ARRAY && m_binding.tex2DArray != NULL);           return *m_binding.tex2DArray;   }
148         const tcu::TextureCubeArray&            getCubeArray            (void) const { DE_ASSERT(getType() == TYPE_CUBE_ARRAY && m_binding.texCubeArray != NULL);       return *m_binding.texCubeArray; }
149
150         void                                                            setParameters           (const Parameters& params) { m_params = params; }
151         const Parameters&                                       getParameters           (void) const { return m_params; }
152
153 private:
154                                                                                 TextureBinding          (const TextureBinding&);        // not allowed!
155         TextureBinding&                                         operator=                       (const TextureBinding&);        // not allowed!
156
157         static de::MovePtr<tcu::Texture2D>      loadTexture2D           (const tcu::Archive& archive, const char* filename);
158
159         Type                                                            m_type;
160         tcu::Sampler                                            m_sampler;
161         Parameters                                                      m_params;
162
163         union
164         {
165                 const tcu::Texture1D*                   tex1D;
166                 const tcu::Texture2D*                   tex2D;
167                 const tcu::Texture3D*                   tex3D;
168                 const tcu::TextureCube*                 texCube;
169                 const tcu::Texture1DArray*              tex1DArray;
170                 const tcu::Texture2DArray*              tex2DArray;
171                 const tcu::TextureCubeArray*    texCubeArray;
172         } m_binding;
173 };
174
175 typedef de::SharedPtr<TextureBinding> TextureBindingSp;
176
177 // ShaderEvalContext.
178
179 class ShaderEvalContext
180 {
181 public:
182         // Limits.
183         enum
184         {
185                 MAX_USER_ATTRIBS        = 4,
186                 MAX_TEXTURES            = 4
187         };
188
189         struct ShaderSampler
190         {
191                 tcu::Sampler                                    sampler;
192                 const tcu::Texture1D*                   tex1D;
193                 const tcu::Texture2D*                   tex2D;
194                 const tcu::Texture3D*                   tex3D;
195                 const tcu::TextureCube*                 texCube;
196                 const tcu::Texture1DArray*              tex1DArray;
197                 const tcu::Texture2DArray*              tex2DArray;
198                 const tcu::TextureCubeArray*    texCubeArray;
199
200                 inline ShaderSampler (void)
201                         : tex1D                 (DE_NULL)
202                         , tex2D                 (DE_NULL)
203                         , tex3D                 (DE_NULL)
204                         , texCube               (DE_NULL)
205                         , tex1DArray    (DE_NULL)
206                         , tex2DArray    (DE_NULL)
207                         , texCubeArray  (DE_NULL)
208                 {
209                 }
210         };
211
212                                                         ShaderEvalContext               (const QuadGrid& quadGrid);
213                                                         ~ShaderEvalContext              (void);
214
215         void                                    reset                                   (float sx, float sy);
216
217         // Inputs.
218         tcu::Vec4                               coords;
219         tcu::Vec4                               unitCoords;
220         tcu::Vec4                               constCoords;
221
222         tcu::Vec4                               in[MAX_USER_ATTRIBS];
223         ShaderSampler                   textures[MAX_TEXTURES];
224
225         // Output.
226         tcu::Vec4                               color;
227         bool                                    isDiscarded;
228
229         // Functions.
230         inline void                             discard                                 (void)  { isDiscarded = true; }
231         tcu::Vec4                               texture2D                               (int unitNdx, const tcu::Vec2& coords);
232
233 private:
234         const QuadGrid&                 m_quadGrid;
235 };
236
237 typedef void (*ShaderEvalFunc) (ShaderEvalContext& c);
238
239 inline void evalCoordsPassthroughX              (ShaderEvalContext& c) { c.color.x() = c.coords.x(); }
240 inline void evalCoordsPassthroughXY             (ShaderEvalContext& c) { c.color.xy() = c.coords.swizzle(0,1); }
241 inline void evalCoordsPassthroughXYZ    (ShaderEvalContext& c) { c.color.xyz() = c.coords.swizzle(0,1,2); }
242 inline void evalCoordsPassthrough               (ShaderEvalContext& c) { c.color = c.coords; }
243 inline void evalCoordsSwizzleWZYX               (ShaderEvalContext& c) { c.color = c.coords.swizzle(3,2,1,0); }
244
245 // ShaderEvaluator
246 // Either inherit a class with overridden evaluate() or just pass in an evalFunc.
247
248 class ShaderEvaluator
249 {
250 public:
251                                                         ShaderEvaluator                 (void);
252                                                         ShaderEvaluator                 (const ShaderEvalFunc evalFunc);
253         virtual                                 ~ShaderEvaluator                (void);
254
255         virtual void                    evaluate                                (ShaderEvalContext& ctx) const;
256
257 private:
258                                                         ShaderEvaluator                 (const ShaderEvaluator&);   // not allowed!
259         ShaderEvaluator&                operator=                               (const ShaderEvaluator&);   // not allowed!
260
261         const ShaderEvalFunc    m_evalFunc;
262 };
263
264 // UniformSetup
265
266 typedef void (*UniformSetupFunc) (ShaderRenderCaseInstance& instance, const tcu::Vec4& constCoords);
267
268 class UniformSetup
269 {
270 public:
271                                                         UniformSetup                    (void);
272                                                         UniformSetup                    (const UniformSetupFunc setup);
273         virtual                                 ~UniformSetup                   (void);
274         virtual void                    setup                                   (ShaderRenderCaseInstance& instance, const tcu::Vec4& constCoords) const;
275
276 private:
277                                                         UniformSetup                    (const UniformSetup&);  // not allowed!
278         UniformSetup&                   operator=                               (const UniformSetup&);  // not allowed!
279
280         const UniformSetupFunc  m_setupFunc;
281 };
282
283 typedef void (*AttributeSetupFunc) (ShaderRenderCaseInstance& instance, deUint32 numVertices);
284
285 class ShaderRenderCase : public vkt::TestCase
286 {
287 public:
288                                                                                                         ShaderRenderCase        (tcu::TestContext&                      testCtx,
289                                                                                                                                                  const std::string&                     name,
290                                                                                                                                                  const std::string&                     description,
291                                                                                                                                                  const bool                                     isVertexCase,
292                                                                                                                                                  const ShaderEvalFunc           evalFunc,
293                                                                                                                                                  const UniformSetup*            uniformSetup,
294                                                                                                                                                  const AttributeSetupFunc       attribFunc);
295
296                                                                                                         ShaderRenderCase        (tcu::TestContext&                      testCtx,
297                                                                                                                                                  const std::string&                     name,
298                                                                                                                                                  const std::string&                     description,
299                                                                                                                                                  const bool                                     isVertexCase,
300                                                                                                                                                  const ShaderEvaluator*         evaluator,
301                                                                                                                                                  const UniformSetup*            uniformSetup,
302                                                                                                                                                  const AttributeSetupFunc       attribFunc);
303
304         virtual                                                                                 ~ShaderRenderCase       (void);
305         virtual void                                                                    initPrograms            (vk::SourceCollections& programCollection) const;
306         virtual TestInstance*                                                   createInstance          (Context& context) const;
307
308 protected:
309         std::string                                                                             m_vertShaderSource;
310         std::string                                                                             m_fragShaderSource;
311
312         const bool                                                                              m_isVertexCase;
313         const de::UniquePtr<const ShaderEvaluator>              m_evaluator;
314         const de::UniquePtr<const UniformSetup>                 m_uniformSetup;
315         const AttributeSetupFunc                                                m_attribFunc;
316 };
317
318 enum BaseUniformType
319 {
320 // Bool
321         UB_FALSE,
322         UB_TRUE,
323
324 // BVec4
325         UB4_FALSE,
326         UB4_TRUE,
327
328 // Integers
329         UI_ZERO,
330         UI_ONE,
331         UI_TWO,
332         UI_THREE,
333         UI_FOUR,
334         UI_FIVE,
335         UI_SIX,
336         UI_SEVEN,
337         UI_EIGHT,
338         UI_ONEHUNDREDONE,
339
340 // IVec2
341         UI2_MINUS_ONE,
342         UI2_ZERO,
343         UI2_ONE,
344         UI2_TWO,
345         UI2_THREE,
346         UI2_FOUR,
347         UI2_FIVE,
348
349 // IVec3
350         UI3_MINUS_ONE,
351         UI3_ZERO,
352         UI3_ONE,
353         UI3_TWO,
354         UI3_THREE,
355         UI3_FOUR,
356         UI3_FIVE,
357
358 // IVec4
359         UI4_MINUS_ONE,
360         UI4_ZERO,
361         UI4_ONE,
362         UI4_TWO,
363         UI4_THREE,
364         UI4_FOUR,
365         UI4_FIVE,
366
367 // Float
368         UF_ZERO,
369         UF_ONE,
370         UF_TWO,
371         UF_THREE,
372         UF_FOUR,
373         UF_FIVE,
374         UF_SIX,
375         UF_SEVEN,
376         UF_EIGHT,
377
378         UF_HALF,
379         UF_THIRD,
380         UF_FOURTH,
381         UF_FIFTH,
382         UF_SIXTH,
383         UF_SEVENTH,
384         UF_EIGHTH,
385
386 // Vec2
387         UV2_MINUS_ONE,
388         UV2_ZERO,
389         UV2_ONE,
390         UV2_TWO,
391         UV2_THREE,
392
393         UV2_HALF,
394
395 // Vec3
396         UV3_MINUS_ONE,
397         UV3_ZERO,
398         UV3_ONE,
399         UV3_TWO,
400         UV3_THREE,
401
402         UV3_HALF,
403
404 // Vec4
405         UV4_MINUS_ONE,
406         UV4_ZERO,
407         UV4_ONE,
408         UV4_TWO,
409         UV4_THREE,
410
411         UV4_HALF,
412
413         UV4_BLACK,
414         UV4_GRAY,
415         UV4_WHITE,
416
417 // Last
418         U_LAST
419 };
420
421 enum BaseAttributeType
422 {
423 // User attributes
424         A_IN0,
425         A_IN1,
426         A_IN2,
427         A_IN3,
428
429 // Matrices
430         MAT2,
431         MAT2x3,
432         MAT2x4,
433         MAT3x2,
434         MAT3,
435         MAT3x4,
436         MAT4x2,
437         MAT4x3,
438         MAT4
439 };
440
441 // ShaderRenderCaseInstance.
442
443 class ShaderRenderCaseInstance : public vkt::TestInstance
444 {
445 public:
446         enum ImageBackingMode
447         {
448                 IMAGE_BACKING_MODE_REGULAR = 0,
449                 IMAGE_BACKING_MODE_SPARSE,
450         };
451
452         // Default wertex and fragment grid sizes are used by a large collection of tests
453         // to generate input sets. Some tests might change their behavior if the
454         // default grid size values are altered, so care should be taken to confirm that
455         // any changes to default values do not produce regressions.
456         // If a particular tests needs to use a different grid size value, rather than
457         // modifying the default grid size values for all tests, it is recommended that
458         // the test specifies the required grid size using the gridSize parameter in the
459         // ShaderRenderCaseInstance constuctor instead.
460         enum
461         {
462                 GRID_SIZE_DEFAULTS                      = 0,
463                 GRID_SIZE_DEFAULT_VERTEX        = 90,
464                 GRID_SIZE_DEFAULT_FRAGMENT      = 4,
465         };
466
467                                                                                                                 ShaderRenderCaseInstance        (Context&                                       context);
468                                                                                                                 ShaderRenderCaseInstance        (Context&                                       context,
469                                                                                                                                                                         const bool                                      isVertexCase,
470                                                                                                                                                                         const ShaderEvaluator&          evaluator,
471                                                                                                                                                                         const UniformSetup&                     uniformSetup,
472                                                                                                                                                                         const AttributeSetupFunc        attribFunc,
473                                                                                                                                                                         const ImageBackingMode          imageBackingMode = IMAGE_BACKING_MODE_REGULAR,
474                                                                                                                                                                         const deUint32                          gridSize = static_cast<deUint32>(GRID_SIZE_DEFAULTS),
475                                                                                                                                                                         const bool                                      fuzzyCompare = true);
476
477         virtual                                                                                         ~ShaderRenderCaseInstance       (void);
478         virtual tcu::TestStatus                                                         iterate                                         (void);
479
480         void                                                                                            addAttribute                            (deUint32                       bindingLocation,
481                                                                                                                                                                         vk::VkFormat            format,
482                                                                                                                                                                         deUint32                        sizePerElement,
483                                                                                                                                                                         deUint32                        count,
484                                                                                                                                                                         const void*                     data);
485         void                                                                                            useAttribute                            (deUint32                       bindingLocation,
486                                                                                                                                                                         BaseAttributeType       type);
487
488         template<typename T>
489         void                                                                                            addUniform                                      (deUint32                               bindingLocation,
490                                                                                                                                                                         vk::VkDescriptorType    descriptorType,
491                                                                                                                                                                         const T&                                data);
492         void                                                                                            addUniform                                      (deUint32                               bindingLocation,
493                                                                                                                                                                         vk::VkDescriptorType    descriptorType,
494                                                                                                                                                                         size_t                                  dataSize,
495                                                                                                                                                                         const void*                             data);
496         void                                                                                            useUniform                                      (deUint32                               bindingLocation,
497                                                                                                                                                                         BaseUniformType                 type);
498         void                                                                                            useSampler                                      (deUint32                               bindingLocation,
499                                                                                                                                                                         deUint32                                textureId);
500
501         static const tcu::Vec4                                                          getDefaultConstCoords           (void) { return tcu::Vec4(0.125f, 0.25f, 0.5f, 1.0f); }
502         void                                                                                            setPushConstantRanges           (const deUint32 rangeCount, const vk::VkPushConstantRange* const pcRanges);
503         virtual void                                                                            updatePushConstants                     (vk::VkCommandBuffer commandBuffer, vk::VkPipelineLayout pipelineLayout);
504
505 protected:
506                                                                                                                 ShaderRenderCaseInstance        (Context&                                       context,
507                                                                                                                                                                          const bool                                     isVertexCase,
508                                                                                                                                                                          const ShaderEvaluator*         evaluator,
509                                                                                                                                                                          const UniformSetup*            uniformSetup,
510                                                                                                                                                                          const AttributeSetupFunc       attribFunc,
511                                                                                                                                                                          const ImageBackingMode         imageBackingMode = IMAGE_BACKING_MODE_REGULAR,
512                                                                                                                                                                          const deUint32                         gridSize = static_cast<deUint32>(GRID_SIZE_DEFAULTS));
513
514         virtual void                                                                            setup                                           (void);
515         virtual void                                                                            setupUniforms                           (const tcu::Vec4& constCoords);
516         virtual void                                                                            setupDefaultInputs                      (void);
517
518         void                                                                                            render                                          (deUint32                                       numVertices,
519                                                                                                                                                                          deUint32                                       numTriangles,
520                                                                                                                                                                          const deUint16*                        indices,
521                                                                                                                                                                          const tcu::Vec4&                       constCoords             = getDefaultConstCoords());
522
523         void                                                                                            render                                          (deUint32                                       numVertices,
524                                                                                                                                                                          deUint32                                       numIndices,
525                                                                                                                                                                          const deUint16*                        indices,
526                                                                                                                                                                          vk::VkPrimitiveTopology        topology,
527                                                                                                                                                                          const tcu::Vec4&                       constCoords             = getDefaultConstCoords());
528
529         const tcu::TextureLevel&                                                        getResultImage                          (void) const { return m_resultImage; }
530
531         const tcu::UVec2                                                                        getViewportSize                         (void) const;
532
533         void                                                                                            setSampleCount                          (vk::VkSampleCountFlagBits sampleCount);
534
535         bool                                                                                            isMultiSampling                         (void) const;
536
537         ImageBackingMode                                                                        m_imageBackingMode;
538
539         deUint32                                                                                        m_quadGridSize;
540
541 protected:
542         vk::Allocator&                                                                          m_memAlloc;
543         const tcu::Vec4                                                                         m_clearColor;
544         const bool                                                                                      m_isVertexCase;
545
546         std::vector<tcu::Mat4>                                                          m_userAttribTransforms;
547         std::vector<TextureBindingSp>                                           m_textures;
548
549         std::string                                                                                     m_vertexShaderName;
550         std::string                                                                                     m_fragmentShaderName;
551         tcu::UVec2                                                                                      m_renderSize;
552         vk::VkFormat                                                                            m_colorFormat;
553
554         de::SharedPtr<vk::Unique<vk::VkCommandPool>     >               m_externalCommandPool;
555 private:
556         typedef std::vector<tcu::ConstPixelBufferAccess>        TextureLayerData;
557         typedef std::vector<TextureLayerData>                           TextureData;
558
559         void                                                                                            uploadImage                                     (const tcu::TextureFormat&              texFormat,
560                                                                                                                                                                          const TextureData&                             textureData,
561                                                                                                                                                                          const tcu::Sampler&                    refSampler,
562                                                                                                                                                                          deUint32                                               mipLevels,
563                                                                                                                                                                          deUint32                                               arrayLayers,
564                                                                                                                                                                          vk::VkImage                                    destImage);
565
566         void                                                                                            clearImage                                      (const tcu::Sampler&                    refSampler,
567                                                                                                                                                                          deUint32                                               mipLevels,
568                                                                                                                                                                          deUint32                                               arrayLayers,
569                                                                                                                                                                          vk::VkImage                                    destImage);
570
571         void                                                                                            checkSparseSupport                      (const vk::VkImageCreateInfo&   imageInfo) const;
572 #ifndef CTS_USES_VULKANSC
573         void                                                                                            uploadSparseImage                       (const tcu::TextureFormat&              texFormat,
574                                                                                                                                                                          const TextureData&                             textureData,
575                                                                                                                                                                          const tcu::Sampler&                    refSampler,
576                                                                                                                                                                          const deUint32                                 mipLevels,
577                                                                                                                                                                          const deUint32                                 arrayLayers,
578                                                                                                                                                                          const vk::VkImage                              sparseImage,
579                                                                                                                                                                          const vk::VkImageCreateInfo&   imageCreateInfo,
580                                                                                                                                                                          const tcu::UVec3                               texSize);
581 #endif // CTS_USES_VULKANSC
582         void                                                                                            createSamplerUniform            (deUint32                                               bindingLocation,
583                                                                                                                                                                          TextureBinding::Type                   textureType,
584                                                                                                                                                                          TextureBinding::Init                   textureInit,
585                                                                                                                                                                          const tcu::TextureFormat&              texFormat,
586                                                                                                                                                                          const tcu::UVec3                               texSize,
587                                                                                                                                                                          const TextureData&                             textureData,
588                                                                                                                                                                          const tcu::Sampler&                    refSampler,
589                                                                                                                                                                          deUint32                                               mipLevels,
590                                                                                                                                                                          deUint32                                               arrayLayers,
591                                                                                                                                                                          TextureBinding::Parameters             textureParams);
592
593         void                                                                                            setupUniformData                        (deUint32 bindingLocation, size_t size, const void* dataPtr);
594
595         void                                                                                            computeVertexReference          (tcu::Surface& result, const QuadGrid& quadGrid);
596         void                                                                                            computeFragmentReference        (tcu::Surface& result, const QuadGrid& quadGrid);
597         bool                                                                                            compareImages                           (const tcu::Surface&    resImage,
598                                                                                                                                                                          const tcu::Surface&    refImage,
599                                                                                                                                                                          float                                  errorThreshold);
600
601 private:
602         const ShaderEvaluator*                                                          m_evaluator;
603         const UniformSetup*                                                                     m_uniformSetup;
604         const AttributeSetupFunc                                                        m_attribFunc;
605         de::MovePtr<QuadGrid>                                                           m_quadGrid;
606         tcu::TextureLevel                                                                       m_resultImage;
607
608         struct EnabledBaseAttribute
609         {
610                 deUint32                        location;
611                 BaseAttributeType       type;
612         };
613         std::vector<EnabledBaseAttribute>                                       m_enabledBaseAttributes;
614
615         de::MovePtr<vk::DescriptorSetLayoutBuilder>                     m_descriptorSetLayoutBuilder;
616         de::MovePtr<vk::DescriptorPoolBuilder>                          m_descriptorPoolBuilder;
617         de::MovePtr<vk::DescriptorSetUpdateBuilder>                     m_descriptorSetUpdateBuilder;
618
619         typedef de::SharedPtr<vk::Unique<vk::VkBuffer> >                VkBufferSp;
620         typedef de::SharedPtr<vk::Unique<vk::VkImage> >                 VkImageSp;
621         typedef de::SharedPtr<vk::Unique<vk::VkImageView> >             VkImageViewSp;
622         typedef de::SharedPtr<vk::Unique<vk::VkSampler> >               VkSamplerSp;
623         typedef de::SharedPtr<vk::Allocation>                                   AllocationSp;
624
625         class UniformInfo
626         {
627         public:
628                                                                         UniformInfo             (void) {}
629                 virtual                                         ~UniformInfo    (void) {}
630
631                 vk::VkDescriptorType            type;
632                 deUint32                                        location;
633         };
634
635         class BufferUniform : public UniformInfo
636         {
637         public:
638                                                                         BufferUniform   (void) {}
639                 virtual                                         ~BufferUniform  (void) {}
640
641                 VkBufferSp                                      buffer;
642                 AllocationSp                            alloc;
643                 vk::VkDescriptorBufferInfo      descriptor;
644         };
645
646         class SamplerUniform : public UniformInfo
647         {
648         public:
649                                                                         SamplerUniform  (void) {}
650                 virtual                                         ~SamplerUniform (void) {}
651
652                 VkImageSp                                       image;
653                 VkImageViewSp                           imageView;
654                 VkSamplerSp                                     sampler;
655                 AllocationSp                            alloc;
656                 vk::VkDescriptorImageInfo       descriptor;
657         };
658
659         typedef de::SharedPtr<de::UniquePtr<UniformInfo> >      UniformInfoSp;
660         std::vector<UniformInfoSp>                                                      m_uniformInfos;
661
662         std::vector< de::SharedPtr<vk::Allocation> >            m_allocations;
663
664         std::vector<vk::VkVertexInputBindingDescription>        m_vertexBindingDescription;
665         std::vector<vk::VkVertexInputAttributeDescription>      m_vertexAttributeDescription;
666
667         std::vector<VkBufferSp>                                                         m_vertexBuffers;
668         std::vector<AllocationSp>                                                       m_vertexBufferAllocs;
669
670         vk::VkSampleCountFlagBits                                                       m_sampleCount;
671         std::vector<vk::VkPushConstantRange>                            m_pushConstantRanges;
672
673         bool                                                                                            m_fuzzyCompare;
674 protected:
675         vk::VkDevice                                                                            getDevice                                               (void) const;
676         deUint32                                                                                        getUniversalQueueFamilyIndex    (void) const;
677         deUint32                                                                                        getSparseQueueFamilyIndex               (void) const;
678         const vk::DeviceInterface&                                                      getDeviceInterface                              (void) const;
679         vk::VkQueue                                                                                     getUniversalQueue                               (void) const;
680         vk::VkQueue                                                                                     getSparseQueue                                  (void) const;
681         vk::VkPhysicalDevice                                                            getPhysicalDevice                               (void) const;
682         const vk::InstanceInterface&                                            getInstanceInterface                    (void) const;
683         vk::Allocator&                                                                          getAllocator                                    (void) const;
684 };
685
686 template<typename T>
687 void ShaderRenderCaseInstance::addUniform (deUint32 bindingLocation, vk::VkDescriptorType descriptorType, const T& data)
688 {
689         addUniform(bindingLocation, descriptorType, sizeof(T), &data);
690 }
691
692 vk::VkImageViewType             textureTypeToImageViewType      (TextureBinding::Type type);
693 vk::VkImageType                 viewTypeToImageType                     (vk::VkImageViewType type);
694 vk::VkImageUsageFlags   textureUsageFlags                       (void);
695 vk::VkImageCreateFlags  textureCreateFlags                      (vk::VkImageViewType viewType, ShaderRenderCaseInstance::ImageBackingMode backingMode);
696
697 } // sr
698 } // vkt
699
700 #endif // _VKTSHADERRENDER_HPP