From 064c28f58e845be67a31283cb885b22f32118f49 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Sun, 9 Jul 2017 18:08:22 -0700 Subject: 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. --- source/slang/slang.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'source/slang/slang.cpp') 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( -- cgit v1.2.3