#version 450

layout(
  local_size_x = 64,
  local_size_y = 1,
  local_size_z = 1) in;

struct d32s8_t {
  float d32;
  uint  s8;
};

layout(binding = 0, r32f) writeonly uniform  imageBuffer u_depth;
layout(binding = 1, r8ui) writeonly uniform uimageBuffer u_stencil;

layout(binding = 2)
readonly buffer s_buffer_t {
  d32s8_t data[];
} s_buffer;

layout(push_constant)
uniform u_info_t {
  uvec2 dst_extent;
  uvec2 src_extent;
} u_info;

void main() {
  if (all(lessThan(gl_GlobalInvocationID.xy, u_info.dst_extent))) {
    uint src_index = gl_GlobalInvocationID.x
                   + gl_GlobalInvocationID.y * u_info.src_extent.x
                   + gl_GlobalInvocationID.z * u_info.src_extent.y;
    
    uint dst_index = gl_GlobalInvocationID.x
                   + gl_GlobalInvocationID.y * u_info.dst_extent.x
                   + gl_GlobalInvocationID.z * u_info.dst_extent.y;
    
    d32s8_t src_data = s_buffer.data[src_index];
    imageStore(u_depth,   int(dst_index),  vec4(src_data.d32));
    imageStore(u_stencil, int(dst_index), uvec4(src_data.s8));
  }
}