summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-options.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-01-31 23:53:28 -0800
committerGitHub <noreply@github.com>2024-02-01 15:53:28 +0800
commita2d2018a8be41aecd2c1810db8556e0c07595fb9 (patch)
tree747494c7c56cc50a47eca57dbcc200ebf6280b36 /source/slang/slang-options.cpp
parent2d0912bfe2de7799b32e80722fa5c8dc279a339b (diff)
Add slangc option to specialize entrypoint + auto glsl mode. (#3531)
* Add slangc option to specialize entrypoint. * Auto enable glsl mode when input file has glsl extension name. * Fix test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-options.cpp')
-rw-r--r--source/slang/slang-options.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index c9527bf5e..ae6195700 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -52,6 +52,7 @@ enum class OptionKind
MacroDefine,
DepFile,
EntryPointName,
+ Specialize,
Help,
HelpStyle,
Include,
@@ -393,6 +394,8 @@ void initCommandOptions(CommandOptions& options)
"When they do, the file associated with the entry point will be the first one found when searching to the left in the command line.\n"
"If no -entry options are given, compiler will use [shader(...)] "
"attributes to detect entry points."},
+ { OptionKind::Specialize, "-specialize", "-specialize <typename>",
+ "Specialize the last entrypoint with <typename>.\n"},
{ OptionKind::EmitIr, "-emit-ir", nullptr, "Emit IR typically as a '.slang-module' when outputting to a container." },
{ OptionKind::Help, "-h,-help,--help", "-h or -h <help-category>", "Print this message, or help in specified category." },
{ OptionKind::HelpStyle, "-help-style", "-help-style <help-style>", "Help formatting style" },
@@ -744,7 +747,7 @@ struct OptionsParser
Stage stage = Stage::Unknown;
int translationUnitIndex = -1;
int entryPointID = -1;
-
+ List<String> specializationArgs;
// State for tracking command-line errors
bool conflictingStagesSet = false;
bool redundantStageSet = false;
@@ -786,8 +789,6 @@ struct OptionsParser
static Profile::RawVal findGlslProfileFromPath(const String& path);
- static SlangSourceLanguage findSourceLanguageFromPath(const String& path, Stage& outImpliedStage);
-
SlangResult addInputPath(char const* inPath, SourceLanguage langOverride = SourceLanguage::Unknown);
void addOutputPath(String const& path, CodeGenTarget impliedFormat);
@@ -1007,7 +1008,7 @@ void OptionsParser::addInputForeignShaderPath(
return Profile::Unknown;
}
-/* static */SlangSourceLanguage OptionsParser::findSourceLanguageFromPath(const String& path, Stage& outImpliedStage)
+SlangSourceLanguage findSourceLanguageFromPath(const String& path, Stage& outImpliedStage)
{
struct Entry
{
@@ -1032,6 +1033,12 @@ void OptionsParser::addInputForeignShaderPath(
{ ".comp", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_COMPUTE },
{ ".mesh", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_MESH },
{ ".task", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_AMPLIFICATION },
+ { ".rgen", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_RAY_GENERATION },
+ { ".rint", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_INTERSECTION },
+ { ".rahit", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_ANY_HIT },
+ { ".rchit", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_CLOSEST_HIT },
+ { ".rmiss", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_MISS },
+ { ".rcall", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_CALLABLE },
{ ".c", SLANG_SOURCE_LANGUAGE_C, SLANG_STAGE_NONE },
{ ".cpp", SLANG_SOURCE_LANGUAGE_CPP, SLANG_STAGE_NONE },
@@ -2179,6 +2186,24 @@ SlangResult OptionsParser::_parse(
m_rawEntryPoints.add(rawEntryPoint);
break;
}
+ case OptionKind::Specialize:
+ {
+ for (;;)
+ {
+ CommandLineArg name;
+ SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
+ if (m_rawEntryPoints.getCount() > 0)
+ {
+ auto& lastEntryPoint = m_rawEntryPoints.getLast();
+ lastEntryPoint.specializationArgs.add(name.value);
+ }
+ if (m_reader.hasArg() && m_reader.peekArg().value == ",")
+ m_reader.advance();
+ else
+ break;
+ }
+ break;
+ }
case OptionKind::Language:
{
CommandLineArg name;
@@ -2668,10 +2693,16 @@ SlangResult OptionsParser::_parse(
auto translationUnitID = m_rawTranslationUnits[rawEntryPoint.translationUnitIndex].translationUnitID;
- int entryPointID = m_compileRequest->addEntryPoint(
+ List<const char*> specializationArgs;
+ for (auto& arg : rawEntryPoint.specializationArgs)
+ specializationArgs.add(arg.getBuffer());
+
+ int entryPointID = m_compileRequest->addEntryPointEx(
translationUnitID,
rawEntryPoint.name.begin(),
- SlangStage(rawEntryPoint.stage));
+ SlangStage(rawEntryPoint.stage),
+ (int)specializationArgs.getCount(),
+ specializationArgs.getBuffer());
rawEntryPoint.entryPointID = entryPointID;
}