yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
5ec41675d
master
1//TEST_CATEGORY(wave, compute) 2//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-directly 3//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -profile sm_6_0 4//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-via-glsl -profile sm_6_0 -Xslang... -capability GL_KHR_shader_subgroup_rotate -X. 5//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-directly -xslang -DUSE_GLSL_SYNTAX -allow-glsl 6//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-via-glsl -profile sm_6_0 -allow-glsl -Xslang... -DUSE_GLSL_SYNTAX -capability GL_KHR_shader_subgroup_rotate -X. 7 8#if defined(USE_GLSL_SYNTAX) 9#define __clusteredRotate subgroupClusteredRotate 10#else 11#define __clusteredRotate WaveClusteredRotate 12#endif 13 14//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer 15RWStructuredBuffer<uint> outputBuffer; 16 17#define SUBGROUP_SIZE 32 18#define DELTA 3 19#define CLUSTER_SIZE 8 20 21static uint threadIndex; 22static uint clusterIndex; 23static uint rotatedValue; 24 25__generic<T : __BuiltinArithmeticType> 26bool test1ClusteredRotate() 27{ 28 return __clusteredRotate(T(threadIndex), DELTA, CLUSTER_SIZE) == T(rotatedValue); 29} 30 31__generic<T : __BuiltinArithmeticType, let N : int> 32bool testVRClusteredRotate() 33{ 34 typealias gvec = vector<T, N>; 35 36#if defined(USE_GLSL_SYNTAX) 37 return (__clusteredRotate(gvec(T(threadIndex)), DELTA, CLUSTER_SIZE) == gvec(T(rotatedValue))); 38#else 39 return (__clusteredRotate(gvec(T(threadIndex)), DELTA, CLUSTER_SIZE) == gvec(T(rotatedValue)))[0]; 40#endif 41} 42 43bool test1ClusteredRotateBool() 44{ 45 bool currentValue = (threadIndex % 2 == 0) ? true : false; 46 bool rotatedValueBool = (threadIndex % 2 == 0) ? false : true; 47 return __clusteredRotate(currentValue, DELTA, CLUSTER_SIZE) == rotatedValueBool; 48} 49 50__generic<let N : int> 51bool testVRClusteredRotateBool() 52{ 53 typealias gvec = vector<bool, N>; 54 bool currentValue = (threadIndex % 2 == 0) ? true : false; 55 bool rotatedValueBool = (threadIndex % 2 == 0) ? false : true; 56 57#if defined(USE_GLSL_SYNTAX) 58 return (__clusteredRotate(gvec(currentValue), DELTA, CLUSTER_SIZE) == gvec(rotatedValueBool)); 59#else 60 return (__clusteredRotate(gvec(currentValue), DELTA, CLUSTER_SIZE) == gvec(rotatedValueBool))[0]; 61#endif 62} 63 64bool testClusteredRotate() 65{ 66 return true 67 & test1ClusteredRotate<float>() 68 & testVRClusteredRotate<float, 2>() 69 & testVRClusteredRotate<float, 3>() 70 & testVRClusteredRotate<float, 4>() 71 & test1ClusteredRotate<half>() 72 & testVRClusteredRotate<half, 2>() 73 & testVRClusteredRotate<half, 3>() 74 & testVRClusteredRotate<half, 4>() 75 & test1ClusteredRotate<uint>() 76 & testVRClusteredRotate<uint, 2>() 77 & testVRClusteredRotate<uint, 3>() 78 & testVRClusteredRotate<uint, 4>() 79 & test1ClusteredRotate<uint16_t>() 80 & testVRClusteredRotate<uint16_t, 2>() 81 & testVRClusteredRotate<uint16_t, 3>() 82 & testVRClusteredRotate<uint16_t, 4>() 83 & test1ClusteredRotate<int>() 84 & testVRClusteredRotate<int, 2>() 85 & testVRClusteredRotate<int, 3>() 86 & testVRClusteredRotate<int, 4>() 87 & test1ClusteredRotate<int16_t>() 88 & testVRClusteredRotate<int16_t, 2>() 89 & testVRClusteredRotate<int16_t, 3>() 90 & testVRClusteredRotate<int16_t, 4>() 91 & test1ClusteredRotate<uint8_t>() 92 & testVRClusteredRotate<uint8_t, 2>() 93 & testVRClusteredRotate<uint8_t, 3>() 94 & testVRClusteredRotate<uint8_t, 4>() 95 & test1ClusteredRotate<uint64_t>() 96 & testVRClusteredRotate<uint64_t, 2>() 97 & testVRClusteredRotate<uint64_t, 3>() 98 & testVRClusteredRotate<uint64_t, 4>() 99 & test1ClusteredRotate<int8_t>() 100 & testVRClusteredRotate<int8_t, 2>() 101 & testVRClusteredRotate<int8_t, 3>() 102 & testVRClusteredRotate<int8_t, 4>() 103 & test1ClusteredRotate<int64_t>() 104 & testVRClusteredRotate<int64_t, 2>() 105 & testVRClusteredRotate<int64_t, 3>() 106 & testVRClusteredRotate<int64_t, 4>() 107 & test1ClusteredRotateBool() 108 & testVRClusteredRotateBool<2>() 109 & testVRClusteredRotateBool<3>() 110 & testVRClusteredRotateBool<4>() 111 ; 112} 113 114[shader("compute")] 115[numthreads(SUBGROUP_SIZE, 1, 1)] 116void computeMain(uint3 dispatchID : SV_DispatchThreadID) 117{ 118 threadIndex = dispatchID.x; 119 clusterIndex = dispatchID.x % CLUSTER_SIZE; 120 121 // Determine expected value of clustered rotate in current invocation. 122 // The values passed in are global invocation ids, and we rotate them withina cluster of size `CLUSTER_SIZE`. 123 uint clusterStart = (threadIndex / CLUSTER_SIZE) * CLUSTER_SIZE; 124 rotatedValue = clusterStart + ((threadIndex - clusterStart + DELTA) % CLUSTER_SIZE); 125 126 bool result = true 127 & testClusteredRotate() 128 ; 129 130 // CHECK: 1 131 outputBuffer[0] = uint(result); 132} 133