yum-mirror/slang

Making it easier to work with shaders

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

Anders Leinowgsl: Conditionally enable some tests based on 'half' support (#5694)0f3ff5f38

master
1.4 KiB53 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type
4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -wgpu -shaderobj -output-using-type -render-features half
5
6//TEST:SIMPLE(filecheck=CHECK): -target glsl
7// CHECK-NOT: NullDifferential
8
9//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
10RWStructuredBuffer<float> outputBuffer;
11
12struct S<T:__BuiltinArithmeticType>
13{
14    T v;
15    __init(T x)
16    {
17        v = x;
18    }
19}
20
21
22S<T> makeS<T:__BuiltinArithmeticType>(T x)
23{
24    return S<T>(x);
25}
26bool cmp<T:__BuiltinArithmeticType>(T a, int b)
27{
28    return a > T(b);
29}
30void accept<each T>(expand each T value) {}
31
32T writeSingle<T : __BuiltinFloatingPointType>(inout int offset, T value)
33{
34    outputBuffer[offset++] = __realCast<float>(value);
35    return value;
36}
37
38void write<each T : __BuiltinFloatingPointType>(expand S<each T> value)
39{
40    int offset = 0;
41    accept(expand writeSingle(offset, cmp((each value).v, 0) ? (each value).v : __realCast<each T>(0.0)));
42}
43
44[numthreads(1,1,1)]
45void computeMain()
46{
47    // CHECK: 1.0
48    // CHECK: 2.0
49    // CHECK: 3.0
50    // CHECK: 4.0
51    write();
52    write(makeS(1.0), makeS(2.0h), makeS(3.0), makeS(4.0));
53}