1#version 450 core 2#define PRECISION ${PRECISION} 3#define FORMAT ${FORMAT} 4 5layout(std430) buffer; 6 7/* Qualifiers: layout - storage - precision - memory */ 8 9layout(set = 0, binding = 0, FORMAT) uniform PRECISION restrict writeonly image3D uOutput; 10layout(set = 0, binding = 1) uniform PRECISION sampler3D uInput; 11layout(set = 0, binding = 2) uniform PRECISION restrict Block { 12 ivec4 size; 13 ivec4 kernel; 14 ivec2 stride; 15 ivec2 padding; 16} uBlock; 17 18layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; 19 20void main() { 21 const ivec3 pos = ivec3(gl_GlobalInvocationID); 22 23 if (all(lessThan(pos, uBlock.size.xyz))) { 24 const ivec2 ipos = pos.xy * uBlock.stride - uBlock.padding; 25 26 const ivec2 start = max(ivec2(0), ipos); 27 const ivec2 end = min(ipos + uBlock.kernel.xy, uBlock.kernel.zw); 28 29 vec4 sum = vec4(0); 30 31 for (int y = start.y; y < end.y; ++y) { 32 for (int x = start.x; x < end.x; ++x) { 33 sum += texelFetch(uInput, ivec3(x, y, pos.z), 0); 34 } 35 } 36 37 imageStore( 38 uOutput, 39 pos, 40 sum / uBlock.size.w); 41 } 42} 43