Non-functional: Rationalize some existing use of SPIRV-Tools.

This commit is contained in:
John Kessenich 2018-08-22 17:12:46 -06:00
parent 1323bf8e39
commit e7df8e0b76
3 changed files with 86 additions and 70 deletions

View File

@ -3219,7 +3219,7 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& structType
// adjusting this late means inconsistencies with earlier code, which for reflection is an issue
// Until reflection is brought in sync with these adjustments, don't apply to $Global,
// which is the most likely to rely on reflection, and least likely to rely implicit layouts
if (glslangIntermediate->usingHlslOFfsets() &&
if (glslangIntermediate->usingHlslOffsets() &&
! memberType.isArray() && memberType.isVector() && structType.getTypeName().compare("$Global") != 0) {
int dummySize;
int componentAlignment = glslangIntermediate->getBaseAlignmentScalar(memberType, dummySize);
@ -7003,31 +7003,12 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsign
GlslangToSpv(intermediate, spirv, &logger, options);
}
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
spv::SpvBuildLogger* logger, SpvOptions* options)
{
TIntermNode* root = intermediate.getTreeRoot();
if (root == 0)
return;
glslang::SpvOptions defaultOptions;
if (options == nullptr)
options = &defaultOptions;
glslang::GetThreadPoolAllocator().push();
TGlslangToSpvTraverser it(intermediate.getSpv().spv, &intermediate, logger, *options);
root->traverse(&it);
it.finishSpv();
it.dumpSpv(spirv);
#if ENABLE_OPT
// If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan
// eg. forward and remove memory writes of opaque types.
if ((intermediate.getSource() == EShSourceHlsl ||
options->optimizeSize) &&
!options->disableOptimizer) {
// Apply the SPIRV-Tools validator to generated SPIR-V.
void SpirvToolsLegalize(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
spv::SpvBuildLogger* logger, const SpvOptions* options)
{
spv_target_env target_env = SPV_ENV_UNIVERSAL_1_2;
spvtools::Optimizer optimizer(target_env);
@ -7091,8 +7072,36 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsign
optimizer.RegisterPass(CreateAggressiveDCEPass());
optimizer.RegisterPass(CreateCFGCleanupPass());
if (!optimizer.Run(spirv.data(), spirv.size(), &spirv))
optimizer.Run(spirv.data(), spirv.size(), &spirv);
}
#endif
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
spv::SpvBuildLogger* logger, SpvOptions* options)
{
TIntermNode* root = intermediate.getTreeRoot();
if (root == 0)
return;
glslang::SpvOptions defaultOptions;
if (options == nullptr)
options = &defaultOptions;
glslang::GetThreadPoolAllocator().push();
TGlslangToSpvTraverser it(intermediate.getSpv().spv, &intermediate, logger, *options);
root->traverse(&it);
it.finishSpv();
it.dumpSpv(spirv);
#if ENABLE_OPT
// If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan
// eg. forward and remove memory writes of opaque types.
if ((intermediate.getSource() == EShSourceHlsl || options->optimizeSize) &&
!options->disableOptimizer) {
SpirvToolsLegalize(intermediate, spirv, logger, options);
}
#endif

View File

@ -723,16 +723,23 @@ void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream)
// Use the SPIRV-Tools disassembler to print SPIR-V.
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv)
{
// disassemble
spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3);
spv_text text;
spv_diagnostic diagnostic = nullptr;
spvBinaryToText(context, &spirv.front(), spirv.size(),
spvBinaryToText(context, spirv.data(), spirv.size(),
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT,
&text, &diagnostic);
// dump
if (diagnostic == nullptr)
out << text->str;
else
spvDiagnosticPrint(diagnostic);
// teardown
spvDiagnosticDestroy(diagnostic);
spvContextDestroy(context);
}
#endif

View File

@ -349,7 +349,7 @@ public:
if (hlslOffsets)
processes.addProcess("hlsl-offsets");
}
bool usingHlslOFfsets() const { return hlslOffsets; }
bool usingHlslOffsets() const { return hlslOffsets; }
void setUseStorageBuffer()
{
useStorageBuffer = true;