#version 450

layout (local_size_x = 16, local_size_y = 16) in;

layout (set = 0, binding = 0) uniform usampler2D inputImage;
layout (set = 1, binding = 1, rgb10_a2) uniform image2D resultImage;

layout(push_constant) uniform constants
{
	uint width;
	uint height;
} image_size;

void main()
{   
    ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);
    if(pixelCoords.x >= image_size.width || pixelCoords.y >= image_size.height){
        return;
    }
    
    uvec4 x = texelFetch(inputImage, pixelCoords, 0);
    // RGBA in big endian representation
    // RRRRRRRR|RRGGGGGG|GGGGBBBB|BBBBBBAA

    uint r = (x[0] << 2)          | (x[1] >> 6);
    uint g = ((x[1] & 0x3f) << 4) | (x[2] >> 4);
    uint b = ((x[2] & 0x0f) << 6) | (x[3] >> 2);

    imageStore(resultImage, pixelCoords, vec4(r, g, b, 1024) / 1024.0);
}
