From 46529df2c4f73a4655bdd79d48004f29374a99a8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 6 Nov 2023 14:40:38 -0800 Subject: Fix ICE when lowering an associatedtype declref from an derived interface. (#3312) * Fix ICE when lowering an associatedtype declref from an derived interface. * Fixes. * Fix test. * Fix GLSL/SPIRV image subscript swizzle store regression. * Fix. --------- Co-authored-by: Yong He --- tests/autodiff/derived-interface.slang | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/autodiff/derived-interface.slang (limited to 'tests/autodiff') diff --git a/tests/autodiff/derived-interface.slang b/tests/autodiff/derived-interface.slang new file mode 100644 index 000000000..68e84ebad --- /dev/null +++ b/tests/autodiff/derived-interface.slang @@ -0,0 +1,55 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +interface IFoo : IDifferentiable +{ + [Differentiable] + __init(T d); + + [Differentiable] + static This create(Differential d); + + [Differentiable] + float getVal(); +} + +struct Impl : IFoo +{ + float x; + [Differentiable] + __init(T d) + { + this = (Impl)d; + } + + [Differentiable] + static This create(Differential d) + { + This v; + v.x = d.x * d.x; + return v; + } + + [Differentiable] + float getVal() { return x; } +} + +[Differentiable] +float test(T.Differential d) +{ + return T.create(d).getVal(); +} + +[numthreads(1,1,1)] +void computeMain(uint threadId: SV_DispatchThreadID) +{ + Impl.Differential d; + d.x = 3.0; + Impl.Differential dd; + dd.x = 1.0; + outputBuffer[0] = fwd_diff(test)(diffPair(d, dd)).d; + // CHECK: 6.0 +} -- cgit v1.2.3