From 9e7a576ceed473dea031262f9d19489b9e841cbf Mon Sep 17 00:00:00 2001 From: Miguel Pozo Date: Fri, 13 Oct 2023 19:18:46 +0200 Subject: [PATCH] Workbench: Fix: depth_in_front not being copied after the first sample --- .../workbench/workbench_effect_antialiasing.cc | 14 +++++++++----- .../draw/engines/workbench/workbench_engine.cc | 4 ++-- .../draw/engines/workbench/workbench_private.hh | 12 ++++++++---- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc index f21e2cbd3cc..c8e01c58261 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc +++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc @@ -166,8 +166,6 @@ void AntiAliasingPass::sync(const SceneState &scene_state, SceneResources &resou sample0_depth_tx_.ensure_2d(GPU_DEPTH24_STENCIL8, scene_state.resolution, GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT); - sample0_depth_in_front_tx_.ensure_2d( - GPU_DEPTH24_STENCIL8, scene_state.resolution, GPU_TEXTURE_USAGE_ATTACHMENT); taa_accumulation_ps_.init(); taa_accumulation_ps_.state_set(scene_state.sample == 0 ? @@ -257,7 +255,8 @@ void AntiAliasingPass::setup_view(View &view, const SceneState &scene_state) void AntiAliasingPass::draw(Manager &manager, View &view, const SceneState &scene_state, - SceneResources &resources) + SceneResources &resources, + GPUTexture *depth_in_front_tx) { if (resources.depth_in_front_tx.is_valid() && scene_state.sample == 0 && scene_state.overlays_enabled) @@ -278,14 +277,19 @@ void AntiAliasingPass::draw(Manager &manager, if (scene_state.sample == 0) { GPU_texture_copy(sample0_depth_tx_, resources.depth_tx); if (resources.depth_in_front_tx.is_valid()) { + sample0_depth_in_front_tx_.ensure_2d( + GPU_DEPTH24_STENCIL8, scene_state.resolution, GPU_TEXTURE_USAGE_ATTACHMENT); GPU_texture_copy(sample0_depth_in_front_tx_, resources.depth_in_front_tx); } + else { + sample0_depth_in_front_tx_.free(); + } } else if (!DRW_state_is_scene_render() || last_sample) { /* Copy back the saved depth buffer for correct overlays. */ GPU_texture_copy(resources.depth_tx, sample0_depth_tx_); - if (resources.depth_in_front_tx.is_valid()) { - GPU_texture_copy(resources.depth_in_front_tx, sample0_depth_in_front_tx_); + if (sample0_depth_in_front_tx_.is_valid()) { + GPU_texture_copy(depth_in_front_tx, sample0_depth_in_front_tx_); } } } diff --git a/source/blender/draw/engines/workbench/workbench_engine.cc b/source/blender/draw/engines/workbench/workbench_engine.cc index 416941269c0..667a381d2f5 100644 --- a/source/blender/draw/engines/workbench/workbench_engine.cc +++ b/source/blender/draw/engines/workbench/workbench_engine.cc @@ -446,7 +446,7 @@ class Instance { if (scene_state.render_finished) { /* Just copy back the already rendered result */ - anti_aliasing_ps.draw(manager, view, scene_state, resources); + anti_aliasing_ps.draw(manager, view, scene_state, resources, depth_in_front_tx); return; } @@ -476,7 +476,7 @@ class Instance { volume_ps.draw(manager, view, resources); outline_ps.draw(manager, resources); dof_ps.draw(manager, view, resources, resolution); - anti_aliasing_ps.draw(manager, view, scene_state, resources); + anti_aliasing_ps.draw(manager, view, scene_state, resources, depth_in_front_tx); resources.object_id_tx.release(); } diff --git a/source/blender/draw/engines/workbench/workbench_private.hh b/source/blender/draw/engines/workbench/workbench_private.hh index eead3b2049b..eadaac8d85f 100644 --- a/source/blender/draw/engines/workbench/workbench_private.hh +++ b/source/blender/draw/engines/workbench/workbench_private.hh @@ -563,10 +563,14 @@ class AntiAliasingPass { void init(const SceneState &scene_state); void sync(const SceneState &scene_state, SceneResources &resources); void setup_view(View &view, const SceneState &scene_state); - void draw(Manager &manager, - View &view, - const SceneState &scene_state, - SceneResources &resources); + void draw( + Manager &manager, + View &view, + const SceneState &scene_state, + SceneResources &resources, + /** Passed directly since we may need to copy back the results from the first sample, + * and resources.depth_in_front_tx is only valid when mesh passes have to draw to it. */ + GPUTexture *depth_in_front_tx); }; } // namespace blender::workbench