mirror of
https://github.com/RPCS3/glslang.git
synced 2024-11-24 03:39:51 +00:00
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
|
||||
)
|
||||
target_link_libraries(SPIRV glslang SPIRV-Tools-opt)
|
||||
target_include_directories(SPIRV PUBLIC ../External)
|
||||
else()
|
||||
target_link_libraries(SPIRV glslang)
|
||||
endif(ENABLE_OPT)
|
||||
|
@ -716,4 +716,25 @@ void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream)
|
||||
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
|
||||
|
@ -45,8 +45,12 @@
|
||||
|
||||
namespace spv {
|
||||
|
||||
// disassemble with glslang custom disassembler
|
||||
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
|
||||
|
||||
#endif // disassembler_H
|
||||
|
@ -33,6 +33,7 @@ endif(WIN32)
|
||||
|
||||
target_link_libraries(glslangValidator ${LIBRARIES})
|
||||
target_link_libraries(spirv-remap ${LIBRARIES})
|
||||
target_include_directories(glslangValidator PUBLIC ../External)
|
||||
|
||||
if(WIN32)
|
||||
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),
|
||||
};
|
||||
bool targetHlslFunctionality1 = false;
|
||||
bool SpvToolsDisassembler = false;
|
||||
|
||||
//
|
||||
// Return codes from main/exit().
|
||||
@ -506,6 +507,8 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
||||
sourceEntryPointName = argv[1];
|
||||
bumpArg();
|
||||
break;
|
||||
} else if (lowerword == "spirv-dis") {
|
||||
SpvToolsDisassembler = true;
|
||||
} else if (lowerword == "stdin") {
|
||||
Options |= EOptionStdin;
|
||||
shaderStageName = argv[1];
|
||||
@ -982,9 +985,15 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1405,6 +1414,8 @@ void usage()
|
||||
" --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 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"
|
||||
" --source-entrypoint <name> the given shader source function is\n"
|
||||
" renamed to be the <name> given in -e\n"
|
||||
|
Loading…
Reference in New Issue
Block a user