From ce879112cb16e3def1b8673104e7123b8b17ee2a Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 21 Jan 2018 07:09:55 -0500 Subject: Improvements and bug fixes for global type parameters 1. allow spReflection_FindTypeByName to accept arbitrary type expression string 2. allow const int generic value to be used as expression value, and as array size 3. various bug fixes in witness table specialization / function cloning during specializeIRForEntryPoint to avoid creating duplicate global values, not copying the right definition of a function from the other module, not cloning witness tables that are required by specializeGenerics etc. --- tests/compute/array-param.slang.expected.txt | 12 +++---- tests/compute/global-type-param-array.slang | 24 ++++++++++++++ .../global-type-param-array.slang.expected.txt | 1 + tests/compute/global-type-param3.slang | 37 ---------------------- .../compute/global-type-param3.slang.expected.txt | 1 - tests/compute/globalTypeParamArrayShared.slang | 31 ++++++++++++++++++ 6 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 tests/compute/global-type-param-array.slang create mode 100644 tests/compute/global-type-param-array.slang.expected.txt delete mode 100644 tests/compute/global-type-param3.slang delete mode 100644 tests/compute/global-type-param3.slang.expected.txt create mode 100644 tests/compute/globalTypeParamArrayShared.slang (limited to 'tests') diff --git a/tests/compute/array-param.slang.expected.txt b/tests/compute/array-param.slang.expected.txt index 61b9a3dcd..ef529012e 100644 --- a/tests/compute/array-param.slang.expected.txt +++ b/tests/compute/array-param.slang.expected.txt @@ -1,8 +1,4 @@ -0 -3F80000 -0 -3F80000 -0 -3F80000 -0 -3F80000 \ No newline at end of file +1 +1 +1 +1 \ No newline at end of file diff --git a/tests/compute/global-type-param-array.slang b/tests/compute/global-type-param-array.slang new file mode 100644 index 000000000..74e52d5d4 --- /dev/null +++ b/tests/compute/global-type-param-array.slang @@ -0,0 +1,24 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT: cbuffer(data=[1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0], stride=4):dxbinding(0),glbinding(0) +//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(0),glbinding(0),out +//TEST_INPUT: type Pair, Pair , Base> > + +RWStructuredBuffer outputBuffer; +import globalTypeParamArrayShared; + +__generic_param TImpl : IBase; + +ParameterBlock impl; + +float doCompute(T t) +{ + return t.compute(1.0); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + float outVal = doCompute(impl); + outputBuffer[tid] = outVal; +} \ No newline at end of file diff --git a/tests/compute/global-type-param-array.slang.expected.txt b/tests/compute/global-type-param-array.slang.expected.txt new file mode 100644 index 000000000..bdf6b77dc --- /dev/null +++ b/tests/compute/global-type-param-array.slang.expected.txt @@ -0,0 +1 @@ +40800000 diff --git a/tests/compute/global-type-param3.slang b/tests/compute/global-type-param3.slang deleted file mode 100644 index 05793dce4..000000000 --- a/tests/compute/global-type-param3.slang +++ /dev/null @@ -1,37 +0,0 @@ -//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir -//TEST_INPUT: cbuffer(data=[1.0], stride=4):dxbinding(0),glbinding(0) -//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(0),glbinding(0),out -//TEST_INPUT: type Impl - -RWStructuredBuffer outputBuffer; - -interface IBase -{ - float compute(); -} - -struct Impl : IBase -{ - float base; // = 1.0 - float compute() - { - return 1.0; - } -}; - -__generic_param TImpl : IBase; - -ParameterBlock impl; - -float doCompute(T t) -{ - return t.compute(); -} - -[numthreads(1, 1, 1)] -void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) -{ - uint tid = dispatchThreadID.x; - float outVal = doCompute(impl); - outputBuffer[tid] = outVal; -} \ No newline at end of file diff --git a/tests/compute/global-type-param3.slang.expected.txt b/tests/compute/global-type-param3.slang.expected.txt deleted file mode 100644 index deb1c3630..000000000 --- a/tests/compute/global-type-param3.slang.expected.txt +++ /dev/null @@ -1 +0,0 @@ -3F800000 diff --git a/tests/compute/globalTypeParamArrayShared.slang b/tests/compute/globalTypeParamArrayShared.slang new file mode 100644 index 000000000..65d09f14e --- /dev/null +++ b/tests/compute/globalTypeParamArrayShared.slang @@ -0,0 +1,31 @@ +interface IBase +{ + float compute(T g); +} +struct Base:IBase +{ + float b; + float compute(T g) { return b; } +}; + +struct Pair : IBase +{ + T1 head; + T2 tail; + float compute(T g) + { + return head.compute(g) + tail.compute(g); + } +}; + +struct Arr : IBase +{ + T base[N]; // = 1.0 + float compute(T g) + { + float sum = 0.0; + for (int i = 0; i < N; i++) + sum += base[i].compute(g); + return sum; + } +}; -- cgit v1.2.3