From fef0a87ddee9c0f252a6625395b684b1cb5d85e0 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Tue, 30 Jul 2024 23:03:24 -0400 Subject: Fix invalid code generation for when using nested resource specialization (#4751) --- tests/current-bugs/resource-struct-out.slang | 30 ----------- tests/current-bugs/resource-struct-return.slang | 28 ----------- ...urce-specialization-nested-specialization.slang | 58 ++++++++++++++++++++++ .../resource-specialization-struct-out.slang | 31 ++++++++++++ .../resource-specialization-struct-return.slang | 29 +++++++++++ 5 files changed, 118 insertions(+), 58 deletions(-) delete mode 100644 tests/current-bugs/resource-struct-out.slang delete mode 100644 tests/current-bugs/resource-struct-return.slang create mode 100644 tests/language-feature/resource-specialization-nested-specialization.slang create mode 100644 tests/language-feature/resource-specialization-struct-out.slang create mode 100644 tests/language-feature/resource-specialization-struct-return.slang (limited to 'tests') diff --git a/tests/current-bugs/resource-struct-out.slang b/tests/current-bugs/resource-struct-out.slang deleted file mode 100644 index d47b2ec7c..000000000 --- a/tests/current-bugs/resource-struct-out.slang +++ /dev/null @@ -1,30 +0,0 @@ -//DISABLE_TEST:SIMPLE:-target hlsl -entry computeMain -profile cs_6_2 - -// This test demonstrates out parameter with a struct & resource type crashes - -RWTexture1D g_t; - -RWStructuredBuffer outputBuffer; - -struct Thing -{ - int a; - RWTexture1D t; -}; - -void setThing(out Thing t) -{ - t.a = 10; - t.t = g_t; -} - -[numthreads(4, 4, 1)] -void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) -{ - int x = dispatchThreadID.x; - - Thing thing; - setThing(thing); - - outputBuffer[dispatchThreadID.x] = x + thing.t.Load(1); -} diff --git a/tests/current-bugs/resource-struct-return.slang b/tests/current-bugs/resource-struct-return.slang deleted file mode 100644 index 8d0508097..000000000 --- a/tests/current-bugs/resource-struct-return.slang +++ /dev/null @@ -1,28 +0,0 @@ -//DISABLE_TEST:SIMPLE:-target hlsl -entry computeMain -profile cs_6_2 - -// This test demonstrates returning struct with resource causes internal compiler error - -RWTexture1D g_t; -RWStructuredBuffer outputBuffer; - -struct Thing -{ - int a; - RWTexture1D t; -}; - -Thing makeThing() -{ - Thing t; - t.a = 10; - t.t = g_t; - return t; -} - -[numthreads(4, 4, 1)] -void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) -{ - int x = dispatchThreadID.x; - Thing thing = makeThing(); - outputBuffer[dispatchThreadID.x] = x + thing.t.Load(1); -} \ No newline at end of file diff --git a/tests/language-feature/resource-specialization-nested-specialization.slang b/tests/language-feature/resource-specialization-nested-specialization.slang new file mode 100644 index 000000000..2b88e7611 --- /dev/null +++ b/tests/language-feature/resource-specialization-nested-specialization.slang @@ -0,0 +1,58 @@ +//TEST:SIMPLE(filecheck=CHECK_DXIL): -target dxil -profile sm_6_0 -entry computeMain -stage compute -DMEMBER_FUNCTION_CALL +//TEST:SIMPLE(filecheck=CHECK_DXIL): -target dxil -profile sm_6_0 -entry computeMain -stage compute + +//CHECK_DXIL: computeMain + +struct Grid +{ + uint bufSize; + StructuredBuffer buf; +}; + +struct GridGeo +{ + Grid grids[2]; + + void getGrid(uint index, out Grid grid) + { + grid = grids[index]; + } +}; + +struct Scene +{ + GridGeo gridGeo; + + void getGrid_BAD(uint index, out Grid grid) + { + gridGeo.getGrid(index, grid); + } + + void getGrid_GOOD(uint index, out Grid grid) + { + grid = gridGeo.grids[index]; + } +}; + +ParameterBlock gScene; +RWStructuredBuffer gridBuffers[2]; +RWStructuredBuffer outputBuffer; + +void direct_getGrid_BAD(uint index, out Grid grid) +{ + gScene.gridGeo.getGrid(index, grid); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 threadId: SV_DispatchThreadID) +{ + + Grid grid; + +#ifdef MEMBER_FUNCTION_CALL + direct_getGrid_BAD(1, grid); +#else + gScene.getGrid_BAD(1, grid); +#endif + gridBuffers[0][1] = grid.buf[1]; +} diff --git a/tests/language-feature/resource-specialization-struct-out.slang b/tests/language-feature/resource-specialization-struct-out.slang new file mode 100644 index 000000000..b525dafb9 --- /dev/null +++ b/tests/language-feature/resource-specialization-struct-out.slang @@ -0,0 +1,31 @@ +//TEST:SIMPLE(filecheck=CHECK_DXIL):-target dxil -entry computeMain -profile cs_6_2 +//CHECK_DXIL: computeMain + +// This test demonstrates out parameter with a struct & resource type. + +RWTexture1D g_t; + +RWStructuredBuffer outputBuffer; + +struct Thing +{ + int a; + RWTexture1D t; +}; + +void setThing(out Thing t) +{ + t.a = 10; + t.t = g_t; +} + +[numthreads(4, 4, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int x = dispatchThreadID.x; + + Thing thing; + setThing(thing); + + outputBuffer[dispatchThreadID.x] = x + thing.t.Load(1); +} diff --git a/tests/language-feature/resource-specialization-struct-return.slang b/tests/language-feature/resource-specialization-struct-return.slang new file mode 100644 index 000000000..ca01f55d2 --- /dev/null +++ b/tests/language-feature/resource-specialization-struct-return.slang @@ -0,0 +1,29 @@ +//TEST:SIMPLE(filecheck=CHECK_DXIL):-target dxil -entry computeMain -profile cs_6_2 +//CHECK_DXIL: computeMain + +// This test demonstrates returning struct with resource. + +RWTexture1D g_t; +RWStructuredBuffer outputBuffer; + +struct Thing +{ + int a; + RWTexture1D t; +}; + +Thing makeThing() +{ + Thing t; + t.a = 10; + t.t = g_t; + return t; +} + +[numthreads(4, 4, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int x = dispatchThreadID.x; + Thing thing = makeThing(); + outputBuffer[dispatchThreadID.x] = x + thing.t.Load(1); +} \ No newline at end of file -- cgit v1.2.3