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