DRW: Add option to only resolve framebuffer colors without depth test
This commit is contained in:
@@ -120,7 +120,16 @@ typedef char DRWViewportEmptyList;
|
||||
if (dfbl->multisample_fb != NULL) { \
|
||||
DRW_stats_query_start("Multisample Resolve"); \
|
||||
GPU_framebuffer_bind(dfbl->default_fb); \
|
||||
DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color); \
|
||||
DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color, true); \
|
||||
DRW_stats_query_end(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define MULTISAMPLE_SYNC_DISABLE_NO_DEPTH(dfbl, dtxl) { \
|
||||
if (dfbl->multisample_fb != NULL) { \
|
||||
DRW_stats_query_start("Multisample Resolve"); \
|
||||
GPU_framebuffer_bind(dfbl->default_fb); \
|
||||
DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color, false); \
|
||||
DRW_stats_query_end(); \
|
||||
} \
|
||||
}
|
||||
@@ -228,7 +237,7 @@ void DRW_uniformbuffer_free(struct GPUUniformBuffer *ubo);
|
||||
void DRW_transform_to_display(struct GPUTexture *tex);
|
||||
void DRW_transform_none(struct GPUTexture *tex);
|
||||
void DRW_multisamples_resolve(
|
||||
struct GPUTexture *src_depth, struct GPUTexture *src_color);
|
||||
struct GPUTexture *src_depth, struct GPUTexture *src_color, bool use_depth);
|
||||
|
||||
/* Shaders */
|
||||
struct GPUShader *DRW_shader_create(
|
||||
|
||||
@@ -317,10 +317,14 @@ void DRW_transform_none(GPUTexture *tex)
|
||||
/* Use manual multisample resolve pass.
|
||||
* Much quicker than blitting back and forth.
|
||||
* Assume destination fb is bound*/
|
||||
void DRW_multisamples_resolve(GPUTexture *src_depth, GPUTexture *src_color)
|
||||
void DRW_multisamples_resolve(GPUTexture *src_depth, GPUTexture *src_color, bool use_depth)
|
||||
{
|
||||
drw_state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_PREMUL |
|
||||
DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL);
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_PREMUL;
|
||||
|
||||
if (use_depth) {
|
||||
state |= DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
|
||||
}
|
||||
drw_state_set(state);
|
||||
|
||||
int samples = GPU_texture_samples(src_depth);
|
||||
|
||||
@@ -330,22 +334,39 @@ void DRW_multisamples_resolve(GPUTexture *src_depth, GPUTexture *src_color)
|
||||
GPUBatch *geom = DRW_cache_fullscreen_quad_get();
|
||||
|
||||
int builtin;
|
||||
switch (samples) {
|
||||
case 2: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2; break;
|
||||
case 4: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_4; break;
|
||||
case 8: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_8; break;
|
||||
case 16: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_16; break;
|
||||
default:
|
||||
BLI_assert(0);
|
||||
builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2;
|
||||
break;
|
||||
if (use_depth) {
|
||||
switch (samples) {
|
||||
case 2: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2_DEPTH_TEST; break;
|
||||
case 4: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_4_DEPTH_TEST; break;
|
||||
case 8: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_8_DEPTH_TEST; break;
|
||||
case 16: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_16_DEPTH_TEST; break;
|
||||
default:
|
||||
BLI_assert("Mulisample count unsupported by blit shader.");
|
||||
builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2_DEPTH_TEST;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (samples) {
|
||||
case 2: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2; break;
|
||||
case 4: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_4; break;
|
||||
case 8: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_8; break;
|
||||
case 16: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_16; break;
|
||||
default:
|
||||
BLI_assert("Mulisample count unsupported by blit shader.");
|
||||
builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GPU_batch_program_set_builtin(geom, builtin);
|
||||
|
||||
GPU_texture_bind(src_depth, 0);
|
||||
if (use_depth) {
|
||||
GPU_texture_bind(src_depth, 0);
|
||||
GPU_batch_uniform_1i(geom, "depthMulti", 0);
|
||||
}
|
||||
|
||||
GPU_texture_bind(src_color, 1);
|
||||
GPU_batch_uniform_1i(geom, "depthMulti", 0);
|
||||
GPU_batch_uniform_1i(geom, "colorMulti", 1);
|
||||
|
||||
float mat[4][4];
|
||||
|
||||
@@ -158,6 +158,10 @@ typedef enum GPUBuiltinShader {
|
||||
GPU_SHADER_2D_IMAGE_MULTISAMPLE_4,
|
||||
GPU_SHADER_2D_IMAGE_MULTISAMPLE_8,
|
||||
GPU_SHADER_2D_IMAGE_MULTISAMPLE_16,
|
||||
GPU_SHADER_2D_IMAGE_MULTISAMPLE_2_DEPTH_TEST,
|
||||
GPU_SHADER_2D_IMAGE_MULTISAMPLE_4_DEPTH_TEST,
|
||||
GPU_SHADER_2D_IMAGE_MULTISAMPLE_8_DEPTH_TEST,
|
||||
GPU_SHADER_2D_IMAGE_MULTISAMPLE_16_DEPTH_TEST,
|
||||
GPU_SHADER_2D_CHECKER,
|
||||
GPU_SHADER_2D_DIAG_STRIPES,
|
||||
/* for simple 3D drawing */
|
||||
|
||||
@@ -738,6 +738,10 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
||||
[GPU_SHADER_2D_IMAGE_MULTISAMPLE_4] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_MULTISAMPLE_8] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_MULTISAMPLE_16] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_MULTISAMPLE_2_DEPTH_TEST] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_MULTISAMPLE_4_DEPTH_TEST] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_MULTISAMPLE_8_DEPTH_TEST] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_MULTISAMPLE_16_DEPTH_TEST] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
|
||||
|
||||
[GPU_SHADER_2D_IMAGE_INTERLACE] = { datatoc_gpu_shader_2D_image_vert_glsl,
|
||||
datatoc_gpu_shader_image_interlace_frag_glsl },
|
||||
@@ -873,15 +877,31 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_2:
|
||||
defines = "#define SAMPLES 2\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_2_DEPTH_TEST:
|
||||
defines = "#define SAMPLES 2\n"
|
||||
"#define USE_DEPTH\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_4:
|
||||
defines = "#define SAMPLES 4\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_4_DEPTH_TEST:
|
||||
defines = "#define SAMPLES 4\n"
|
||||
"#define USE_DEPTH\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_8:
|
||||
defines = "#define SAMPLES 8\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_8_DEPTH_TEST:
|
||||
defines = "#define SAMPLES 8\n"
|
||||
"#define USE_DEPTH\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_16:
|
||||
defines = "#define SAMPLES 16\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_IMAGE_MULTISAMPLE_16_DEPTH_TEST:
|
||||
defines = "#define SAMPLES 16\n"
|
||||
"#define USE_DEPTH\n";
|
||||
break;
|
||||
case GPU_SHADER_2D_WIDGET_BASE_INST:
|
||||
case GPU_SHADER_2D_NODELINK_INST:
|
||||
defines = "#define USE_INSTANCE\n";
|
||||
|
||||
@@ -8,8 +8,6 @@ out vec4 fragColor;
|
||||
#error "Too many samples"
|
||||
#endif
|
||||
|
||||
// #define USE_DEPTH_WEIGHTING
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 texel = ivec2(gl_FragCoord.xy);
|
||||
@@ -19,26 +17,26 @@ void main()
|
||||
vec4 d1, d2, d3, d4;
|
||||
vec4 c1, c2, c3, c4, c5, c6, c7, c8;
|
||||
vec4 c9, c10, c11, c12, c13, c14, c15, c16;
|
||||
d1 = d2 = d3 = d4 = vec4(1.0);
|
||||
d1 = d2 = d3 = d4 = vec4(0.5);
|
||||
w1 = w2 = w3 = w4 = vec4(0.0);
|
||||
c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = vec4(0.0);
|
||||
c9 = c10 = c11 = c12 = c13 = c14 = c15 = c16 = vec4(0.0);
|
||||
|
||||
#ifdef USE_DEPTH
|
||||
/* Depth */
|
||||
|
||||
d1.x = texelFetch(depthMulti, texel, 0).r;
|
||||
d1.y = texelFetch(depthMulti, texel, 1).r;
|
||||
#if SAMPLES > 2
|
||||
# if SAMPLES > 2
|
||||
d1.z = texelFetch(depthMulti, texel, 2).r;
|
||||
d1.w = texelFetch(depthMulti, texel, 3).r;
|
||||
#endif
|
||||
#if SAMPLES > 4
|
||||
# endif
|
||||
# if SAMPLES > 4
|
||||
d2.x = texelFetch(depthMulti, texel, 4).r;
|
||||
d2.y = texelFetch(depthMulti, texel, 5).r;
|
||||
d2.z = texelFetch(depthMulti, texel, 6).r;
|
||||
d2.w = texelFetch(depthMulti, texel, 7).r;
|
||||
#endif
|
||||
#if SAMPLES > 8
|
||||
# endif
|
||||
# if SAMPLES > 8
|
||||
d3.x = texelFetch(depthMulti, texel, 8).r;
|
||||
d3.y = texelFetch(depthMulti, texel, 9).r;
|
||||
d3.z = texelFetch(depthMulti, texel, 10).r;
|
||||
@@ -47,6 +45,7 @@ void main()
|
||||
d4.y = texelFetch(depthMulti, texel, 13).r;
|
||||
d4.z = texelFetch(depthMulti, texel, 14).r;
|
||||
d4.w = texelFetch(depthMulti, texel, 15).r;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* COLOR */
|
||||
@@ -89,22 +88,26 @@ void main()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SAMPLES > 8
|
||||
d1 = min(d1, min(d3, d4));
|
||||
#endif
|
||||
#if SAMPLES > 4
|
||||
d1 = min(d1, d2);
|
||||
#endif
|
||||
#if SAMPLES > 2
|
||||
d1.xy = min(d1.xy, d1.zw);
|
||||
#endif
|
||||
gl_FragDepth = min(d1.x, d1.y);
|
||||
|
||||
#ifdef USE_DEPTH_WEIGHTING
|
||||
c1 *= w1.x; c2 *= w1.y; c3 *= w1.z; c4 *= w1.w;
|
||||
c5 *= w2.x; c6 *= w2.y; c7 *= w2.z; c8 *= w2.w;
|
||||
c9 *= w3.x; c10 *= w3.y; c11 *= w3.z; c12 *= w3.w;
|
||||
c13 *= w4.x; c14 *= w4.y; c15 *= w4.z; c16 *= w4.w;
|
||||
#ifdef USE_DEPTH
|
||||
d1 *= 1.0 - step(1.0, d1); /* make far plane depth = 0 */
|
||||
# if SAMPLES > 8
|
||||
d4 *= 1.0 - step(1.0, d4);
|
||||
d3 *= 1.0 - step(1.0, d3);
|
||||
d1 = max(d1, max(d3, d4));
|
||||
# endif
|
||||
# if SAMPLES > 4
|
||||
d2 *= 1.0 - step(1.0, d2);
|
||||
d1 = max(d1, d2);
|
||||
d1 = max(d1, d2);
|
||||
# endif
|
||||
# if SAMPLES > 2
|
||||
d1.xy = max(d1.xy, d1.zw);
|
||||
# endif
|
||||
gl_FragDepth = max(d1.x, d1.y);
|
||||
/* Don't let the 0.0 farplane occlude other things */
|
||||
if (gl_FragDepth == 0.0) {
|
||||
gl_FragDepth = 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
c1 = c1 + c2;
|
||||
|
||||
Reference in New Issue
Block a user