summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/diagnostics/vk-bindings.slang16
-rw-r--r--tests/diagnostics/vk-bindings.slang.expected7
-rw-r--r--tests/reflection/parameter-block-explicit-space.slang104
-rw-r--r--tests/reflection/parameter-block-explicit-space.slang.expected103
4 files changed, 230 insertions, 0 deletions
diff --git a/tests/diagnostics/vk-bindings.slang b/tests/diagnostics/vk-bindings.slang
new file mode 100644
index 000000000..f5a8bdeba
--- /dev/null
+++ b/tests/diagnostics/vk-bindings.slang
@@ -0,0 +1,16 @@
+// vk-bindings.slang
+
+//TEST:SIMPLE:-target spirv
+
+// D3D `register` without VK binding
+Texture2D t : register(t0);
+
+struct S { float4 a; };
+
+// Parameter block with non-zero binding:
+[[vk::binding(2,1)]]
+ParameterBlock<S> b;
+
+[shader("compute")]
+void main()
+{} \ No newline at end of file
diff --git a/tests/diagnostics/vk-bindings.slang.expected b/tests/diagnostics/vk-bindings.slang.expected
new file mode 100644
index 000000000..8e085b55f
--- /dev/null
+++ b/tests/diagnostics/vk-bindings.slang.expected
@@ -0,0 +1,7 @@
+result code = -1
+standard error = {
+tests/diagnostics/vk-bindings.slang(6): warning 39013: shader parameter 't' has a 'register' specified for D3D, but no '[[vk::binding(...)]]` specified for Vulkan
+tests/diagnostics/vk-bindings.slang(11): error 39015: shader parameter 'b' consumes whole descriptor sets, so the binding must be in the form '[[vk::binding(0, ...)]]'; the non-zero binding '2' is not allowed
+}
+standard output = {
+}
diff --git a/tests/reflection/parameter-block-explicit-space.slang b/tests/reflection/parameter-block-explicit-space.slang
new file mode 100644
index 000000000..5679a1c35
--- /dev/null
+++ b/tests/reflection/parameter-block-explicit-space.slang
@@ -0,0 +1,104 @@
+// parameter-block-explicit-space.slang
+
+//TEST:REFLECTION:-D__SLANG__ -stage fragment -entry main -profile sm_5_1 -target hlsl
+//TEST:COMPARE_HLSL:-stage fragment -entry main -profile sm_5_1
+
+#ifdef __SLANG__
+struct A
+{
+ float4 au;
+ Texture2D at1;
+ Texture2D at2;
+ SamplerState as;
+}
+
+struct X
+{
+ float4 xu;
+}
+
+struct B
+{
+ float4 bu;
+ Texture2D bt;
+ SamplerState bs;
+
+ // TODO: This line leads to a crash
+// ConstantBuffer<X> bx;
+}
+
+
+
+[[vk::binding(0,2)]]
+ParameterBlock<A> a : register(space2);
+
+[[vk::binding(0,3)]]
+ParameterBlock<B> b : register(space3);
+
+float4 use(float4 val) { return val; }
+float4 use(Texture2D t, SamplerState s)
+{
+ return t.Sample(s, 0.0);
+}
+
+float4 main() : SV_Target
+{
+ return use(a.au)
+ + use(a.at1, a.as)
+ + use(a.at2, a.as)
+ + use(b.bu)
+ + use(b.bt, b.bs)
+ // + use(b.bx.xu)
+ ;
+}
+
+#else
+
+#define A A_0
+#define a a_0
+#define au au_0
+#define at1 a_at1_0
+#define at2 a_at2_0
+#define as a_as_0
+
+#define B B_0
+#define b b_0
+#define bu bu_0
+#define bt b_bt_0
+#define bs b_bs_0
+
+struct A
+{
+ float4 au;
+};
+cbuffer _S1 : register(b0, space2)
+{ A a; }
+Texture2D at1 : register(t0, space2);
+Texture2D at2 : register(t1, space2);
+SamplerState as : register(s0, space2);
+
+struct B
+{
+ float4 bu;
+};
+cbuffer _S3 : register(b0, space3)
+{ B b; }
+Texture2D bt : register(t0, space3);
+SamplerState bs : register(s0, space3);
+
+float4 use(float4 val) { return val; }
+float4 use(Texture2D t, SamplerState s)
+{
+ return t.Sample(s, 0.0);
+}
+
+float4 main() : SV_TARGET
+{
+ return use(a.au)
+ + use(at1, as)
+ + use(at2, as)
+ + use(b.bu)
+ + use(bt, bs);
+}
+
+#endif
diff --git a/tests/reflection/parameter-block-explicit-space.slang.expected b/tests/reflection/parameter-block-explicit-space.slang.expected
new file mode 100644
index 000000000..e683a641f
--- /dev/null
+++ b/tests/reflection/parameter-block-explicit-space.slang.expected
@@ -0,0 +1,103 @@
+result code = 0
+standard error = {
+}
+standard output = {
+{
+ "parameters": [
+ {
+ "name": "a",
+ "binding": {"kind": "constantBuffer", "space": 2, "index": 0, "count": 0},
+ "type": {
+ "kind": "parameterBlock",
+ "elementType": {
+ "kind": "struct",
+ "name": "A",
+ "fields": [
+ {
+ "name": "au",
+ "type": {
+ "kind": "vector",
+ "elementCount": 4,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 16}
+ },
+ {
+ "name": "at1",
+ "type": {
+ "kind": "resource",
+ "baseShape": "texture2D"
+ },
+ "binding": {"kind": "shaderResource", "index": 0}
+ },
+ {
+ "name": "at2",
+ "type": {
+ "kind": "resource",
+ "baseShape": "texture2D"
+ },
+ "binding": {"kind": "shaderResource", "index": 1}
+ },
+ {
+ "name": "as",
+ "type": {
+ "kind": "samplerState"
+ },
+ "binding": {"kind": "samplerState", "index": 0}
+ }
+ ]
+ }
+ }
+ },
+ {
+ "name": "b",
+ "binding": {"kind": "constantBuffer", "space": 3, "index": 0, "count": 0},
+ "type": {
+ "kind": "parameterBlock",
+ "elementType": {
+ "kind": "struct",
+ "name": "B",
+ "fields": [
+ {
+ "name": "bu",
+ "type": {
+ "kind": "vector",
+ "elementCount": 4,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 16}
+ },
+ {
+ "name": "bt",
+ "type": {
+ "kind": "resource",
+ "baseShape": "texture2D"
+ },
+ "binding": {"kind": "shaderResource", "index": 0}
+ },
+ {
+ "name": "bs",
+ "type": {
+ "kind": "samplerState"
+ },
+ "binding": {"kind": "samplerState", "index": 0}
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
+ ]
+}
+}