diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-11-30 15:03:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-30 15:03:31 -0800 |
| commit | 7f2d2c9a248a9413e236826a4c6473a6fc104714 (patch) | |
| tree | 418d63baef8fd736e3e9ba28a3ce948451621687 /tests/reflection | |
| parent | e40c106d6f8c4218de5a16450f201c0e395f8167 (diff) | |
Allow parameter blocks to be explicitly bound to spaces (#736)
* Don't look at VK bindings when compiling for D3D and vice versa
The compiler had been looking at all the modifiers on a declaration when piecing together binding information, whether or not those modifiers should apply on the chosen target API. This was working in practice because the "layout resource kinds" used by each API target were disjoint, for the most part.
This change ensures that we don't even look at modifiers that don't apply on the chosen target, and furthermore adds a new warning that applies if the user is compiling a shader with explicit `register` bindings for Vulkan, if there are no corresponding `[[vk::binding(...)]]` attributes (under the assumption that if they want to be explicit in one case, they probably want to be explicit in all cases).
* Allow explicit space/set bindings on parameter blocks
The syntax for the D3D case is to specify a `space` in a `register` modifier, without any other register class:
```hlsl
ParameterBlock<X> myBlock : regsiter(space999);
```
In the Vulkan case, the user must apply the `[[vk::binding(...)]]` attribute and is expected to use a `binding` of zero:
```hlsl
[[vk::binding(0,999)]]
ParameterBlock<X> myBlock;
```
This change includes a reflection test for the new capability (where we also confirm that it produces the expected output when compared with fxc), and a test for the diagnostic messages when the user messes up bindings for Vulkan.
The implementation itself is fairly straightforward, since the compiler already treats registe spaces/sets as a resource that parameters can consume directly.
Note: the test case for explicit parameter block space/set bindings includes some commented out code that lead to a compiler crash. I would like to fix the underlying issue, but it seemed sensible to keep the bug fix out of a change like this that is adding functionality.
Diffstat (limited to 'tests/reflection')
| -rw-r--r-- | tests/reflection/parameter-block-explicit-space.slang | 104 | ||||
| -rw-r--r-- | tests/reflection/parameter-block-explicit-space.slang.expected | 103 |
2 files changed, 207 insertions, 0 deletions
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" + } + ] +} +} |
