refactor renderer

This commit is contained in:
nmzik
2026-07-27 02:24:50 +02:00
parent a720b28b7f
commit a20cf5d298
112 changed files with 18269 additions and 18368 deletions
@@ -0,0 +1,10 @@
#version 450 core
#extension GL_EXT_samplerless_texture_functions : require
layout(binding = 0, set = 0) uniform texture2D color;
layout(location = 0) in vec2 uv;
void main() {
ivec2 coord = ivec2(uv * vec2(textureSize(color, 0)));
gl_FragDepth = texelFetch(color, coord, 0)[gl_SampleID];
}
@@ -0,0 +1,9 @@
#version 450
layout(location = 0) out vec2 uv;
void main() {
vec2 position = vec2(float((gl_VertexIndex & 1u) << 2u), float((gl_VertexIndex & 2u) << 1u));
gl_Position = vec4(position - vec2(1.0), 0.0, 1.0);
uv = position * 0.5;
}
@@ -0,0 +1,23 @@
#version 450
#extension GL_EXT_samplerless_texture_functions : require
layout(local_size_x = 4) in;
layout(set = 0, binding = 0) uniform texture2DMS input_depth;
layout(set = 0, binding = 1, std430) buffer Output {
uint value[];
}
output_data;
layout(push_constant) uniform Push {
uint samples;
}
push;
void main() {
const uint sample_id = gl_LocalInvocationID.x;
if (sample_id < push.samples) {
output_data.value[sample_id] =
floatBitsToUint(texelFetch(input_depth, ivec2(0), int(sample_id)).x);
}
}
@@ -3,7 +3,7 @@ layout(local_size_x = 8, local_size_y = 8) in;
layout(set = 0, binding = 0, std430) readonly buffer Input { uint data[]; } input_buffer;
layout(set = 0, binding = 1, std430) buffer Output { uint data[]; } output_buffer;
layout(push_constant) uniform Push {
layout(set = 0, binding = 2, std140) uniform Push {
uint src_base;
uint dst_base;
uint width;
@@ -27,7 +27,9 @@ void copy_element(uint src, uint dst) {
} else {
uint mask = ELEMENT_BYTES == 1 ? 0xffu : 0xffffu;
uint value = (input_buffer.data[src >> 2] >> ((src & 3u) * 8u)) & mask;
atomicOr(output_buffer.data[dst >> 2], value << ((dst & 3u) * 8u));
uint shift = (dst & 3u) * 8u;
atomicAnd(output_buffer.data[dst >> 2], ~(mask << shift));
atomicOr(output_buffer.data[dst >> 2], value << shift);
}
}
@@ -0,0 +1,45 @@
#version 450
layout(constant_id = 0) const uint D32 = 0u;
layout(local_size_x = 64) in;
layout(set = 0, binding = 0, std430) readonly buffer Input { uint data[]; } input_buffer;
layout(set = 0, binding = 1, std430) buffer Output { uint data[]; } output_buffer;
layout(push_constant, std430) uniform Push {
uint src_base;
uint dst_base;
uint width;
uint height;
uint depth;
uint surface_z;
uint pitch_bytes;
uint slice_bytes;
uint blocks_per_row;
uint blocks_per_slice;
uint tail_x;
uint tail_y;
uint tail;
} params;
uint decode(uint value) {
float normalized = D32 != 0u
? clamp(uintBitsToFloat(value), 0.0, 1.0)
: float(value & 0x00ffffffu) / 16777215.0;
return uint(round(normalized * 65535.0));
}
void main() {
uint x = gl_GlobalInvocationID.x;
uint y = gl_GlobalInvocationID.y;
if (x >= params.width || y >= params.height) {
return;
}
uint src = params.src_base + y * params.pitch_bytes + x * 4u;
uint dst = params.dst_base + y * params.slice_bytes + x * 2u;
uint shift = (dst & 2u) * 8u;
uint mask = 0xffffu << shift;
uint word = dst >> 2u;
atomicAnd(output_buffer.data[word], ~mask);
atomicOr(output_buffer.data[word], decode(input_buffer.data[src >> 2u]) << shift);
}
@@ -0,0 +1,39 @@
#version 450
layout(constant_id = 0) const uint D32 = 0u;
layout(local_size_x = 64) in;
layout(set = 0, binding = 0, std430) readonly buffer Input { uint data[]; } input_buffer;
layout(set = 0, binding = 1, std430) buffer Output { uint data[]; } output_buffer;
layout(push_constant, std430) uniform Push {
uint src_base;
uint dst_base;
uint width;
uint height;
uint depth;
uint surface_z;
uint pitch_bytes;
uint slice_bytes;
uint blocks_per_row;
uint blocks_per_slice;
uint tail_x;
uint tail_y;
uint tail;
} params;
void main() {
uint x = gl_GlobalInvocationID.x;
uint y = gl_GlobalInvocationID.y;
if (x >= params.width || y >= params.height) {
return;
}
uint src = params.src_base + y * params.pitch_bytes + x * 2u;
uint packed = input_buffer.data[src >> 2u];
uint value = (packed >> ((src & 2u) * 8u)) & 0xffffu;
uint encoded = D32 != 0u
? floatBitsToUint(float(value) / 65535.0)
: value * 256u + (value + 128u) / 257u;
uint dst = params.dst_base + y * params.slice_bytes + x * 4u;
output_buffer.data[dst >> 2u] = encoded;
}
@@ -0,0 +1,35 @@
#version 450
layout(local_size_x = 64) in;
layout(set = 0, binding = 0, std430) readonly buffer Input { uint data[]; } input_buffer;
layout(set = 0, binding = 1, std430) buffer Output { uint data[]; } output_buffer;
layout(push_constant, std430) uniform Push {
uint src_base;
uint dst_base;
uint width;
uint height;
uint depth;
uint surface_z;
uint pitch_bytes;
uint slice_bytes;
uint blocks_per_row;
uint blocks_per_slice;
uint tail_x;
uint tail_y;
uint tail;
} params;
void main() {
uint pixel = gl_GlobalInvocationID.x;
if (pixel >= params.width) {
return;
}
uint src = (params.src_base >> 2u) + pixel * 2u;
uint dst = (params.dst_base >> 2u) + pixel * 2u;
uint bg = input_buffer.data[src];
uint ra = input_buffer.data[src + 1u];
output_buffer.data[dst] = (ra & 0x0000ffffu) | (bg & 0xffff0000u);
output_buffer.data[dst + 1u] = (bg & 0x0000ffffu) | (ra & 0xffff0000u);
}