diff options
| author | Yong He <yonghe@outlook.com> | 2024-03-01 15:24:16 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-01 15:24:16 -0800 |
| commit | 9a1e327387ffa8552ac2f0aee8836a0b10a5578f (patch) | |
| tree | 2efdf8c0a62d517c615ef049d1b2ae6f75c630cf | |
| parent | e752a957c452abc1db2e160c738496b47aad2858 (diff) | |
Make slangc commandline parsing compatible with renderdoc. (#3658)
* Make slangc commandline parsing compatible with renderdoc.
* Fix tests.
| -rw-r--r-- | source/slang/slang-options.cpp | 20 | ||||
| -rw-r--r-- | tests/bindings/multi-file.hlsl | 4 | ||||
| -rw-r--r-- | tests/diagnostics/command-line/duplicate-target.slang | 2 | ||||
| -rw-r--r-- | tests/diagnostics/gh-38-vs.hlsl | 4 | ||||
| -rw-r--r-- | tests/spirv/renderdoc-cmd.slang | 0 |
5 files changed, 21 insertions, 9 deletions
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index f8231210c..5e009c46e 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -946,8 +946,14 @@ SlangResult OptionsParser::addInputPath(char const* inPath, SourceLanguage langO } Stage impliedStage = Stage::Unknown; - SlangSourceLanguage sourceLanguage = langOverride == SourceLanguage::Unknown ? findSourceLanguageFromPath(path, impliedStage) : SlangSourceLanguage(langOverride); - + SlangSourceLanguage sourceLanguage = SlangSourceLanguage(langOverride); + if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN) + { + if (m_requestImpl->getLinkage()->m_optionSet.hasOption(CompilerOptionName::Language)) + sourceLanguage = SlangSourceLanguage(m_requestImpl->getLinkage()->m_optionSet.getEnumOption<SlangSourceLanguage>(CompilerOptionName::Language)); + else + sourceLanguage = findSourceLanguageFromPath(path, impliedStage); + } if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN) { m_requestImpl->getSink()->diagnose(SourceLoc(), Diagnostics::cannotDeduceSourceLanguage, inPath); @@ -1888,7 +1894,9 @@ SlangResult OptionsParser::_parse( RawTarget rawTarget; rawTarget.format = CodeGenTarget(format); - + // Silently allow redundant targets if it is the same as the last specified target. + if (m_rawTargets.getCount() != 0 && m_rawTargets.getLast().format == rawTarget.format) + break; m_rawTargets.add(rawTarget); break; } @@ -1991,7 +1999,9 @@ SlangResult OptionsParser::_parse( RawEntryPoint rawEntryPoint; rawEntryPoint.name = name.value; rawEntryPoint.translationUnitIndex = m_currentTranslationUnitIndex; - + // Silently allow duplicate entrypoints if it is the same as the last specified one. + if (m_rawEntryPoints.getCount() != 0 && m_rawEntryPoints.getLast().name == rawEntryPoint.name) + break; m_rawEntryPoints.add(rawEntryPoint); break; } @@ -2032,6 +2042,7 @@ SlangResult OptionsParser::_parse( SLANG_RETURN_ON_FAIL(addInputPath(m_reader.getValueAndAdvance().getBuffer(), sourceLanguage)); } } + linkage->m_optionSet.add(CompilerOptionName::Language, (int)sourceLanguage); break; } case OptionKind::PassThrough: @@ -2762,6 +2773,7 @@ SlangResult OptionsParser::_parse( if (impliedFormat == CodeGenTarget::Unknown) { + // If we hit this case, then it means that we need to pick the // target to assocaite with this output based on its implied // format, but the file path doesn't direclty imply a format diff --git a/tests/bindings/multi-file.hlsl b/tests/bindings/multi-file.hlsl index 73ce181b0..1bf025d9c 100644 --- a/tests/bindings/multi-file.hlsl +++ b/tests/bindings/multi-file.hlsl @@ -1,4 +1,4 @@ -//TEST:COMPARE_HLSL:-no-mangle -profile sm_4_0 -entry main -stage vertex Tests/bindings/multi-file-extra.hlsl -entry main -stage fragment +//TEST:COMPARE_HLSL:-no-mangle -profile sm_4_0 -entry main1 -stage vertex Tests/bindings/multi-file-extra.hlsl -entry main -stage fragment // Here we are going to test that we can correctly generating bindings when we // are presented with a program spanning multiple input files (and multiple entry points) @@ -26,7 +26,7 @@ BEGIN_CBUFFER(vertexC) } END_CBUFFER(vertexC, register(b0)) -float4 main() : SV_POSITION +float4 main1() : SV_POSITION { // Go ahead and use everything here, just to make sure things got placed correctly return use(sharedT, sharedS) diff --git a/tests/diagnostics/command-line/duplicate-target.slang b/tests/diagnostics/command-line/duplicate-target.slang index a9ec96d0f..b1fc8088a 100644 --- a/tests/diagnostics/command-line/duplicate-target.slang +++ b/tests/diagnostics/command-line/duplicate-target.slang @@ -1,3 +1,3 @@ // duplicate-target.slang -//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -target hlsl +//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -target spirv -target hlsl diff --git a/tests/diagnostics/gh-38-vs.hlsl b/tests/diagnostics/gh-38-vs.hlsl index 3e61d7f2e..15dd04847 100644 --- a/tests/diagnostics/gh-38-vs.hlsl +++ b/tests/diagnostics/gh-38-vs.hlsl @@ -1,4 +1,4 @@ -//DIAGNOSTIC_TEST:SIMPLE: -profile sm_5_0 -entry main -stage vertex tests/diagnostics/gh-38-fs.hlsl -entry main -stage fragment -no-codegen +//DIAGNOSTIC_TEST:SIMPLE: -profile sm_5_0 -entry main1 -stage vertex tests/diagnostics/gh-38-fs.hlsl -entry main -stage fragment -no-codegen // Ensure that we catch errors with overlapping or conflicting parameter bindings. @@ -6,4 +6,4 @@ Texture2D overlappingA : register(t0); Texture2D conflicting : register(t1); -float4 main() : SV_Position { return 0; } +float4 main1() : SV_Position { return 0; } diff --git a/tests/spirv/renderdoc-cmd.slang b/tests/spirv/renderdoc-cmd.slang new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/spirv/renderdoc-cmd.slang |
