Eevee: Fix and opimize MinMaxZ generation.

This commit is contained in:
Clément Foucault 2017-08-12 16:13:08 +02:00
parent 76d0ab9750
commit b858b44f2e
Notes: blender-bot 2023-02-14 07:45:38 +01:00
Referenced by issue #52404, can't open blender windows 64bit
3 changed files with 24 additions and 25 deletions

View File

@ -992,13 +992,13 @@ void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, GPUTexture *depth_src, int l
EEVEE_TextureList *txl = vedata->txl;
e_data.depth_src = depth_src;
e_data.depth_src_layer = layer;
DRW_stats_group_start("Min buffer");
/* Copy depth buffer to min texture top level */
DRW_framebuffer_texture_attach(fbl->downsample_fb, stl->g_data->minzbuffer, 0, 0);
DRW_framebuffer_bind(fbl->downsample_fb);
if (layer >= 0) {
e_data.depth_src_layer = layer;
DRW_draw_pass(psl->minz_downdepth_layer_ps);
}
else {
@ -1015,7 +1015,6 @@ void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, GPUTexture *depth_src, int l
DRW_framebuffer_texture_attach(fbl->downsample_fb, txl->maxzbuffer, 0, 0);
DRW_framebuffer_bind(fbl->downsample_fb);
if (layer >= 0) {
e_data.depth_src_layer = layer;
DRW_draw_pass(psl->maxz_downdepth_layer_ps);
}
else {

View File

@ -171,8 +171,6 @@ static void EEVEE_draw_scene(void *vedata)
DRW_draw_pass(psl->depth_pass_cull);
DRW_stats_group_end();
DRW_draw_pass(psl->background_pass);
/* Create minmax texture */
DRW_stats_group_start("Main MinMax buffer");
EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1);
@ -183,6 +181,7 @@ static void EEVEE_draw_scene(void *vedata)
/* Shading pass */
DRW_stats_group_start("Shading");
DRW_draw_pass(psl->background_pass);
EEVEE_draw_default_passes(psl);
DRW_draw_pass(psl->material_pass);
DRW_stats_group_end();

View File

@ -11,23 +11,17 @@ uniform int depthLayer;
uniform sampler2D depthBuffer;
#endif
float sampleLowerMip(ivec2 texel)
{
#ifdef LAYERED
return texelFetch(depthBuffer, ivec3(texel, depthLayer), 0).r;
#define sampleLowerMip(t) texelFetch(depthBuffer, ivec3(t, depthLayer), 0).r
#else
return texelFetch(depthBuffer, texel, 0).r;
#define sampleLowerMip(t) texelFetch(depthBuffer, t, 0).r
#endif
}
void minmax(inout float out_val, float in_val)
{
#ifdef MIN_PASS
out_val = min(out_val, in_val);
#define minmax(a, b) min(a, b)
#else /* MAX_PASS */
out_val = max(out_val, in_val);
#define minmax(a, b) max(a, b)
#endif
}
void main()
{
@ -40,23 +34,30 @@ void main()
float val = sampleLowerMip(texelPos);
#ifndef COPY_DEPTH
minmax(val, sampleLowerMip(texelPos + ivec2(1, 0)));
minmax(val, sampleLowerMip(texelPos + ivec2(1, 1)));
minmax(val, sampleLowerMip(texelPos + ivec2(0, 1)));
float val2 = sampleLowerMip(texelPos + ivec2(1, 0));
float val3 = sampleLowerMip(texelPos + ivec2(1, 1));
float val4 = sampleLowerMip(texelPos + ivec2(0, 1));
val = minmax(val, val2);
val = minmax(val, val3);
val = minmax(val, val4);
/* if we are reducing an odd-width texture then fetch the edge texels */
if (((mipsize.x & 1) != 0) && (int(gl_FragCoord.x) == mipsize.x-3)) {
if (((mipsize.x & 1) != 0) && (int(gl_FragCoord.x)*2 == mipsize.x-3)) {
/* if both edges are odd, fetch the top-left corner texel */
if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y) == mipsize.y-3)) {
minmax(val, sampleLowerMip(texelPos + ivec2(-1, -1)));
if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y)*2 == mipsize.y-3)) {
val = minmax(val, sampleLowerMip(texelPos + ivec2(2, 2)));
}
minmax(val, sampleLowerMip(texelPos + ivec2(0, -1)));
minmax(val, sampleLowerMip(texelPos + ivec2(1, -1)));
float val2 = sampleLowerMip(texelPos + ivec2(2, 0));
float val3 = sampleLowerMip(texelPos + ivec2(2, 1));
val = minmax(val, val2);
val = minmax(val, val3);
}
/* if we are reducing an odd-height texture then fetch the edge texels */
else if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y) == mipsize.y-3)) {
minmax(val, sampleLowerMip(texelPos + ivec2(0, -1)));
minmax(val, sampleLowerMip(texelPos + ivec2(1, -1)));
if (((mipsize.y & 1) != 0) && (int(gl_FragCoord.y)*2 == mipsize.y-3)) {
float val2 = sampleLowerMip(texelPos + ivec2(0, 2));
float val3 = sampleLowerMip(texelPos + ivec2(1, 2));
val = minmax(val, val2);
val = minmax(val, val3);
}
#endif