yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//DISABLE_TEST(compute):COMPARE_COMPUTE:-dx12 -compute -output-using-type -profile cs_6_2 -render-features half -shaderobj 2//TEST(compute):COMPARE_COMPUTE:-vk -compute -output-using-type -profile cs_6_2 -render-features half -shaderobj 3//TEST(compute):COMPARE_COMPUTE:-cuda -compute -output-using-type -render-features half -shaderobj 4 5// Test for doing a calculation using half 6 7//TEST_INPUT:ubuffer(data=[0.2 10.0 12.0 16.0], stride=4):name=inputBuffer 8RWStructuredBuffer<int> inputBuffer; 9 10//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 11RWStructuredBuffer<float> outputBuffer; 12 13struct Values 14{ 15 __init(int index) 16 { 17 m_index = index; 18 } 19 20 [mutating] half next() 21 { 22 float v = inputBuffer[m_index & 3]; 23 m_index++; 24 return half(v); 25 } 26 27 int m_index = 0; 28}; 29 30[numthreads(4, 1, 1)] 31void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 32{ 33 uint tid = dispatchThreadID.x; 34 35 Values values = Values(int(tid)); 36 37 int r = 0; 38 39 half s0 = values.next(); 40 half s1 = values.next(); 41 42 if (s0 < s1) 43 { 44 r += 0x1; 45 } 46 47 half2 h2_0 = half2(values.next(), values.next()); 48 half2 h2_1 = half2(values.next(), values.next()); 49 50 if (any(h2_0 < h2_1)) 51 { 52 r += 0x2; 53 } 54 55 if (all(h2_0 < h2_1)) 56 { 57 r += 0x4; 58 } 59 60 half3 h3_0 = half3(values.next(), values.next(), values.next()); 61 half3 h3_1 = half3(values.next(), values.next(), values.next()); 62 63 if (any(h3_0 > h3_1)) 64 { 65 r += 0x8; 66 } 67 68 if (all(h3_0 <= h3_1)) 69 { 70 r += 0x10; 71 } 72 73 half4 h4_0 = half4(values.next(), values.next(), values.next(), values.next()); 74 half4 h4_1 = half4(values.next(), values.next(), values.next(), values.next()); 75 76 77 if (any(h4_0 > h4_1)) 78 { 79 r += 0x8; 80 } 81 82 if (all(h4_0 <= h4_1)) 83 { 84 r += 0x10; 85 } 86 87 if (any(!(h4_0 == h4_1))) 88 { 89 r += 0x20; 90 } 91 92 if (all(h4_0 != h4_1)) 93 { 94 r += 0x40; 95 } 96 97 outputBuffer[tid] = r; 98}