yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
ae1a5e408
master
1//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage compute -entry computeMain -target glsl 2//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -stage compute -entry computeMain -target spirv -emit-spirv-directly 3//TEST:SIMPLE(filecheck=CHECK_HLSL): -allow-glsl -stage compute -entry computeMain -target hlsl -DTARGET_HLSL 4 5// not testing cuda due to missing impl 6//DISABLE_TEST:SIMPLE(filecheck=CHECK_CUDA): -allow-glsl -stage compute -entry computeMain -target cuda -DTARGET_CUDA 7// not testing cpp due to missing impl 8//DISABLE_TEST:SIMPLE(filecheck=CHECK_CPP): -allow-glsl -stage compute -entry computeMain -target cpp -DTARGET_CPP 9 10//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl 11//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly 12//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-wgpu -compute -entry computeMain -allow-glsl -xslang -DWGPU -render-feature half 13 14// Not testing because CI runners may not support Metal's intrinsics. 15//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-metal -compute -entry computeMain -allow-glsl -xslang -DMETAL 16 17#version 430 18 19// breaks on Nvidia GPU by returning 0 which is trivially wrong (works on Intel Iris Xe) 20//#define TEST_when_glsl_subgroupBallotExclusiveBitCount_is_not_bugged 21 22//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer 23buffer MyBlockName2 24{ 25 uint data[]; 26} outputBuffer; 27 28layout(local_size_x = 32) in; 29 30__generic<T : __BuiltinLogicalType> 31bool test1BroadcastX() { 32 return true 33 & subgroupBroadcast(T(1), 0) == T(1) 34 & subgroupBroadcastFirst(T(1)) == T(1) 35 ; 36} 37__generic<T : __BuiltinLogicalType, let N : int> 38bool testVBroadcastX() { 39 typealias gvec = vector<T, N>; 40 41 return true 42 & subgroupBroadcast(gvec(T(1)), 0) == gvec(T(1)) 43 & subgroupBroadcastFirst(gvec(T(1))) == gvec(T(1)) 44 ; 45} 46 47__generic<T : __BuiltinFloatingPointType> 48bool test1BroadcastX() { 49 return true 50 & subgroupBroadcast(T(1), 0) == T(1) 51 & subgroupBroadcastFirst(T(1)) == T(1) 52 ; 53} 54__generic<T : __BuiltinFloatingPointType, let N : int> 55bool testVBroadcastX() { 56 typealias gvec = vector<T, N>; 57 58 return true 59 & subgroupBroadcast(gvec(T(1)), 0) == gvec(T(1)) 60 & subgroupBroadcastFirst(gvec(T(1))) == gvec(T(1)) 61 ; 62} 63bool testBroadcastX() { 64 return true 65 & test1BroadcastX<float>() 66 & testVBroadcastX<float, 2>() 67 & testVBroadcastX<float, 3>() 68 & testVBroadcastX<float, 4>() 69 & test1BroadcastX<half>() 70 & testVBroadcastX<half, 2>() 71 & testVBroadcastX<half, 3>() 72 & testVBroadcastX<half, 4>() 73 & test1BroadcastX<int>() 74 & testVBroadcastX<int, 2>() 75 & testVBroadcastX<int, 3>() 76 & testVBroadcastX<int, 4>() 77 & test1BroadcastX<uint>() 78 & testVBroadcastX<uint, 2>() 79 & testVBroadcastX<uint, 3>() 80 & testVBroadcastX<uint, 4>() 81 82 // Disabled on WGPU and Metal as these built-in types are not supported as of time of writing. 83#if !defined(WGPU) && !defined(METAL) 84 & test1BroadcastX<double>() // WARNING: intel GPU's lack FP64 support 85 & testVBroadcastX<double, 2>() 86 & testVBroadcastX<double, 3>() 87 & testVBroadcastX<double, 4>() 88 & test1BroadcastX<int8_t>() 89 & testVBroadcastX<int8_t, 2>() 90 & testVBroadcastX<int8_t, 3>() 91 & testVBroadcastX<int8_t, 4>() 92 & test1BroadcastX<int64_t>() 93 & testVBroadcastX<int64_t, 2>() 94 & testVBroadcastX<int64_t, 3>() 95 & testVBroadcastX<int64_t, 4>() 96 & test1BroadcastX<uint8_t>() 97 & testVBroadcastX<uint8_t, 2>() 98 & testVBroadcastX<uint8_t, 3>() 99 & testVBroadcastX<uint8_t, 4>() 100 & test1BroadcastX<uint64_t>() 101 & testVBroadcastX<uint64_t, 2>() 102 & testVBroadcastX<uint64_t, 3>() 103 & testVBroadcastX<uint64_t, 4>() 104 & test1BroadcastX<bool>() 105 & testVBroadcastX<bool, 2>() 106 & testVBroadcastX<bool, 3>() 107 & testVBroadcastX<bool, 4>() 108#endif 109 110 // Disabled on WGPU as these built-in types are not supported as of time of writing. 111#if !defined(WGPU) 112 & test1BroadcastX<int16_t>() 113 & testVBroadcastX<int16_t, 2>() 114 & testVBroadcastX<int16_t, 3>() 115 & testVBroadcastX<int16_t, 4>() 116 & test1BroadcastX<uint16_t>() 117 & testVBroadcastX<uint16_t, 2>() 118 & testVBroadcastX<uint16_t, 3>() 119 & testVBroadcastX<uint16_t, 4>() 120#endif 121 ; 122} 123 124bool testBallot() { 125 return true 126 & (subgroupBallot(true).x == 0xFFFFFFFF) 127 128#if !defined(WGPU) && !defined(METAL) 129 & (subgroupInverseBallot(uvec4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)) == true) 130 & (subgroupBallotBitExtract(uvec4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF), 0) == true) 131 & (subgroupBallotBitCount(uvec4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)) == 32) 132 & (subgroupBallotInclusiveBitCount(uvec4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)) != 0) 133#ifdef TEST_when_glsl_subgroupBallotExclusiveBitCount_is_not_bugged 134 & (subgroupBallotExclusiveBitCount(uvec4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)) != 0) 135#endif 136 & (subgroupBallotFindLSB(uvec4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)) == 0) 137 & (subgroupBallotFindMSB(uvec4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)) == 31) 138#endif 139 ; 140} 141 142[shader("compute")] 143void computeMain() 144{ 145 outputBuffer.data[0] = true 146 & testBroadcastX() 147 ; 148 outputBuffer.data[1] = true 149 & testBallot() 150 ; 151 152 // CHECK_GLSL: void main( 153 // CHECK_SPV: OpEntryPoint 154 // CHECK_HLSL: void computeMain( 155 // CHECK_CUDA: void computeMain( 156 // CHECK_CPP: void _computeMain( 157 // BUF: 1 158 // BUF-NEXT: 1 159}