diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-07-14 16:31:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-14 16:31:12 -0400 |
| commit | 2de296ca00c0e77526ae1a83b4fb3df30419f70b (patch) | |
| tree | 1aeac2f3d07890532ac0d359ca6bf2d1d010dbd8 /source | |
| parent | 68f80f0793cff96b1fc784059a76605888593cd8 (diff) | |
Allow setting of HLSLToVulkan options without having a target specified on the command line options. (#2989)
Diffstat (limited to 'source')
| -rwxr-xr-x | source/slang/slang-compiler.h | 8 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 12 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 29 |
3 files changed, 38 insertions, 11 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index e6385c76d..df9f52010 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -2764,6 +2764,9 @@ namespace Slang DiagnosticSink* getSink() { return &m_sink; } NamePool* getNamePool() { return getLinkage()->getNamePool(); } + void setHLSLToVulkanLayoutOptions(HLSLToVulkanLayoutOptions* hlslToVulkanLayoutOptions) { m_hlslToVulkanLayoutOptions = hlslToVulkanLayoutOptions; } + HLSLToVulkanLayoutOptions* getHLSLToVulkanLayoutOptions() const { return m_hlslToVulkanLayoutOptions; } + FrontEndCompileRequest* getFrontEndReq() { return m_frontEndReq; } ComponentType* getUnspecializedGlobalComponentType() { return getFrontEndReq()->getGlobalComponentType(); } @@ -2823,6 +2826,9 @@ namespace Slang SlangResult _maybeWriteArtifact(const String& path, IArtifact* artifact); SlangResult _writeArtifact(const String& path, IArtifact* artifact); + /// Adds any extra settings to complete a targetRequest + void _completeTargetRequest(UInt targetIndex); + ISlangUnknown* getInterface(const Guid& guid); void generateOutput(ComponentType* program); @@ -2838,6 +2844,8 @@ namespace Slang RefPtr<ComponentType> m_specializedGlobalAndEntryPointsComponentType; List<RefPtr<ComponentType>> m_specializedEntryPoints; + RefPtr<HLSLToVulkanLayoutOptions> m_hlslToVulkanLayoutOptions; + // For output RefPtr<StdWriters> m_writers; diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index ad061a4e5..552d5bc47 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -2351,12 +2351,16 @@ SlangResult OptionsParser::_parse( } } - // If there are no layout settings, we don't need to carry this state - if (m_hlslToVulkanLayoutOptions->isReset()) + // If there is state set on HLSL to Vulkan layout settings, set on the end to end request + // such can be added when target requests are setup + if (!m_hlslToVulkanLayoutOptions->isReset()) { - m_hlslToVulkanLayoutOptions.setNull(); + m_requestImpl->setHLSLToVulkanLayoutOptions(m_hlslToVulkanLayoutOptions); } + // No longer need to track + m_hlslToVulkanLayoutOptions.setNull(); + if (m_compileStdLib) { SLANG_RETURN_ON_FAIL(m_session->compileStdLib(m_compileStdLibFlags)); @@ -2762,8 +2766,6 @@ SlangResult OptionsParser::_parse( int targetID = m_compileRequest->addCodeGenTarget(SlangCompileTarget(rawTarget.format)); rawTarget.targetID = targetID; - m_requestImpl->setHLSLToVulkanLayoutOptions(targetID, m_hlslToVulkanLayoutOptions); - if (rawTarget.profileVersion != ProfileVersion::Unknown) { m_compileRequest->setTargetProfile(targetID, SlangProfileID(Profile(rawTarget.profileVersion).raw)); diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 28227b39b..d8174190b 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -2911,7 +2911,7 @@ UInt Linkage::addTarget( Index result = targets.getCount(); targets.add(targetReq); - return (int) result; + return UInt(result); } void Linkage::loadParsedModule( @@ -4679,19 +4679,36 @@ void EndToEndCompileRequest::setCommandLineCompilerMode() m_isCommandLineCompile = true; } +void EndToEndCompileRequest::_completeTargetRequest(UInt targetIndex) +{ + auto linkage = getLinkage(); + + TargetRequest* targetRequest = linkage->targets[Index(targetIndex)]; + + // If we have vulkan layout options, and the target is khronos add the options + if (m_hlslToVulkanLayoutOptions && isKhronosTarget(targetRequest)) + { + targetRequest->setHLSLToVulkanLayoutOptions(m_hlslToVulkanLayoutOptions); + } + + // Set the current line directive + targetRequest->setLineDirectiveMode(m_lineDirectiveMode); +} + void EndToEndCompileRequest::setCodeGenTarget(SlangCompileTarget target) { auto linkage = getLinkage(); linkage->targets.clear(); - linkage->addTarget(CodeGenTarget(target)); - linkage->targets[0]->setLineDirectiveMode(m_lineDirectiveMode); + const auto targetIndex = linkage->addTarget(CodeGenTarget(target)); + SLANG_ASSERT(targetIndex == 0); + _completeTargetRequest(0); } int EndToEndCompileRequest::addCodeGenTarget(SlangCompileTarget target) { - int targetIndex = (int)getLinkage()->addTarget(CodeGenTarget(target)); - getLinkage()->targets[targetIndex]->setLineDirectiveMode(m_lineDirectiveMode); - return targetIndex; + const auto targetIndex = getLinkage()->addTarget(CodeGenTarget(target)); + _completeTargetRequest(targetIndex); + return int(targetIndex); } void EndToEndCompileRequest::setTargetProfile(int targetIndex, SlangProfileID profile) |
