diff options
| author | Yong He <yonghe@outlook.com> | 2025-06-13 22:13:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-13 22:13:00 -0700 |
| commit | 6a23949f07f4eba38086b656e7073ce3bf8cd2fe (patch) | |
| tree | 132bbe330b6027d323c74175686d006605e4da6d /tests/language-feature/interfaces/default-method-differentiable.slang | |
| parent | e72b3325663ab6d4bb791742574b031f0df6328a (diff) | |
Allow interface methods to have default implementations. (#7439)
Diffstat (limited to 'tests/language-feature/interfaces/default-method-differentiable.slang')
| -rw-r--r-- | tests/language-feature/interfaces/default-method-differentiable.slang | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/language-feature/interfaces/default-method-differentiable.slang b/tests/language-feature/interfaces/default-method-differentiable.slang new file mode 100644 index 000000000..4cd5dc1ed --- /dev/null +++ b/tests/language-feature/interfaces/default-method-differentiable.slang @@ -0,0 +1,42 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type + +// Test that a default interface method can be differentiable. + +interface IFoo<int v> +{ + [Differentiable] + float getVal(float x); + + [Differentiable] + float getGreaterVal<int y>(float x) + { + return getVal(x) + y + v; + } +} + +struct Impl : IFoo<2> +{ + [Differentiable] + float getVal(float x) + { + return x*x; + } + + // Using the default implementation for getGreaterVal. +} + +[Differentiable] +float test<int y, T:IFoo<y>>(T v, float x) { return v.getGreaterVal<1>(x); } + +//TEST_INPUT: set resultBuffer = out ubuffer(data=[0 0 0 0], stride=4) +RWStructuredBuffer<float> resultBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + Impl impl = {}; + var dpx = diffPair(3.0); + bwd_diff(test)(impl, dpx, 1.0f); + resultBuffer[0] = dpx.d; + // CHECK: 6.0 +} |
