summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordubiousconst282 <87553666+dubiousconst282@users.noreply.github.com>2024-07-24 18:20:06 -0300
committerGitHub <noreply@github.com>2024-07-24 14:20:06 -0700
commitefa8d1ab40c24a15678dd4143c9cc7b7b64e04d8 (patch)
treed2df663078d6058dce9fb30920d1ce3415fbb4a4 /tests
parent639576cbe9d9cf604c554fda8dda48485201704f (diff)
Add generic descriptor indexing intrinsic (#4389)
* Add ResourceArray intrinsic type * Move aliased parameter generation to GLSL legalization * Add DynamicResourceEntry type for proxying layout of GenericResourceArray * Reimplement as DynamicResource * Add reflection test * Don't reuse alias cache between different parameters * Add dynamic cast extensions for buffer types * Minor format fix * Fix VarDecl diagnostics after finding non-appliable initializer candidates --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/slang-extension/dynamic-resource-gl.slang59
-rw-r--r--tests/slang-extension/dynamic-resource-gl.slang.1.expected95
2 files changed, 154 insertions, 0 deletions
diff --git a/tests/slang-extension/dynamic-resource-gl.slang b/tests/slang-extension/dynamic-resource-gl.slang
new file mode 100644
index 000000000..0ea82dd8f
--- /dev/null
+++ b/tests/slang-extension/dynamic-resource-gl.slang
@@ -0,0 +1,59 @@
+//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target glsl
+//TEST:REFLECTION: -stage compute -entry computeMain -target glsl
+
+// CHECK-DAG: layout(binding = 0, set = 1)
+// CHECK-DAG: texture2D g_TextureHeap_1[]
+
+// CHECK-DAG: layout(binding = 0, set = 1)
+// CHECK-DAG: utexture2D g_TextureHeap_0[]
+
+[vk::binding(0, 1)]
+__DynamicResource<__DynamicResourceKind.General> g_TextureHeap[];
+
+// CHECK-DAG: layout(binding = 2, set = 1)
+// CHECK-DAG: sampler g_SamplerHeap_0[]
+[vk::binding(2, 1)]
+__DynamicResource<__DynamicResourceKind.Sampler> g_SamplerHeap[];
+
+// CHECK-DAG: layout(binding = 0, set = 2)
+// CHECK-DAG: texture2D g_SingleDynamicResourceA_0;
+[vk::binding(0, 2)]
+__DynamicResource g_SingleDynamicResourceA;
+
+// CHECK-DAG: layout(binding = 1, set = 2)
+// CHECK-DAG: texture2D g_SingleDynamicResourceB_0;
+[vk::binding(1, 2)]
+__DynamicResource g_SingleDynamicResourceB;
+
+// CHECK-DAG: layout(std430, binding = 2, set = 2) buffer
+[vk::binding(2, 2)]
+__DynamicResource g_SingleDynamicResourceC;
+
+// CHECK: IndirectAccess_0
+// CHECK: g_TextureHeap_0[_S1]
+[noinline]
+float4 IndirectAccess(__DynamicResource resource, int2 pos)
+{
+ let texture = resource.as<Texture2D<uint4>>();
+ return texture[pos] / 255.0;
+}
+
+// CHECK: main
+// CHECK-DAG: g_TextureHeap_1[3]
+// CHECK-DAG: g_SamplerHeap_0[2]
+[numthreads(16)]
+void computeMain(int2 tid: SV_DispatchThreadID)
+{
+ Texture2D texture = g_TextureHeap[3];
+ SamplerState sampler = g_SamplerHeap[2].as<SamplerState>();
+
+ float4 value = texture.SampleLevel(sampler, tid / 64.0, 0.0);
+
+ value += IndirectAccess(g_TextureHeap[1], tid);
+
+ value += g_SingleDynamicResourceA.as<Texture2D>()[tid];
+ value += g_SingleDynamicResourceB.as<Texture2D>()[tid];
+
+ RWStructuredBuffer<float4> outputBuffer = g_SingleDynamicResourceC;
+ outputBuffer[tid.x + tid.y * 64] = value;
+} \ No newline at end of file
diff --git a/tests/slang-extension/dynamic-resource-gl.slang.1.expected b/tests/slang-extension/dynamic-resource-gl.slang.1.expected
new file mode 100644
index 000000000..fe48e643a
--- /dev/null
+++ b/tests/slang-extension/dynamic-resource-gl.slang.1.expected
@@ -0,0 +1,95 @@
+result code = 0
+standard error = {
+}
+standard output = {
+{
+ "parameters": [
+ {
+ "name": "g_TextureHeap",
+ "binding": {"kind": "descriptorTableSlot", "space": 1, "index": 0},
+ "type": {
+ "kind": "array",
+ "elementCount": 0,
+ "elementType": {
+ "kind": "DynamicResource"
+ }
+ }
+ },
+ {
+ "name": "g_SamplerHeap",
+ "binding": {"kind": "descriptorTableSlot", "space": 1, "index": 2},
+ "type": {
+ "kind": "array",
+ "elementCount": 0,
+ "elementType": {
+ "kind": "DynamicResource"
+ }
+ }
+ },
+ {
+ "name": "g_SingleDynamicResourceA",
+ "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 0},
+ "type": {
+ "kind": "DynamicResource"
+ }
+ },
+ {
+ "name": "g_SingleDynamicResourceB",
+ "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 1},
+ "type": {
+ "kind": "DynamicResource"
+ }
+ },
+ {
+ "name": "g_SingleDynamicResourceC",
+ "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 2},
+ "type": {
+ "kind": "DynamicResource"
+ }
+ }
+ ],
+ "entryPoints": [
+ {
+ "name": "computeMain",
+ "stage:": "compute",
+ "parameters": [
+ {
+ "name": "tid",
+ "semanticName": "SV_DISPATCHTHREADID",
+ "type": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ }
+ }
+ }
+ ],
+ "threadGroupSize": [16, 1, 1],
+ "bindings": [
+ {
+ "name": "g_TextureHeap",
+ "binding": {"kind": "descriptorTableSlot", "space": 1, "index": 0}
+ },
+ {
+ "name": "g_SamplerHeap",
+ "binding": {"kind": "descriptorTableSlot", "space": 1, "index": 2}
+ },
+ {
+ "name": "g_SingleDynamicResourceA",
+ "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 0}
+ },
+ {
+ "name": "g_SingleDynamicResourceB",
+ "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 1}
+ },
+ {
+ "name": "g_SingleDynamicResourceC",
+ "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 2}
+ }
+ ]
+ }
+ ]
+}
+}