summaryrefslogtreecommitdiff
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-11-14 17:46:05 -0800
committerGitHub <noreply@github.com>2023-11-14 17:46:05 -0800
commit12f7237e4060388494c549623f4a640327b7ca08 (patch)
tree407c0f8d20b4ccd49ae5df57f84c8f9a310f7055 /source/slang/slang.cpp
parentc71b12775c8b13ea2b181e42c04b8db55b10fb2f (diff)
Add GLSL Compatibility. (#3321)
* Parse glsl buffer blocks to GLSLInterfaceBlockDecl * Parse glsl local size layout declarations * Parse (and ignore) glsl version directives * spelling * Better l-value interpretation for glsl interface blocks * Better l-value interpretation for glsl interface blocks * Add compile flag for enabling glsl * Parse and ignore precision modifiers. * Automatically import `glsl` module for compatiblity. * Complete vector and matrix types for glsl * Remove generated file from repo * Bump .gitignore * do not mark out globals as params * Synthesize entrypoint layout from global inout vars. * update test result. * Allow HLSL semantic on global variables. * Fix. * Fix test. * Fix win32 compile error. * Add more builtin input/output and texture intrinsics. * Add struct/array constructor syntax. * Skip `#extension` lines. * overide operator * for matrix/vector multiplication. * Add `matrixCompMult`. * Parse modifiers in for loop init var declr. * Add more glsl intrinsics, add stage into to var layout. * Allow `int[3] x` syntax. * Fix array type syntax. --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com> Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp47
1 files changed, 33 insertions, 14 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index af853102a..0331a5f8e 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -2534,22 +2534,26 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
{
SLANG_AST_BUILDER_RAII(getLinkage()->getASTBuilder());
- // 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.
for (TranslationUnitRequest* translationUnit : translationUnits)
{
// Make sure SourceFile representation is available for all translationUnits
SLANG_RETURN_ON_FAIL(translationUnit->requireSourceFiles());
- switch(translationUnit->sourceLanguage)
+ if(!getLinkage()->getAllowGLSLInput())
{
- default:
- break;
+ // 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;
+ case SourceLanguage::GLSL:
+ getSink()->diagnose(SourceLoc(), Diagnostics::glslIsNotSupported);
+ return SLANG_FAIL;
+ }
}
}
@@ -3230,12 +3234,23 @@ RefPtr<Module> Linkage::findOrImportModule(
PathInfo pathIncludedFromInfo = getSourceManager()->getPathInfo(loc, SourceLocType::Actual);
PathInfo filePathInfo;
+ ComPtr<ISlangBlob> fileContents;
+
// We have to load via the found path - as that is how file was originally loaded
if (SLANG_FAILED(includeSystem.findFile(fileName, pathIncludedFromInfo.foundPath, filePathInfo)))
{
- sink->diagnose(loc, Diagnostics::cannotFindFile, fileName);
- mapNameToLoadedModules[name] = nullptr;
- return nullptr;
+ if (name && name->text == "glsl")
+ {
+ // This is a builtin glsl module, just load it from embedded definition.
+ fileContents = getSessionImpl()->getGLSLLibraryCode();
+ filePathInfo = PathInfo::makeFromString("glsl");
+ }
+ else
+ {
+ sink->diagnose(loc, Diagnostics::cannotFindFile, fileName);
+ mapNameToLoadedModules[name] = nullptr;
+ return nullptr;
+ }
}
// Maybe this was loaded previously at a different relative name?
@@ -3243,8 +3258,7 @@ RefPtr<Module> Linkage::findOrImportModule(
return loadedModule;
// Try to load it
- ComPtr<ISlangBlob> fileContents;
- if(SLANG_FAILED(includeSystem.loadFile(filePathInfo, fileContents)))
+ if( !fileContents && SLANG_FAILED(includeSystem.loadFile(filePathInfo, fileContents)))
{
sink->diagnose(loc, Diagnostics::cannotOpenFile, fileName);
mapNameToLoadedModules[name] = nullptr;
@@ -5267,6 +5281,11 @@ SlangResult EndToEndCompileRequest::setTypeNameForEntryPointExistentialTypeParam
return SLANG_OK;
}
+void EndToEndCompileRequest::setAllowGLSLInput(bool value)
+{
+ getLinkage()->setAllowGLSLInput(value);
+}
+
SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile()
{
SlangResult res = SLANG_FAIL;