From 51705fc01550c7cf7818fcfbd803a8fd61f09b85 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Fri, 13 Dec 2019 10:31:05 +0100 Subject: [PATCH] v3dv: compute tile size for framebuffer Part-of: --- src/broadcom/vulkan/v3dv_device.c | 46 ++++++++++++++++++++++++++++++ src/broadcom/vulkan/v3dv_private.h | 6 ++++ 2 files changed, 52 insertions(+) diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index cc96d3351c3..fee30b5c087 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -33,6 +33,9 @@ #include "v3dv_private.h" #include "common/v3d_debug.h" + +#include "broadcom/cle/v3dx_pack.h" + #include "compiler/glsl_types.h" #include "drm-uapi/v3d_drm.h" #include "vk_util.h" @@ -1294,6 +1297,47 @@ v3dv_DestroyBuffer(VkDevice _device, vk_free2(&device->alloc, pAllocator, buffer); } +static void +compute_tile_size_for_framebuffer(struct v3dv_framebuffer *framebuffer) +{ + static const uint8_t tile_sizes[] = { + 64, 64, + 64, 32, + 32, 32, + 32, 16, + 16, 16, + }; + + uint32_t tile_size_index = 0; + + /* FIXME: MSAA */ + + if (framebuffer->attachment_count > 2) + tile_size_index += 2; + else if (framebuffer->attachment_count > 1) + tile_size_index += 1; + + STATIC_ASSERT(RENDER_TARGET_MAXIMUM_32BPP == 0); + uint8_t max_bpp = RENDER_TARGET_MAXIMUM_32BPP; + for (uint32_t i = 0; i < framebuffer->attachment_count; i++) { + const struct v3dv_image_view *att = framebuffer->attachments[i]; + if (att) + max_bpp = MAX2(max_bpp, att->internal_bpp); + } + framebuffer->internal_bpp = max_bpp; + + tile_size_index += framebuffer->internal_bpp; + assert(tile_size_index < ARRAY_SIZE(tile_sizes)); + + framebuffer->tile_width = tile_sizes[tile_size_index * 2]; + framebuffer->tile_height = tile_sizes[tile_size_index * 2 + 1]; + + framebuffer->draw_tiles_x = + DIV_ROUND_UP(framebuffer->width, framebuffer->tile_width); + framebuffer->draw_tiles_y = + DIV_ROUND_UP(framebuffer->height, framebuffer->tile_height); +} + VkResult v3dv_CreateFramebuffer(VkDevice _device, const VkFramebufferCreateInfo *pCreateInfo, @@ -1321,6 +1365,8 @@ v3dv_CreateFramebuffer(VkDevice _device, v3dv_image_view_from_handle(pCreateInfo->pAttachments[i]); } + compute_tile_size_for_framebuffer(framebuffer); + *pFramebuffer = v3dv_framebuffer_to_handle(framebuffer); return VK_SUCCESS; diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 44d597d35f3..59168dfb278 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -326,6 +326,12 @@ struct v3dv_framebuffer { uint32_t height; uint32_t layers; + uint32_t internal_bpp; + uint32_t tile_width; + uint32_t tile_height; + uint32_t draw_tiles_x; + uint32_t draw_tiles_y; + uint32_t attachment_count; struct v3dv_image_view *attachments[0]; };