yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f9f6a28df
master
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type 3 4//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 5RWStructuredBuffer<int> outputBuffer; 6 7interface IOperation<T : __BuiltinFloatingPointType> 8{ 9 static T apply(T lhs, T rhs); 10}; 11 12T applyOp<T:__BuiltinFloatingPointType, TOp:IOperation<T>>(T lhs, T rhs) 13{ 14 return TOp::apply(lhs, rhs); 15} 16 17struct AddOp<T : __BuiltinFloatingPointType> : IOperation<T> 18{ 19 static T apply(T lhs, T rhs) 20 { 21 return lhs + rhs; 22 } 23} 24 25[numthreads(1, 1, 1)] 26void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 27{ 28 let result = applyOp<float, AddOp<float>>(1.0, 2.0); 29 30 // CHECK: 3 31 outputBuffer[0] = (int)result; 32}