From 7dabfa76ccfb396e9d2019e2b6e01259d1661dc5 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 5 Dec 2024 19:33:55 -0800 Subject: Implement explciit binding for metal and wgsl. (#5778) * Respect explicit bindings in wgsl emit. * Implement explciit binding generation for metal and wgsl. * Update toc. * Fix warnings in tests. * Fix tests. --------- Co-authored-by: Ellie Hermaszewska --- source/slang/slang-parameter-binding.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-parameter-binding.cpp') diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index e45eb4652..f9c4f0c94 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -984,7 +984,8 @@ static void addExplicitParameterBindings_HLSL( // // For now we do the filtering on target in a very direct fashion: // - if (!isD3DTarget(context->getTargetRequest()) && !isMetalTarget(context->getTargetRequest())) + bool isMetal = isMetalTarget(context->getTargetRequest()); + if (!isD3DTarget(context->getTargetRequest()) && !isMetal) return; auto typeLayout = varLayout->typeLayout; @@ -1018,6 +1019,7 @@ static void addExplicitParameterBindings_HLSL( if (kind == LayoutResourceKind::None) continue; + // TODO: need to special-case when this is a `c` register binding... // Find the appropriate resource-binding information @@ -1025,6 +1027,19 @@ static void addExplicitParameterBindings_HLSL( // of the given kind. auto typeRes = typeLayout->FindResourceInfo(kind); + if (isMetal && !typeRes) + { + // Metal doesn't distinguish a unordered access and a readonly/uniform buffer. + switch (kind) + { + case LayoutResourceKind::UnorderedAccess: + case LayoutResourceKind::ShaderResource: + semanticInfo.kind = LayoutResourceKind::MetalBuffer; + typeRes = typeLayout->FindResourceInfo(LayoutResourceKind::MetalBuffer); + break; + } + } + LayoutSize count = 0; if (typeRes) { @@ -1073,7 +1088,7 @@ static void addExplicitParameterBindings_GLSL( // so that we are able to distinguish between // Vulkan and OpenGL as targets. // - if (!isKhronosTarget(context->getTargetRequest())) + if (!isKhronosTarget(context->getTargetRequest()) && !isWGPUTarget(context->getTargetRequest())) return; auto typeLayout = varLayout->typeLayout; -- cgit v1.2.3