From 1a2f23439b4d2a83b5e823d26eadbaf6d6032c54 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Wed, 6 Mar 2024 17:49:57 -0600 Subject: [PATCH] nvk: Use row_stride_B instead of width for render and copies Part-of: --- src/nouveau/nil/nil_image.h | 6 +++++- src/nouveau/vulkan/nvk_cmd_copy.c | 14 ++++++++++++-- src/nouveau/vulkan/nvk_cmd_draw.c | 20 +++++++++++++++++--- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/nouveau/nil/nil_image.h b/src/nouveau/nil/nil_image.h index 9e6d0572def..431f549f4ac 100644 --- a/src/nouveau/nil/nil_image.h +++ b/src/nouveau/nil/nil_image.h @@ -129,7 +129,11 @@ struct nil_image_level { /** Tiling for this level */ struct nil_tiling tiling; - /** Stride between rows in bytes */ + /** Stride between rows in bytes + * + * For linear images, this is the obvious stride. For tiled images, it's + * the width of the mip level rounded up to the tile size. + */ uint32_t row_stride_B; }; diff --git a/src/nouveau/vulkan/nvk_cmd_copy.c b/src/nouveau/vulkan/nvk_cmd_copy.c index 21b4835c898..d42f375e162 100644 --- a/src/nouveau/vulkan/nvk_cmd_copy.c +++ b/src/nouveau/vulkan/nvk_cmd_copy.c @@ -232,7 +232,12 @@ nouveau_copy_rect(struct nvk_cmd_buffer *cmd, struct nouveau_copy *copy) GOB_HEIGHT_GOB_HEIGHT_FERMI_8 : GOB_HEIGHT_GOB_HEIGHT_TESLA_4, }); - P_NV90B5_SET_SRC_WIDTH(p, copy->src.extent_el.width * src_bw); + /* We use the stride for copies because the copy hardware has no + * concept of a tile width. Instead, we just set the width to the + * stride divided by bpp. + */ + uint32_t src_stride_el = copy->src.row_stride / copy->src.bpp; + P_NV90B5_SET_SRC_WIDTH(p, src_stride_el * src_bw); P_NV90B5_SET_SRC_HEIGHT(p, copy->src.extent_el.height); P_NV90B5_SET_SRC_DEPTH(p, copy->src.extent_el.depth); if (copy->src.image_type == VK_IMAGE_TYPE_3D) @@ -268,7 +273,12 @@ nouveau_copy_rect(struct nvk_cmd_buffer *cmd, struct nouveau_copy *copy) GOB_HEIGHT_GOB_HEIGHT_FERMI_8 : GOB_HEIGHT_GOB_HEIGHT_TESLA_4, }); - P_NV90B5_SET_DST_WIDTH(p, copy->dst.extent_el.width * dst_bw); + /* We use the stride for copies because the copy hardware has no + * concept of a tile width. Instead, we just set the width to the + * stride divided by bpp. + */ + uint32_t dst_stride_el = copy->dst.row_stride / copy->dst.bpp; + P_NV90B5_SET_DST_WIDTH(p, dst_stride_el * dst_bw); P_NV90B5_SET_DST_HEIGHT(p, copy->dst.extent_el.height); P_NV90B5_SET_DST_DEPTH(p, copy->dst.extent_el.depth); if (copy->dst.image_type == VK_IMAGE_TYPE_3D) diff --git a/src/nouveau/vulkan/nvk_cmd_draw.c b/src/nouveau/vulkan/nvk_cmd_draw.c index db56f972b14..8932ba84f18 100644 --- a/src/nouveau/vulkan/nvk_cmd_draw.c +++ b/src/nouveau/vulkan/nvk_cmd_draw.c @@ -639,10 +639,17 @@ nvk_CmdBeginRendering(VkCommandBuffer commandBuffer, P_NV9097_SET_COLOR_TARGET_B(p, i, addr); if (level->tiling.is_tiled) { - P_NV9097_SET_COLOR_TARGET_WIDTH(p, i, level_extent_sa.w); - P_NV9097_SET_COLOR_TARGET_HEIGHT(p, i, level_extent_sa.h); const enum pipe_format p_format = vk_format_to_pipe_format(iview->vk.format); + + /* We use the stride for depth/stencil targets because the Z/S + * hardware has no concept of a tile width. Instead, we just set + * the width to the stride divided by bpp. + */ + const uint32_t row_stride_el = + level->row_stride_B / util_format_get_blocksize(p_format); + P_NV9097_SET_COLOR_TARGET_WIDTH(p, i, row_stride_el); + P_NV9097_SET_COLOR_TARGET_HEIGHT(p, i, level_extent_sa.h); const uint8_t ct_format = nil_format_to_color_target(p_format); P_NV9097_SET_COLOR_TARGET_FORMAT(p, i, ct_format); @@ -773,8 +780,15 @@ nvk_CmdBeginRendering(VkCommandBuffer commandBuffer, struct nil_extent4d level_extent_sa = nil_image_level_extent_sa(&nil_image, mip_level); + /* We use the stride for depth/stencil targets because the Z/S hardware + * has no concept of a tile width. Instead, we just set the width to + * the stride divided by bpp. + */ + const uint32_t row_stride_el = + level->row_stride_B / util_format_get_blocksize(p_format); + P_MTHD(p, NV9097, SET_ZT_SIZE_A); - P_NV9097_SET_ZT_SIZE_A(p, level_extent_sa.w); + P_NV9097_SET_ZT_SIZE_A(p, row_stride_el); P_NV9097_SET_ZT_SIZE_B(p, level_extent_sa.h); P_NV9097_SET_ZT_SIZE_C(p, { .third_dimension = base_array_layer + layer_count,