1#version 450 core 2#extension GL_KHR_memory_scope_semantics : enable 3#pragma use_vulkan_memory_model 4 5layout(local_size_x = 16, local_size_y = 16) in; 6 7layout(binding = 0) buffer Buffer 8{ 9 int datai; 10 float dataf; 11 double datad; 12} buf; 13 14shared int atomi; 15shared float atomf; 16shared double atomd; 17 18layout(binding = 0, r32f) volatile coherent uniform image1D fimage1D; 19layout(binding = 1, r32f) volatile coherent uniform image2D fimage2D; 20 21void undeclared_errors() 22{ 23 //atomicAdd 24 float resultf = 0; 25 resultf = atomicAdd(atomf, 3.0); 26 resultf = atomicAdd(atomf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 27 resultf = atomicAdd(buf.dataf, 3.0); 28 resultf = atomicAdd(buf.dataf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 29 30 double resultd = 0; 31 resultd = atomicAdd(atomd, 3.0); 32 resultd = atomicAdd(atomd, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 33 resultd = atomicAdd(buf.datad, 3.0); 34 resultd = atomicAdd(buf.datad, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 35 36 //atomicExchange 37 resultf = atomicExchange(buf.dataf, resultf); 38 resultf = atomicExchange(buf.dataf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 39 resultf = atomicExchange(atomf, resultf); 40 resultf = atomicExchange(atomf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 41 buf.dataf += resultf; 42 43 resultd = atomicExchange(buf.datad, resultd); 44 resultd = atomicExchange(buf.datad, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 45 resultd = atomicExchange(atomd, resultd); 46 resultd = atomicExchange(atomd, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 47 buf.datad += resultd; 48 49 //atomic load/store 50 resultf = atomicLoad(buf.dataf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 51 atomicStore(buf.dataf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 52 resultf = atomicLoad(atomf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 53 atomicStore(atomf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 54 buf.dataf += resultf; 55 56 resultd = atomicLoad(buf.datad, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 57 atomicStore(buf.datad, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 58 resultd = atomicLoad(atomd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 59 atomicStore(atomd, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 60 buf.datad += resultd; 61 62 // image atomics: 63 atomf = imageAtomicAdd(fimage2D, ivec2(0,0), 2.0); 64 atomf = imageAtomicAdd(fimage2D, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed); 65 atomf = imageAtomicExchange(fimage2D, ivec2(1,0), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 66 atomf = imageAtomicLoad(fimage2D, ivec2(1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 67 imageAtomicStore(fimage2D, ivec2(2,2), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 68 buf.dataf += atomf; 69} 70 71#extension GL_EXT_shader_atomic_float: enable 72 73void main() 74{ 75 float resultf = 0; 76 double resultd = 0; 77 int resulti = 0; 78 79 //atomicAdd 80 resultf = atomicAdd(atomi); 81 resultf = atomicAdd(atomi, 3.0); 82 resultf = atomicAdd(atomi, resultf, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 83 resultf = atomicAdd(atomi, resultf, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed); 84 85 //atomicExchange 86 resultf = atomicExchange(buf.datai); 87 resultf = atomicExchange(buf.datai, resultf); 88 resultf = atomicExchange(buf.datai, resultf, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 89 resultf = atomicExchange(buf.datai, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 90 resultf = atomicExchange(atomi, resultf); 91 resultf = atomicExchange(atomi, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 92 buf.dataf += resultf; 93 94 //atomic load/store 95 resultf = atomicLoad(buf.datai, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 96 atomicStore(buf.datai, resulti, gl_StorageSemanticsShared, gl_SemanticsRelaxed); 97 98 // image atomics: 99 atomf = imageAtomicAdd(fimage1D, ivec2(0,0), 2.0); 100 atomf = imageAtomicAdd(fimage2D, ivec3(0,0,0), 2.0); 101 atomf = imageAtomicAdd(fimage2D, 2.0); 102 atomf = imageAtomicExchange(fimage1D, ivec2(1,0), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 103 atomf = imageAtomicExchange(fimage2D, 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 104 atomf = imageAtomicExchange(fimage2D, ivec3(1,0,1), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 105 atomf = imageAtomicLoad(fimage1D, ivec2(1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 106 atomf = imageAtomicLoad(fimage2D, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 107 atomf = imageAtomicLoad(fimage2D, ivec3(1,1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 108 imageAtomicStore(fimage1D, ivec2(2,2), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 109 imageAtomicStore(fimage2D, atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 110 imageAtomicStore(fimage2D, ivec3(2,2,1), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed); 111 buf.dataf += atomf; 112}