diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-02-03 09:28:54 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-03 09:28:54 -0500 |
| commit | 3aaa586c90a688e035e2941a2e0327bd96a681cb (patch) | |
| tree | 31f73cb42bdb1bca65b294124f37e6109011b533 /tests/experiments/generic/explicit-specialization-3.slang | |
| parent | 5deb82929d289d6341e1919ee95b18b10f6db789 (diff) | |
'Explicit specialization' experiments with extensions (#2099)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Explicit specialization with multiple parameters.
* Fix tabs.
* Small improvements in test comments.
Diffstat (limited to 'tests/experiments/generic/explicit-specialization-3.slang')
| -rw-r--r-- | tests/experiments/generic/explicit-specialization-3.slang | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/experiments/generic/explicit-specialization-3.slang b/tests/experiments/generic/explicit-specialization-3.slang new file mode 100644 index 000000000..e53f97158 --- /dev/null +++ b/tests/experiments/generic/explicit-specialization-3.slang @@ -0,0 +1,56 @@ +//DISABLE_TEST:SIMPLE:-target hlsl -entry computeMain -profile cs_6_2 + +/* +In C++ we are able to explicitly specialize over more than one type/value. Here we try to use a 'dummy' generic +type such that an extension can be applied to it. + +I can't just specialize a function also complicating things. + +If I try explicit function specialization in C++. In g++11.1 it will complain if there isn't a specialition visible. +Visual studio it seems to assume it is available for import and doesn't complain. +*/ + +RWStructuredBuffer<float> outputBuffer; + +interface IDoThing +{ + static float doThing(float v); +}; + +struct Combination<T, let V : int> {}; + +extension Combination<int, 10> : IDoThing +{ + static float doThing(float v) + { + return int(v) + 10; + } +}; + +extension Combination<float, 20> : IDoThing +{ + static float doThing(float v) + { + return float(v) + 20; + } +}; + + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + + let v = Combination<float, 20>::doThing(tid) + + Combination<int, 10>::doThing(tid); + + // Produces an error - although the error message of typeof(Combination) + // is probably not great. + // + // slang(35): error 30027: 'doThing' is not a member of 'typeof(Combination)'. + // + //let y = Combination<int, 20>::doThing(tid); + + outputBuffer[tid] = v; +} + |
