diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 3b494790..164fa230 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -7015,7 +7015,8 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vectorvalidate) + SpirvToolsValidate(intermediate, spirv, logger); // If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan // eg. forward and remove memory writes of opaque types. diff --git a/SPIRV/SpvTools.h b/SPIRV/SpvTools.h index 7a164387..08bcf3a2 100755 --- a/SPIRV/SpvTools.h +++ b/SPIRV/SpvTools.h @@ -51,11 +51,12 @@ namespace glslang { struct SpvOptions { SpvOptions() : generateDebugInfo(false), disableOptimizer(true), - optimizeSize(false), disassemble(false) { } + optimizeSize(false), disassemble(false), validate(false) { } bool generateDebugInfo; bool disableOptimizer; bool optimizeSize; bool disassemble; + bool validate; }; #if ENABLE_OPT diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 35b27b21..38ba597d 100755 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -103,6 +103,7 @@ enum TOptions { }; bool targetHlslFunctionality1 = false; bool SpvToolsDisassembler = false; +bool SpvToolsValidate = false; // // Return codes from main/exit(). @@ -514,6 +515,8 @@ void ProcessArguments(std::vector>& workItem break; } else if (lowerword == "spirv-dis") { SpvToolsDisassembler = true; + } else if (lowerword == "spirv-val") { + SpvToolsValidate = true; } else if (lowerword == "stdin") { Options |= EOptionStdin; shaderStageName = argv[1]; @@ -979,6 +982,7 @@ void CompileAndLinkShaderUnits(std::vector compUnits) spvOptions.disableOptimizer = (Options & EOptionOptimizeDisable) != 0; spvOptions.optimizeSize = (Options & EOptionOptimizeSize) != 0; spvOptions.disassemble = SpvToolsDisassembler; + spvOptions.validate = SpvToolsValidate; glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger, &spvOptions); // Dump the spv to a file or stdout, etc., but only if not doing @@ -1421,6 +1425,7 @@ void usage() " --shift-cbuffer-binding | --scb synonyms for --shift-UBO-binding\n" " --spirv-dis output standard-form disassembly; works only\n" " when a SPIR-V generation option is also used\n" + " --spirv-val execute the SPIRV-Tools validator\n" " --source-entrypoint the given shader source function is\n" " renamed to be the given in -e\n" " --sep synonym for --source-entrypoint\n" diff --git a/Test/runtests b/Test/runtests index ddd77ce8..d36f3a8c 100755 --- a/Test/runtests +++ b/Test/runtests @@ -130,13 +130,13 @@ diff -b $BASEDIR/spv.looseUniformNoLoc.vert.out $TARGETDIR/spv.looseUniformNoLoc # Testing debug information # echo Testing SPV Debug Information -$EXE -g --relaxed-errors --suppress-warnings --aml --amb --hlsl-offsets --nsf \ +$EXE -g --relaxed-errors --suppress-warnings --aml --amb --hlsl-offsets --nsf --spirv-val \ -G -H spv.debugInfo.frag --rsb frag 3 > $TARGETDIR/spv.debugInfo.frag.out diff -b $BASEDIR/spv.debugInfo.frag.out $TARGETDIR/spv.debugInfo.frag.out || HASERROR=1 -$EXE -g -Od --target-env vulkan1.1 --relaxed-errors --suppress-warnings --aml --hlsl-offsets --nsf \ +$EXE -g -Od --target-env vulkan1.1 --relaxed-errors --suppress-warnings --aml --hlsl-offsets --nsf --spirv-val \ -G -H spv.debugInfo.frag --rsb frag 3 > $TARGETDIR/spv.debugInfo.1.1.frag.out diff -b $BASEDIR/spv.debugInfo.1.1.frag.out $TARGETDIR/spv.debugInfo.1.1.frag.out || HASERROR=1 -$EXE -g -D -Od -e newMain -g --amb --aml --fua --hlsl-iomap --nsf --sib 1 --ssb 2 --sbb 3 --stb 4 --suavb 5 --sub 6 \ +$EXE -g -D -Od -e newMain -g --amb --aml --fua --hlsl-iomap --nsf --spirv-val --sib 1 --ssb 2 --sbb 3 --stb 4 --suavb 5 --sub 6 \ --sep origMain -H -Od spv.hlslDebugInfo.vert --rsb vert t0 0 0 > $TARGETDIR/spv.hlslDebugInfo.frag.out diff -b $BASEDIR/spv.hlslDebugInfo.frag.out $TARGETDIR/spv.hlslDebugInfo.frag.out || HASERROR=1 diff --git a/gtests/Link.FromFile.Vk.cpp b/gtests/Link.FromFile.Vk.cpp index beb79e18..22892f0b 100755 --- a/gtests/Link.FromFile.Vk.cpp +++ b/gtests/Link.FromFile.Vk.cpp @@ -79,6 +79,7 @@ TEST_P(LinkTestVulkan, FromFile) std::vector spirv_binary; glslang::SpvOptions options; options.disableOptimizer = true; + options.validate = true; glslang::GlslangToSpv(*program.getIntermediate(shaders.front()->getStage()), spirv_binary, &logger, &options); diff --git a/gtests/TestFixture.h b/gtests/TestFixture.h index a58978d3..3329fa3c 100755 --- a/gtests/TestFixture.h +++ b/gtests/TestFixture.h @@ -243,6 +243,7 @@ public: std::vector spirv_binary; glslang::SpvOptions options; options.disableOptimizer = !enableOptimizer; + options.validate = true; glslang::GlslangToSpv(*program.getIntermediate(stage), spirv_binary, &logger, &options); @@ -298,8 +299,10 @@ public: if (success && (controls & EShMsgSpvRules)) { std::vector spirv_binary; + glslang::SpvOptions options; + options.validate = true; glslang::GlslangToSpv(*program.getIntermediate(stage), - spirv_binary, &logger); + spirv_binary, &logger, &options); std::ostringstream disassembly_stream; spv::Parameterize(); @@ -338,8 +341,10 @@ public: if (success && (controls & EShMsgSpvRules)) { std::vector spirv_binary; + glslang::SpvOptions options; + options.validate = true; glslang::GlslangToSpv(*program.getIntermediate(stage), - spirv_binary, &logger); + spirv_binary, &logger, &options); spv::spirvbin_t(0 /*verbosity*/).remap(spirv_binary, remapOptions);