SPV: Add option for controling when the SPIRV-Tools validator is used.

This commit is contained in:
John Kessenich 2018-08-23 15:29:08 -06:00
parent 717c80a9de
commit c340425bb2
6 changed files with 20 additions and 7 deletions

View File

@ -7015,6 +7015,7 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsign
it.dumpSpv(spirv); it.dumpSpv(spirv);
#if ENABLE_OPT #if ENABLE_OPT
if (options->validate)
SpirvToolsValidate(intermediate, spirv, logger); SpirvToolsValidate(intermediate, spirv, logger);
// If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan // If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan

View File

@ -51,11 +51,12 @@ namespace glslang {
struct SpvOptions { struct SpvOptions {
SpvOptions() : generateDebugInfo(false), disableOptimizer(true), SpvOptions() : generateDebugInfo(false), disableOptimizer(true),
optimizeSize(false), disassemble(false) { } optimizeSize(false), disassemble(false), validate(false) { }
bool generateDebugInfo; bool generateDebugInfo;
bool disableOptimizer; bool disableOptimizer;
bool optimizeSize; bool optimizeSize;
bool disassemble; bool disassemble;
bool validate;
}; };
#if ENABLE_OPT #if ENABLE_OPT

View File

@ -103,6 +103,7 @@ enum TOptions {
}; };
bool targetHlslFunctionality1 = false; bool targetHlslFunctionality1 = false;
bool SpvToolsDisassembler = false; bool SpvToolsDisassembler = false;
bool SpvToolsValidate = false;
// //
// Return codes from main/exit(). // Return codes from main/exit().
@ -514,6 +515,8 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
break; break;
} else if (lowerword == "spirv-dis") { } else if (lowerword == "spirv-dis") {
SpvToolsDisassembler = true; SpvToolsDisassembler = true;
} else if (lowerword == "spirv-val") {
SpvToolsValidate = true;
} else if (lowerword == "stdin") { } else if (lowerword == "stdin") {
Options |= EOptionStdin; Options |= EOptionStdin;
shaderStageName = argv[1]; shaderStageName = argv[1];
@ -979,6 +982,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
spvOptions.disableOptimizer = (Options & EOptionOptimizeDisable) != 0; spvOptions.disableOptimizer = (Options & EOptionOptimizeDisable) != 0;
spvOptions.optimizeSize = (Options & EOptionOptimizeSize) != 0; spvOptions.optimizeSize = (Options & EOptionOptimizeSize) != 0;
spvOptions.disassemble = SpvToolsDisassembler; spvOptions.disassemble = SpvToolsDisassembler;
spvOptions.validate = SpvToolsValidate;
glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger, &spvOptions); glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger, &spvOptions);
// Dump the spv to a file or stdout, etc., but only if not doing // 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" " --shift-cbuffer-binding | --scb synonyms for --shift-UBO-binding\n"
" --spirv-dis output standard-form disassembly; works only\n" " --spirv-dis output standard-form disassembly; works only\n"
" when a SPIR-V generation option is also used\n" " when a SPIR-V generation option is also used\n"
" --spirv-val execute the SPIRV-Tools validator\n"
" --source-entrypoint <name> the given shader source function is\n" " --source-entrypoint <name> the given shader source function is\n"
" renamed to be the <name> given in -e\n" " renamed to be the <name> given in -e\n"
" --sep synonym for --source-entrypoint\n" " --sep synonym for --source-entrypoint\n"

View File

@ -130,13 +130,13 @@ diff -b $BASEDIR/spv.looseUniformNoLoc.vert.out $TARGETDIR/spv.looseUniformNoLoc
# Testing debug information # Testing debug information
# #
echo Testing SPV 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 -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 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 -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 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 --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 -b $BASEDIR/spv.hlslDebugInfo.frag.out $TARGETDIR/spv.hlslDebugInfo.frag.out || HASERROR=1

View File

@ -79,6 +79,7 @@ TEST_P(LinkTestVulkan, FromFile)
std::vector<uint32_t> spirv_binary; std::vector<uint32_t> spirv_binary;
glslang::SpvOptions options; glslang::SpvOptions options;
options.disableOptimizer = true; options.disableOptimizer = true;
options.validate = true;
glslang::GlslangToSpv(*program.getIntermediate(shaders.front()->getStage()), glslang::GlslangToSpv(*program.getIntermediate(shaders.front()->getStage()),
spirv_binary, &logger, &options); spirv_binary, &logger, &options);

View File

@ -243,6 +243,7 @@ public:
std::vector<uint32_t> spirv_binary; std::vector<uint32_t> spirv_binary;
glslang::SpvOptions options; glslang::SpvOptions options;
options.disableOptimizer = !enableOptimizer; options.disableOptimizer = !enableOptimizer;
options.validate = true;
glslang::GlslangToSpv(*program.getIntermediate(stage), glslang::GlslangToSpv(*program.getIntermediate(stage),
spirv_binary, &logger, &options); spirv_binary, &logger, &options);
@ -298,8 +299,10 @@ public:
if (success && (controls & EShMsgSpvRules)) { if (success && (controls & EShMsgSpvRules)) {
std::vector<uint32_t> spirv_binary; std::vector<uint32_t> spirv_binary;
glslang::SpvOptions options;
options.validate = true;
glslang::GlslangToSpv(*program.getIntermediate(stage), glslang::GlslangToSpv(*program.getIntermediate(stage),
spirv_binary, &logger); spirv_binary, &logger, &options);
std::ostringstream disassembly_stream; std::ostringstream disassembly_stream;
spv::Parameterize(); spv::Parameterize();
@ -338,8 +341,10 @@ public:
if (success && (controls & EShMsgSpvRules)) { if (success && (controls & EShMsgSpvRules)) {
std::vector<uint32_t> spirv_binary; std::vector<uint32_t> spirv_binary;
glslang::SpvOptions options;
options.validate = true;
glslang::GlslangToSpv(*program.getIntermediate(stage), glslang::GlslangToSpv(*program.getIntermediate(stage),
spirv_binary, &logger); spirv_binary, &logger, &options);
spv::spirvbin_t(0 /*verbosity*/).remap(spirv_binary, remapOptions); spv::spirvbin_t(0 /*verbosity*/).remap(spirv_binary, remapOptions);