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 /tests/glsl-intrinsic/subpass-input | |
| 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 'tests/glsl-intrinsic/subpass-input')
6 files changed, 197 insertions, 0 deletions
diff --git a/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error1.slang b/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error1.slang new file mode 100644 index 000000000..82b56f872 --- /dev/null +++ b/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error1.slang @@ -0,0 +1,23 @@ +//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage fragment -entry main -allow-glsl +//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage fragment -entry main -allow-glsl +#version 450 +// CHECK: warning 39001 +buffer MyBlockName +{ + uvec4 idata[2]; +} keepAliveBuffer; + +layout(location = 0) in highp vec4 a_position; +layout(location = 0) in highp vec4 b_position; + +layout (input_attachment_index = 2, set = 0, binding = 0) uniform isubpassInput isubpass; +layout (input_attachment_index = 2, set = 0, binding = 1) uniform isubpassInputMS isubpassMS; + +layout (location = 0) out vec4 outColor; + +void main() { + keepAliveBuffer.idata[0] = subpassLoad(isubpass); + keepAliveBuffer.idata[1] = subpassLoad(isubpassMS, 0); + + outColor = vec4(0); +}
\ No newline at end of file diff --git a/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error2.slang b/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error2.slang new file mode 100644 index 000000000..d70377660 --- /dev/null +++ b/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error2.slang @@ -0,0 +1,20 @@ +//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage fragment -entry main -allow-glsl +//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage fragment -entry main -allow-glsl +#version 450 +// CHECK: warning 39001 +buffer MyBlockName +{ + uvec4 idata[2]; +} keepAliveBuffer; + +layout (input_attachment_index = 0, set = 0, binding = 1) uniform isubpassInput isubpass; +layout (input_attachment_index = 1, set = 0, binding = 1) uniform isubpassInputMS isubpassMS; + +layout (location = 0) out vec4 outColor; + +void main() { + keepAliveBuffer.idata[0] = subpassLoad(isubpass); + keepAliveBuffer.idata[1] = subpassLoad(isubpassMS, 0); + + outColor = vec4(0); +}
\ No newline at end of file diff --git a/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error3.slang b/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error3.slang new file mode 100644 index 000000000..c2396dbfe --- /dev/null +++ b/tests/glsl-intrinsic/subpass-input/input-attachment-index-overlapping-error3.slang @@ -0,0 +1,20 @@ +//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage fragment -entry main -allow-glsl +//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage fragment -entry main -allow-glsl +#version 450 +// CHECK: warning 39001 +buffer MyBlockName +{ + uvec4 idata[2]; +} keepAliveBuffer; + +layout (input_attachment_index = 0, binding = 1) uniform isubpassInput isubpass; +layout (input_attachment_index = 1, binding = 1) uniform isubpassInputMS isubpassMS; + +layout (location = 0) out vec4 outColor; + +void main() { + keepAliveBuffer.idata[0] = subpassLoad(isubpass); + keepAliveBuffer.idata[1] = subpassLoad(isubpassMS, 0); + + outColor = vec4(0); +}
\ No newline at end of file diff --git a/tests/glsl-intrinsic/subpass-input/input-attachment-index-use-error.slang b/tests/glsl-intrinsic/subpass-input/input-attachment-index-use-error.slang new file mode 100644 index 000000000..889a4e205 --- /dev/null +++ b/tests/glsl-intrinsic/subpass-input/input-attachment-index-use-error.slang @@ -0,0 +1,11 @@ +//TEST:SIMPLE(filecheck=CHECK): -target glsl -stage fragment -entry main -allow-glsl +#version 450 + +// CHECK: error 31207 +layout (input_attachment_index = 1, set = 0, binding = 1) uniform vec3 image; + +layout (location = 0) out vec4 outColor; + +void main() { + outColor = vec4(0); +}
\ No newline at end of file diff --git a/tests/glsl-intrinsic/subpass-input/subpass-input-as-parameter.slang b/tests/glsl-intrinsic/subpass-input/subpass-input-as-parameter.slang new file mode 100644 index 000000000..a415fcf81 --- /dev/null +++ b/tests/glsl-intrinsic/subpass-input/subpass-input-as-parameter.slang @@ -0,0 +1,35 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -target glsl -stage fragment -entry main -allow-glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -target spirv -emit-spirv-directly -stage fragment -entry main -allow-glsl + +#version 450 + +// CHECK_SPV-DAG: InputAttachmentIndex 0 +// CHECK_SPV-DAG: OpTypeImage %float SubpassData 2 0 0 2 Unknown +// CHECK_GLSL: subpassInput + +layout (input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput subpass; + +// CHECK_SPV-DAG: InputAttachmentIndex 1 +// CHECK_SPV-DAG: OpTypeImage %float SubpassData 2 0 1 2 Unknown +// CHECK_GLSL: subpassInputMS +layout (input_attachment_index = 1, set = 0, binding = 1) uniform subpassInputMS subpassMS; + +layout (location = 0) out vec4 outColor; + +void someSideEffect(subpassInput subpassTmp) +{ + outColor.xy = subpassLoad(subpassTmp).xy; +} + +void someSideEffectMS(subpassInputMS subpassTmp) +{ + outColor.zw = subpassLoad(subpassTmp, 0).zw; +} + +// CHECK_GLSL-DAG: void main( +// CHECK_SPV-DAG: OpEntryPoint + +void main() { + someSideEffect(subpass); + someSideEffectMS(subpassMS); +}
\ No newline at end of file diff --git a/tests/glsl-intrinsic/subpass-input/subpass-input.slang b/tests/glsl-intrinsic/subpass-input/subpass-input.slang new file mode 100644 index 000000000..0597cc06c --- /dev/null +++ b/tests/glsl-intrinsic/subpass-input/subpass-input.slang @@ -0,0 +1,88 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -target glsl -stage fragment -entry main -allow-glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -target spirv -emit-spirv-directly -stage fragment -entry main -allow-glsl +//TEST:SIMPLE(filecheck=CHECK_HLSL): -target hlsl -stage fragment -entry main -allow-glsl + +#version 450 +// CHECK_SPV-DAG: OpEntryPoint + +// CHECK_SPV-DAG: InputAttachmentIndex 0 +// CHECK_SPV-DAG: InputAttachmentIndex 1 +// CHECK_SPV-DAG: InputAttachmentIndex 2 +// CHECK_SPV-DAG: InputAttachmentIndex 3 +// CHECK_SPV-DAG: InputAttachmentIndex 4 +// CHECK_SPV-DAG: InputAttachmentIndex 5 + +// CHECK_SPV-DAG: OpTypeImage %float SubpassData 2 0 0 2 Unknown +// CHECK_GLSL-DAG: input_attachment_index = 0 +// CHECK_GLSL-DAG: subpassInput +// CHECK_HLSL-DAG: vk::input_attachment_index(0) +// CHECK_HLSL-DAG: SubpassInput<float4> +layout (input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput subpass; + +// CHECK_SPV-DAG: OpTypeImage %float SubpassData 2 0 1 2 Unknown +// CHECK_GLSL-DAG: input_attachment_index = 1 +// CHECK_GLSL-DAG: subpassInputMS +// CHECK_HLSL-DAG: vk::input_attachment_index(1) +// CHECK_HLSL-DAG: SubpassInputMS<float4> +layout (input_attachment_index = 1, set = 0, binding = 1) uniform subpassInputMS subpassMS; + +// CHECK_SPV-DAG: OpTypeImage %uint SubpassData 2 0 0 2 Unknown +// CHECK_GLSL-DAG: input_attachment_index = 2 +// CHECK_GLSL-DAG: usubpassInput +// CHECK_HLSL-DAG: vk::input_attachment_index(2) +// CHECK_HLSL-DAG: SubpassInput<uint4> +layout (input_attachment_index = 2, set = 0, binding = 2) uniform usubpassInput usubpass; + +// CHECK_SPV-DAG: OpTypeImage %uint SubpassData 2 0 1 2 Unknown +// CHECK_GLSL-DAG: input_attachment_index = 3 +// CHECK_GLSL-DAG: usubpassInputMS +// CHECK_HLSL-DAG: vk::input_attachment_index(3) +// CHECK_HLSL-DAG: SubpassInputMS<uint4> +layout (input_attachment_index = 3, set = 0, binding = 3) uniform usubpassInputMS usubpassMS; + +// CHECK_SPV-DAG: OpTypeImage %int SubpassData 2 0 0 2 Unknown +// CHECK_GLSL-DAG: input_attachment_index = 4 +// CHECK_GLSL-DAG: isubpassInput +// CHECK_HLSL-DAG: vk::input_attachment_index(4) +// CHECK_HLSL-DAG: SubpassInput<int4> +layout (input_attachment_index = 4, set = 0, binding = 4) uniform isubpassInput isubpass; + +// CHECK_SPV-DAG: OpTypeImage %int SubpassData 2 0 1 2 Unknown +// CHECK_GLSL-DAG: input_attachment_index = 5 +// CHECK_GLSL-DAG: isubpassInputMS +// CHECK_HLSL-DAG: vk::input_attachment_index(5) +// CHECK_HLSL-DAG: SubpassInputMS<int4> +layout (input_attachment_index = 5, set = 0, binding = 5) uniform isubpassInputMS isubpassMS; + +layout (location = 0) out vec4 outColor; + +// CHECK_GLSL-DAG: void main() +// CHECK_HLSL-DAG: main() +void main() { +// CHECK_SPV: OpImageRead +// CHECK_GLSL: subpassLoad +// CHECK_HLSL: SubpassLoad +// CHECK_SPV: OpImageRead +// CHECK_GLSL: subpassLoad +// CHECK_HLSL: SubpassLoad +// CHECK_SPV: OpImageRead +// CHECK_GLSL: subpassLoad +// CHECK_HLSL: SubpassLoad +// CHECK_SPV: OpImageRead +// CHECK_GLSL: subpassLoad +// CHECK_HLSL: SubpassLoad +// CHECK_SPV: OpImageRead +// CHECK_GLSL: subpassLoad +// CHECK_HLSL: SubpassLoad +// CHECK_SPV: OpImageRead +// CHECK_GLSL: subpassLoad +// CHECK_HLSL: SubpassLoad + outColor = vec4(true + && subpassLoad(subpass) == vec4(1) + && subpassLoad(subpassMS, 0) == vec4(1) + && subpassLoad(isubpass) == ivec4(1) + && subpassLoad(isubpassMS, 0) == ivec4(1) + && subpassLoad(usubpass) == uvec4(1) + && subpassLoad(usubpassMS, 0) == uvec4(1) + ); +}
\ No newline at end of file |
