summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ast-modifier.h2
-rw-r--r--source/slang/slang-check-modifier.cpp6
-rw-r--r--source/slang/slang-diagnostic-defs.h1
-rw-r--r--source/slang/slang-options.cpp43
-rw-r--r--source/slang/slang-options.h4
-rw-r--r--source/slang/slang-parser.cpp5
-rw-r--r--source/slang/slang.cpp27
7 files changed, 60 insertions, 28 deletions
diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h
index 97487f131..53d13d1b5 100644
--- a/source/slang/slang-ast-modifier.h
+++ b/source/slang/slang-ast-modifier.h
@@ -32,7 +32,7 @@ class ConstExprModifier : public Modifier { SLANG_AST_CLASS(ConstExprModifier)};
class GloballyCoherentModifier : public Modifier { SLANG_AST_CLASS(GloballyCoherentModifier)};
class ExternCppModifier : public Modifier { SLANG_AST_CLASS(ExternCppModifier)};
class GLSLPrecisionModifier : public Modifier { SLANG_AST_CLASS(GLSLPrecisionModifier)};
-
+class GLSLModuleModifier : public Modifier {SLANG_AST_CLASS(GLSLModuleModifier)};
// Marks that the definition of a decl is not yet synthesized.
class ToBeSynthesizedModifier : public Modifier {SLANG_AST_CLASS(ToBeSynthesizedModifier)};
diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp
index 96ec0acc8..1a7f64944 100644
--- a/source/slang/slang-check-modifier.cpp
+++ b/source/slang/slang-check-modifier.cpp
@@ -1125,7 +1125,11 @@ namespace Slang
if (auto decl = as<Decl>(syntaxNode))
{
- if (!isModifierAllowedOnDecl(getLinkage()->getAllowGLSLInput(), m->astNodeType, decl))
+ auto moduleDecl = getModuleDecl(decl);
+ bool isGLSLInput = getLinkage()->getAllowGLSLInput();
+ if (!isGLSLInput && moduleDecl && moduleDecl->findModifier<GLSLModuleModifier>())
+ isGLSLInput = true;
+ if (!isModifierAllowedOnDecl(isGLSLInput, m->astNodeType, decl))
{
getSink()->diagnose(m, Diagnostics::modifierNotAllowed, m);
return m;
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 9bad4b716..d0e188292 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -66,7 +66,6 @@ DIAGNOSTIC( 8, Error, outputPathsImplyDifferentFormats,
"the output paths '$0' and '$1' require different code-generation targets")
DIAGNOSTIC( 10, Error, explicitOutputPathsAndMultipleTargets, "canot use both explicit output paths ('-o') and multiple targets ('-target')")
-DIAGNOSTIC( 11, Error, glslIsNotSupported, "the Slang compiler does not support GLSL as a source language by default, please use -allow-glsl")
DIAGNOSTIC( 12, Error, cannotDeduceSourceLanguage, "can't deduce language for input file '$0'")
DIAGNOSTIC( 13, Error, unknownCodeGenerationTarget, "unknown code generation target '$0'")
DIAGNOSTIC( 14, Error, unknownProfile, "unknown profile '$0'")
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;
}
diff --git a/source/slang/slang-options.h b/source/slang/slang-options.h
index bb05312a3..92c11a88a 100644
--- a/source/slang/slang-options.h
+++ b/source/slang/slang-options.h
@@ -19,5 +19,9 @@ SlangResult parseOptions(
// Initialize command options. Holds the details how parsing works.
void initCommandOptions(CommandOptions& commandOptions);
+enum class Stage : SlangUInt32;
+
+SlangSourceLanguage findSourceLanguageFromPath(const String& path, Stage& outImpliedStage);
+
}
#endif
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index f5312e645..a086b3c7a 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -4650,6 +4650,8 @@ namespace Slang
importDecl->scope = currentScope;
AddMember(currentScope, importDecl);
}
+ auto glslModuleModifier = astBuilder->create<GLSLModuleModifier>();
+ addModifier(currentModule, glslModuleModifier);
}
parseDecls(this, program, MatchedTokenType::File);
@@ -7360,7 +7362,8 @@ namespace Slang
{
ParserOptions options = {};
options.enableEffectAnnotations = translationUnit->compileRequest->getLinkage()->getEnableEffectAnnotations();
- options.allowGLSLInput = translationUnit->compileRequest->getLinkage()->getAllowGLSLInput();
+ options.allowGLSLInput = translationUnit->compileRequest->getLinkage()->getAllowGLSLInput() ||
+ translationUnit->sourceLanguage == SourceLanguage::GLSL;
options.isInLanguageServer = translationUnit->compileRequest->getLinkage()->isInLanguageServer();
Parser parser(astBuilder, tokens, sink, outerScope, options);
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 8eb75c119..a027340b5 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -25,7 +25,6 @@
#include "slang-mangle.h"
#include "slang-parser.h"
#include "slang-preprocessor.h"
-
#include "slang-type-layout.h"
#include "slang-options.h"
@@ -2601,23 +2600,6 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
{
// Make sure SourceFile representation is available for all translationUnits
SLANG_RETURN_ON_FAIL(translationUnit->requireSourceFiles());
-
- if(!getLinkage()->getAllowGLSLInput())
- {
- // We currently allow GlSL files on the command line so that we can
- // drive our "pass-through" mode, but we really want to issue an error
- // message if the user is seriously asking us to compile them and
- // doesn't explicitly opt into the glsl frontend
- switch(translationUnit->sourceLanguage)
- {
- default:
- break;
-
- case SourceLanguage::GLSL:
- getSink()->diagnose(SourceLoc(), Diagnostics::glslIsNotSupported);
- return SLANG_FAIL;
- }
- }
}
@@ -3138,8 +3120,17 @@ RefPtr<Module> Linkage::loadModule(
RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest(frontEndReq);
translationUnit->compileRequest = frontEndReq;
translationUnit->moduleName = name;
+ Stage impliedStage;
translationUnit->sourceLanguage = SourceLanguage::Slang;
+ // If we are loading from a file with apparaent glsl extension,
+ // set the source language to GLSL to enable GLSL compatibility mode.
+ if ((SourceLanguage)findSourceLanguageFromPath(filePathInfo.getName(), impliedStage) ==
+ SourceLanguage::GLSL)
+ {
+ translationUnit->sourceLanguage = SourceLanguage::GLSL;
+ }
+
frontEndReq->addTranslationUnit(translationUnit);
auto module = translationUnit->getModule();