From 8c68434d6fa6ff1b2e54586637869cceace9d1bb Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 25 Aug 2017 15:18:10 -0700 Subject: Fix some resources-in-structs bugs Fixes #171 Fixes #172 These two bugs related to bad logic in handling of splitting resource-containing `cbuffer` declarations. - Issue #171 was the case where a `cbuffer` *only* had resource fields, in which case we crashed whenever referencing any field (some code was assuming there had to be non-resource fields) - Issue #172 was a case where two fields were declared with a single declaration (`Texture2D a, b;`), and the logic we had for tracking resource-type fields was accidentally tagging *both* fields with a single modifier so that field `b` would get confused for `a` in some contexts, and attempts to access `b` would crash. Both issues are now fixed, and regression tests have been added. --- tests/bugs/gh-171.slang | 34 ++++++++++++++++++++++++++++++++++ tests/bugs/gh-172.slang | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/bugs/gh-171.slang create mode 100644 tests/bugs/gh-172.slang (limited to 'tests') diff --git a/tests/bugs/gh-171.slang b/tests/bugs/gh-171.slang new file mode 100644 index 000000000..6a8d27ff0 --- /dev/null +++ b/tests/bugs/gh-171.slang @@ -0,0 +1,34 @@ +//TEST:COMPARE_HLSL: -profile ps_5_0 -entry main -target dxbc-assembly -split-mixed-types +// Make sure we don't crash when desugaring resources +// in structs when a `cbuffer` only contains resources. + +#ifdef __SLANG__ + +cbuffer C +{ + Texture2D t; + SamplerState s; +}; + +float4 main(float2 uv: UV) : SV_Target +{ + return t.Sample(s, uv); +} + +#else + +cbuffer C : register(b0) +{ +}; + +Texture2D SLANG_parameterBlock_C_t : register(t0); +SamplerState SLANG_parameterBlock_C_s : register(s0); + +float4 main(float2 uv: UV) : SV_Target +{ + return SLANG_parameterBlock_C_t.Sample(SLANG_parameterBlock_C_s, uv); +} + +#endif + + diff --git a/tests/bugs/gh-172.slang b/tests/bugs/gh-172.slang new file mode 100644 index 000000000..f898b5f4b --- /dev/null +++ b/tests/bugs/gh-172.slang @@ -0,0 +1,41 @@ +//TEST:COMPARE_HLSL: -profile ps_5_0 -entry main -target dxbc-assembly -split-mixed-types + +// Make sure we don't crash when desugaring resource in structs, +// when the user also declares multiple variables with a +// single declaration. + +#ifdef __SLANG__ + +cbuffer C +{ + Texture2D t0, t1; + SamplerState s; + float2 uv; +}; + +float4 main() : SV_Target +{ + return t0.Sample(s, uv) + + t1.Sample(s, uv); +} + +#else + +cbuffer C : register(b0) +{ + float2 uv; +}; + +Texture2D SLANG_parameterBlock_C_t0 : register(t0); +Texture2D SLANG_parameterBlock_C_t1 : register(t1); +SamplerState SLANG_parameterBlock_C_s : register(s0); + +float4 main() : SV_Target +{ + return SLANG_parameterBlock_C_t0.Sample(SLANG_parameterBlock_C_s, uv) + + SLANG_parameterBlock_C_t1.Sample(SLANG_parameterBlock_C_s, uv); +} + +#endif + + -- cgit v1.2.3 From c077a08652377194f9076fc41b1b3793301b25ae Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 25 Aug 2017 19:21:55 -0700 Subject: Fixup for test failure AppVeyor has a different version of fxc installed by default, and it produces subtly different output for this test case. It seems like later versions are clever enough to completely eliminate an empty `cbuffer` declaration, but earlier versions aren't. I'm actually not entirely sure why Slang is successfully eliminating the cbuffer as well, but the output DXBC implies it was not generated. --- tests/bugs/gh-171.slang | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/bugs/gh-171.slang b/tests/bugs/gh-171.slang index 6a8d27ff0..b37f77ce2 100644 --- a/tests/bugs/gh-171.slang +++ b/tests/bugs/gh-171.slang @@ -17,10 +17,6 @@ float4 main(float2 uv: UV) : SV_Target #else -cbuffer C : register(b0) -{ -}; - Texture2D SLANG_parameterBlock_C_t : register(t0); SamplerState SLANG_parameterBlock_C_s : register(s0); -- cgit v1.2.3