From eaf3d840b16a8646ab4545487679c869eef500b7 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 27 Dec 2017 21:51:56 -0500 Subject: Using a visitor to systematically replace lookup scopes of generic function's return type expression. fixes #336 Add a `ReplaceScopeVisitor` to replace the scopes of the return type expression tree to use the generic decl's scope instead of module's scope after parser has determined the decl is a generic function header decl. --- tests/compute/generics-syntax-2.slang | 28 ++++++++++++++++++++++ tests/compute/generics-syntax-2.slang.expected.txt | 4 ++++ 2 files changed, 32 insertions(+) create mode 100644 tests/compute/generics-syntax-2.slang create mode 100644 tests/compute/generics-syntax-2.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/generics-syntax-2.slang b/tests/compute/generics-syntax-2.slang new file mode 100644 index 000000000..29ed64825 --- /dev/null +++ b/tests/compute/generics-syntax-2.slang @@ -0,0 +1,28 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +// Confirm that generics syntax can be used in user +// code and generates valid output. + +RWStructuredBuffer outputBuffer; + +struct GenStruct +{ + T x; +}; + +GenStruct test(T val) +{ + GenStruct rs; + rs.x = val; + return rs; +} + + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + float inVal = float(tid); + GenStruct outVal = test(inVal); + outputBuffer[tid] = outVal.x; +} \ No newline at end of file diff --git a/tests/compute/generics-syntax-2.slang.expected.txt b/tests/compute/generics-syntax-2.slang.expected.txt new file mode 100644 index 000000000..98798bd61 --- /dev/null +++ b/tests/compute/generics-syntax-2.slang.expected.txt @@ -0,0 +1,4 @@ +0 +3F800000 +40000000 +40400000 \ No newline at end of file -- cgit v1.2.3