yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
dd06524f5
master
1//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage compute -entry computeMain -target glsl -DTARGET_GLSL 2//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -stage compute -entry computeMain -target spirv -emit-spirv-directly -DTARGET_SPIRV 3//TEST:SIMPLE(filecheck=CHECK_HLSL): -allow-glsl -stage compute -entry computeMain -target hlsl -DTARGET_HLSL 4//TEST:SIMPLE(filecheck=CHECK_CUDA): -allow-glsl -stage compute -entry computeMain -target cuda -DTARGET_CUDA 5 6// not testing cpp due to missing impl 7//DISABLE_TEST:SIMPLE(filecheck=CHECK_CPP): -allow-glsl -stage compute -entry computeMain -target cpp -DTARGET_CPP 8 9//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl 10//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly 11//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-wgpu -compute -entry computeMain -allow-glsl -xslang -DWGPU 12 13// Not testing because CI runners may not support Metal's intrinsics. 14//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-metal -compute -entry computeMain -allow-glsl -xslang -DMETAL 15 16#version 430 17 18#if 1 \ 19 && !defined(TARGET_HLSL) \ 20 && !defined(TARGET_CUDA) \ 21 && !defined(WGPU) \ 22 && !defined(METAL) 23// hlsl does not treat boolean types with subgroup.* as a logical operator 24// cuda, wgsl, and metal is missing an implementation 25#define TEST_when_logical_operators_are_implemented 26#endif 27 28//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer 29buffer MyBlockName2 30{ 31 uint data[]; 32} outputBuffer; 33 34#define local_size_x_v 4 35layout(local_size_x = local_size_x_v) in; 36 37__generic<T : __BuiltinLogicalType> 38bool test1Logical() { 39 return true 40#if defined(TEST_when_logical_operators_are_implemented) 41 & subgroupInclusiveAnd(T(1)) == T(1) 42 & subgroupInclusiveOr(T(1)) == T(1) 43 & subgroupInclusiveXor(T(1)) == T(0) 44#endif // #if defined(TEST_when_logical_operators_are_implemented) 45 ; 46} 47 48__generic<T : __BuiltinLogicalType, let N : int> 49bool testVLogical() { 50 typealias gvec = vector<T, N>; 51 52 return true 53#if defined(TEST_when_logical_operators_are_implemented) 54 & subgroupInclusiveAnd(gvec(T(1))) == gvec(T(1)) 55 & subgroupInclusiveOr(gvec(T(1))) == gvec(T(1)) 56 & subgroupInclusiveXor(gvec(T(1))) == gvec(T(0)) 57#endif // #if defined(TEST_when_logical_operators_are_implemented) 58 ; 59} 60 61bool testLogical() { 62 return true 63 & test1Logical<int>() 64 & testVLogical<int, 2>() 65 & testVLogical<int, 3>() 66 & testVLogical<int, 4>() 67 & test1Logical<int8_t>() 68 & testVLogical<int8_t, 2>() 69 & testVLogical<int8_t, 3>() 70 & testVLogical<int8_t, 4>() 71 & test1Logical<int16_t>() 72 & testVLogical<int16_t, 2>() 73 & testVLogical<int16_t, 3>() 74 & testVLogical<int16_t, 4>() 75 & test1Logical<int64_t>() 76 & testVLogical<int64_t, 2>() 77 & testVLogical<int64_t, 3>() 78 & testVLogical<int64_t, 4>() 79 & test1Logical<uint>() 80 & testVLogical<uint, 2>() 81 & testVLogical<uint, 3>() 82 & testVLogical<uint, 4>() 83 & test1Logical<uint8_t>() 84 & testVLogical<uint8_t, 2>() 85 & testVLogical<uint8_t, 3>() 86 & testVLogical<uint8_t, 4>() 87 & test1Logical<uint16_t>() 88 & testVLogical<uint16_t, 2>() 89 & testVLogical<uint16_t, 3>() 90 & testVLogical<uint16_t, 4>() 91 & test1Logical<uint64_t>() 92 & testVLogical<uint64_t, 2>() 93 & testVLogical<uint64_t, 3>() 94 & testVLogical<uint64_t, 4>() 95 & test1Logical<bool>() 96 & testVLogical<bool, 2>() 97 & testVLogical<bool, 3>() 98 & testVLogical<bool, 4>() 99 ; 100} 101 102__generic<T : __BuiltinArithmeticType> 103bool test1Arithmetic() { 104 return true 105 & subgroupInclusiveAdd(T(1)) == T(4) 106 & subgroupInclusiveMul(T(1)) == T(1) 107 108 // WGSL and Metal does not support inclusive min/max 109#if !defined(WGPU) && !defined(METAL) 110 & subgroupInclusiveMin(T(1)) == T(1) 111 & subgroupInclusiveMax(T(1)) == T(1) 112#endif 113 ; 114} 115__generic<T : __BuiltinArithmeticType, let N : int> 116bool testVArithmetic() { 117 typealias gvec = vector<T, N>; 118 119 return true 120 & subgroupInclusiveAdd(gvec(T(1))) == gvec(T(4)) 121 // & subgroupInclusiveMul(gvec(T(1))) == gvec(T(1)) 122 123 // WGSL and Metal does not support inclusive min/max 124#if !defined(WGPU) && !defined(METAL) 125 & subgroupInclusiveMin(gvec(T(1))) == gvec(T(1)) 126 & subgroupInclusiveMax(gvec(T(1))) == gvec(T(1)) 127#endif 128 ; 129} 130 131bool testArithmetic() { 132 return true 133 & test1Arithmetic<float>() 134 & testVArithmetic<float, 2>() 135 // & testVArithmetic<float, 3>() 136 // & testVArithmetic<float, 4>() 137 // & test1Arithmetic<half>() 138 // & testVArithmetic<half, 2>() 139 // & testVArithmetic<half, 3>() 140 // & testVArithmetic<half, 4>() 141 // & test1Arithmetic<int>() 142 // & testVArithmetic<int, 2>() 143 // & testVArithmetic<int, 3>() 144 // & testVArithmetic<int, 4>() 145 // & test1Arithmetic<uint>() 146 // & testVArithmetic<uint, 2>() 147 // & testVArithmetic<uint, 3>() 148 // & testVArithmetic<uint, 4>() 149 150 // Disabled on WGPU and Metal as these built-in types are not supported as of time of writing. 151#if !defined(WGPU) && !defined(METAL) 152 & test1Arithmetic<double>() // WARNING: intel GPU's lack FP64 support 153 & testVArithmetic<double, 2>() 154 & testVArithmetic<double, 3>() 155 & testVArithmetic<double, 4>() 156 & test1Arithmetic<uint8_t>() 157 & testVArithmetic<uint8_t, 2>() 158 & testVArithmetic<uint8_t, 3>() 159 & testVArithmetic<uint8_t, 4>() 160 & test1Arithmetic<uint64_t>() 161 & testVArithmetic<uint64_t, 2>() 162 & testVArithmetic<uint64_t, 3>() 163 & testVArithmetic<uint64_t, 4>() 164 & test1Arithmetic<int8_t>() 165 & testVArithmetic<int8_t, 2>() 166 & testVArithmetic<int8_t, 3>() 167 & testVArithmetic<int8_t, 4>() 168 & test1Arithmetic<int64_t>() 169 & testVArithmetic<int64_t, 2>() 170 & testVArithmetic<int64_t, 3>() 171 & testVArithmetic<int64_t, 4>() 172#endif 173 174 // Disabled on WGPU as these built-in types are not supported as of time of writing. 175#if !defined (WGPU) 176 & test1Arithmetic<uint16_t>() 177 & testVArithmetic<uint16_t, 2>() 178 & testVArithmetic<uint16_t, 3>() 179 & testVArithmetic<uint16_t, 4>() 180 & test1Arithmetic<int16_t>() 181 & testVArithmetic<int16_t, 2>() 182 & testVArithmetic<int16_t, 3>() 183 & testVArithmetic<int16_t, 4>() 184#endif 185 ; 186} 187 188[shader("compute")] 189void computeMain() 190{ 191 192 bool res0 = true 193 // WGSL and Metal does not support bitwise inclusive intrinsics. 194#if !defined(WGPU) && !defined(METAL) 195 & testLogical() 196#endif 197 ; 198 199 bool res1 = true 200 & testArithmetic() 201 ; 202 203 if (gl_LocalInvocationID.x == 3) { 204 // seperate so if there is an erroneous error the "major" 205 // tests are issolated into 2 branches without polluting the 206 // file with a bunch of individual test values 207 outputBuffer.data[0] = res0; 208 outputBuffer.data[1] = res1; 209 } 210 211 // CHECK_GLSL: void main( 212 // CHECK_SPV: OpEntryPoint 213 // CHECK_HLSL: void computeMain( 214 // CHECK_CUDA: void computeMain( 215 // CHECK_CPP: void _computeMain( 216 // BUF: 1 217 // BUF-NEXT: 1 218}