yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaInitial version of spirv_asm block (#3151)ef4c9f1f1

master
889 B32 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly -output-using-type
2
3//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
4RWStructuredBuffer<int> outputBuffer;
5
6// CHECK:      10
7// CHECK-NEXT: 20
8// CHECK-NEXT: 30
9// CHECK-NEXT: 40
10
11//
12// This test checks that although we have a generic function and the spirv_asm
13// block references the type parameter 'T', specialization resolves this before
14// the SPIR-V is rendered.
15//
16func foo<T : __BuiltinFloatingPointType>(T x) -> T
17{
18    return spirv_asm
19    {
20        OpConstant $$int %int_10 10;
21        OpConvertSToF $$T %float_10 %int_10;
22        OpFMul $$T result $x %float_10;
23    };
24}
25
26[numthreads(4, 1, 1)]
27void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
28{
29    int i = dispatchThreadID.x;
30    int n = outputBuffer[i];
31    outputBuffer[i] = int(foo<float>(n));
32}