vk_rasterizer: Fix stencil clears (#1840)

This commit is contained in:
TheTurtle 2024-12-22 02:49:42 +02:00 committed by GitHub
parent 611c55bda0
commit 02998934b2
3 changed files with 14 additions and 4 deletions

View file

@ -161,10 +161,18 @@ RenderState Rasterizer::PrepareRenderState(u32 mrt_mask) {
state.depth_attachment = { state.depth_attachment = {
.imageView = *image_view.image_view, .imageView = *image_view.image_view,
.imageLayout = vk::ImageLayout::eUndefined, .imageLayout = vk::ImageLayout::eUndefined,
.loadOp = is_clear ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad, .loadOp = is_clear && regs.depth_control.depth_enable ? vk::AttachmentLoadOp::eClear
: vk::AttachmentLoadOp::eLoad,
.storeOp = vk::AttachmentStoreOp::eStore, .storeOp = vk::AttachmentStoreOp::eStore,
.clearValue = vk::ClearValue{.depthStencil = {.depth = regs.depth_clear, .clearValue = vk::ClearValue{.depthStencil = {.depth = regs.depth_clear}},
.stencil = regs.stencil_clear}}, };
state.stencil_attachment = {
.imageView = *image_view.image_view,
.imageLayout = vk::ImageLayout::eUndefined,
.loadOp = is_clear && regs.depth_control.stencil_enable ? vk::AttachmentLoadOp::eClear
: vk::AttachmentLoadOp::eLoad,
.storeOp = vk::AttachmentStoreOp::eStore,
.clearValue = vk::ClearValue{.depthStencil = {.stencil = regs.stencil_clear}},
}; };
texture_cache.TouchMeta(htile_address, slice, false); texture_cache.TouchMeta(htile_address, slice, false);
state.has_depth = state.has_depth =
@ -778,6 +786,7 @@ void Rasterizer::BeginRendering(const GraphicsPipeline& pipeline, RenderState& s
desc.view_info.range); desc.view_info.range);
} }
state.depth_attachment.imageLayout = image.last_state.layout; state.depth_attachment.imageLayout = image.last_state.layout;
state.stencil_attachment.imageLayout = image.last_state.layout;
image.usage.depth_target = true; image.usage.depth_target = true;
image.usage.stencil = has_stencil; image.usage.stencil = has_stencil;
} }

View file

@ -47,7 +47,7 @@ void Scheduler::BeginRendering(const RenderState& new_state) {
? render_state.color_attachments.data() ? render_state.color_attachments.data()
: nullptr, : nullptr,
.pDepthAttachment = render_state.has_depth ? &render_state.depth_attachment : nullptr, .pDepthAttachment = render_state.has_depth ? &render_state.depth_attachment : nullptr,
.pStencilAttachment = render_state.has_stencil ? &render_state.depth_attachment : nullptr, .pStencilAttachment = render_state.has_stencil ? &render_state.stencil_attachment : nullptr,
}; };
current_cmdbuf.beginRendering(rendering_info); current_cmdbuf.beginRendering(rendering_info);

View file

@ -21,6 +21,7 @@ class Instance;
struct RenderState { struct RenderState {
std::array<vk::RenderingAttachmentInfo, 8> color_attachments{}; std::array<vk::RenderingAttachmentInfo, 8> color_attachments{};
vk::RenderingAttachmentInfo depth_attachment{}; vk::RenderingAttachmentInfo depth_attachment{};
vk::RenderingAttachmentInfo stencil_attachment{};
u32 num_color_attachments{}; u32 num_color_attachments{};
bool has_depth{}; bool has_depth{};
bool has_stencil{}; bool has_stencil{};