mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-22 04:24:59 +01:00
Vulkan: parity with GL (P1–P7), shared GPU culling records (N6c), threaded command recording and render thread (M1, M4)
This commit is contained in:
46
shaders/vk14/hiz_build.comp
Normal file
46
shaders/vk14/hiz_build.comp
Normal file
@@ -0,0 +1,46 @@
|
||||
#version 460 core
|
||||
#define STAGE_COMPUTE 1
|
||||
// one level of the depth pyramid of the occlusion test of the instances (the hi-z of the renderers): each texel holds the farthest
|
||||
// depth of the texels of the level below it which it covers. the depth is reversed (1 near, 0 far), so the farthest is
|
||||
// the smallest. the first level is made from the resolved depth of the scene, the others from the level below.
|
||||
// a level halves the one below, rounding down; when that one has an odd size, the last row and column of the new level
|
||||
// take its last row and column as well, so that nothing is left out
|
||||
|
||||
#define LAYOUT_COMPUTE 1
|
||||
#include "common.glsl"
|
||||
|
||||
layout(local_size_x = HIZ_GROUP_SIZE, local_size_y = HIZ_GROUP_SIZE) in;
|
||||
|
||||
layout(set = COMPUTE_SET, binding = 0) uniform sampler2D source;
|
||||
layout(r32f, set = COMPUTE_SET, binding = 1) writeonly uniform image2D target;
|
||||
|
||||
// the parameters of the kernel (push constants)
|
||||
layout(push_constant) uniform kernel_constants
|
||||
{
|
||||
// xy: size of the source level, zw: size of the target level
|
||||
ivec4 sizes;
|
||||
// x: level of the source read
|
||||
ivec4 params;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
|
||||
if (any(greaterThanEqual(texel, sizes.zw)))
|
||||
return;
|
||||
|
||||
ivec2 first = min(2 * texel, sizes.xy - 1);
|
||||
ivec2 last = min(2 * texel + 1, sizes.xy - 1);
|
||||
if (texel.x == sizes.z - 1)
|
||||
last.x = sizes.x - 1;
|
||||
if (texel.y == sizes.w - 1)
|
||||
last.y = sizes.y - 1;
|
||||
|
||||
float farthest = 1.0;
|
||||
for (int y = first.y; y <= last.y; ++y)
|
||||
{
|
||||
for (int x = first.x; x <= last.x; ++x)
|
||||
farthest = min(farthest, texelFetch(source, ivec2(x, y), params.x).r);
|
||||
}
|
||||
imageStore(target, texel, vec4(farthest));
|
||||
}
|
||||
Reference in New Issue
Block a user