diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2024-04-03 09:30:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-03 09:30:46 -0400 |
| commit | a697b2c6707ee699cb734a03fa529dd214ac66cc (patch) | |
| tree | 1b68f4267159828092b512361faff4729510ea39 /source/slang/slang-lower-to-ir.cpp | |
| parent | c0482ec12d683e53aca56543b620a4ec02082e29 (diff) | |
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.
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 1e324b4a4..2d9ecf574 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -2204,6 +2204,16 @@ void addVarDecorations( builder->addDecoration(inst, kIROp_GLSLLocationDecoration, builder->getIntValue(builder->getIntType(), stringToInt(glslLocationMod->valToken.getContent()))); } + else if (auto glslInputAttachmentMod = as<GLSLInputAttachmentIndexLayoutModifier>(mod)) + { + auto subpassType = as<IRSubpassInputType>(inst->getDataType()); + + if (!subpassType) + context->getSink()->diagnose(inst, Diagnostics::InputAttachmentIndexOnlyAllowedOnSubpass); + + builder->addDecoration(inst, kIROp_GLSLInputAttachmentIndexDecoration, + builder->getIntValue(builder->getIntType(), stringToInt(glslInputAttachmentMod->valToken.getContent()))); + } else if (auto glslOffsetMod = as<GLSLOffsetLayoutAttribute>(mod)) { builder->addDecoration(inst, kIROp_GLSLOffsetDecoration, @@ -3546,6 +3556,21 @@ struct ExprLoweringContext // TODO: also need to handle this-type substitution here? } + void validateInvokeExprArgsWithFunctionModifiers( + InvokeExpr* expr, + FunctionDeclBase* decl, + List<IRInst*>& irArgs) + { + if (auto glslRequireShaderInputParameter = decl->findModifier<GLSLRequireShaderInputParameterAttribute>()) + { + if (!irArgs[glslRequireShaderInputParameter->parameterNumber]->findDecoration<IRGlobalInputDecoration>()) + { + this->context->getSink()->diagnose(expr, Diagnostics::requireInputDecoratedVarForParameter, decl, glslRequireShaderInputParameter->parameterNumber); + } + return; + } + } + /// Lower an invoke expr, and attempt to fuse a store of the expr's result into destination. /// If the store is fused, returns LoweredValInfo::None. Otherwise, returns the IR val representing the RValue. LoweredValInfo visitInvokeExprImpl(InvokeExpr* expr, LoweredValInfo destination, const TryClauseEnvironment& tryEnv) @@ -3663,6 +3688,8 @@ struct ExprLoweringContext auto funcType = funcTypeInfo.type; addDirectCallArgs(expr, funcDeclRef, &irArgs, &argFixups); + validateInvokeExprArgsWithFunctionModifiers(expr, as<FunctionDeclBase>(funcDeclRef.getDecl()), irArgs); + LoweredValInfo result; if (funcTypeInfo.returnViaLastRefParam) { |
