From 7a4757d2e97f92aae3ddb5dc353a54f72e23351e Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:39:58 -0400 Subject: 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 --- source/slang/slang-hlsl-to-vulkan-layout-options.h | 1 + source/slang/slang-parameter-binding.cpp | 38 +++++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/slang/slang-hlsl-to-vulkan-layout-options.h b/source/slang/slang-hlsl-to-vulkan-layout-options.h index 1b7daf330..b8ae40da0 100644 --- a/source/slang/slang-hlsl-to-vulkan-layout-options.h +++ b/source/slang/slang-hlsl-to-vulkan-layout-options.h @@ -75,6 +75,7 @@ public: { enum Enum : KindFlags { + None = 0, UnorderedAccess = KindFlags(1) << Index(Kind::UnorderedAccess), Sampler = KindFlags(1) << Index(Kind::Sampler), ShaderResource = KindFlags(1) << Index(Kind::ShaderResource), 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) { // 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()); - 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()); - return; + if(!warnedMissingVulkanLayoutModifier) + { + _maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as()); + 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(varDecl.getDecl()), semanticInfo, count); -- cgit v1.2.3