diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-12-22 10:48:55 -0800 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-12-22 10:50:32 -0800 |
| commit | 7ebc9875bbd765c1f6d7763b4ff0823ecc282e00 (patch) | |
| tree | b1296002e172be8d2554f85f97b8f9a5727c5e16 /tests/compute/implicit-generic-app.slang | |
| parent | fab52a1bd6aa056ba91a2697133e62a169866242 (diff) | |
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.
Diffstat (limited to 'tests/compute/implicit-generic-app.slang')
| -rw-r--r-- | tests/compute/implicit-generic-app.slang | 40 |
1 files changed, 40 insertions, 0 deletions
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 : ISimple>(T obj) +{ + return obj.getVal(); +} + +int test(int val) +{ + Simple simple; + simple.val = val; + return doIt(simple); +} + +RWStructuredBuffer<int> 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 |
