1#version 450 core 2 3#extension GL_KHR_memory_scope_semantics : enable 4#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable 5#extension GL_EXT_shader_atomic_float2: enable 6#pragma use_vulkan_memory_model 7 8layout(local_size_x = 16, local_size_y = 16) in; 9 10layout(binding = 0) buffer Buffer 11{ 12 float16_t datah; 13 float dataf; 14 double datad; 15} buf; 16 17shared float16_t atomh; 18shared float atomf; 19shared double atomd; 20 21layout(binding = 0, r32f) volatile coherent uniform image1D fimage1D; 22layout(binding = 1, r32f) volatile coherent uniform image1DArray fimage1DArray; 23layout(binding = 2, r32f) volatile coherent uniform image2D fimage2D; 24layout(binding = 3, r32f) volatile coherent uniform image2DArray fimage2DArray; 25layout(binding = 4, r32f) volatile coherent uniform image2DRect fimage2DRect; 26layout(binding = 5, r32f) volatile coherent uniform imageCube fimageCube; 27layout(binding = 6, r32f) volatile coherent uniform imageCubeArray fimageCubeArray; 28layout(binding = 9, r32f) volatile coherent uniform image3D fimage3D; 29 30void main() 31{ 32 //atomicAdd 33 float16_t resulth = float16_t(0.0); 34 resulth = atomicAdd(atomh, float16_t(3.0)); 35 resulth = atomicAdd(atomh, float16_t(4.5), gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 36 resulth = atomicAdd(buf.datah, float16_t(3.0)); 37 resulth = atomicAdd(buf.datah, float16_t(4.5), gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 38 39 //atomicMin 40 resulth = atomicMin(atomh, float16_t(3.0)); 41 resulth = atomicMin(atomh, float16_t(4.5), gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 42 resulth = atomicMin(buf.datah, float16_t(3.0)); 43 resulth = atomicMin(buf.datah, float16_t(4.5), gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 44 45 float resultf = 0.0; 46 resultf = atomicMin(atomf, 3.0); 47 resultf = atomicMin(atomf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 48 resultf = atomicMin(buf.dataf, 3.0); 49 resultf = atomicMin(buf.dataf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 50 51 double resultd = 0.0; 52 resultd = atomicMin(atomd, 3.0); 53 resultd = atomicMin(atomd, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 54 resultd = atomicMin(buf.datad, 3.0); 55 resultd = atomicMin(buf.datad, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 56 57 //atomicMax 58 resulth = atomicMax(atomh, float16_t(3.0)); 59 resulth = atomicMax(atomh, float16_t(4.5), gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 60 resulth = atomicMax(buf.datah, float16_t(3.0)); 61 resulth = atomicMax(buf.datah, float16_t(4.5), gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 62 63 resultf = atomicMax(atomf, 3.0); 64 resultf = atomicMax(atomf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 65 resultf = atomicMax(buf.dataf, 3.0); 66 resultf = atomicMax(buf.dataf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 67 68 resultd = atomicMax(atomd, 3.0); 69 resultd = atomicMax(atomd, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 70 resultd = atomicMax(buf.datad, 3.0); 71 resultd = atomicMax(buf.datad, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 72 73 //atomicExchange 74 resulth = atomicExchange(buf.datah, resulth); 75 buf.datah += resulth; 76 resulth = atomicExchange(buf.datah, resulth, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 77 buf.datah += resulth; 78 resulth = atomicExchange(atomh, resulth); 79 buf.datah += resulth; 80 resulth = atomicExchange(atomh, resulth, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 81 buf.datah += resulth; 82 83 //atomic load/store 84 resulth = atomicLoad(buf.datah, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 85 atomicStore(buf.datah, resulth, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 86 buf.datah += resulth; 87 88 resulth = atomicLoad(atomh, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 89 atomicStore(atomh, resulth, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 90 buf.datah += resulth; 91 92 // image atomics on 1D: 93 atomf = imageAtomicMin(fimage1D, int(0), 2.0); 94 buf.dataf += atomf; 95 atomf = imageAtomicMin(fimage1D, int(1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 96 buf.dataf += atomf; 97 98 atomf = imageAtomicMax(fimage1D, int(0), 2.0); 99 buf.dataf += atomf; 100 atomf = imageAtomicMax(fimage1D, int(1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 101 buf.dataf += atomf; 102 103 // image atomics on 1D Array: 104 atomf = imageAtomicMin(fimage1DArray, ivec2(0,0), 2.0); 105 buf.dataf += atomf; 106 atomf = imageAtomicMin(fimage1DArray, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 107 buf.dataf += atomf; 108 109 atomf = imageAtomicMax(fimage1DArray, ivec2(0,0), 2.0); 110 buf.dataf += atomf; 111 atomf = imageAtomicMax(fimage1DArray, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 112 buf.dataf += atomf; 113 114 // image atomics on 2D: 115 atomf = imageAtomicMin(fimage2D, ivec2(0,0), 2.0); 116 buf.dataf += atomf; 117 atomf = imageAtomicMin(fimage2D, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 118 buf.dataf += atomf; 119 120 atomf = imageAtomicMax(fimage2D, ivec2(0,0), 2.0); 121 buf.dataf += atomf; 122 atomf = imageAtomicMax(fimage2D, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 123 buf.dataf += atomf; 124 125 // image atomics on 2D Rect: 126 atomf = imageAtomicMin(fimage2DRect, ivec2(0,0), 2.0); 127 buf.dataf += atomf; 128 atomf = imageAtomicMin(fimage2DRect, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 129 buf.dataf += atomf; 130 131 atomf = imageAtomicMax(fimage2DRect, ivec2(0,0), 2.0); 132 buf.dataf += atomf; 133 atomf = imageAtomicMax(fimage2DRect, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 134 buf.dataf += atomf; 135 136 // image atomics on 2D Array: 137 atomf = imageAtomicMin(fimage2DArray, ivec3(0,0,0), 2.0); 138 buf.dataf += atomf; 139 atomf = imageAtomicMin(fimage2DArray, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 140 buf.dataf += atomf; 141 142 atomf = imageAtomicMax(fimage2DArray, ivec3(0,0,0), 2.0); 143 buf.dataf += atomf; 144 atomf = imageAtomicMax(fimage2DArray, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 145 buf.dataf += atomf; 146 147 // image atomics on Cube: 148 atomf = imageAtomicMin(fimageCube, ivec3(0,0,0), 2.0); 149 buf.dataf += atomf; 150 atomf = imageAtomicMin(fimageCube, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 151 buf.dataf += atomf; 152 153 atomf = imageAtomicMax(fimageCube, ivec3(0,0,0), 2.0); 154 buf.dataf += atomf; 155 atomf = imageAtomicMax(fimageCube, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 156 buf.dataf += atomf; 157 158 // image atomics on Cube Array: 159 atomf = imageAtomicMin(fimageCubeArray, ivec3(0,0,0), 2.0); 160 buf.dataf += atomf; 161 atomf = imageAtomicMin(fimageCubeArray, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 162 buf.dataf += atomf; 163 164 atomf = imageAtomicMax(fimageCubeArray, ivec3(0,0,0), 2.0); 165 buf.dataf += atomf; 166 atomf = imageAtomicMax(fimageCubeArray, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 167 buf.dataf += atomf; 168 169 // image atomics on 3D: 170 atomf = imageAtomicMin(fimage3D, ivec3(0,0,0), 2.0); 171 buf.dataf += atomf; 172 atomf = imageAtomicMin(fimage3D, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 173 buf.dataf += atomf; 174 175 atomf = imageAtomicMax(fimage3D, ivec3(0,0,0), 2.0); 176 buf.dataf += atomf; 177 atomf = imageAtomicMax(fimage3D, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 178 buf.dataf += atomf; 179} 180