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-emit-hlsl.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-emit-hlsl.cpp') diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 37411c93e..120e37f09 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -92,6 +92,7 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV } break; + case LayoutResourceKind::InputAttachmentIndex: case LayoutResourceKind::RegisterSpace: case LayoutResourceKind::GenericResource: case LayoutResourceKind::ExistentialTypeParam: @@ -304,6 +305,18 @@ void HLSLSourceEmitter::_emitHLSLTextureType(IRTextureTypeBase* texType) m_writer->emit(" >"); } +void HLSLSourceEmitter::_emitHLSLSubpassInputType(IRSubpassInputType* subpassType) +{ + m_writer->emit("SubpassInput"); + if (subpassType->isMultisample()) + { + m_writer->emit("MS"); + } + m_writer->emit("<"); + emitType(subpassType->getElementType()); + m_writer->emit(">"); +} + void HLSLSourceEmitter::emitLayoutSemanticsImpl(IRInst* inst, char const* uniformSemanticSpelling) { auto layout = getVarLayout(inst); @@ -981,6 +994,11 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) _emitHLSLTextureType(imageType); return; } + else if (auto subpassType = as(type)) + { + _emitHLSLSubpassInputType(subpassType); + return; + } else if (auto structuredBufferType = as(type)) { switch (structuredBufferType->getOp()) @@ -1246,9 +1264,20 @@ void HLSLSourceEmitter::emitMeshShaderModifiersImpl(IRInst* varInst) void HLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl) { - if (varDecl->findDecoration()) + for(auto decoration : varDecl->getDecorations()) { - m_writer->emit("globallycoherent\n"); + if (as(decoration)) + { + m_writer->emit("globallycoherent\n"); + continue; + } + else if(auto glslInputAttachmentIndex = as(decoration)) + { + m_writer->emit("[[vk::input_attachment_index("); + m_writer->emit(glslInputAttachmentIndex->getIndex()->getValue()); + m_writer->emit(")]]\n"); + continue; + } } } -- cgit v1.2.3