summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-parameter-binding.cpp
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-06-12 12:39:58 -0400
committerGitHub <noreply@github.com>2024-06-12 09:39:58 -0700
commit7a4757d2e97f92aae3ddb5dc353a54f72e23351e (patch)
tree1f759f8449f4672c51ef408708b89d3561d400f9 /source/slang/slang-parameter-binding.cpp
parent180d6b13c6794a0bbb209df023301701cda15158 (diff)
Implicit register binding for hlsl to non-hlsl targets (#4338)
* implicit register binding for hlsl to non-hlsl targets * fix regressions only warn once with `_maybeDiagnoseMissingVulkanLayoutModifier` remove unneeded else * address review and change bindings address review comments on testing to make the tests indiscriminate over order of code emitted. Change bindings to 1:1 map to vulkan bindings * don't set bindings 1:1 with vulkan if command line option was added --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-parameter-binding.cpp')
-rw-r--r--source/slang/slang-parameter-binding.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp
index cfbd7f2c5..523ba9287 100644
--- a/source/slang/slang-parameter-binding.cpp
+++ b/source/slang/slang-parameter-binding.cpp
@@ -1048,7 +1048,7 @@ static void addExplicitParameterBindings_GLSL(
RefPtr<VarLayout> varLayout)
{
// We only want to apply GLSL-style layout modifers
- // when compiling for a Khronos-related target.
+ // when compiling for a Khronos-related target.
//
// TODO: This should have some finer granularity
// so that we are able to distinguish between
@@ -1143,15 +1143,13 @@ static void addExplicitParameterBindings_GLSL(
return;
}
- // See if we can infer vulkan binding from HLSL if we have such options set, we know
- // we can't map
auto hlslToVulkanLayoutOptions = context->getTargetProgram()->getHLSLToVulkanLayoutOptions();
-
- // If we have the options, but cannot infer bindings, we don't need to go further
+ bool warnedMissingVulkanLayoutModifier = false;
+ // If we are not told how to infer bindings with a compile option, we warn
if (hlslToVulkanLayoutOptions == nullptr || !hlslToVulkanLayoutOptions->canInferBindings())
{
+ warnedMissingVulkanLayoutModifier = true;
_maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as<VarDeclBase>());
- return;
}
// We need an HLSL register semantic to to infer from
@@ -1188,20 +1186,38 @@ static void addExplicitParameterBindings_GLSL(
}
// If inference is not enabled for this kind, we can issue a warning
- if (!hlslToVulkanLayoutOptions->canInfer(vulkanKind, hlslInfo.space))
+ if (hlslToVulkanLayoutOptions && !hlslToVulkanLayoutOptions->canInfer(vulkanKind, hlslInfo.space))
{
- _maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as<VarDeclBase>());
- return;
+ if(!warnedMissingVulkanLayoutModifier)
+ {
+ _maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as<VarDeclBase>());
+ warnedMissingVulkanLayoutModifier = true;
+ }
}
// We use the HLSL binding directly (even though this notionally for GLSL/Vulkan)
// We'll do the shifting at later later point in _maybeApplyHLSLToVulkanShifts
resInfo = typeLayout->findOrAddResourceInfo(hlslInfo.kind);
-
+
+ if (warnedMissingVulkanLayoutModifier)
+ {
+ // If we warn due to invalid bindings and user did not set how to interpret 'hlsl style bindings', we should map
+ // `register` 1:1 with equivlent vulkan bindings.
+ if(!hlslToVulkanLayoutOptions
+ || hlslToVulkanLayoutOptions->getKindShiftEnabledFlags() == HLSLToVulkanLayoutOptions::KindFlag::None)
+ {
+ resInfo->kind = LayoutResourceKind::DescriptorTableSlot;
+ resInfo->count = 1;
+ }
+ else
+ {
+ return;
+ }
+ }
+
semanticInfo.kind = resInfo->kind;
semanticInfo.index = UInt(hlslInfo.index);
semanticInfo.space = UInt(hlslInfo.space);
-
const LayoutSize count = resInfo->count;
addExplicitParameterBinding(context, parameterInfo, as<VarDeclBase>(varDecl.getDecl()), semanticInfo, count);