Need Float16 in some derivative tests
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / spirv_assembly / vktSpvAsmGraphicsShaderTestUtil.hpp
index 6951acd..57f5bc1 100644 (file)
@@ -266,7 +266,6 @@ struct InstanceContext
        bool                                                                    hasTessellation;
        vk::VkShaderStageFlagBits                               requiredStages;
        std::vector<std::string>                                requiredDeviceExtensions;
-       std::vector<std::string>                                requiredDeviceFeatures;
        VulkanFeatures                                                  requestedFeatures;
        PushConstants                                                   pushConstants;
        // Specifies the (one or more) stages that use a customized shader code.
@@ -295,7 +294,6 @@ struct InstanceContext
                                         const GraphicsResources&                                       resources_,
                                         const GraphicsInterfaces&                                      interfaces_,
                                         const std::vector<std::string>&                        extensions_,
-                                        const std::vector<std::string>&                        features_,
                                         VulkanFeatures                                                         vulkanFeatures_,
                                         VkShaderStageFlags                                                     customizedStages_);
 
@@ -304,6 +302,40 @@ struct InstanceContext
        std::string getSpecializedFailMessage (const std::string& failureReason);
 };
 
+enum ShaderTask
+{
+       SHADER_TASK_NONE = 0,
+       SHADER_TASK_NORMAL,
+       SHADER_TASK_UNUSED_VAR,
+       SHADER_TASK_UNUSED_FUNC,
+       SHADER_TASK_LAST
+};
+
+enum ShaderTaskIndex
+{
+       SHADER_TASK_INDEX_VERTEX                = 0,
+       SHADER_TASK_INDEX_GEOMETRY              = 1,
+       SHADER_TASK_INDEX_TESS_CONTROL  = 2,
+       SHADER_TASK_INDEX_TESS_EVAL             = 3,
+       SHADER_TASK_INDEX_FRAGMENT              = 4,
+       SHADER_TASK_INDEX_LAST                  = 5
+};
+
+typedef ShaderTask ShaderTaskArray[SHADER_TASK_INDEX_LAST];
+
+struct UnusedVariableContext
+{
+       InstanceContext         instanceContext;
+       ShaderTaskArray         shaderTasks;
+       VariableLocation        variableLocation;
+
+       UnusedVariableContext(const InstanceContext& ctx, const ShaderTaskArray& tasks, const VariableLocation& location)
+               : instanceContext(ctx), shaderTasks(), variableLocation(location)
+       {
+               deMemcpy(shaderTasks, tasks, sizeof(tasks));
+       }
+};
+
 // A description of a shader to be used for a single stage of the graphics pipeline.
 struct ShaderElement
 {
@@ -327,21 +359,6 @@ const std::string numberToString (T number)
        return ss.str();
 }
 
-// Performs a bitwise copy of source to the destination type Dest.
-template <typename Dest, typename Src>
-Dest bitwiseCast (Src source)
-{
-  Dest dest;
-  DE_STATIC_ASSERT(sizeof(source) == sizeof(dest));
-  deMemcpy(&dest, &source, sizeof(dest));
-  return dest;
-}
-
-template<typename T>   T                       randomScalar    (de::Random& rnd, T minValue, T maxValue);
-template<> inline              float           randomScalar    (de::Random& rnd, float minValue, float maxValue)               { return rnd.getFloat(minValue, maxValue);      }
-template<> inline              deInt32         randomScalar    (de::Random& rnd, deInt32 minValue, deInt32 maxValue)   { return rnd.getInt(minValue, maxValue);        }
-
-
 void getDefaultColors (tcu::RGBA (&colors)[4]);
 
 void getHalfColorsFullAlpha (tcu::RGBA (&colors)[4]);
@@ -351,18 +368,20 @@ void getInvertedDefaultColors (tcu::RGBA (&colors)[4]);
 // Creates fragments that specialize into a simple pass-through shader (of any kind).
 std::map<std::string, std::string> passthruFragments (void);
 
-// Creates a combined shader module based on VkShaderStageFlagBits defined in InstanceContext
+// Creates a combined shader module based on VkShaderStageFlagBits defined in InstanceContext.
 void createCombinedModule (vk::SourceCollections& dst, InstanceContext ctx);
 
+// Creates shaders with unused variables based on the UnusedVariableContext.
+void createUnusedVariableModules (vk::SourceCollections& dst, UnusedVariableContext ctx);
+
 // This has two shaders of each stage. The first
 // is a passthrough, the second inverts the color.
 void createMultipleEntries (vk::SourceCollections& dst, InstanceContext);
 
-// Turns a statically sized array of ShaderElements into an instance-context
-// by setting up the mapping of modules to their contained shaders and stages.
-// The inputs and expected outputs are given by inputColors and outputColors
-template<size_t N>
-InstanceContext createInstanceContext (const ShaderElement                                                     (&elements)[N],
+// Turns a vector of ShaderElements into an instance-context by setting up the mapping of modules
+// to their contained shaders and stages. The inputs and expected outputs are given by inputColors
+// and outputColors
+InstanceContext createInstanceContext (const std::vector<ShaderElement>&                       elements,
                                                                           const tcu::RGBA                                                              (&inputColors)[4],
                                                                           const tcu::RGBA                                                              (&outputColors)[4],
                                                                           const std::map<std::string, std::string>&    testCodeFragments,
@@ -371,47 +390,66 @@ InstanceContext createInstanceContext (const ShaderElement                                                        (&elements)[N],
                                                                           const GraphicsResources&                                             resources,
                                                                           const GraphicsInterfaces&                                    interfaces,
                                                                           const std::vector<std::string>&                              extensions,
-                                                                          const std::vector<std::string>&                              features,
                                                                           VulkanFeatures                                                               vulkanFeatures,
                                                                           VkShaderStageFlags                                                   customizedStages,
                                                                           const qpTestResult                                                   failResult                      = QP_TEST_RESULT_FAIL,
-                                                                          const std::string&                                                   failMessageTemplate     = std::string())
+                                                                          const std::string&                                                   failMessageTemplate     = std::string());
+
+// Same as above but using a statically sized array.
+template <size_t N>
+inline InstanceContext createInstanceContext (const ShaderElement                                                      (&elements)[N],
+                                                                                         const tcu::RGBA                                                               (&inputColors)[4],
+                                                                                         const tcu::RGBA                                                               (&outputColors)[4],
+                                                                                         const std::map<std::string, std::string>&             testCodeFragments,
+                                                                                         const StageToSpecConstantMap&                                 specConstants,
+                                                                                         const PushConstants&                                                  pushConstants,
+                                                                                         const GraphicsResources&                                              resources,
+                                                                                         const GraphicsInterfaces&                                             interfaces,
+                                                                                         const std::vector<std::string>&                               extensions,
+                                                                                         VulkanFeatures                                                                vulkanFeatures,
+                                                                                         VkShaderStageFlags                                                    customizedStages,
+                                                                                         const qpTestResult                                                    failResult                      = QP_TEST_RESULT_FAIL,
+                                                                                         const std::string&                                                    failMessageTemplate     = std::string())
 {
-       InstanceContext ctx (inputColors, outputColors, testCodeFragments, specConstants, pushConstants, resources, interfaces, extensions, features, vulkanFeatures, customizedStages);
-       for (size_t i = 0; i < N; ++i)
-       {
-               ctx.moduleMap[elements[i].moduleName].push_back(std::make_pair(elements[i].entryName, elements[i].stage));
-               ctx.requiredStages = static_cast<VkShaderStageFlagBits>(ctx.requiredStages | elements[i].stage);
-       }
-       ctx.failResult                          = failResult;
-       if (!failMessageTemplate.empty())
-               ctx.failMessageTemplate = failMessageTemplate;
-       return ctx;
+       std::vector<ShaderElement> elementsVector(elements, elements + N);
+       return createInstanceContext(elementsVector, inputColors, outputColors, testCodeFragments, specConstants, pushConstants,
+                                                                resources, interfaces, extensions, vulkanFeatures, customizedStages, failResult, failMessageTemplate);
 }
 
 // The same as createInstanceContext above, without extensions, spec constants, and resources.
-template<size_t N>
-inline InstanceContext createInstanceContext (const ShaderElement                                              (&elements)[N],
-                                                                                         tcu::RGBA                                                                     (&inputColors)[4],
-                                                                                         const tcu::RGBA                                                       (&outputColors)[4],
-                                                                                         const std::map<std::string, std::string>&     testCodeFragments)
+InstanceContext createInstanceContext (const std::vector<ShaderElement>&                       elements,
+                                                                          tcu::RGBA                                                                    (&inputColors)[4],
+                                                                          const tcu::RGBA                                                              (&outputColors)[4],
+                                                                          const std::map<std::string, std::string>&    testCodeFragments);
+
+// Same as above, but using a statically sized array.
+template <size_t N>
+inline InstanceContext createInstanceContext (const ShaderElement                                                      (&elements)[N],
+                                                                                         tcu::RGBA                                                                             (&inputColors)[4],
+                                                                                         const tcu::RGBA                                                               (&outputColors)[4],
+                                                                                         const std::map<std::string, std::string>&             testCodeFragments)
 {
-       return createInstanceContext(elements, inputColors, outputColors, testCodeFragments,
-                                                                StageToSpecConstantMap(), PushConstants(), GraphicsResources(),
-                                                                GraphicsInterfaces(), std::vector<std::string>(), std::vector<std::string>(),
-                                                                VulkanFeatures(), vk::VK_SHADER_STAGE_ALL);
+       std::vector<ShaderElement> elementsVector(elements, elements + N);
+       return createInstanceContext(elementsVector, inputColors, outputColors, testCodeFragments);
 }
 
 // The same as createInstanceContext above, but with default colors.
+InstanceContext createInstanceContext (const std::vector<ShaderElement>&                       elements,
+                                                                          const std::map<std::string, std::string>&    testCodeFragments);
+
+// Same as above, but using a statically sized array.
 template<size_t N>
-InstanceContext createInstanceContext (const ShaderElement                                                     (&elements)[N],
-                                                                          const std::map<std::string, std::string>&    testCodeFragments)
+inline InstanceContext createInstanceContext (const ShaderElement                                              (&elements)[N],
+                                                                                         const std::map<std::string, std::string>&     testCodeFragments)
 {
-       tcu::RGBA defaultColors[4];
-       getDefaultColors(defaultColors);
-       return createInstanceContext(elements, defaultColors, defaultColors, testCodeFragments);
+       std::vector<ShaderElement> elementsVector(elements, elements + N);
+       return createInstanceContext(elementsVector, testCodeFragments);
 }
 
+
+// Create an unused variable context for the given combination.
+UnusedVariableContext createUnusedVariableContext(const ShaderTaskArray& shaderTasks, const VariableLocation& location);
+
 void addShaderCodeCustomVertex (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
 void addShaderCodeCustomTessControl (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
 void addShaderCodeCustomTessEval (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions);
@@ -428,7 +466,6 @@ void createTestForStage (vk::VkShaderStageFlagBits                                  stage,
                                                 const GraphicsResources&                                       resources,
                                                 const GraphicsInterfaces&                                      interfaces,
                                                 const std::vector<std::string>&                        extensions,
-                                                const std::vector<std::string>&                        features,
                                                 VulkanFeatures                                                         vulkanFeatures,
                                                 tcu::TestCaseGroup*                                            tests,
                                                 const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
@@ -444,7 +481,6 @@ void createTestsForAllStages (const std::string&                                            name,
                                                          const GraphicsResources&                                      resources,
                                                          const GraphicsInterfaces&                                     interfaces,
                                                          const std::vector<std::string>&                       extensions,
-                                                         const std::vector<std::string>&                       features,
                                                          VulkanFeatures                                                        vulkanFeatures,
                                                          tcu::TestCaseGroup*                                           tests,
                                                          const qpTestResult                                            failResult                      = QP_TEST_RESULT_FAIL,
@@ -463,11 +499,10 @@ inline void createTestsForAllStages (const std::string&                                                   name,
        GraphicsResources                       noResources;
        GraphicsInterfaces                      noInterfaces;
        std::vector<std::string>        noExtensions;
-       std::vector<std::string>        noFeatures;
 
        createTestsForAllStages(
                        name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
-                       noResources, noInterfaces, noExtensions, noFeatures, VulkanFeatures(),
+                       noResources, noInterfaces, noExtensions, VulkanFeatures(),
                        tests, failResult, failMessageTemplate);
 }
 
@@ -484,33 +519,10 @@ inline void createTestsForAllStages (const std::string&                                                   name,
        GraphicsResources                               noResources;
        GraphicsInterfaces                              noInterfaces;
        std::vector<std::string>                noExtensions;
-       std::vector<std::string>                noFeatures;
 
        createTestsForAllStages(
                        name, inputColors, outputColors, testCodeFragments, specConstants, noPushConstants,
-                       noResources, noInterfaces, noExtensions, noFeatures, VulkanFeatures(),
-                       tests, failResult, failMessageTemplate);
-}
-
-inline void createTestsForAllStages (const std::string&                                                        name,
-                                                                        const tcu::RGBA                                                        (&inputColors)[4],
-                                                                        const tcu::RGBA                                                        (&outputColors)[4],
-                                                                        const std::map<std::string, std::string>&      testCodeFragments,
-                                                                        const GraphicsResources&                                       resources,
-                                                                        const std::vector<std::string>&                        extensions,
-                                                                        tcu::TestCaseGroup*                                            tests,
-                                                                        VulkanFeatures                                                         vulkanFeatures          = VulkanFeatures(),
-                                                                        const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
-                                                                        const std::string&                                                     failMessageTemplate     = std::string())
-{
-       SpecConstants                           noSpecConstants;
-       PushConstants                           noPushConstants;
-       GraphicsInterfaces                      noInterfaces;
-       std::vector<std::string>        noFeatures;
-
-       createTestsForAllStages(
-                       name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
-                       resources, noInterfaces, extensions, noFeatures, vulkanFeatures,
+                       noResources, noInterfaces, noExtensions, VulkanFeatures(),
                        tests, failResult, failMessageTemplate);
 }
 
@@ -520,7 +532,6 @@ inline void createTestsForAllStages (const std::string&                                                     name,
                                                                         const std::map<std::string, std::string>&      testCodeFragments,
                                                                         const GraphicsResources&                                       resources,
                                                                         const std::vector<std::string>&                        extensions,
-                                                                        const std::vector<std::string>&                        features,
                                                                         tcu::TestCaseGroup*                                            tests,
                                                                         VulkanFeatures                                                         vulkanFeatures          = VulkanFeatures(),
                                                                         const qpTestResult                                                     failResult                      = QP_TEST_RESULT_FAIL,
@@ -532,7 +543,7 @@ inline void createTestsForAllStages (const std::string&                                                     name,
 
        createTestsForAllStages(
                        name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
-                       resources, noInterfaces, extensions, features, vulkanFeatures,
+                       resources, noInterfaces, extensions, vulkanFeatures,
                        tests, failResult, failMessageTemplate);
 }
 
@@ -549,12 +560,11 @@ inline void createTestsForAllStages (const std::string& name,
 {
        GraphicsResources                       noResources;
        SpecConstants                           noSpecConstants;
-       std::vector<std::string>        noFeatures;
        PushConstants                           noPushConstants;
 
        createTestsForAllStages(
                        name, inputColors, outputColors, testCodeFragments, noSpecConstants, noPushConstants,
-                       noResources, interfaces, extensions, noFeatures, vulkanFeatures,
+                       noResources, interfaces, extensions, vulkanFeatures,
                        tests, failResult, failMessageTemplate);
 }
 
@@ -572,11 +582,10 @@ inline void createTestsForAllStages (const std::string& name,
 {
        SpecConstants                                   noSpecConstants;
        GraphicsInterfaces                              noInterfaces;
-       std::vector<std::string>                noFeatures;
 
        createTestsForAllStages(
                        name, inputColors, outputColors, testCodeFragments, noSpecConstants, pushConstants,
-                       resources, noInterfaces, extensions, noFeatures, vulkanFeatures,
+                       resources, noInterfaces, extensions, vulkanFeatures,
                        tests, failResult, failMessageTemplate);
 }
 
@@ -586,6 +595,9 @@ inline void createTestsForAllStages (const std::string& name,
 // whatever the shaders draw can be directly spot-checked.
 tcu::TestStatus runAndVerifyDefaultPipeline (Context& context, InstanceContext instance);
 
+// Use the instance context in the UnusedVariableContext to run the function above.
+tcu::TestStatus runAndVerifyUnusedVariablePipeline (Context &context, UnusedVariableContext unusedVariableContext);
+
 // Adds a new test to group using custom fragments for the tessellation-control
 // stage and passthrough fragments for all other stages.  Uses default colors
 // for input and expected output.