From 6540e09684e6a0584523b25d93312dc20b234a63 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 26 Mar 2024 18:27:03 +0100 Subject: [PATCH] Make use of STORE_OP_NONE when appropriate. --- renderer/render_graph.cpp | 2 +- vulkan/render_pass.cpp | 10 ++++++++++ vulkan/render_pass.hpp | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/renderer/render_graph.cpp b/renderer/render_graph.cpp index 0f923209..288b0bce 100644 --- a/renderer/render_graph.cpp +++ b/renderer/render_graph.cpp @@ -1214,7 +1214,7 @@ void RenderGraph::build_render_pass_info() if (preserve_depth) { // Have to store here, or the attachment becomes undefined in future passes. - rp.op_flags |= Vulkan::RENDER_PASS_OP_STORE_DEPTH_STENCIL_BIT; + rp.op_flags |= Vulkan::RENDER_PASS_OP_PRESERVE_DEPTH_STENCIL_BIT; } } diff --git a/vulkan/render_pass.cpp b/vulkan/render_pass.cpp index e31c2e4a..52764156 100644 --- a/vulkan/render_pass.cpp +++ b/vulkan/render_pass.cpp @@ -177,7 +177,17 @@ RenderPass::RenderPass(Hash hash, Device *device_, const RenderPassInfo &info) ds_load_op = VK_ATTACHMENT_LOAD_OP_LOAD; if (info.op_flags & RENDER_PASS_OP_STORE_DEPTH_STENCIL_BIT) + { ds_store_op = VK_ATTACHMENT_STORE_OP_STORE; + } + else if (info.op_flags & RENDER_PASS_OP_PRESERVE_DEPTH_STENCIL_BIT) + { + ds_store_op = device->get_device_features().device_api_core_version >= VK_API_VERSION_1_3 ? + VK_ATTACHMENT_STORE_OP_NONE : VK_ATTACHMENT_STORE_OP_STORE; + + if (ds_load_op != VK_ATTACHMENT_LOAD_OP_LOAD) + ds_store_op = VK_ATTACHMENT_STORE_OP_STORE; + } bool ds_read_only = (info.op_flags & RENDER_PASS_OP_DEPTH_STENCIL_READ_ONLY_BIT) != 0; VkImageLayout depth_stencil_layout = VK_IMAGE_LAYOUT_UNDEFINED; diff --git a/vulkan/render_pass.hpp b/vulkan/render_pass.hpp index 16728035..d463bfe2 100644 --- a/vulkan/render_pass.hpp +++ b/vulkan/render_pass.hpp @@ -40,7 +40,8 @@ enum RenderPassOp RENDER_PASS_OP_STORE_DEPTH_STENCIL_BIT = 1 << 2, RENDER_PASS_OP_DEPTH_STENCIL_READ_ONLY_BIT = 1 << 3, RENDER_PASS_OP_ENABLE_TRANSIENT_STORE_BIT = 1 << 4, - RENDER_PASS_OP_ENABLE_TRANSIENT_LOAD_BIT = 1 << 5 + RENDER_PASS_OP_ENABLE_TRANSIENT_LOAD_BIT = 1 << 5, + RENDER_PASS_OP_PRESERVE_DEPTH_STENCIL_BIT = 1 << 6 }; using RenderPassOpFlags = uint32_t;