Skip to content

Commit 08de73a

Browse files
authored
Copy default target's optionSet to code-gen target's optionSet (shader-slang#4073)
In current implementation, the some options will be to added to the target that is only specified by command line "-target". But if user specifies the target by just using slang API, e.g. 'spAddCodeGenTarget', those options will be missed. To fix the problem, we copy the default target's options to the code-gen target's option set. The default target will only be useful when there is no target specified in the command line.
1 parent 9043bc5 commit 08de73a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

source/slang/slang-compiler.h

+2
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,8 @@ namespace Slang
28352835
};
28362836
Dictionary<TargetRequest*, RefPtr<TargetInfo>> m_targetInfos;
28372837

2838+
CompilerOptionSet m_optionSetForDefaultTarget;
2839+
28382840
CompilerOptionSet& getTargetOptionSet(TargetRequest* req);
28392841

28402842
CompilerOptionSet& getTargetOptionSet(Index targetIndex);

source/slang/slang-options.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,23 @@ SlangResult OptionsParser::_parse(
29092909

29102910
// Copy all settings from linkage to targets.
29112911
for (auto target : linkage->targets)
2912+
{
29122913
target->getOptionSet().inheritFrom(linkage->m_optionSet);
2914+
2915+
// If there is no target specified in command line, we should inherit the default target options.
2916+
if(m_rawTargets.getCount() == 0)
2917+
{
2918+
target->getOptionSet().inheritFrom(m_defaultTarget.optionSet);
2919+
}
2920+
}
2921+
2922+
// If there are no targets specified in command line, and addCodeGenTarget() is not called
2923+
// yet, the options for the default target will be gone after option parsing. We
2924+
// should save the option for the future use when addCodeGenTarget() is called.
2925+
if ((linkage->targets.getCount() == 0) && (m_rawTargets.getCount() == 0))
2926+
{
2927+
m_requestImpl->m_optionSetForDefaultTarget = m_defaultTarget.optionSet;
2928+
}
29132929

29142930
applySettingsToDiagnosticSink(m_requestImpl->getSink(), m_sink, linkage->m_optionSet);
29152931

source/slang/slang.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5529,6 +5529,7 @@ void EndToEndCompileRequest::_completeTargetRequest(UInt targetIndex)
55295529
TargetRequest* targetRequest = linkage->targets[Index(targetIndex)];
55305530

55315531
targetRequest->getOptionSet().inheritFrom(getLinkage()->m_optionSet);
5532+
targetRequest->getOptionSet().inheritFrom(m_optionSetForDefaultTarget);
55325533
}
55335534

55345535
void EndToEndCompileRequest::setCodeGenTarget(SlangCompileTarget target)

0 commit comments

Comments
 (0)