From 4a94473eb34376dd8474f8ca3f2834b5c1daac14 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 1 Sep 2022 10:01:13 -0700 Subject: Deduplicate consts and IRSpecialize in IR, propagate type info for `IntVal`. (#2388) --- tests/bugs/generic-type-duplication.slang | 33 ++++++++++++++++++++++ .../generic-type-duplication.slang.expected.txt | 4 +++ 2 files changed, 37 insertions(+) create mode 100644 tests/bugs/generic-type-duplication.slang create mode 100644 tests/bugs/generic-type-duplication.slang.expected.txt (limited to 'tests') diff --git a/tests/bugs/generic-type-duplication.slang b/tests/bugs/generic-type-duplication.slang new file mode 100644 index 000000000..4117a7f81 --- /dev/null +++ b/tests/bugs/generic-type-duplication.slang @@ -0,0 +1,33 @@ +// Test that the same generic type specialization does not get emitted as different types in target code. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj +//TEST(compute,vulkan):COMPARE_COMPUTE_EX:-vk -slang -compute -shaderobj + +struct MyGeneric +{ + int value; + + [mutating] + void load(RWStructuredBuffer> buffer) + { + var m = buffer.Load(0); + if (addOne) + value = m.value + 1; + else + value = m.value; + } +}; + +//TEST_INPUT:set myBuffer = ubuffer(data=[1],stride=4) +RWStructuredBuffer> myBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + MyGeneric obj; + obj.load(myBuffer); + outputBuffer[dispatchThreadID.x] = obj.value; +} diff --git a/tests/bugs/generic-type-duplication.slang.expected.txt b/tests/bugs/generic-type-duplication.slang.expected.txt new file mode 100644 index 000000000..487b11653 --- /dev/null +++ b/tests/bugs/generic-type-duplication.slang.expected.txt @@ -0,0 +1,4 @@ +2 +2 +2 +2 -- cgit v1.2.3