From 90444f8366255f274993ce4699738d9ab7cf4ee1 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 15 Jun 2020 09:04:53 -0700 Subject: Generate IRType for interfaces, and reference them as `operand[0]` in IRWitnessTable values (#1387) * Generate IRType for interfaces, and use them as the type of IRWitnessTable values. This results the following IR for the included test case: ``` [export("_S3tu010IInterface7Computep1pii")] let %1 : _ = key [export("_ST3tu010IInterface")] [nameHint("IInterface")] interface %IInterface : _(%1); [export("_S3tu04Impl7Computep1pii")] [nameHint("Impl.Compute")] func %Implx5FCompute : Func(Int, Int) { block %2( [nameHint("inVal")] param %inVal : Int): let %3 : Int = mul(%inVal, %inVal) return_val(%3) } [export("_SW3tu04Impl3tu010IInterface")] witness_table %4 : %IInterface { witness_table_entry(%1,%Implx5FCompute) } ``` * Fixes per code review comments. Moved interface type reference in IRWitnessTable from their type to operand[0]. * Fix typo in comment. --- tests/compute/dynamic-generics-simple.slang | 36 ++++++++++++++++++++++ .../dynamic-generics-simple.slang.expected.txt | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 tests/compute/dynamic-generics-simple.slang create mode 100644 tests/compute/dynamic-generics-simple.slang.expected.txt (limited to 'tests/compute') diff --git a/tests/compute/dynamic-generics-simple.slang b/tests/compute/dynamic-generics-simple.slang new file mode 100644 index 000000000..bb009204e --- /dev/null +++ b/tests/compute/dynamic-generics-simple.slang @@ -0,0 +1,36 @@ +//TEST_IGNORE_FILE +//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -allow-dynamic-code -xslang -dump-ir + +// Test basic dynamic dispatch code gen + +interface IInterface +{ + static int Compute(int inVal); +}; + +int GenericCompute(int inVal) +{ + return T.Compute(inVal); +} + +struct Impl : IInterface +{ + static int Compute(int inVal) { return inVal * inVal; } +}; + +int test(int inVal) +{ + return GenericCompute(inVal); +} + +//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer : register(u0); + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = outputBuffer[tid]; + int outVal = test(inVal); + outputBuffer[tid] = outVal; +} \ No newline at end of file diff --git a/tests/compute/dynamic-generics-simple.slang.expected.txt b/tests/compute/dynamic-generics-simple.slang.expected.txt new file mode 100644 index 000000000..bf72fb434 --- /dev/null +++ b/tests/compute/dynamic-generics-simple.slang.expected.txt @@ -0,0 +1,4 @@ +0 +1 +4 +9 \ No newline at end of file -- cgit v1.2.3