summaryrefslogtreecommitdiffstats
path: root/tests/reflection
diff options
context:
space:
mode:
Diffstat (limited to 'tests/reflection')
-rw-r--r--tests/reflection/arrays.hlsl.expected4
-rw-r--r--tests/reflection/buffer-layout.slang109
-rw-r--r--tests/reflection/buffer-layout.slang.1.expected192
-rw-r--r--tests/reflection/buffer-layout.slang.expected192
-rw-r--r--tests/reflection/matrix-layout.slang.1.expected6
-rw-r--r--tests/reflection/matrix-layout.slang.expected10
-rw-r--r--tests/reflection/structured-buffer.slang.expected40
7 files changed, 528 insertions, 25 deletions
diff --git a/tests/reflection/arrays.hlsl.expected b/tests/reflection/arrays.hlsl.expected
index b586e362a..f815ea88c 100644
--- a/tests/reflection/arrays.hlsl.expected
+++ b/tests/reflection/arrays.hlsl.expected
@@ -31,7 +31,7 @@ standard output = {
},
"uniformStride": 16
},
- "binding": {"kind": "uniform", "offset": 16, "size": 160}
+ "binding": {"kind": "uniform", "offset": 16, "size": 148}
},
{
"name": "y",
@@ -39,7 +39,7 @@ standard output = {
"kind": "scalar",
"scalarType": "float32"
},
- "binding": {"kind": "uniform", "offset": 176, "size": 4}
+ "binding": {"kind": "uniform", "offset": 164, "size": 4}
}
]
}
diff --git a/tests/reflection/buffer-layout.slang b/tests/reflection/buffer-layout.slang
new file mode 100644
index 000000000..51b9680d1
--- /dev/null
+++ b/tests/reflection/buffer-layout.slang
@@ -0,0 +1,109 @@
+// buffer-layout.slang
+
+// This test mirrors `tests/compute/buffer-layout.slang`, and it meant
+// to confirm that our reflection logic correctly reports the offsets
+// that the compute test sees in practice.
+
+//TEST:REFLECTION:-stage compute -entry main -target hlsl
+//TEST:REFLECTION:-stage compute -entry main -target spirv
+
+struct A
+{
+ float x;
+ float y;
+}
+
+struct S
+{
+ // The first field in a struct isn't going to be that
+ // interesting, because it will always get offset zero,
+ // so we just use this to establish a poorly-aligned
+ // starting point for the next field.
+ //
+ // offset size alignment
+ //
+ // 0 4 4
+ //
+ float z;
+
+ // The `std140` and D3D constant buffer ruless both
+ // ensure a minimum of 16-byte alignment on `struct`
+ // types, but differ in that D3D does not round up
+ // the total size of a type to its alignment.
+ //
+ // The `std430` and structured buffer rules don't
+ // perform any over-alignment on `struct` types and
+ // instead align them using the "natural" rules one
+ // might expect of, e.g., a C compiler.
+ //
+ // offset size alignment
+ //
+ // cbuffer 16 8 16
+ // std140 16 16 16
+ //
+ // struct 4 8 4
+ // std430 4 8 4
+ //
+ A a;
+
+ // Now we insert an ordinary `int` field just as
+ // a way to probe the offset so far.
+ //
+ // offset size alignment
+ //
+ // cbuffer 24 4 4
+ // std140 32 4 4
+ //
+ // struct 12 4 4
+ // std430 12 4 4
+ //
+ int b;
+
+ // As our next stress-test case, we will insert an
+ // array with elements that aren't a multiple of
+ // 16 bytes in size.
+ //
+ // The contant/uniform buffer rules will set the
+ // array stride to a multiple of 16 bytes in this case.
+ // The only difference between D3D rules and `std140`
+ // here is that D3D does not round up the size to
+ // the alignment.
+ //
+ // The structured/std430 rules don't do anything
+ // to over-align an array, so it is laid out relatively
+ // naturally, but note that D3D still follows its rule
+ // of not letting a vector "straddle" a 16-byte boundary,
+ // even if it doesn't bump up the alignment of
+ // vector types.
+ //
+ // offset size alignment
+ //
+ // cbuffer 32 24 16
+ // std140 48 32 32
+ //
+ // struct 16 16 4
+ // std430 16 16 8
+ //
+ float2 c[2];
+
+ // Now we put in one more ordinary `int` field
+ // just to probe the offset computed so far.
+ // offset size alignment
+ //
+ // cbuffer 56 4 4
+ // std140 80 4 4
+ //
+ // struct 32 4 4
+ // std430 32 4 4
+ //
+ int d;
+}
+
+ConstantBuffer<S> cb;
+RWStructuredBuffer<S> sb;
+
+[numthreads(1, 1, 1)]
+void main(
+ uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+} \ No newline at end of file
diff --git a/tests/reflection/buffer-layout.slang.1.expected b/tests/reflection/buffer-layout.slang.1.expected
new file mode 100644
index 000000000..890f31481
--- /dev/null
+++ b/tests/reflection/buffer-layout.slang.1.expected
@@ -0,0 +1,192 @@
+result code = 0
+standard error = {
+}
+standard output = {
+{
+ "parameters": [
+ {
+ "name": "cb",
+ "binding": {"kind": "descriptorTableSlot", "index": 0},
+ "type": {
+ "kind": "constantBuffer",
+ "elementType": {
+ "kind": "struct",
+ "name": "S",
+ "fields": [
+ {
+ "name": "z",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "a",
+ "type": {
+ "kind": "struct",
+ "name": "A",
+ "fields": [
+ {
+ "name": "x",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "y",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 4, "size": 4}
+ }
+ ]
+ },
+ "binding": {"kind": "uniform", "offset": 16, "size": 16}
+ },
+ {
+ "name": "b",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 32, "size": 4}
+ },
+ {
+ "name": "c",
+ "type": {
+ "kind": "array",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "uniformStride": 16
+ },
+ "binding": {"kind": "uniform", "offset": 48, "size": 32}
+ },
+ {
+ "name": "d",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 80, "size": 4}
+ }
+ ]
+ }
+ }
+ },
+ {
+ "name": "sb",
+ "binding": {"kind": "descriptorTableSlot", "index": 1},
+ "type": {
+ "kind": "resource",
+ "baseShape": "structuredBuffer",
+ "access": "readWrite",
+ "resultType": {
+ "kind": "struct",
+ "name": "S",
+ "fields": [
+ {
+ "name": "z",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "a",
+ "type": {
+ "kind": "struct",
+ "name": "A",
+ "fields": [
+ {
+ "name": "x",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "y",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 4, "size": 4}
+ }
+ ]
+ },
+ "binding": {"kind": "uniform", "offset": 4, "size": 8}
+ },
+ {
+ "name": "b",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 12, "size": 4}
+ },
+ {
+ "name": "c",
+ "type": {
+ "kind": "array",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "uniformStride": 8
+ },
+ "binding": {"kind": "uniform", "offset": 16, "size": 16}
+ },
+ {
+ "name": "d",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 32, "size": 4}
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "compute",
+ "parameters": [
+ {
+ "name": "dispatchThreadID",
+ "semanticName": "SV_DISPATCHTHREADID",
+ "type": {
+ "kind": "vector",
+ "elementCount": 3,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "uint32"
+ }
+ }
+ }
+ ],
+ "threadGroupSize": [1, 1, 1]
+ }
+ ]
+}
+}
diff --git a/tests/reflection/buffer-layout.slang.expected b/tests/reflection/buffer-layout.slang.expected
new file mode 100644
index 000000000..25a41bc6d
--- /dev/null
+++ b/tests/reflection/buffer-layout.slang.expected
@@ -0,0 +1,192 @@
+result code = 0
+standard error = {
+}
+standard output = {
+{
+ "parameters": [
+ {
+ "name": "cb",
+ "binding": {"kind": "constantBuffer", "index": 0},
+ "type": {
+ "kind": "constantBuffer",
+ "elementType": {
+ "kind": "struct",
+ "name": "S",
+ "fields": [
+ {
+ "name": "z",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "a",
+ "type": {
+ "kind": "struct",
+ "name": "A",
+ "fields": [
+ {
+ "name": "x",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "y",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 4, "size": 4}
+ }
+ ]
+ },
+ "binding": {"kind": "uniform", "offset": 16, "size": 8}
+ },
+ {
+ "name": "b",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 24, "size": 4}
+ },
+ {
+ "name": "c",
+ "type": {
+ "kind": "array",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "uniformStride": 16
+ },
+ "binding": {"kind": "uniform", "offset": 32, "size": 24}
+ },
+ {
+ "name": "d",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 56, "size": 4}
+ }
+ ]
+ }
+ }
+ },
+ {
+ "name": "sb",
+ "binding": {"kind": "unorderedAccess", "index": 0},
+ "type": {
+ "kind": "resource",
+ "baseShape": "structuredBuffer",
+ "access": "readWrite",
+ "resultType": {
+ "kind": "struct",
+ "name": "S",
+ "fields": [
+ {
+ "name": "z",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "a",
+ "type": {
+ "kind": "struct",
+ "name": "A",
+ "fields": [
+ {
+ "name": "x",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ },
+ {
+ "name": "y",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 4, "size": 4}
+ }
+ ]
+ },
+ "binding": {"kind": "uniform", "offset": 4, "size": 8}
+ },
+ {
+ "name": "b",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 12, "size": 4}
+ },
+ {
+ "name": "c",
+ "type": {
+ "kind": "array",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "uniformStride": 8
+ },
+ "binding": {"kind": "uniform", "offset": 16, "size": 16}
+ },
+ {
+ "name": "d",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 32, "size": 4}
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "compute",
+ "parameters": [
+ {
+ "name": "dispatchThreadID",
+ "semanticName": "SV_DISPATCHTHREADID",
+ "type": {
+ "kind": "vector",
+ "elementCount": 3,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "uint32"
+ }
+ }
+ }
+ ],
+ "threadGroupSize": [1, 1, 1]
+ }
+ ]
+}
+}
diff --git a/tests/reflection/matrix-layout.slang.1.expected b/tests/reflection/matrix-layout.slang.1.expected
index 221b96a0b..57fd29c6d 100644
--- a/tests/reflection/matrix-layout.slang.1.expected
+++ b/tests/reflection/matrix-layout.slang.1.expected
@@ -49,7 +49,7 @@ standard output = {
"scalarType": "float32"
}
},
- "binding": {"kind": "uniform", "offset": 96, "size": 64}
+ "binding": {"kind": "uniform", "offset": 96, "size": 60}
}
]
}
@@ -106,11 +106,11 @@ standard output = {
"scalarType": "float32"
}
},
- "binding": {"kind": "uniform", "offset": 96, "size": 64}
+ "binding": {"kind": "uniform", "offset": 96, "size": 60}
}
]
},
- "binding": {"kind": "uniform", "offset": 0, "size": 160}
+ "binding": {"kind": "uniform", "offset": 0, "size": 156}
}
]
}
diff --git a/tests/reflection/matrix-layout.slang.expected b/tests/reflection/matrix-layout.slang.expected
index 04c861ed3..c8aeb2ae1 100644
--- a/tests/reflection/matrix-layout.slang.expected
+++ b/tests/reflection/matrix-layout.slang.expected
@@ -23,7 +23,7 @@ standard output = {
"scalarType": "float32"
}
},
- "binding": {"kind": "uniform", "offset": 0, "size": 64}
+ "binding": {"kind": "uniform", "offset": 0, "size": 60}
},
{
"name": "ab",
@@ -49,7 +49,7 @@ standard output = {
"scalarType": "float32"
}
},
- "binding": {"kind": "uniform", "offset": 112, "size": 64}
+ "binding": {"kind": "uniform", "offset": 112, "size": 60}
}
]
}
@@ -80,7 +80,7 @@ standard output = {
"scalarType": "float32"
}
},
- "binding": {"kind": "uniform", "offset": 0, "size": 64}
+ "binding": {"kind": "uniform", "offset": 0, "size": 60}
},
{
"name": "bb",
@@ -106,11 +106,11 @@ standard output = {
"scalarType": "float32"
}
},
- "binding": {"kind": "uniform", "offset": 112, "size": 64}
+ "binding": {"kind": "uniform", "offset": 112, "size": 60}
}
]
},
- "binding": {"kind": "uniform", "offset": 0, "size": 176}
+ "binding": {"kind": "uniform", "offset": 0, "size": 172}
}
]
}
diff --git a/tests/reflection/structured-buffer.slang.expected b/tests/reflection/structured-buffer.slang.expected
index 70ceb64f2..3e79fd1c5 100644
--- a/tests/reflection/structured-buffer.slang.expected
+++ b/tests/reflection/structured-buffer.slang.expected
@@ -40,25 +40,35 @@ standard output = {
"baseShape": "structuredBuffer",
"resultType": {
"kind": "struct",
+ "name": "S",
"fields": [
- "name": "a",
- "type": {
- "kind": "vector",
- "elementCount": 2,
- "elementType": {
+ {
+ "name": "a",
+ "type": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 8}
+ },
+ {
+ "name": "b",
+ "type": {
"kind": "scalar",
"scalarType": "float32"
- }
- },
- "name": "b",
- "type": {
- "kind": "scalar",
- "scalarType": "float32"
+ },
+ "binding": {"kind": "uniform", "offset": 8, "size": 4}
},
- "name": "c",
- "type": {
- "kind": "scalar",
- "scalarType": "uint32"
+ {
+ "name": "c",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "uint32"
+ },
+ "binding": {"kind": "uniform", "offset": 12, "size": 4}
}
]
}