From a5cce9528072ed4ca60c6191471eca9bbe2e08cc Mon Sep 17 00:00:00 2001 From: Jonathan Marek Date: Thu, 9 Apr 2020 19:17:54 -0400 Subject: [PATCH] turnip: enable VK_FORMAT_S8_UINT as stencil format Signed-off-by: Jonathan Marek Part-of: --- src/freedreno/vulkan/tu_clear_blit.c | 29 ++++++++++++++-------------- src/freedreno/vulkan/tu_cmd_buffer.c | 19 ++++++++++++------ src/freedreno/vulkan/tu_formats.c | 1 + src/freedreno/vulkan/tu_image.c | 4 ++++ 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/freedreno/vulkan/tu_clear_blit.c b/src/freedreno/vulkan/tu_clear_blit.c index 621449285d6..550c6617463 100644 --- a/src/freedreno/vulkan/tu_clear_blit.c +++ b/src/freedreno/vulkan/tu_clear_blit.c @@ -1777,8 +1777,6 @@ tu_clear_sysmem_attachments_2d(struct tu_cmd_buffer *cmd, for (uint32_t j = 0; j < attachment_count; j++) { uint32_t a; - uint8_t mask = 0xf; - if (attachments[j].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { a = subpass->color_attachments[attachments[j].colorAttachment].attachment; } else { @@ -1789,17 +1787,19 @@ tu_clear_sysmem_attachments_2d(struct tu_cmd_buffer *cmd, /* also flush color to avoid losing contents from invalidate */ tu6_emit_event_write(cmd, cs, PC_CCU_FLUSH_COLOR_TS, true); tu6_emit_event_write(cmd, cs, PC_CCU_INVALIDATE_COLOR, false); + } + if (a == VK_ATTACHMENT_UNUSED) + continue; + uint8_t mask = 0xf; + if (cmd->state.pass->attachments[a].format == VK_FORMAT_D24_UNORM_S8_UINT) { if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT)) mask &= ~0x7; if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) mask &= ~0x8; } - if (a == VK_ATTACHMENT_UNUSED) - continue; - const struct tu_image_view *iview = cmd->state.framebuffer->attachments[a].attachment; @@ -2071,21 +2071,22 @@ tu_clear_gmem_attachments(struct tu_cmd_buffer *cmd, for (unsigned j = 0; j < attachment_count; j++) { uint32_t a; - unsigned clear_mask = 0; - if (attachments[j].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { - clear_mask = 0xf; + if (attachments[j].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) a = subpass->color_attachments[attachments[j].colorAttachment].attachment; - } else { + else a = subpass->depth_stencil_attachment.attachment; - if (attachments[j].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) - clear_mask |= 0x7; - if (attachments[j].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) - clear_mask |= 0x8; - } if (a == VK_ATTACHMENT_UNUSED) continue; + unsigned clear_mask = 0xf; + if (cmd->state.pass->attachments[a].format == VK_FORMAT_D24_UNORM_S8_UINT) { + if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT)) + clear_mask &= ~0x7; + if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) + clear_mask &= ~0x8; + } + tu_emit_clear_gmem_attachment(cmd, cs, a, clear_mask, &attachments[j].clearValue); } diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index b6ca849c80c..6cf74b3f0c4 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -387,12 +387,14 @@ tu6_emit_zs(struct tu_cmd_buffer *cmd, } const struct tu_image_view *iview = fb->attachments[a].attachment; - enum a6xx_depth_format fmt = tu6_pipe2depth(cmd->state.pass->attachments[a].format); + const struct tu_render_pass_attachment *attachment = + &cmd->state.pass->attachments[a]; + enum a6xx_depth_format fmt = tu6_pipe2depth(attachment->format); tu_cs_emit_pkt4(cs, REG_A6XX_RB_DEPTH_BUFFER_INFO, 6); tu_cs_emit(cs, A6XX_RB_DEPTH_BUFFER_INFO(.depth_format = fmt).value); tu_cs_image_ref(cs, iview, 0); - tu_cs_emit(cs, cmd->state.pass->attachments[a].gmem_offset); + tu_cs_emit(cs, attachment->gmem_offset); tu_cs_emit_regs(cs, A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format = fmt)); @@ -405,10 +407,15 @@ tu6_emit_zs(struct tu_cmd_buffer *cmd, A6XX_GRAS_LRZ_BUFFER_PITCH(0), A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE(0)); - tu_cs_emit_regs(cs, - A6XX_RB_STENCIL_INFO(0)); - - /* enable zs? */ + if (attachment->format == VK_FORMAT_S8_UINT) { + tu_cs_emit_pkt4(cs, REG_A6XX_RB_STENCIL_INFO, 6); + tu_cs_emit(cs, A6XX_RB_STENCIL_INFO(.separate_stencil = true).value); + tu_cs_image_ref(cs, iview, 0); + tu_cs_emit(cs, attachment->gmem_offset); + } else { + tu_cs_emit_regs(cs, + A6XX_RB_STENCIL_INFO(0)); + } } static void diff --git a/src/freedreno/vulkan/tu_formats.c b/src/freedreno/vulkan/tu_formats.c index 528a4176f4a..d4100760032 100644 --- a/src/freedreno/vulkan/tu_formats.c +++ b/src/freedreno/vulkan/tu_formats.c @@ -354,6 +354,7 @@ tu6_pipe2depth(VkFormat format) case VK_FORMAT_D24_UNORM_S8_UINT: return DEPTH6_24_8; case VK_FORMAT_D32_SFLOAT: + case VK_FORMAT_S8_UINT: return DEPTH6_32; default: return ~0; diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c index f53566774a3..d6abef74063 100644 --- a/src/freedreno/vulkan/tu_image.c +++ b/src/freedreno/vulkan/tu_image.c @@ -100,6 +100,10 @@ tu_image_create(VkDevice _device, if (image->vk_format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) ubwc_enabled = false; + /* separate stencil doesn't have a UBWC enable bit */ + if (image->vk_format == VK_FORMAT_S8_UINT) + ubwc_enabled = false; + if (image->extent.depth > 1) { tu_finishme("UBWC with 3D textures"); ubwc_enabled = false; -- 2.30.2