summaryrefslogtreecommitdiffstats
path: root/tests/bindings
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-07-23 23:44:47 -0500
committerGitHub <noreply@github.com>2024-07-23 21:44:47 -0700
commit5339f613cefd5d048bd8fba0a1f275184a229b96 (patch)
treedbbb4c1c3febacae78d06b9184ed3da57c6ad1a0 /tests/bindings
parent72f7ea60461df520668de0947f350b85219db577 (diff)
Allow only specific spv storage classes for binding decoration (#4713)
* Allow only specific spv storage classes for binding decoration In https://registry.khronos.org/vulkan/specs/1.3/html/chap37.html#VUID-StandaloneSpirv-DescriptorSet-06491 it states that If a variable is decorated by DescriptorSet or Binding, the Storage class must be UniformConstant, Uniform and StorageBuffer. So apply this rule to our emit-spirv logic. * Add a unit test * Address few comments
Diffstat (limited to 'tests/bindings')
-rw-r--r--tests/bindings/binding-spv-storage-class.slang55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/bindings/binding-spv-storage-class.slang b/tests/bindings/binding-spv-storage-class.slang
new file mode 100644
index 000000000..5e93a1fbd
--- /dev/null
+++ b/tests/bindings/binding-spv-storage-class.slang
@@ -0,0 +1,55 @@
+// binding-spv-storage-class.slang
+
+//TEST:SIMPLE(filecheck=GL-SPIRV): -stage anyhit -entry main -target spirv-assembly -emit-spirv-via-glsl
+//TEST:SIMPLE(filecheck=SPIRV): -stage anyhit -entry main -target spirv
+
+// This test checks that the only the resource with Uniform, Storage or UniformConstant storage class can be decorated by binding or descriptor set.
+struct MyStruct
+{
+ float3 org;
+ float3 dir;
+};
+
+// ShaderRecordKHR storage class
+layout(shaderRecordNV) ConstantBuffer<MyStruct> myStruct : register(b0, space1);
+
+// Uniform buffer
+ConstantBuffer<MyStruct> myStruct1 : register(b1, space1);
+
+// Storage buffer
+RWStructuredBuffer<MyStruct> myStruct2 : register(b2, space1);
+
+// UniformConstant
+Texture2D<float> texture: register(b3, space1);
+SamplerState sampler: register(b4, space1);
+
+[shader("anyhit")]
+void main(out float3 pos)
+{
+ pos = myStruct.org + myStruct.dir +
+ myStruct1.org + myStruct1.dir +
+ myStruct2[0].org + myStruct2[0].dir;
+
+ pos.x = texture.SampleLevel(
+ sampler,
+ pos.xy, 0);
+}
+
+// SPIRV: OpDecorate %myStruct1{{.*}} Binding 1
+// SPIRV: OpDecorate %myStruct1{{.*}} DescriptorSet 1
+// SPIRV: OpDecorate %myStruct2{{.*}} Binding 2
+// SPIRV: OpDecorate %myStruct2{{.*}} DescriptorSet 1
+// SPIRV: OpDecorate %texture{{.*}} Binding 3
+// SPIRV: OpDecorate %texture{{.*}} DescriptorSet 1
+// SPIRV: OpDecorate %sampler{{.*}} Binding 4
+// SPIRV: OpDecorate %sampler{{.*}} DescriptorSet 1
+//
+//
+// GL-SPIRV: OpDecorate %myStruct1{{.*}} DescriptorSet 1
+// GL-SPIRV: OpDecorate %myStruct1{{.*}} Binding 1
+// GL-SPIRV: OpDecorate %myStruct2{{.*}} DescriptorSet 1
+// GL-SPIRV: OpDecorate %myStruct2{{.*}} Binding 2
+// GL-SPIRV: OpDecorate %texture{{.*}} DescriptorSet 1
+// GL-SPIRV: OpDecorate %texture{{.*}} Binding 3
+// GL-SPIRV: OpDecorate %sampler{{.*}} DescriptorSet 1
+// GL-SPIRV: OpDecorate %sampler{{.*}} Binding 4