v3dv: Fix stencil clear values for only stencil clears

The attachment loadOp for stencil buffers is not stored at
attachment->desc.loadOp. It is stored at attachment->desc.stencilLoadOp
so v3dv was ignoring the clear values for stencil if the depth buffer
wasn't setup with the VK_ATTACHMENT_LOAD_OP_CLEAR.

Fixes: 4d0e497a3e ("v3dv: implement support for depth testing")
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37228>
(cherry picked from commit 914b60f0dd)
This commit is contained in:
Jose Maria Casanova Crespo 2025-09-08 13:06:55 +02:00 committed by Eric Engestrom
parent e5c8ed73db
commit 88a8e4fea1
2 changed files with 17 additions and 13 deletions

View file

@ -7494,7 +7494,7 @@
"description": "v3dv: Fix stencil clear values for only stencil clears",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "4d0e497a3e69c9665b12bed87b964f35d3142f7d",
"notes": null

View file

@ -1285,20 +1285,24 @@ cmd_buffer_state_set_clear_values(struct v3dv_cmd_buffer *cmd_buffer,
const struct v3dv_render_pass_attachment *attachment =
&pass->attachments[i];
if (attachment->desc.loadOp != VK_ATTACHMENT_LOAD_OP_CLEAR)
continue;
VkImageAspectFlags aspects = vk_format_aspects(attachment->desc.format);
if (aspects & VK_IMAGE_ASPECT_COLOR_BIT) {
cmd_buffer_state_set_attachment_clear_color(cmd_buffer, i,
&values[i].color);
} else if (aspects & (VK_IMAGE_ASPECT_DEPTH_BIT |
VK_IMAGE_ASPECT_STENCIL_BIT)) {
cmd_buffer_state_set_attachment_clear_depth_stencil(
cmd_buffer, i,
aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
&values[i].depthStencil);
if (attachment->desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
cmd_buffer_state_set_attachment_clear_color(cmd_buffer, i,
&values[i].color);
}
} else {
bool clear_depth = aspects & VK_IMAGE_ASPECT_DEPTH_BIT &&
attachment->desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR;
bool clear_stencil = aspects & VK_IMAGE_ASPECT_STENCIL_BIT &&
attachment->desc.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR;
if (clear_depth || clear_stencil) {
cmd_buffer_state_set_attachment_clear_depth_stencil(
cmd_buffer, i,
clear_depth,
clear_stencil,
&values[i].depthStencil);
}
}
}
}