yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile sm_5_0 -use-dxbc -output-using-type 2 3// Test that we can specialize a generic method called through a dynamic interface. 4 5interface IValue 6{ 7 float getVal(); 8} 9 10struct SimpleVal : IValue 11{ 12 float val; 13 float getVal() { return val; } 14} 15 16[anyValueSize(16)] 17interface IInterface 18{ 19 associatedtype V : IValue; 20 V run<let N : int>(float arr[N]); 21} 22 23struct Add : IInterface 24{ 25 float base; 26 typealias V = SimpleVal; 27 V run<let N : int>(float arr[N]) 28 { 29 float sum = base; 30 for (int i = 0; i < N; i++) 31 sum += arr[i]; 32 V rs; 33 rs.val = sum; 34 return rs; 35 } 36} 37 38struct Mul : IInterface 39{ 40 float base; 41 typealias V = SimpleVal; 42 V run<let N : int>(float arr[N]) 43 { 44 float sum = base; 45 for (int i = 0; i < N; i++) 46 sum *= arr[i]; 47 V rs; 48 rs.val = sum; 49 return rs; 50 } 51} 52 53//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer 54RWStructuredBuffer<float> gOutputBuffer; 55 56//TEST_INPUT:type_conformance Add:IInterface=1 57//TEST_INPUT:type_conformance Mul:IInterface=2 58 59[numthreads(1, 1, 1)] 60void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 61{ 62 var obj = createDynamicObject<IInterface>(1, 1.0); // Add. 63 float arr[3] = { 2, 3, 4 }; 64 gOutputBuffer[0] = obj.run(arr).getVal(); 65}