yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
26ca9c5b0
master
1// Test that we can synthesize requirements for generic methods. 2 3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-dx11 -compute -output-using-type 4//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -output-using-type 5 6interface IBase 7{ 8 static float get(); 9} 10interface IBar : IBase 11{ 12 float derivedMethod(); 13} 14 15struct Bar : IBar 16{ 17 static float get() { return 1.0f; } 18 float derivedMethod() { return 2.0f; } 19} 20 21interface ITestInterface<Real : IFloat> 22{ 23 Real sample<T : IBar>(T t); 24 25 __init<T : IBar>(T t); 26 27 __generic<T : IBar> 28 __subscript(T t)->Real { get; } 29} 30 31struct TestInterfaceImpl<Real : IFloat> : ITestInterface<Real> 32{ 33 // The signature of this sample method is different from the one in the 34 // interface. However, we should be able to form a call into this method 35 // from the synthesized implementation matching the interface definition, 36 // so the conformance should hold. 37 Real sample<T : IBase>(T t) 38 { 39 return x + Real(T.get()); 40 } 41 42 // Test the same thing for constructors. 43 __init<T : IBase>(T t) 44 { 45 x = Real(T.get()); 46 } 47 48 // Test the same thing for subscript operators. 49 __generic<T : IBase> 50 __subscript(T t)->Real { get { return x + Real(T.get()); } } 51 Real x; 52} 53 54float test(ITestInterface<float> obj) 55{ 56 Bar b = {}; 57 return obj.sample<Bar>(b); 58} 59 60float test1(ITestInterface<float> obj) 61{ 62 Bar b = {}; 63 return obj[b]; 64} 65 66float test2<T:ITestInterface<float>>() 67{ 68 Bar b = {}; 69 T obj = T(b); 70 return obj[b]; 71} 72 73//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4); 74RWStructuredBuffer<int> outputBuffer; 75 76[numthreads(1, 1, 1)] 77void computeMain() 78{ 79 TestInterfaceImpl<float> obj; 80 obj.x = 1.0f; 81 82 // CHECK: 2 83 outputBuffer[0] = int(test(obj)); 84 85 // CHECK: 2 86 outputBuffer[1] = int(test1(obj)); 87 88 // CHECK: 2 89 outputBuffer[3] = int(test2<TestInterfaceImpl<float>>()); 90}