diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-07-09 18:08:22 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-07-09 18:08:22 -0700 |
| commit | 064c28f58e845be67a31283cb885b22f32118f49 (patch) | |
| tree | 559cde481de3dc37ad0e571380367bb0a6ebc3ca /source/slang/slang.cpp | |
| parent | 54364eb1aef3fc6aa87b144ba91ca0a77818e4a4 (diff) | |
Pick layout rules based on target languge, not source.
The tricky bit here was that the `reflection-json` output format isn't really a code generation target like the others, and we need to be able to have multiple "targets" active to make sense of it. This needs cleaning-up.
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index e5bfcb923..af68060cd 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -179,6 +179,30 @@ void CompileRequest::checkAllTranslationUnits() checkTranslationUnit(translationUnit.Ptr()); } } +// Try to infer a single common source language for a request +static SourceLanguage inferSourceLanguage(CompileRequest* request) +{ + SourceLanguage language = SourceLanguage::Unknown; + for (auto& translationUnit : request->translationUnits) + { + // Allow any other language to overide Slang as a choice + if (language == SourceLanguage::Unknown + || language == SourceLanguage::Slang) + { + language = translationUnit->sourceLanguage; + } + else if (language == translationUnit->sourceLanguage) + { + // same language as we currently have, so keep going + } + else + { + // we found a mismatch, so inference fails + return SourceLanguage::Unknown; + } + } + return language; +} int CompileRequest::executeActionsInner() { @@ -197,6 +221,26 @@ int CompileRequest::executeActionsInner() } } + // If no code-generation target was specified, then try to infer one from the source language, + // just to make sure we can do something reasonable when `reflection-json` is specified + if (Target == CodeGenTarget::Unknown) + { + auto language = inferSourceLanguage(this); + switch (language) + { + case SourceLanguage::HLSL: + Target = CodeGenTarget::DXBytecodeAssembly; + break; + + case SourceLanguage::GLSL: + Target = CodeGenTarget::SPIRVAssembly; + break; + + default: + break; + } + } + #if 0 // If we are being asked to do pass-through, then we need to do that here... if (passThrough != PassThroughMode::None) @@ -628,7 +672,17 @@ SLANG_API void spSetCodeGenTarget( SlangCompileRequest* request, int target) { - REQ(request)->Target = (Slang::CodeGenTarget)target; + if (target == SLANG_REFLECTION_JSON) + { + // HACK: We special case this because reflection JSON is actually + // an additional output step that layers on top of an existing + // target + REQ(request)->extraTarget = Slang::CodeGenTarget::ReflectionJSON; + } + else + { + REQ(request)->Target = (Slang::CodeGenTarget)target; + } } SLANG_API void spSetPassThrough( |
