From 7ebc9875bbd765c1f6d7763b4ff0823ecc282e00 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 22 Dec 2017 10:48:55 -0800 Subject: Support generic type constraints when implicitly invoking generic Fixes #326 This basically just copy-pastes logic from the explicit case over to the implicit case. After we've solved for the explicit type/value arguments, we loop over the constraints and for each one we try to find a suitable subtype witness to use (after substituting in the arguments solved so far). This change includes a test case for the new functionality. --- tests/compute/implicit-generic-app.slang | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/compute/implicit-generic-app.slang (limited to 'tests/compute/implicit-generic-app.slang') diff --git a/tests/compute/implicit-generic-app.slang b/tests/compute/implicit-generic-app.slang new file mode 100644 index 000000000..d917a5f9a --- /dev/null +++ b/tests/compute/implicit-generic-app.slang @@ -0,0 +1,40 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +// Testing that we can implicitly specialize a generic +// that has a constrained type parameter. + + +interface ISimple +{ + int getVal(); +} + +struct Simple : ISimple +{ + int val; + + int getVal() { return val; } +}; + +int doIt(T obj) +{ + return obj.getVal(); +} + +int test(int val) +{ + Simple simple; + simple.val = val; + return doIt(simple); +} + +RWStructuredBuffer outputBuffer : register(u0); +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = (int) dispatchThreadID.x; + int outVal = test(tid); + outputBuffer[tid] = outVal; +} \ No newline at end of file -- cgit v1.2.3