diff --git a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp index c27b1c8fe..d4793be9f 100644 --- a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp +++ b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp @@ -311,7 +311,6 @@ void RenderExecutor::ResolveRenderDepthTarget(CommandBuffer& buffer, RenderDepth } r.desc = MakeDepthTargetDesc(buffer, z); r.depth_clear_enable = rc.depth_clear_enable; - r.depth_load_clear_enable = r.depth_clear_enable; r.depth_clear_value = hw.GetDepthClearValue(); r.depth_test_enable = dc.z_enable; r.depth_write_enable = r.depth_test_enable && dc.z_write_enable && @@ -322,6 +321,9 @@ void RenderExecutor::ResolveRenderDepthTarget(CommandBuffer& buffer, RenderDepth r.stencil_clear_enable = has_stencil && rc.stencil_clear_enable && !z.depth_view.stencil_write_disable; + r.load_clear_aspects = {}; + if (r.depth_clear_enable) r.load_clear_aspects |= vk::ImageAspectFlagBits::eDepth; + if (r.stencil_clear_enable) r.load_clear_aspects |= vk::ImageAspectFlagBits::eStencil; r.stencil_clear_value = hw.GetStencilClearValue(); r.stencil_test_enable = has_stencil && dc.stencil_enable; if (r.stencil_test_enable) { @@ -421,9 +423,9 @@ vk::ImageAspectFlags RenderDepthInfo::AttachmentWriteAspects() const { } const auto available = ImageViewOps::DepthAspectMask(format); - vk::ImageAspectFlags writes {}; + vk::ImageAspectFlags writes = load_clear_aspects & available; if ((available & vk::ImageAspectFlagBits::eDepth) && - (depth_load_clear_enable || depth_write_enable)) { + depth_write_enable) { writes |= vk::ImageAspectFlagBits::eDepth; } if (!(available & vk::ImageAspectFlagBits::eStencil)) { @@ -461,8 +463,7 @@ vk::ImageAspectFlags RenderDepthInfo::AttachmentWriteAspects() const { (can_pass && depth_pass && state.passOp != vk::StencilOp::eKeep) || (can_pass && depth_fail && state.depthFailOp != vk::StencilOp::eKeep); }; - if (stencil_clear_enable || - (stencil_test_enable && (face_writes(stencil_front) || face_writes(stencil_back)))) { + if (stencil_test_enable && (face_writes(stencil_front) || face_writes(stencil_back))) { writes |= vk::ImageAspectFlagBits::eStencil; } return writes; diff --git a/src/graphics/host_gpu/renderer/depthRenderTarget.h b/src/graphics/host_gpu/renderer/depthRenderTarget.h index 612f8d2ba..8911e41dd 100644 --- a/src/graphics/host_gpu/renderer/depthRenderTarget.h +++ b/src/graphics/host_gpu/renderer/depthRenderTarget.h @@ -22,7 +22,7 @@ struct RenderDepthInfo { // Discovery keeps guest image information but can remap the view into a larger cache image. TextureCache::ImageDesc desc; bool depth_clear_enable = false; - bool depth_load_clear_enable = false; + vk::ImageAspectFlags load_clear_aspects; float depth_clear_value = 0.0f; bool depth_test_enable = false; // Effective draw writes; discovery applies test, target-write and clear controls. diff --git a/src/graphics/host_gpu/renderer/renderDraw.cpp b/src/graphics/host_gpu/renderer/renderDraw.cpp index b9120240a..18a8dbf4c 100644 --- a/src/graphics/host_gpu/renderer/renderDraw.cpp +++ b/src/graphics/host_gpu/renderer/renderDraw.cpp @@ -514,7 +514,11 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo const bool meta_clear = metadata.kind == ImageMetadataKind::Htile && cache.IsMetaCleared(metadata.range.address, depth.desc.view_info.base_layer); - depth.depth_load_clear_enable = depth.depth_clear_enable || meta_clear; + depth.load_clear_aspects = {}; + if (depth.depth_clear_enable || meta_clear) + depth.load_clear_aspects |= vk::ImageAspectFlagBits::eDepth; + if (depth.stencil_clear_enable) + depth.load_clear_aspects |= vk::ImageAspectFlagBits::eStencil; if (meta_clear && !cache.TouchMeta(metadata.range.address, depth.desc.view_info.base_layer, false)) { EXIT("failed to consume HTile clear state\n"); @@ -567,9 +571,11 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo attachment.clear_value[0] = std::bit_cast(depth.depth_clear_value); attachment.clear_value[1] = depth.stencil_clear_value; attachment.has_depth = static_cast(aspects & vk::ImageAspectFlagBits::eDepth); - attachment.depth_clear = depth.depth_load_clear_enable; + attachment.depth_clear = + static_cast(depth.load_clear_aspects & vk::ImageAspectFlagBits::eDepth); attachment.has_stencil = static_cast(aspects & vk::ImageAspectFlagBits::eStencil); - attachment.stencil_clear = depth.stencil_clear_enable; + attachment.stencil_clear = + static_cast(depth.load_clear_aspects & vk::ImageAspectFlagBits::eStencil); } if (color_count == 0 && !depth.image_id) { const auto& limits = buffer.GetGraphics().GetPhysicalDeviceProperties().limits; @@ -1060,7 +1066,7 @@ bool RenderExecutor::CopyDepthToColor(CommandBuffer& buffer, const DrawCallInfo& state.ps_input_info.ps_sample_mask_export_enable); vk::ImageAspectFlags feedback; const auto rendering = AcquireRenderTargets(buffer, &color, 1, depth, feedback); - if (depth.depth_load_clear_enable) { + if (depth.load_clear_aspects) { m_context.GetCommandScheduler().BeginRendering(rendering); } auto& cache = m_context.GetTextureCache(); diff --git a/tests/ShaderRecompilerComputeTests.cpp b/tests/ShaderRecompilerComputeTests.cpp index c42b29bc1..e305e38b1 100644 --- a/tests/ShaderRecompilerComputeTests.cpp +++ b/tests/ShaderRecompilerComputeTests.cpp @@ -14672,7 +14672,7 @@ public: phased_rendering.num_color_attachments == 0 && phased_rendering.depth_stencil_attachment.has_depth && phased_rendering.depth_stencil_attachment.depth_clear && - phased_depth.depth_load_clear_enable && + static_cast(phased_depth.load_clear_aspects & vk::ImageAspectFlagBits::eDepth) && texture_cache.IsMeta(phased_depth.desc.info.metadata.range.address) && !texture_cache.IsMetaCleared( phased_depth.desc.info.metadata.range.address, @@ -14853,7 +14853,7 @@ public: bounds_depth.image_id == depth_only.image_id && bounds_depth.depth_bounds_test_enable && !bounds_depth.depth_write_enable && - bounds_depth.depth_load_clear_enable == (pass == 0) && + static_cast(bounds_depth.load_clear_aspects & vk::ImageAspectFlagBits::eDepth) == (pass == 0) && !texture_cache.IsMetaCleared(depth_only_htile_address, 0) && bounds_feedback == (pass == 0 ? vk::ImageAspectFlagBits::eDepth @@ -14932,7 +14932,7 @@ public: executor, scheduler.Current(), &no_color, 0, acquired_high_slice); Require(name, "high HTile slice clear consumption", acquired_high_slice.image_id == high_slice.image_id && - acquired_high_slice.depth_load_clear_enable == (pass == 0) && + static_cast(acquired_high_slice.load_clear_aspects & vk::ImageAspectFlagBits::eDepth) == (pass == 0) && rendering.depth_stencil_attachment.depth_clear == (pass == 0) && !texture_cache.IsMetaCleared(high_slice_target.htile_data_base_addr, 86) && texture_cache.IsMetaCleared(high_slice_target.htile_data_base_addr, 85), @@ -45703,12 +45703,12 @@ void CheckDepthAttachmentWrites() { target.depth_test_enable = false; target.depth_write_enable = false; - target.depth_load_clear_enable = true; + target.load_clear_aspects = vk::ImageAspectFlagBits::eDepth; Require("DepthAttachmentWrites", "depth clear", target.AttachmentWriteAspects() == vk::ImageAspectFlagBits::eDepth, "depth attachment clear did not claim depth"); - target.depth_load_clear_enable = false; + target.load_clear_aspects = {}; target.stencil_test_enable = true; target.stencil_front = {vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways, 0xff, 0xff, 0}; @@ -45734,7 +45734,7 @@ void CheckDepthAttachmentWrites() { "masked front write or KEEP-only back face claimed stencil"); target.stencil_test_enable = false; - target.stencil_clear_enable = true; + target.load_clear_aspects = vk::ImageAspectFlagBits::eStencil; Require("DepthAttachmentWrites", "stencil clear", target.AttachmentWriteAspects() == vk::ImageAspectFlagBits::eStencil, "stencil attachment clear did not claim stencil"); @@ -45808,12 +45808,11 @@ void CheckDepthFeedbackAspects() { feedback(sampled) == vk::ImageAspectFlagBits::eDepth, "overlapping mip and layer boundaries missed depth feedback"); target.depth_write_enable = false; - target.depth_load_clear_enable = true; + target.load_clear_aspects = vk::ImageAspectFlagBits::eDepth; Require("DepthFeedbackAspects", "depth clear only", feedback(sampled) == vk::ImageAspectFlagBits::eDepth, "a sampled depth attachment clear missed feedback"); - target.depth_load_clear_enable = false; - target.stencil_clear_enable = true; + target.load_clear_aspects = vk::ImageAspectFlagBits::eStencil; sampled.aspect = vk::ImageAspectFlagBits::eStencil; Require("DepthFeedbackAspects", "stencil clear only", feedback(sampled) == vk::ImageAspectFlagBits::eStencil, @@ -45867,7 +45866,7 @@ void CheckDynamicRenderingState() { depth_attachment_layout(attachment) == vk::ImageLayout::eDepthStencilReadOnlyOptimal, "fully read-only depth/stencil used a writable layout"); - attachment.depth_load_clear_enable = true; + attachment.load_clear_aspects = vk::ImageAspectFlagBits::eDepth; Require("DynamicRenderingState", "deferred depth clear layout", depth_attachment_layout(attachment) == vk::ImageLayout::eDepthAttachmentStencilReadOnlyOptimal, @@ -45878,9 +45877,9 @@ void CheckDynamicRenderingState() { depth_attachment_layout(attachment) == vk::ImageLayout::eDepthAttachmentStencilReadOnlyOptimal, "depth-only writes did not retain read-only stencil"); - attachment.depth_load_clear_enable = false; + attachment.load_clear_aspects = {}; attachment.depth_write_enable = false; - attachment.stencil_clear_enable = true; + attachment.load_clear_aspects = vk::ImageAspectFlagBits::eStencil; Require("DynamicRenderingState", "depth-read stencil-write layout", depth_attachment_layout(attachment) == vk::ImageLayout::eDepthReadOnlyStencilAttachmentOptimal,