From a697b2c6707ee699cb734a03fa529dd214ac66cc Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Wed, 3 Apr 2024 09:30:46 -0400 Subject: Implement 8.14-8.19 of OpenGL-GLSL specification The following PR implements 8.14-8.19 of the [OpenGL-GLSL specification](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf). Fully implements all functions and built-in type's, resolves https://github.com/shader-slang/slang/issues/3692 for GLSL & SPRI-V targets. _Notes:_ Testing Tools: * Fragment shaders cannot test computational results. Only OpCodes are checked for proper emitting. Implementation Notes: * SubpassInput requires an unknown image format. * SubpassInput is disjoint from TextureType: __SubpassImpl (.slang) & SubpassInputType (Compiler) to reduce code generation required. * SubpassInput required an additional input layout modifier, input_attachment_index, this was added as a new parameter binding attribute. Since the following qualifiers can overlap with different resources (`layout(input_attachment_index = 0, binding = 0, set = 0)`) input_attachment_index is checked for overlapping resource bindings separately from other qualifiers with `LayoutResourceKind::InputAttachmentIndex`. * `GLSLInputAttachmentIndexLayoutModifier` was added to enforce function parameters only accepting `in` decorated variables. * `in` decorated variables needed to have emitting modified to allow directly emitting the variable into function calls if used as a parameter, normally Slang has a "global variable" shadow as a "global parameter" through a copy. This does not work and is solved using `GlobalVariableShadowingGlobalParameterDecoration` to build a relationship of "global variable" to "global parameter", we then resolve this relationship and replace "global variable" uses later in compile. * `AtomicCounterMemory` memory-constraint requires `OpCapability AtomicStorage`, `AtomicStorage` is invalid for Vulkan targets. glslang outputs for `barrier`, `memoryBarrier`, and `groupMemoryBarrier` `AtomicCounterMemory` as a memory constraint. This compiles as valid SPIR-V for Vulkan since `OpCapability AtomicStorage` is not declared. This behavior of glslang is undefined as per [3.31.Capability of the SPIR-V specification](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_capability). We will omit `AtomicCounterMemory` from our barrier calls. --- source/slang/slang-parameter-binding.cpp | 35 +++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 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 01b7f6724..6725380f2 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -1072,14 +1072,35 @@ static void addExplicitParameterBindings_GLSL( semanticInfo.index = 0; semanticInfo.space = 0; + LayoutSemanticInfo subpassSemanticInfo; + bool foundBinding = false; + bool foundSubpass = false; + if( (foundResInfo = typeLayout->FindResourceInfo(LayoutResourceKind::DescriptorTableSlot)) != nullptr ) { - // Try to find `binding` and `set` - if (auto attr = varDecl.getDecl()->findModifier()) + for (auto dec : varDecl.getDecl()->modifiers) { - resInfo = foundResInfo; - semanticInfo.index = attr->binding; - semanticInfo.space = attr->set; + // Try to find `binding` and `set` + if (auto glslBindingAttr = as(dec)) + { + resInfo = foundResInfo; + semanticInfo.index = glslBindingAttr->binding; + semanticInfo.space = glslBindingAttr->set; + foundBinding = true; + if (foundSubpass) + break; + } + // Try to find `input_attachment_index` + else if (auto glslAttachmentIndexAttr = as(dec)) + { + // Subpass fills semantic info of a descriptor & subpass + subpassSemanticInfo.index = stringToInt(glslAttachmentIndexAttr->valToken.getContent()); + subpassSemanticInfo.space = 0; + subpassSemanticInfo.kind = LayoutResourceKind::InputAttachmentIndex; + foundSubpass = true; + if (foundBinding) + break; + } } } else if( (foundResInfo = typeLayout->FindResourceInfo(LayoutResourceKind::SubElementRegisterSpace)) != nullptr ) @@ -1113,6 +1134,9 @@ static void addExplicitParameterBindings_GLSL( semanticInfo.kind = kind; addExplicitParameterBinding(context, parameterInfo, varDecl.getDecl(), semanticInfo, count); + if (foundSubpass) + addExplicitParameterBinding(context, parameterInfo, varDecl.getDecl(), subpassSemanticInfo, count); + return; } @@ -2066,6 +2090,7 @@ static RefPtr processEntryPointVaryingParameter( return arrayTypeLayout; } // Ignore a bunch of types that don't make sense here... + else if (const auto subpassType = as(type)) { return nullptr; } else if (const auto textureType = as(type)) { return nullptr; } else if(const auto samplerStateType = as(type)) { return nullptr; } else if(const auto constantBufferType = as(type)) { return nullptr; } -- cgit v1.2.3