summaryrefslogtreecommitdiffstats
path: root/tests/reflection/structured-buffer.slang.expected
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-11-29 07:48:38 -0800
committerGitHub <noreply@github.com>2018-11-29 07:48:38 -0800
commite5cc4660c634a0dd35a9813e03192d380f253332 (patch)
treebcd7395a1d602faf3bad7209b7422677e723a837 /tests/reflection/structured-buffer.slang.expected
parentc3c34bf4ca78caff285fbf5f24c5f355ca040bd1 (diff)
Fix uses of dynamic_cast on types in reflection API (#731)
The `Type` infrastructure uses a class hierarchy, but blindly `dynamic_cast`ing to a desired case doesn't always give the expected result, because a `Type` could represent a `typedef` (a `NamedExpressionType`) that itself resolves to, e.g, a vector type (a `VectorExpressionType`). In that case a `dynamic_cast<VectorExpressionType*>(someType)` would fail, even though the type logically represents a vector. The `Type::As<T>()` method is designed to handle this case, by "looking through" simple `typedef`s to get at the real definition of a type. The fix in this case is to use `Type::As<T>()` at various points in the reflection code (`reflection.cpp`) instead of `dynamic_cast`. This problem surfaced with a `StructuredBuffer<float2>` not reflecting correctly, because the element type (`float2`) is actually a `typedef` (for `vector<float,2>`), so I've included a test case that stresses that case. Getting the right output in the test required tweaking the `slang-reflection-test` tool to produce additional output for resource types (currently narrowed down to only affect structured buffers to avoid large diffs in expected test outputs).
Diffstat (limited to 'tests/reflection/structured-buffer.slang.expected')
-rw-r--r--tests/reflection/structured-buffer.slang.expected75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/reflection/structured-buffer.slang.expected b/tests/reflection/structured-buffer.slang.expected
new file mode 100644
index 000000000..70ceb64f2
--- /dev/null
+++ b/tests/reflection/structured-buffer.slang.expected
@@ -0,0 +1,75 @@
+result code = 0
+standard error = {
+}
+standard output = {
+{
+ "parameters": [
+ {
+ "name": "x",
+ "binding": {"kind": "shaderResource", "index": 0},
+ "type": {
+ "kind": "resource",
+ "baseShape": "structuredBuffer",
+ "resultType": {
+ "kind": "scalar",
+ "scalarType": "uint32"
+ }
+ }
+ },
+ {
+ "name": "y",
+ "binding": {"kind": "shaderResource", "index": 1},
+ "type": {
+ "kind": "resource",
+ "baseShape": "structuredBuffer",
+ "resultType": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ }
+ }
+ },
+ {
+ "name": "z",
+ "binding": {"kind": "shaderResource", "index": 2},
+ "type": {
+ "kind": "resource",
+ "baseShape": "structuredBuffer",
+ "resultType": {
+ "kind": "struct",
+ "fields": [
+ "name": "a",
+ "type": {
+ "kind": "vector",
+ "elementCount": 2,
+ "elementType": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
+ },
+ "name": "b",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ },
+ "name": "c",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "uint32"
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
+ ]
+}
+}