From 394983d61efa2bf99ba96aa68a47df8927a8a634 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 23 Jan 2020 12:24:13 -0800 Subject: Fix a bug in handling explicit register space bindings (#1175) The logic for handling explicit `space`/`set` bindings on shader parameters for parameter blocks was not correctly marking the `space`/`set` that gets grabbed as used, and as a result it was possible for another parameter block that relies on implicit assignment to end up with a conflicting space. This change fixes the original oversight, and adds a test case to prevent against regression. --- .../mix-explicit-and-implicit-spaces.slang | 18 +++ ...mix-explicit-and-implicit-spaces.slang.expected | 157 +++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 tests/reflection/mix-explicit-and-implicit-spaces.slang create mode 100644 tests/reflection/mix-explicit-and-implicit-spaces.slang.expected (limited to 'tests/reflection') diff --git a/tests/reflection/mix-explicit-and-implicit-spaces.slang b/tests/reflection/mix-explicit-and-implicit-spaces.slang new file mode 100644 index 000000000..52dd4321e --- /dev/null +++ b/tests/reflection/mix-explicit-and-implicit-spaces.slang @@ -0,0 +1,18 @@ +// mix-explicit-and-implicit-spaces.slang +//TEST:REFLECTION:-profile cs_5_1 -target hlsl + +// Ensure that correct layout/reflection is computed +// when mixing implicit and explicit spaces for +// parameter blocks. + +struct A { float x; } +ParameterBlock a : register(space0); + +struct B { float y; } +ParameterBlock b : register(space1); + +struct C { float z; } +ParameterBlock c; + +void main() +{} diff --git a/tests/reflection/mix-explicit-and-implicit-spaces.slang.expected b/tests/reflection/mix-explicit-and-implicit-spaces.slang.expected new file mode 100644 index 000000000..2e4ead342 --- /dev/null +++ b/tests/reflection/mix-explicit-and-implicit-spaces.slang.expected @@ -0,0 +1,157 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "a", + "bindings": [ + {"kind": "constantBuffer", "index": 0, "count": 0}, + {"kind": "registerSpace", "index": 0} + ], + "type": { + "kind": "parameterBlock", + "elementType": { + "kind": "struct", + "name": "A", + "fields": [ + { + "name": "x", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + ] + }, + "containerVarLayout": { + "bindings": [ + {"kind": "constantBuffer", "index": 0}, + {"kind": "registerSpace", "index": 0} + ] + }, + "elementVarLayout": { + "type": { + "kind": "struct", + "name": "A", + "fields": [ + { + "name": "x", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + ] + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + } + }, + { + "name": "b", + "bindings": [ + {"kind": "constantBuffer", "index": 0, "count": 0}, + {"kind": "registerSpace", "index": 1} + ], + "type": { + "kind": "parameterBlock", + "elementType": { + "kind": "struct", + "name": "B", + "fields": [ + { + "name": "y", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + ] + }, + "containerVarLayout": { + "bindings": [ + {"kind": "constantBuffer", "index": 0}, + {"kind": "registerSpace", "index": 0} + ] + }, + "elementVarLayout": { + "type": { + "kind": "struct", + "name": "B", + "fields": [ + { + "name": "y", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + ] + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + } + }, + { + "name": "c", + "bindings": [ + {"kind": "constantBuffer", "index": 0, "count": 0}, + {"kind": "registerSpace", "index": 2} + ], + "type": { + "kind": "parameterBlock", + "elementType": { + "kind": "struct", + "name": "C", + "fields": [ + { + "name": "z", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + ] + }, + "containerVarLayout": { + "bindings": [ + {"kind": "constantBuffer", "index": 0}, + {"kind": "registerSpace", "index": 0} + ] + }, + "elementVarLayout": { + "type": { + "kind": "struct", + "name": "C", + "fields": [ + { + "name": "z", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + ] + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + } + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage:": "compute", + "threadGroupSize": [1, 1, 1] + } + ] +} +} -- cgit v1.2.3