SPV: Add option to print disassembly in standard form using SPIRV-Tools.
This commit is contained in:
parent
6d61684f4b
commit
e2156222d3
@ -60,6 +60,7 @@ if(ENABLE_OPT)
|
|||||||
PRIVATE ${spirv-tools_SOURCE_DIR}/source
|
PRIVATE ${spirv-tools_SOURCE_DIR}/source
|
||||||
)
|
)
|
||||||
target_link_libraries(SPIRV glslang SPIRV-Tools-opt)
|
target_link_libraries(SPIRV glslang SPIRV-Tools-opt)
|
||||||
|
target_include_directories(SPIRV PUBLIC ../External)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(SPIRV glslang)
|
target_link_libraries(SPIRV glslang)
|
||||||
endif(ENABLE_OPT)
|
endif(ENABLE_OPT)
|
||||||
|
|||||||
@ -716,4 +716,25 @@ void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream)
|
|||||||
SpirvStream.processInstructions();
|
SpirvStream.processInstructions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_OPT
|
||||||
|
|
||||||
|
#include "spirv-tools/source/disassemble.h"
|
||||||
|
|
||||||
|
// Use the SPIRV-Tools disassembler to print SPIR-V.
|
||||||
|
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv)
|
||||||
|
{
|
||||||
|
spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3);
|
||||||
|
spv_text text;
|
||||||
|
spv_diagnostic diagnostic = nullptr;
|
||||||
|
spvBinaryToText(context, &spirv.front(), spirv.size(),
|
||||||
|
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT,
|
||||||
|
&text, &diagnostic);
|
||||||
|
if (diagnostic == nullptr)
|
||||||
|
out << text->str;
|
||||||
|
else
|
||||||
|
spvDiagnosticPrint(diagnostic);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
}; // end namespace spv
|
}; // end namespace spv
|
||||||
|
|||||||
@ -45,8 +45,12 @@
|
|||||||
|
|
||||||
namespace spv {
|
namespace spv {
|
||||||
|
|
||||||
|
// disassemble with glslang custom disassembler
|
||||||
void Disassemble(std::ostream& out, const std::vector<unsigned int>&);
|
void Disassemble(std::ostream& out, const std::vector<unsigned int>&);
|
||||||
|
|
||||||
|
// disassemble with SPIRV-Tools disassembler
|
||||||
|
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& stream);
|
||||||
|
|
||||||
}; // end namespace spv
|
}; // end namespace spv
|
||||||
|
|
||||||
#endif // disassembler_H
|
#endif // disassembler_H
|
||||||
|
|||||||
@ -33,6 +33,7 @@ endif(WIN32)
|
|||||||
|
|
||||||
target_link_libraries(glslangValidator ${LIBRARIES})
|
target_link_libraries(glslangValidator ${LIBRARIES})
|
||||||
target_link_libraries(spirv-remap ${LIBRARIES})
|
target_link_libraries(spirv-remap ${LIBRARIES})
|
||||||
|
target_include_directories(glslangValidator PUBLIC ../External)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
source_group("Source" FILES ${SOURCES})
|
source_group("Source" FILES ${SOURCES})
|
||||||
|
|||||||
15
StandAlone/StandAlone.cpp
Normal file → Executable file
15
StandAlone/StandAlone.cpp
Normal file → Executable file
@ -102,6 +102,7 @@ enum TOptions {
|
|||||||
EOptionDumpBareVersion = (1 << 31),
|
EOptionDumpBareVersion = (1 << 31),
|
||||||
};
|
};
|
||||||
bool targetHlslFunctionality1 = false;
|
bool targetHlslFunctionality1 = false;
|
||||||
|
bool SpvToolsDisassembler = false;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Return codes from main/exit().
|
// Return codes from main/exit().
|
||||||
@ -506,6 +507,8 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
|||||||
sourceEntryPointName = argv[1];
|
sourceEntryPointName = argv[1];
|
||||||
bumpArg();
|
bumpArg();
|
||||||
break;
|
break;
|
||||||
|
} else if (lowerword == "spirv-dis") {
|
||||||
|
SpvToolsDisassembler = true;
|
||||||
} else if (lowerword == "stdin") {
|
} else if (lowerword == "stdin") {
|
||||||
Options |= EOptionStdin;
|
Options |= EOptionStdin;
|
||||||
shaderStageName = argv[1];
|
shaderStageName = argv[1];
|
||||||
@ -982,14 +985,20 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
} else {
|
} else {
|
||||||
glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
|
glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
|
||||||
}
|
}
|
||||||
if (Options & EOptionHumanReadableSpv) {
|
#if ENABLE_OPT
|
||||||
|
if (SpvToolsDisassembler)
|
||||||
|
spv::SpirvToolsDisassemble(std::cout, spirv);
|
||||||
|
#else
|
||||||
|
if (SpvToolsDisassembler)
|
||||||
|
printf("SPIRV-Tools is not enabled; use -H for human readable SPIR-V\n");
|
||||||
|
#endif
|
||||||
|
if (!SpvToolsDisassembler && (Options & EOptionHumanReadableSpv))
|
||||||
spv::Disassemble(std::cout, spirv);
|
spv::Disassemble(std::cout, spirv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Free everything up, program has to go before the shaders
|
// Free everything up, program has to go before the shaders
|
||||||
// because it might have merged stuff from the shaders, and
|
// because it might have merged stuff from the shaders, and
|
||||||
@ -1405,6 +1414,8 @@ void usage()
|
|||||||
" --shift-UBO-binding [stage] [num set]... per-descriptor-set shift values\n"
|
" --shift-UBO-binding [stage] [num set]... per-descriptor-set shift values\n"
|
||||||
" --shift-cbuffer-binding [stage] num synonym for --shift-UBO-binding\n"
|
" --shift-cbuffer-binding [stage] num synonym for --shift-UBO-binding\n"
|
||||||
" --shift-cbuffer-binding [stage] [num set]... per-descriptor-set shift values\n"
|
" --shift-cbuffer-binding [stage] [num set]... per-descriptor-set shift values\n"
|
||||||
|
" --spirv-dis output standard form disassembly; works only\n"
|
||||||
|
" when a SPIR-V generation option is also used\n"
|
||||||
" --sub [stage] num synonym for --shift-UBO-binding\n"
|
" --sub [stage] num synonym for --shift-UBO-binding\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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user