Merge vk-gl-cts/vulkan-cts-1.1.1 into vk-gl-cts/vulkan-cts-1.1.2
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / spirv_assembly / vktSpvAsmGraphicsShaderTestUtil.hpp
1 #ifndef _VKTSPVASMGRAPHICSSHADERTESTUTIL_HPP
2 #define _VKTSPVASMGRAPHICSSHADERTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2017 Google Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Graphics pipeline and helper functions for SPIR-V assembly tests
24  *//*--------------------------------------------------------------------*/
25
26 #include "tcuCommandLine.hpp"
27 #include "tcuRGBA.hpp"
28
29 #include "vkPrograms.hpp"
30 #include "vktSpvAsmComputeShaderTestUtil.hpp"
31 #include "vktSpvAsmUtils.hpp"
32 #include "vktTestCaseUtil.hpp"
33
34 #include "deRandom.hpp"
35 #include "deSharedPtr.hpp"
36
37 #include <map>
38 #include <sstream>
39 #include <string>
40 #include <utility>
41
42 namespace vkt
43 {
44 namespace SpirVAssembly
45 {
46
47 typedef vk::Unique<VkBuffer>                                                                            BufferHandleUp;
48 typedef vk::Unique<VkImage>                                                                                     ImageHandleUp;
49 typedef vk::Unique<VkImageView>                                                                         ImageViewHandleUp;
50 typedef vk::Unique<VkSampler>                                                                           SamplerHandleUp;
51 typedef de::SharedPtr<BufferHandleUp>                                                           BufferHandleSp;
52 typedef de::SharedPtr<ImageHandleUp>                                                            ImageHandleSp;
53 typedef de::SharedPtr<ImageViewHandleUp>                                                        ImageViewHandleSp;
54 typedef de::SharedPtr<SamplerHandleUp>                                                          SamplerHandleSp;
55 typedef vk::Unique<vk::VkShaderModule>                                                          ModuleHandleUp;
56 typedef de::SharedPtr<ModuleHandleUp>                                                           ModuleHandleSp;
57 typedef std::pair<std::string, vk::VkShaderStageFlagBits>                       EntryToStage;
58 typedef std::map<std::string, std::vector<EntryToStage> >                       ModuleMap;
59 typedef std::map<vk::VkShaderStageFlagBits, std::vector<deInt32> >      StageToSpecConstantMap;
60 typedef std::pair<vk::VkDescriptorType, BufferSp>                                       Resource;
61
62 enum NumberType
63 {
64         NUMBERTYPE_INT32,
65         NUMBERTYPE_UINT32,
66         NUMBERTYPE_FLOAT32,
67         NUMBERTYPE_END32,               // Marks the end of 32-bit scalar types
68         NUMBERTYPE_INT16,
69         NUMBERTYPE_UINT16,
70         NUMBERTYPE_FLOAT16,
71 };
72
73 typedef enum RoundingModeFlags_e
74 {
75         ROUNDINGMODE_RTE = 0x1, // Round to nearest even
76         ROUNDINGMODE_RTZ = 0x2, // Round to zero
77 } RoundingModeFlags;
78
79 typedef bool (*GraphicsVerifyIOFunc) (const std::vector<Resource>&              inputs,
80                                                                           const std::vector<AllocationSp>&      outputAllocations,
81                                                                           const std::vector<Resource>&          expectedOutputs,
82                                                                           tcu::TestLog&                                         log);
83
84 typedef bool (*GraphicsVerifyBinaryFunc) (const ProgramBinary&  binary);
85
86 // Resources used by graphics-pipeline-based tests.
87 struct GraphicsResources
88 {
89         // Resources used as inputs.
90         std::vector<Resource>           inputs;
91         // Input resource format if used
92         VkFormat                                        inputFormat;
93         // Resources used as outputs. The data supplied will be used as
94         // the expected outputs for the corresponding bindings by default.
95         // If other behaviors are needed, please provide a custom verifyIO.
96         std::vector<Resource>           outputs;
97         // If null, a default verification will be performed by comparing the
98         // memory pointed to by outputAllocations  and the contents of
99         // expectedOutputs. Otherwise the function pointed to by verifyIO will
100         // be called. If true is returned, then the test case is assumed to
101         // have passed, if false is returned, then the test case is assumed
102         // to have failed.
103         GraphicsVerifyIOFunc            verifyIO;
104         GraphicsVerifyBinaryFunc        verifyBinary;
105         SpirvVersion                            spirvVersion;
106
107                                                         GraphicsResources()
108                                                                 : inputFormat   (VK_FORMAT_R32G32B32A32_SFLOAT)
109                                                                 , verifyIO              (DE_NULL)
110                                                                 , verifyBinary  (DE_NULL)
111                                                                 , spirvVersion  (SPIRV_VERSION_1_0)
112                                                         {}
113 };
114
115 // Interface data type.
116 struct IFDataType
117 {
118                                                 IFDataType                      (deUint32 numE, NumberType elementT)
119                                                         : numElements   (numE)
120                                                         , elementType   (elementT)
121                                                 {
122                                                         DE_ASSERT(numE > 0 && numE < 5);
123                                                         DE_ASSERT(elementT != NUMBERTYPE_END32);
124                                                 }
125
126                                                 IFDataType                      (const IFDataType& that)
127                                                         : numElements   (that.numElements)
128                                                         , elementType   (that.elementType)
129                                                 {}
130
131         deUint32                        getElementNumBytes      (void) const;
132         deUint32                        getNumBytes                     (void) const { return numElements * getElementNumBytes(); }
133
134         vk::VkFormat            getVkFormat                     (void) const;
135
136         tcu::TextureFormat      getTextureFormat        (void) const;
137
138         std::string                     str                                     (void) const;
139
140         bool                            elementIs32bit          (void) const { return elementType < NUMBERTYPE_END32; }
141         bool                            isVector                        (void) const { return numElements > 1; }
142
143         deUint32                        numElements;
144         NumberType                      elementType;
145 };
146
147 typedef std::pair<IFDataType, BufferSp>                 Interface;
148
149 // Interface variables used by graphics-pipeline-based tests.
150 class GraphicsInterfaces
151 {
152 public:
153                                                 GraphicsInterfaces      ()
154                                                         : rndMode       (static_cast<RoundingModeFlags>(0))
155                                                 {}
156
157                                                 GraphicsInterfaces      (const GraphicsInterfaces& that)
158                                                         : inputs        (that.inputs)
159                                                         , outputs       (that.outputs)
160                                                         , rndMode       (that.rndMode)
161                                                 {}
162
163         void                            setInputOutput          (const Interface& input, const Interface&  output)
164                                                 {
165                                                         inputs.clear();
166                                                         outputs.clear();
167                                                         inputs.push_back(input);
168                                                         outputs.push_back(output);
169                                                 }
170
171         const IFDataType&       getInputType            (void) const
172                                                 {
173                                                         DE_ASSERT(inputs.size() == 1);
174                                                         return inputs.front().first;
175                                                 }
176
177         const IFDataType&       getOutputType           (void) const
178                                                 {
179                                                         DE_ASSERT(outputs.size() == 1);
180                                                         return outputs.front().first;
181                                                 }
182
183         const BufferSp&         getInputBuffer          (void) const
184                                                 {
185                                                         DE_ASSERT(inputs.size() == 1);
186                                                         return inputs.front().second;
187                                                 }
188
189         const BufferSp&         getOutputBuffer         (void) const
190                                                 {
191                                                         DE_ASSERT(outputs.size() == 1);
192                                                         return outputs.front().second;
193                                                 }
194
195         bool                            empty                           (void) const
196                                                 {
197                                                         return inputs.size() == 0;
198                                                 }
199
200         void                            setRoundingMode         (RoundingModeFlags flag)
201                                                 {
202                                                         rndMode = flag;
203                                                 }
204         RoundingModeFlags       getRoundingMode         (void) const
205                                                 {
206                                                         return rndMode;
207                                                 }
208 private:
209         // vector<Interface> acts as a null-able Interface here. Canonically we should use
210         // std::unique_ptr, but sadly we cannot leverage C++11 in dEQP. dEQP has its own
211         // de::UniquePtr, but still cumbersome to use in InstanceContext and do copies
212         // at various places.
213         // Public methods should make sure that there are less than two elements in both
214         // members and both members have the same number of elements.
215         std::vector<Interface>  inputs;
216         std::vector<Interface>  outputs;
217         RoundingModeFlags               rndMode;
218
219 };
220
221 struct PushConstants
222 {
223 public:
224                                                         PushConstants (void)
225                                                         {}
226
227                                                         PushConstants (const PushConstants& that)
228                                                                 : pcs   (that.pcs)
229                                                         {}
230
231         void                                    setPushConstant (const BufferSp& pc)
232                                                         {
233                                                                 pcs.clear();
234                                                                 pcs.push_back(pc);
235                                                         }
236
237         bool                                    empty (void) const
238                                                         {
239                                                                 return pcs.empty();
240                                                         }
241
242         const BufferSp&                 getBuffer(void) const
243                                                         {
244                                                                 DE_ASSERT(pcs.size() == 1);
245                                                                 return pcs[0];
246                                                         }
247
248 private:
249         // Right now we only support one field in the push constant block.
250         std::vector<BufferSp>   pcs;
251 };
252
253 // Returns the corresponding buffer usage flag bit for the given descriptor type.
254 VkBufferUsageFlagBits getMatchingBufferUsageFlagBit (VkDescriptorType dType);
255
256 // Context for a specific test instantiation. For example, an instantiation
257 // may test colors yellow/magenta/cyan/mauve in a tesselation shader
258 // with an entry point named 'main_to_the_main'
259 struct InstanceContext
260 {
261         // Map of modules to what entry_points we care to use from those modules.
262         ModuleMap                                                               moduleMap;
263         tcu::RGBA                                                               inputColors[4];
264         tcu::RGBA                                                               outputColors[4];
265         // Concrete SPIR-V code to test via boilerplate specialization.
266         std::map<std::string, std::string>              testCodeFragments;
267         StageToSpecConstantMap                                  specConstants;
268         bool                                                                    hasTessellation;
269         vk::VkShaderStageFlagBits                               requiredStages;
270         std::vector<std::string>                                requiredDeviceExtensions;
271         std::vector<std::string>                                requiredDeviceFeatures;
272         VulkanFeatures                                                  requestedFeatures;
273         PushConstants                                                   pushConstants;
274         // Specifies the (one or more) stages that use a customized shader code.
275         VkShaderStageFlags                                              customizedStages;
276         // Possible resources used by the graphics pipeline.
277         // If it is not empty, a single descriptor set (number 0) will be allocated
278         // to point to all resources specified. Binding numbers are allocated in
279         // accord with the resources' order in the vector; outputs are allocated
280         // after inputs.
281         GraphicsResources                                               resources;
282         // Possible interface variables use by the graphics pipeline.
283         // If it is not empty, input/output variables will be set up for shader stages
284         // in the test. Both the input and output variable will take location #2 in the
285         // pipeline for all stages, except that the output variable in the fragment
286         // stage will take location #1.
287         GraphicsInterfaces                                              interfaces;
288         qpTestResult                                                    failResult;
289         std::string                                                             failMessageTemplate;    //!< ${reason} in the template will be replaced with a detailed failure message
290
291         InstanceContext (const tcu::RGBA                                                        (&inputs)[4],
292                                          const tcu::RGBA                                                        (&outputs)[4],
293                                          const std::map<std::string, std::string>&      testCodeFragments_,
294                                          const StageToSpecConstantMap&                          specConstants_,
295                                          const PushConstants&                                           pushConsants_,
296                                          const GraphicsResources&                                       resources_,
297                                          const GraphicsInterfaces&                                      interfaces_,
298                                          const std::vector<std::string>&                        extensions_,
299                                          const std::vector<std::string>&                        features_,
300                                          VulkanFeatures                                                         vulkanFeatures_,
301                                          VkShaderStageFlags                                                     customizedStages_);
302
303         InstanceContext (const InstanceContext& other);
304
305         std::string getSpecializedFailMessage (const std::string& failureReason);
306 };
307
308 // A description of a shader to be used for a single stage of the graphics pipeline.
309 struct ShaderElement
310 {
311         // The module that contains this shader entrypoint.
312         std::string                                     moduleName;
313
314         // The name of the entrypoint.
315         std::string                                     entryName;
316
317         // Which shader stage this entry point represents.
318         vk::VkShaderStageFlagBits       stage;
319
320         ShaderElement (const std::string& moduleName_, const std::string& entryPoint_, vk::VkShaderStageFlagBits shaderStage_);
321 };
322
323 template <typename T>
324 const std::string numberToString (T number)
325 {
326         std::stringstream ss;
327         ss << number;
328         return ss.str();
329 }
330
331 // Performs a bitwise copy of source to the destination type Dest.
332 template <typename Dest, typename Src>
333 Dest bitwiseCast (Src source)
334 {
335   Dest dest;
336   DE_STATIC_ASSERT(sizeof(source) == sizeof(dest));
337   deMemcpy(&dest, &source, sizeof(dest));
338   return dest;
339 }
340
341 template<typename T>    T                       randomScalar    (de::Random& rnd, T minValue, T maxValue);
342 template<> inline               float           randomScalar    (de::Random& rnd, float minValue, float maxValue)               { return rnd.getFloat(minValue, maxValue);      }
343 template<> inline               deInt32         randomScalar    (de::Random& rnd, deInt32 minValue, deInt32 maxValue)   { return rnd.getInt(minValue, maxValue);        }
344
345
346 void getDefaultColors (tcu::RGBA (&colors)[4]);
347
348 void getHalfColorsFullAlpha (tcu::RGBA (&colors)[4]);
349
350 void getInvertedDefaultColors (tcu::RGBA (&colors)[4]);
351
352 // Creates fragments that specialize into a simple pass-through shader (of any kind).
353 std::map<std::string, std::string> passthruFragments (void);
354
355 void createCombinedModule (vk::SourceCollections& dst, InstanceContext);
356
357 // This has two shaders of each stage. The first
358 // is a passthrough, the second inverts the color.
359 void createMultipleEntries (vk::SourceCollections& dst, InstanceContext);
360
361 // Turns a statically sized array of ShaderElements into an instance-context
362 // by setting up the mapping of modules to their contained shaders and stages.
363 // The inputs and expected outputs are given by inputColors and outputColors
364 template<size_t N>
365 InstanceContext createInstanceContext (const ShaderElement                                                      (&elements)[N],
366                                                                            const tcu::RGBA                                                              (&inputColors)[4],
367                                                                            const tcu::RGBA                                                              (&outputColors)[4],
368                                                                            const std::map<std::string, std::string>&    testCodeFragments,
369                                                                            const StageToSpecConstantMap&                                specConstants,
370                                                                            const PushConstants&                                                 pushConstants,
371                                                                            const GraphicsResources&                                             resources,
372                                                                            const GraphicsInterfaces&                                    interfaces,
373                                                                            const std::vector<std::string>&                              extensions,
374                                                                            const std::vector<std::string>&                              features,
375                                                                            VulkanFeatures                                                               vulkanFeatures,
376                                                                            VkShaderStageFlags                                                   customizedStages,
377                                                                            const qpTestResult                                                   failResult                      = QP_TEST_RESULT_FAIL,
378                                                                            const std::string&                                                   failMessageTemplate     = std::string())
379 {
380         InstanceContext ctx (inputColors, outputColors, testCodeFragments, specConstants, pushConstants, resources, interfaces, extensions, features, vulkanFeatures, customizedStages);
381         for (size_t i = 0; i < N; ++i)
382         {
383                 ctx.moduleMap[elements[i].moduleName].push_back(std::make_pair(elements[i].entryName, elements[i].stage));
384                 ctx.requiredStages = static_cast<VkShaderStageFlagBits>(ctx.requiredStages | elements[i].stage);
385         }
386         ctx.failResult                          = failResult;
387         if (!failMessageTemplate.empty())
388                 ctx.failMessageTemplate = failMessageTemplate;
389         return ctx;
390 }
391
392 // The same as createInstanceContext above, without extensions, spec constants, and resources.
393 template<size_t N>
394 inline InstanceContext createInstanceContext (const ShaderElement                                               (&elements)[N],
395                                                                                           tcu::RGBA                                                                     (&inputColors)[4],
396                                                                                           const tcu::RGBA                                                       (&outputColors)[4],
397                                                                                           const std::map<std::string, std::string>&     testCodeFragments)
398 {
399         return createInstanceContext(elements, inputColors, outputColors, testCodeFragments,
400                                                                  StageToSpecConstantMap(), PushConstants(), GraphicsResources(),
401                                                                  GraphicsInterfaces(), std::vector<std::string>(), std::vector<std::string>(),
402                                                                  VulkanFeatures(), vk::VK_SHADER_STAGE_ALL);
403 }
404
405 // The same as createInstanceContext above, but with default colors.
406 template<size_t N>
407 InstanceContext createInstanceContext (const ShaderElement                                                      (&elements)[N],
408                                                                            const std::map<std::string, std::string>&    testCodeFragments)
409 {
410         tcu::RGBA defaultColors[4];
411         getDefaultColors(defaultColors);
412         return createInstanceContext(elements, defaultColors, defaultColors, testCodeFragments);
413 }
414
415 void addShaderCodeCustomVertex (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
416 void addShaderCodeCustomTessControl (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
417 void addShaderCodeCustomTessEval (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
418 void addShaderCodeCustomGeometry (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
419 void addShaderCodeCustomFragment (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
420
421 void createTestForStage (vk::VkShaderStageFlagBits                                      stage,
422                                                  const std::string&                                                     name,
423                                                  const tcu::RGBA                                                        (&inputColors)[4],
424                                                  const tcu::RGBA                                                        (&outputColors)[4],
425                                                  const std::map<std::string, std::string>&      testCodeFragments,
426                                                  const std::vector<deInt32>&                            specConstants,
427                                                  const PushConstants&                                           pushConstants,
428                                                  const GraphicsResources&                                       resources,
429                                                  const GraphicsInterfaces&                                      interfaces,
430                                                  const std::vector<std::string>&                        extensions,
431                                                  const std::vector<std::string>&                        features,
432                                                  VulkanFeatures                                                         vulkanFeatures,
433                                                  tcu::TestCaseGroup*                                            tests,
434                                                  const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
435                                                  const std::string&                                                     failMessageTemplate = std::string());
436
437 void createTestsForAllStages (const std::string&                                                name,
438                                                           const tcu::RGBA                                                       (&inputColors)[4],
439                                                           const tcu::RGBA                                                       (&outputColors)[4],
440                                                           const std::map<std::string, std::string>&     testCodeFragments,
441                                                           const std::vector<deInt32>&                           specConstants,
442                                                           const PushConstants&                                          pushConstants,
443                                                           const GraphicsResources&                                      resources,
444                                                           const GraphicsInterfaces&                                     interfaces,
445                                                           const std::vector<std::string>&                       extensions,
446                                                           const std::vector<std::string>&                       features,
447                                                           VulkanFeatures                                                        vulkanFeatures,
448                                                           tcu::TestCaseGroup*                                           tests,
449                                                           const qpTestResult                                            failResult                      = QP_TEST_RESULT_FAIL,
450                                                           const std::string&                                            failMessageTemplate     = std::string());
451
452 inline void createTestsForAllStages (const std::string&                                                 name,
453                                                                          const tcu::RGBA                                                        (&inputColors)[4],
454                                                                          const tcu::RGBA                                                        (&outputColors)[4],
455                                                                          const std::map<std::string, std::string>&      testCodeFragments,
456                                                                          tcu::TestCaseGroup*                                            tests,
457                                                                          const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
458                                                                          const std::string&                                                     failMessageTemplate     = std::string())
459 {
460         std::vector<deInt32>            noSpecConstants;
461         PushConstants                           noPushConstants;
462         GraphicsResources                       noResources;
463         GraphicsInterfaces                      noInterfaces;
464         std::vector<std::string>        noExtensions;
465         std::vector<std::string>        noFeatures;
466
467         createTestsForAllStages(
468                         name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
469                         noResources, noInterfaces, noExtensions, noFeatures, VulkanFeatures(),
470                         tests, failResult, failMessageTemplate);
471 }
472
473 inline void createTestsForAllStages (const std::string&                                                 name,
474                                                                          const tcu::RGBA                                                        (&inputColors)[4],
475                                                                          const tcu::RGBA                                                        (&outputColors)[4],
476                                                                          const std::map<std::string, std::string>&      testCodeFragments,
477                                                                          const std::vector<deInt32>&                            specConstants,
478                                                                          tcu::TestCaseGroup*                                            tests,
479                                                                          const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
480                                                                          const std::string&                                                     failMessageTemplate     = std::string())
481 {
482         PushConstants                                   noPushConstants;
483         GraphicsResources                               noResources;
484         GraphicsInterfaces                              noInterfaces;
485         std::vector<std::string>                noExtensions;
486         std::vector<std::string>                noFeatures;
487
488         createTestsForAllStages(
489                         name, inputColors, outputColors, testCodeFragments, specConstants, noPushConstants,
490                         noResources, noInterfaces, noExtensions, noFeatures, VulkanFeatures(),
491                         tests, failResult, failMessageTemplate);
492 }
493
494 inline void createTestsForAllStages (const std::string&                                                 name,
495                                                                          const tcu::RGBA                                                        (&inputColors)[4],
496                                                                          const tcu::RGBA                                                        (&outputColors)[4],
497                                                                          const std::map<std::string, std::string>&      testCodeFragments,
498                                                                          const GraphicsResources&                                       resources,
499                                                                          const std::vector<std::string>&                        extensions,
500                                                                          tcu::TestCaseGroup*                                            tests,
501                                                                          VulkanFeatures                                                         vulkanFeatures          = VulkanFeatures(),
502                                                                          const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
503                                                                          const std::string&                                                     failMessageTemplate     = std::string())
504 {
505         std::vector<deInt32>            noSpecConstants;
506         PushConstants                           noPushConstants;
507         GraphicsInterfaces                      noInterfaces;
508         std::vector<std::string>        noFeatures;
509
510         createTestsForAllStages(
511                         name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
512                         resources, noInterfaces, extensions, noFeatures, vulkanFeatures,
513                         tests, failResult, failMessageTemplate);
514 }
515
516 inline void createTestsForAllStages (const std::string&                                                 name,
517                                                                          const tcu::RGBA                                                        (&inputColors)[4],
518                                                                          const tcu::RGBA                                                        (&outputColors)[4],
519                                                                          const std::map<std::string, std::string>&      testCodeFragments,
520                                                                          const GraphicsResources&                                       resources,
521                                                                          const std::vector<std::string>&                        extensions,
522                                                                          const std::vector<std::string>&                        features,
523                                                                          tcu::TestCaseGroup*                                            tests,
524                                                                          VulkanFeatures                                                         vulkanFeatures          = VulkanFeatures(),
525                                                                          const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
526                                                                          const std::string&                                                     failMessageTemplate     = std::string())
527 {
528         std::vector<deInt32>            noSpecConstants;
529         PushConstants                           noPushConstants;
530         GraphicsInterfaces                      noInterfaces;
531
532         createTestsForAllStages(
533                         name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
534                         resources, noInterfaces, extensions, features, vulkanFeatures,
535                         tests, failResult, failMessageTemplate);
536 }
537
538 inline void createTestsForAllStages (const std::string& name,
539                                                                          const tcu::RGBA                                                        (&inputColors)[4],
540                                                                          const tcu::RGBA                                                        (&outputColors)[4],
541                                                                          const std::map<std::string, std::string>&      testCodeFragments,
542                                                                          const GraphicsInterfaces                                       interfaces,
543                                                                          const std::vector<std::string>&                        extensions,
544                                                                          tcu::TestCaseGroup*                                            tests,
545                                                                          VulkanFeatures                                                         vulkanFeatures          = VulkanFeatures(),
546                                                                          const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
547                                                                          const std::string&                                                     failMessageTemplate     = std::string())
548 {
549         GraphicsResources                       noResources;
550         std::vector<deInt32>            noSpecConstants;
551         std::vector<std::string>        noFeatures;
552         PushConstants                           noPushConstants;
553
554         createTestsForAllStages(
555                         name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
556                         noResources, interfaces, extensions, noFeatures, vulkanFeatures,
557                         tests, failResult, failMessageTemplate);
558 }
559
560 inline void createTestsForAllStages (const std::string& name,
561                                                                          const tcu::RGBA                                                        (&inputColors)[4],
562                                                                          const tcu::RGBA                                                        (&outputColors)[4],
563                                                                          const std::map<std::string, std::string>&      testCodeFragments,
564                                                                          const PushConstants&                                           pushConstants,
565                                                                          const GraphicsResources&                                       resources,
566                                                                          const std::vector<std::string>&                        extensions,
567                                                                          tcu::TestCaseGroup*                                            tests,
568                                                                          VulkanFeatures                                                         vulkanFeatures          = VulkanFeatures(),
569                                                                          const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
570                                                                          const std::string&                                                     failMessageTemplate     = std::string())
571 {
572         std::vector<deInt32>                    noSpecConstants;
573         GraphicsInterfaces                              noInterfaces;
574         std::vector<std::string>                noFeatures;
575
576         createTestsForAllStages(
577                         name, inputColors, outputColors, testCodeFragments, noSpecConstants, pushConstants,
578                         resources, noInterfaces, extensions, noFeatures, vulkanFeatures,
579                         tests, failResult, failMessageTemplate);
580 }
581
582 // Sets up and runs a Vulkan pipeline, then spot-checks the resulting image.
583 // Feeds the pipeline a set of colored triangles, which then must occur in the
584 // rendered image.  The surface is cleared before executing the pipeline, so
585 // whatever the shaders draw can be directly spot-checked.
586 tcu::TestStatus runAndVerifyDefaultPipeline (Context& context, InstanceContext instance);
587
588 // Adds a new test to group using custom fragments for the tessellation-control
589 // stage and passthrough fragments for all other stages.  Uses default colors
590 // for input and expected output.
591 void addTessCtrlTest (tcu::TestCaseGroup* group, const char* name, const std::map<std::string, std::string>& fragments);
592
593 // Given the original 32-bit float value, computes the corresponding 16-bit
594 // float value under the given rounding mode flags and compares with the
595 // returned 16-bit float value. Returns true if they are considered as equal.
596 //
597 // The following equivalence criteria are respected:
598 // * Positive and negative zeros are considered equivalent.
599 // * Denormalized floats are allowed to be flushed to zeros, including
600 //   * Inputted 32bit denormalized float
601 //   * Generated 16bit denormalized float
602 // * Different bit patterns of NaNs are allowed.
603 // * For the rest, require exactly the same bit pattern.
604 bool compare16BitFloat (float original, deUint16 returned, RoundingModeFlags flags, tcu::TestLog& log);
605
606 // Given the original 16-bit float value, computes the corresponding 32-bit
607 // float value and compares with the returned 32-bit float value.
608 // Returns true if they are considered as equal.
609 //
610 // The following equivalence criteria are respected:
611 // * Positive and negative zeros are considered equivalent.
612 // * Denormalized floats are allowed to be flushed to zeros, including
613 //   * Inputted 16bit denormalized float
614 //   * Generated 32bit denormalized float
615 // * Different bit patterns of NaNs are allowed.
616 // * For the rest, require exactly the same bit pattern.
617 bool compare16BitFloat (deUint16 returned, float original, tcu::TestLog& log);
618
619 // Compare the returned 32-bit float against its expected value.
620 //
621 // The following equivalence criteria are respected:
622 // * Denormalized floats are allowed to be flushed to zeros, including
623 //   * The expected value itself is a denormalized float
624 //   * The expected value is a denormalized float if converted to 16bit
625 // * Different bit patterns of NaNs/Infs are allowed.
626 // * For the rest, use C++ float equivalence check.
627 bool compare32BitFloat (float expected, float returned, tcu::TestLog& log);
628
629 } // SpirVAssembly
630 } // vkt
631
632 #endif // _VKTSPVASMGRAPHICSSHADERTESTUTIL_HPP