Allow tests to be executed with SPIR-V 1.4
authorVictor Lomuller <victor@codeplay.com>
Wed, 12 Jun 2019 14:53:49 +0000 (15:53 +0100)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 10 Oct 2019 13:27:52 +0000 (09:27 -0400)
Components: Framework

Change-Id: I3135d7b0d96234bec53bbc4ec0185f4c816a5dcf
(cherry picked from commit 9b4c4d1645edb2e09d8357fa62b810df5ba3b9ec)

external/vulkancts/framework/vulkan/vkShaderProgram.hpp
external/vulkancts/framework/vulkan/vkShaderToSpirV.cpp
external/vulkancts/framework/vulkan/vkValidatorOptions.hpp
external/vulkancts/modules/vulkan/vktBuildPrograms.cpp

index c5e6853..f0ec36c 100644 (file)
@@ -50,17 +50,20 @@ struct ShaderBuildOptions
        deUint32                vulkanVersion;
        SpirvVersion    targetVersion;
        deUint32                flags;
+       bool                    supports_VK_KHR_spirv_1_4;
 
-       ShaderBuildOptions (deUint32 vulkanVersion_, SpirvVersion targetVersion_, deUint32 flags_)
+       ShaderBuildOptions (deUint32 vulkanVersion_, SpirvVersion targetVersion_, deUint32 flags_, bool allowSpirv14 = false)
                : vulkanVersion (vulkanVersion_)
                , targetVersion (targetVersion_)
                , flags                 (flags_)
+               , supports_VK_KHR_spirv_1_4(allowSpirv14)
        {}
 
        ShaderBuildOptions (void)
                : vulkanVersion (VK_MAKE_VERSION(1, 0, 0))
                , targetVersion (SPIRV_VERSION_1_0)
                , flags                 (0u)
+               , supports_VK_KHR_spirv_1_4 (false)
        {}
 
        SpirvValidatorOptions getSpirvValidatorOptions() const
@@ -80,7 +83,7 @@ struct ShaderBuildOptions
                        rules = SpirvValidatorOptions::kRelaxedBlockLayout;
                }
 
-               return SpirvValidatorOptions(vulkanVersion, rules);
+               return SpirvValidatorOptions(vulkanVersion, rules, supports_VK_KHR_spirv_1_4);
        }
 };
 
index e09d1b4..1fe287a 100644 (file)
@@ -293,6 +293,9 @@ bool compileShaderToSpirV (const std::vector<std::string>* sources, const Shader
                        case SPIRV_VERSION_1_3:
                                shader.setEnvTarget(glslang::EshTargetSpv, (glslang::EShTargetLanguageVersion)0x10300);
                                break;
+                       case SPIRV_VERSION_1_4:
+                               shader.setEnvTarget(glslang::EshTargetSpv, (glslang::EShTargetLanguageVersion)0x10400);
+                               break;
                        default:
                                TCU_THROW(InternalError, "Unsupported SPIR-V target version");
                        }
index e14b4c7..f593913 100644 (file)
@@ -44,8 +44,8 @@ struct SpirvValidatorOptions
                kScalarBlockLayout
        };
 
-       SpirvValidatorOptions(deUint32 the_vulkan_version = VK_MAKE_VERSION(1, 0, 0), BlockLayoutRules the_layout = kDefaultBlockLayout)
-       : vulkanVersion(the_vulkan_version), blockLayout(the_layout), supports_VK_KHR_spirv_1_4(false) {}
+       SpirvValidatorOptions(deUint32 the_vulkan_version = VK_MAKE_VERSION(1, 0, 0), BlockLayoutRules the_layout = kDefaultBlockLayout, bool allowSpirv14 = false)
+       : vulkanVersion(the_vulkan_version), blockLayout(the_layout), supports_VK_KHR_spirv_1_4(allowSpirv14) {}
 
        // The target Vulkan version.  This determines the SPIR-V environment rules to
        // be checked. The bit pattern is as produced by VK_MAKE_VERSION.
index f04e39c..f93bb00 100644 (file)
@@ -394,7 +394,8 @@ BuildStats buildPrograms (tcu::TestContext&                 testCtx,
                                                  const bool                            validateBinaries,
                                                  const deUint32                        usedVulkanVersion,
                                                  const vk::SpirvVersion        baselineSpirvVersion,
-                                                 const vk::SpirvVersion        maxSpirvVersion)
+                                                 const vk::SpirvVersion        maxSpirvVersion,
+                                                 const bool                            allowSpirV14)
 {
        const deUint32                                          numThreads                      = deGetNumAvailableLogicalCores();
 
@@ -447,7 +448,8 @@ BuildStats buildPrograms (tcu::TestContext&                 testCtx,
                                                 ++progIter)
                                        {
                                                // Source program requires higher SPIR-V version than available: skip it to avoid fail
-                                               if (progIter.getProgram().buildOptions.targetVersion > maxSpirvVersion)
+                                               // Unless this is SPIR-V 1.4 and is explicitly allowed.
+                                               if (progIter.getProgram().buildOptions.targetVersion > maxSpirvVersion && !(allowSpirV14 && progIter.getProgram().buildOptions.supports_VK_KHR_spirv_1_4 && progIter.getProgram().buildOptions.targetVersion == vk::SPIRV_VERSION_1_4))
                                                        continue;
 
                                                programs.pushBack(Program(vk::ProgramIdentifier(casePath, progIter.getName()), progIter.getProgram().buildOptions.getSpirvValidatorOptions()));
@@ -461,7 +463,8 @@ BuildStats buildPrograms (tcu::TestContext&                 testCtx,
                                                 ++progIter)
                                        {
                                                // Source program requires higher SPIR-V version than available: skip it to avoid fail
-                                               if (progIter.getProgram().buildOptions.targetVersion > maxSpirvVersion)
+                                               // Unless this is SPIR-V 1.4 and is explicitly allowed.
+                                               if (progIter.getProgram().buildOptions.targetVersion > maxSpirvVersion && !(allowSpirV14 && progIter.getProgram().buildOptions.supports_VK_KHR_spirv_1_4 && progIter.getProgram().buildOptions.targetVersion == vk::SPIRV_VERSION_1_4))
                                                        continue;
 
                                                programs.pushBack(Program(vk::ProgramIdentifier(casePath, progIter.getName()), progIter.getProgram().buildOptions.getSpirvValidatorOptions()));
@@ -475,7 +478,8 @@ BuildStats buildPrograms (tcu::TestContext&                 testCtx,
                                                 ++progIter)
                                        {
                                                // Source program requires higher SPIR-V version than available: skip it to avoid fail
-                                               if (progIter.getProgram().buildOptions.targetVersion > maxSpirvVersion)
+                                               // Unless this is SPIR-V 1.4 and is explicitly allowed.
+                                               if (progIter.getProgram().buildOptions.targetVersion > maxSpirvVersion && !(allowSpirV14 && progIter.getProgram().buildOptions.supports_VK_KHR_spirv_1_4 && progIter.getProgram().buildOptions.targetVersion == vk::SPIRV_VERSION_1_4))
                                                        continue;
 
                                                programs.pushBack(Program(vk::ProgramIdentifier(casePath, progIter.getName()), progIter.getProgram().buildOptions.getSpirvValidatorOptions()));
@@ -562,6 +566,7 @@ DE_DECLARE_COMMAND_LINE_OPT(ShaderCacheFilename,    std::string);
 DE_DECLARE_COMMAND_LINE_OPT(ShaderCacheTruncate,       bool);
 DE_DECLARE_COMMAND_LINE_OPT(SpirvOptimize,                     bool);
 DE_DECLARE_COMMAND_LINE_OPT(SpirvOptimizationRecipe,std::string);
+DE_DECLARE_COMMAND_LINE_OPT(SpirvAllow14,                      bool);
 
 static const de::cmdline::NamedValue<bool> s_enableNames[] =
 {
@@ -590,7 +595,8 @@ void registerOptions (de::cmdline::Parser& parser)
                << Option<opt::ShaderCacheFilename>("r", "shadercache-filename", "Write shader cache to given file", "shadercache.bin")
                << Option<opt::ShaderCacheTruncate>("x", "shadercache-truncate", "Truncate shader cache before running", s_enableNames, "enable")
                << Option<opt::SpirvOptimize>("o", "deqp-optimize-spirv", "Enable optimization for SPIR-V", s_enableNames, "disable")
-               << Option<opt::SpirvOptimizationRecipe>("p","deqp-optimization-recipe", "Shader optimization recipe");
+               << Option<opt::SpirvOptimizationRecipe>("p","deqp-optimization-recipe", "Shader optimization recipe")
+               << Option<opt::SpirvAllow14>("e","allow-spirv-14", "Allow SPIR-V 1.4 with Vulkan 1.1");
 }
 
 } // opt
@@ -682,7 +688,8 @@ int main (int argc, const char* argv[])
                                                                                                                                 cmdLine.getOption<opt::Validate>(),
                                                                                                                                 cmdLine.getOption<opt::VulkanVersion>(),
                                                                                                                                 baselineSpirvVersion,
-                                                                                                                                maxSpirvVersion);
+                                                                                                                                maxSpirvVersion,
+                                                                                                                                cmdLine.getOption<opt::SpirvAllow14>());
 
                tcu::print("DONE: %d passed, %d failed, %d not supported\n", stats.numSucceeded, stats.numFailed, stats.notSupported);