ColorCopyShorteningComputeShaderSource.comp 1010 B

123456789101112131415161718192021222324252627282930313233343536
  1. #version 450 core
  2. layout (std140, binding = 0) uniform ratio_in
  3. {
  4. int ratio;
  5. };
  6. layout (set = 2, binding = 0) uniform usampler2D src;
  7. layout (set = 3, binding = 0) writeonly uniform uimage2D dst;
  8. layout (local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
  9. void main()
  10. {
  11. uvec2 coords = gl_GlobalInvocationID.xy;
  12. ivec2 textureSz = textureSize(src, 0);
  13. if (int(coords.x) >= textureSz.x || int(coords.y) >= textureSz.y)
  14. {
  15. return;
  16. }
  17. uint coordsShifted = coords.x << ratio;
  18. uvec2 dstCoords0 = uvec2(coordsShifted, coords.y);
  19. uvec2 dstCoords1 = uvec2(coordsShifted + 1, coords.y);
  20. uvec2 dstCoords2 = uvec2(coordsShifted + 2, coords.y);
  21. uvec2 dstCoords3 = uvec2(coordsShifted + 3, coords.y);
  22. uvec4 rgba = texelFetch(src, ivec2(coords), 0);
  23. imageStore(dst, ivec2(dstCoords0), rgba.rrrr);
  24. imageStore(dst, ivec2(dstCoords1), rgba.gggg);
  25. imageStore(dst, ivec2(dstCoords2), rgba.bbbb);
  26. imageStore(dst, ivec2(dstCoords3), rgba.aaaa);
  27. }