From 134f8ccc930a8da28808c2e288344c21c67a577e Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 31 Jul 2024 10:03:39 -0700 Subject: Fix IR lowering for generic interface types. (#4761) * Fix IR lowering for generic interface types. * Fix. * Fix. --- .../static-const-in-generic-interface.slang | 33 ++++++++++++++++++++++ .../interfaces/generic-interface-conformance.slang | 31 ++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/language-feature/constants/static-const-in-generic-interface.slang create mode 100644 tests/language-feature/interfaces/generic-interface-conformance.slang (limited to 'tests') diff --git a/tests/language-feature/constants/static-const-in-generic-interface.slang b/tests/language-feature/constants/static-const-in-generic-interface.slang new file mode 100644 index 000000000..87d8e3be8 --- /dev/null +++ b/tests/language-feature/constants/static-const-in-generic-interface.slang @@ -0,0 +1,33 @@ +// static-const-in-generic-interface.slang + +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj + +// Test that `static const` variable declarations inside of +// a generic `interface` type correctly translate to interface requirements. + +interface ITest +{ + static const T kUserDefinedValue; +} + +struct Impl : ITest +{ + static const int kUserDefinedValue = 4; +} + +struct EnsureCompileTimeEval +{ + static T getValue>() { return U.kUserDefinedValue; } +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + static const int result = EnsureCompileTimeEval.getValue(); + int outVal = result; + // CHECK: 4 + outputBuffer[0] = outVal; +} diff --git a/tests/language-feature/interfaces/generic-interface-conformance.slang b/tests/language-feature/interfaces/generic-interface-conformance.slang new file mode 100644 index 000000000..9e0510125 --- /dev/null +++ b/tests/language-feature/interfaces/generic-interface-conformance.slang @@ -0,0 +1,31 @@ +// Test that we allow type conformances whose base interface is generic. + +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-dx11 -compute -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -output-using-type + +public interface ITestInterface { + Real sample(); +} + +struct TestInterfaceImpl : ITestInterface { + Real sample() { + return x; + } + Real x; +} + +//TEST_INPUT: set data = new StructuredBuffer >[new TestInterfaceImpl{1.0}]; +StructuredBuffer> data; + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4); +RWStructuredBuffer outputBuffer; + +//TEST_INPUT: type_conformance TestInterfaceImpl:ITestInterface = 3 + +[numthreads(1, 1, 1)] +void computeMain() +{ + let obj = data[0]; + // CHECK: 1 + outputBuffer[0] = int(obj.sample()); +} \ No newline at end of file -- cgit v1.2.3