summaryrefslogtreecommitdiff
path: root/tests/glsl-intrinsic/fragment-processing
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-04-03 09:30:46 -0400
committerGitHub <noreply@github.com>2024-04-03 09:30:46 -0400
commita697b2c6707ee699cb734a03fa529dd214ac66cc (patch)
tree1b68f4267159828092b512361faff4729510ea39 /tests/glsl-intrinsic/fragment-processing
parentc0482ec12d683e53aca56543b620a4ec02082e29 (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/fragment-processing')
-rw-r--r--tests/glsl-intrinsic/fragment-processing/fragment-processing-interpolate-simple.slang28
-rw-r--r--tests/glsl-intrinsic/fragment-processing/fragment-processing-non-input-param-error.slang20
-rw-r--r--tests/glsl-intrinsic/fragment-processing/fragment-processing.slang137
3 files changed, 185 insertions, 0 deletions
diff --git a/tests/glsl-intrinsic/fragment-processing/fragment-processing-interpolate-simple.slang b/tests/glsl-intrinsic/fragment-processing/fragment-processing-interpolate-simple.slang
new file mode 100644
index 000000000..fb1c72ed7
--- /dev/null
+++ b/tests/glsl-intrinsic/fragment-processing/fragment-processing-interpolate-simple.slang
@@ -0,0 +1,28 @@
+//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: OpEntryPoint
+// CHECK_GLSL-DAG: void main(
+
+layout(location = 0) out ivec4 outColorActual;
+
+layout (location = 0) in float inDataV1;
+
+bool isOk(float a, float b) { return (a == b); }
+
+bool testFragmentProcessingInterpolateFunctions()
+{
+ float tmpStore = inDataV1;
+ return true
+ && interpolateAtCentroid(inDataV1) != -1.0f
+ && (tmpStore + inDataV1) != -0.1f
+ && isOk(inDataV1, tmpStore)
+ && inDataV1 != -1.0f
+ ;
+}
+
+void main() {
+ outColorActual = ivec4(true
+ && testFragmentProcessingInterpolateFunctions()
+ );
+} \ No newline at end of file
diff --git a/tests/glsl-intrinsic/fragment-processing/fragment-processing-non-input-param-error.slang b/tests/glsl-intrinsic/fragment-processing/fragment-processing-non-input-param-error.slang
new file mode 100644
index 000000000..638dd0ea7
--- /dev/null
+++ b/tests/glsl-intrinsic/fragment-processing/fragment-processing-non-input-param-error.slang
@@ -0,0 +1,20 @@
+//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: error 31208
+// CHECK_GLSL-DAG: error 31208
+
+layout(location = 0) out ivec4 outColorActual;
+
+layout (location = 0) in float inDataV1;
+bool testFragmentProcessingInterpolateFunctions()
+{
+ float v = 1.0f;
+ return interpolateAtCentroid(v) != -1.0f;
+}
+
+void main() {
+ outColorActual = ivec4(true
+ && testFragmentProcessingInterpolateFunctions()
+ );
+} \ No newline at end of file
diff --git a/tests/glsl-intrinsic/fragment-processing/fragment-processing.slang b/tests/glsl-intrinsic/fragment-processing/fragment-processing.slang
new file mode 100644
index 000000000..909679bbe
--- /dev/null
+++ b/tests/glsl-intrinsic/fragment-processing/fragment-processing.slang
@@ -0,0 +1,137 @@
+//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
+
+layout(location = 0) out ivec4 outColorActual;
+
+layout (location = 0) in float inDataV1;
+layout (location = 1) in vec2 inDataV2;
+layout (location = 2) in vec3 inDataV3;
+layout (location = 3) in vec4 inDataV4;
+
+bool testFragmentProcessingDerivativeFunctionsScalar()
+{
+// CHECK_SPV: OpDPdx
+// CHECK_GLSL: dFdx
+// CHECK_SPV: OpDPdy
+// CHECK_GLSL: dFdy
+// CHECK_SPV: OpDPdxFine
+// CHECK_GLSL: dFdxFine
+// CHECK_SPV: OpDPdyFine
+// CHECK_GLSL: dFdyFine
+// CHECK_SPV: OpDPdxCoarse
+// CHECK_GLSL: dFdxCoarse
+// CHECK_SPV: OpDPdyCoarse
+// CHECK_GLSL: dFdyCoarse
+// CHECK_SPV: OpFwidth
+// CHECK_GLSL: fwidth
+// CHECK_SPV: OpFwidthFine
+// CHECK_GLSL: fwidthFine
+// CHECK_SPV: OpFwidthCoarse
+// CHECK_GLSL: fwidthCoarse
+ return true
+ && dFdx(1.0f) != -1.0f
+ && dFdy(1.0f) != -1.0f
+ && dFdxFine(1.0f) != -1.0f
+ && dFdyFine(1.0f) != -1.0f
+ && dFdxCoarse(1.0f) != -1.0f
+ && dFdyCoarse(1.0f) != -1.0f
+ && fwidth(1.0f) != -1.0f
+ && fwidthFine(1.0f) != -1.0f
+ && fwidthCoarse(1.0f) != -1.0f
+ ;
+}
+__generic<let N:int>
+bool testFragmentProcessingDerivativeFunctionsVector()
+{
+// CHECK_SPV: OpDPdx
+// CHECK_GLSL: dFdx
+// CHECK_SPV: OpDPdy
+// CHECK_GLSL: dFdy
+// CHECK_SPV: OpDPdxFine
+// CHECK_GLSL: dFdxFine
+// CHECK_SPV: OpDPdyFine
+// CHECK_GLSL: dFdyFine
+// CHECK_SPV: OpDPdxCoarse
+// CHECK_GLSL: dFdxCoarse
+// CHECK_SPV: OpDPdyCoarse
+// CHECK_GLSL: dFdyCoarse
+// CHECK_SPV: OpFwidth
+// CHECK_GLSL: fwidth
+// CHECK_SPV: OpFwidthFine
+// CHECK_GLSL: fwidthFine
+// CHECK_SPV: OpFwidthCoarse
+// CHECK_GLSL: fwidthCoarse
+ return true
+ && dFdx(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && dFdy(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && dFdxFine(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && dFdyFine(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && dFdxCoarse(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && dFdyCoarse(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && fwidth(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && fwidthFine(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ && fwidthCoarse(vector<float,N>(1.0f)) != vector<float,N>(-1.0f)
+ ;
+}
+bool testFragmentProcessingInterpolateFunctions()
+{
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtCentroid %inDataV1
+// CHECK_GLSL: interpolateAtCentroid{{.*}}inDataV1
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtSample %inDataV1 {{.*}}
+// CHECK_GLSL: interpolateAtSample{{.*}}inDataV1
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtOffset %inDataV1 {{.*}}
+// CHECK_GLSL: interpolateAtOffset{{.*}}inDataV1
+
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtCentroid %inDataV2
+// CHECK_GLSL: interpolateAtCentroid{{.*}}inDataV2
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtSample %inDataV2 {{.*}}
+// CHECK_GLSL: interpolateAtSample{{.*}}inDataV2
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtOffset %inDataV2 {{.*}}
+// CHECK_GLSL: interpolateAtOffset{{.*}}inDataV2
+
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtCentroid %inDataV3
+// CHECK_GLSL: interpolateAtCentroid{{.*}}inDataV3
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtSample %inDataV3 {{.*}}
+// CHECK_GLSL: interpolateAtSample{{.*}}inDataV3
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtOffset %inDataV3 {{.*}}
+// CHECK_GLSL: interpolateAtOffset{{.*}}inDataV3
+
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtCentroid %inDataV4
+// CHECK_GLSL: interpolateAtCentroid{{.*}}inDataV4
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtSample %inDataV4 {{.*}}
+// CHECK_GLSL: interpolateAtSample{{.*}}inDataV4
+// CHECK_SPV: {{.*}} = OpExtInst {{.*}} {{.*}} InterpolateAtOffset %inDataV4 {{.*}}
+// CHECK_GLSL: interpolateAtOffset{{.*}}inDataV4
+ return true
+ && interpolateAtCentroid(inDataV1) != -1.0f
+ && interpolateAtSample(inDataV1, 0) != -1.0f
+ && interpolateAtOffset(inDataV1, vec2(0.0f)) != -1.0f
+ && interpolateAtCentroid(inDataV2) != vector<float,2>(-1.0f)
+ && interpolateAtSample(inDataV2, 0) != vector<float,2>(-1.0f)
+ && interpolateAtOffset(inDataV2, vec2(0.0f)) != vector<float,2>(-1.0f)
+ && interpolateAtCentroid(inDataV3) != vector<float,3>(-1.0f)
+ && interpolateAtSample(inDataV3, 0) != vector<float,3>(-1.0f)
+ && interpolateAtOffset(inDataV3, vec2(0.0f)) != vector<float,3>(-1.0f)
+ && interpolateAtCentroid(inDataV4) != vector<float,4>(-1.0f)
+ && interpolateAtSample(inDataV4, 0) != vector<float,4>(-1.0f)
+ && interpolateAtOffset(inDataV4, vec2(0.0f)) != vector<float,4>(-1.0f)
+ ;
+}
+bool testFragmentProcessingFunctions()
+{
+ return true
+ && testFragmentProcessingDerivativeFunctionsScalar()
+ && testFragmentProcessingDerivativeFunctionsVector<2>()
+ && testFragmentProcessingDerivativeFunctionsVector<3>()
+ && testFragmentProcessingDerivativeFunctionsVector<4>()
+ && testFragmentProcessingInterpolateFunctions()
+ ;
+ ;
+}
+
+void main() {
+ outColorActual = ivec4(true
+ && testFragmentProcessingFunctions()
+ );
+} \ No newline at end of file