Skip to content

Commit

Permalink
Make slangc commandline parsing compatible with renderdoc. (#3658)
Browse files Browse the repository at this point in the history
* Make slangc commandline parsing compatible with renderdoc.

* Fix tests.
  • Loading branch information
csyonghe authored Mar 1, 2024
1 parent e752a95 commit 9a1e327
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
20 changes: 16 additions & 4 deletions source/slang/slang-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/bindings/multi-file.hlsl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/diagnostics/command-line/duplicate-target.slang
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// duplicate-target.slang

//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -target hlsl
//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -target spirv -target hlsl
4 changes: 2 additions & 2 deletions tests/diagnostics/gh-38-vs.hlsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//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.

Texture2D overlappingA : register(t0);

Texture2D conflicting : register(t1);

float4 main() : SV_Position { return 0; }
float4 main1() : SV_Position { return 0; }
Empty file added tests/spirv/renderdoc-cmd.slang
Empty file.

0 comments on commit 9a1e327

Please sign in to comment.