diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit.cpp | 17 | ||||
| -rw-r--r-- | source/slang/slang-ir-strip-debug-info.cpp | 33 | ||||
| -rw-r--r-- | source/slang/slang-ir-strip-debug-info.h | 9 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 15 |
4 files changed, 73 insertions, 1 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index d8594ffdd..70521c7ee 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -94,6 +94,7 @@ #include "slang-ir-ssa-simplification.h" #include "slang-ir-ssa.h" #include "slang-ir-string-hash.h" +#include "slang-ir-strip-debug-info.h" #include "slang-ir-strip-default-construct.h" #include "slang-ir-strip-legalization-insts.h" #include "slang-ir-synthesize-active-mask.h" @@ -301,6 +302,7 @@ struct LinkingAndOptimizationOptions // struct RequiredLoweringPassSet { + bool debugInfo; bool resultType; bool optionalType; bool combinedTextureSamplers; @@ -332,6 +334,13 @@ void calcRequiredLoweringPassSet( { switch (inst->getOp()) { + case kIROp_DebugValue: + case kIROp_DebugVar: + case kIROp_DebugLine: + case kIROp_DebugLocationDecoration: + case kIROp_DebugSource: + result.debugInfo = true; + break; case kIROp_ResultType: result.resultType = true; break; @@ -584,6 +593,7 @@ Result linkAndOptimizeIR( auto target = codeGenContext->getTargetFormat(); auto targetRequest = codeGenContext->getTargetReq(); auto targetProgram = codeGenContext->getTargetProgram(); + auto targetCompilerOptions = targetRequest->getOptionSet(); // Get the artifact desc for the target const auto artifactDesc = ArtifactDescUtil::makeDescForCompileTarget(asExternal(target)); @@ -615,6 +625,13 @@ Result linkAndOptimizeIR( RequiredLoweringPassSet requiredLoweringPassSet = {}; calcRequiredLoweringPassSet(requiredLoweringPassSet, codeGenContext, irModule->getModuleInst()); + // Debug info is added by the front-end, and therefore needs to be stripped out by targets that + // opt out of debug info. + if (requiredLoweringPassSet.debugInfo && + (targetCompilerOptions.getIntOption(CompilerOptionName::DebugInformation) == + SLANG_DEBUG_INFO_LEVEL_NONE)) + stripDebugInfo(irModule); + if (!isKhronosTarget(targetRequest) && requiredLoweringPassSet.glslSSBO) lowerGLSLShaderStorageBufferObjectsToStructuredBuffers(irModule, sink); diff --git a/source/slang/slang-ir-strip-debug-info.cpp b/source/slang/slang-ir-strip-debug-info.cpp new file mode 100644 index 000000000..8b2a07663 --- /dev/null +++ b/source/slang/slang-ir-strip-debug-info.cpp @@ -0,0 +1,33 @@ +#include "slang-ir-strip-debug-info.h" + +#include "slang-ir-insts.h" + +namespace Slang +{ +static void findDebugInfo(IRInst* inst, List<IRInst*>& debugInstructions) +{ + switch (inst->getOp()) + { + case kIROp_DebugValue: + case kIROp_DebugVar: + case kIROp_DebugLine: + case kIROp_DebugLocationDecoration: + case kIROp_DebugSource: + debugInstructions.add(inst); + break; + default: + break; + } + + for (auto child : inst->getChildren()) + findDebugInfo(child, debugInstructions); +} + +void stripDebugInfo(IRModule* irModule) +{ + List<IRInst*> debugInstructions; + findDebugInfo(irModule->getModuleInst(), debugInstructions); + for (auto debugInst : debugInstructions) + debugInst->removeAndDeallocate(); +} +} // namespace Slang diff --git a/source/slang/slang-ir-strip-debug-info.h b/source/slang/slang-ir-strip-debug-info.h new file mode 100644 index 000000000..67aac1abb --- /dev/null +++ b/source/slang/slang-ir-strip-debug-info.h @@ -0,0 +1,9 @@ +#pragma once + +namespace Slang +{ +struct IRModule; + +/// Strip all debug info instructions from `irModule` +void stripDebugInfo(IRModule* irModule); +} // namespace Slang diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 21944e4f3..ee0aa4c14 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -842,6 +842,16 @@ Session::createSession(slang::SessionDesc const& inDesc, slang::ISession** outSe } } + // If any target requires debug info, then we will need to enable debug info when lowering to + // target-agnostic IR. The target-agnostic IR will only include debug info if the linkage IR + // options specify that it should, so make sure the linkage debug info level is greater than or + // equal to that of any target. + DebugInfoLevel linkageDebugInfoLevel = linkage->m_optionSet.getDebugInfoLevel(); + for (auto target : linkage->targets) + linkageDebugInfoLevel = + Math::Max(linkageDebugInfoLevel, target->getOptionSet().getDebugInfoLevel()); + linkage->m_optionSet.set(CompilerOptionName::DebugInformation, linkageDebugInfoLevel); + *outSession = asExternal(linkage.detach()); return SLANG_OK; } @@ -1337,7 +1347,10 @@ void Linkage::addTarget(slang::TargetDesc const& desc) optionSet.setProfile(Profile(desc.profile)); optionSet.set(CompilerOptionName::LineDirectiveMode, LineDirectiveMode(desc.lineDirectiveMode)); optionSet.set(CompilerOptionName::GLSLForceScalarLayout, desc.forceGLSLScalarBufferLayout); - optionSet.load(desc.compilerOptionEntryCount, desc.compilerOptionEntries); + + CompilerOptionSet targetOptions; + targetOptions.load(desc.compilerOptionEntryCount, desc.compilerOptionEntries); + optionSet.overrideWith(targetOptions); } #if 0 |
