diff options
-rw-r--r-- | video.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -1527,7 +1527,7 @@ void Renderpass_Vk::init( ad.storeOp = VK_ATTACHMENT_STORE_OP_STORE; ad.stencilLoadOp = ad.loadOp; ad.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; - if (rpk.is_first || rp.depth.mode == Clear_Mode::clear) + if (rp.depth.mode != Clear_Mode::restore) ad.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; else ad.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; @@ -2097,6 +2097,7 @@ void Context::transition(Texture_Id id, Resource_State state) { VkImageLayout src_layout = state_to_image_layout(tex.state); VkImageLayout dst_layout = state_to_image_layout(state); VkPipelineStageFlags src_stage, dst_stage; + if (tex.state == state) return; tex.state = state; b.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; b.oldLayout = src_layout; @@ -2110,6 +2111,21 @@ void Context::transition(Texture_Id id, Resource_State state) { b.subresourceRange.baseArrayLayer = 0; b.subresourceRange.layerCount = 1; if ( + tex.fmt == texture_format_d16 || + tex.fmt == texture_format_d24s8 || + tex.fmt == texture_format_d32 + ) { + if (src_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) + src_layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + if (dst_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) + dst_layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + b.subresourceRange.aspectMask = + VK_IMAGE_ASPECT_DEPTH_BIT | + VK_IMAGE_ASPECT_STENCIL_BIT; + b.oldLayout = src_layout; + b.newLayout = dst_layout; + } + if ( src_layout == VK_IMAGE_LAYOUT_UNDEFINED && dst_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL ) { @@ -2157,6 +2173,20 @@ void Context::transition(Texture_Id id, Resource_State state) { b.dstAccessMask = 0; src_stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; dst_stage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; + } else if ( + src_layout == VK_IMAGE_LAYOUT_UNDEFINED && + dst_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL + ) { + b.srcAccessMask = 0; + b.dstAccessMask = + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; + src_stage = + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; + dst_stage = + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; } else { print_err("Bad resource transition.\n"); pbreak(389); @@ -2205,6 +2235,8 @@ std::pair<Renderpass_Vk&, Framebuffer_Vk&> Context_Vk::begin_rp( dc.depthStencil.depth = rp.depth.clear.depth; dc.depthStencil.stencil = 0; /* todo */ clears[clear_count++] = dc; + if (rp.depth.mode == Clear_Mode::restore) + transition(rp.depth.id, Resource_State::render_target); } rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; rpbi.renderPass = rpo.rpo; |