From e01d5a0471bdf7e679eb576da2706e5436695fe9 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Mon, 14 Sep 2015 10:58:43 -0700 Subject: [PATCH] vk: Refactor anv_image_make_surface() Move the code that calculates the layout of 2D surfaces into a switch case. --- src/vulkan/anv_image.c | 56 +++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/vulkan/anv_image.c b/src/vulkan/anv_image.c index fbcd435a1a0..0db87753e28 100644 --- a/src/vulkan/anv_image.c +++ b/src/vulkan/anv_image.c @@ -164,29 +164,43 @@ anv_image_make_surface(const struct anv_image_create_info *create_info, const uint32_t i = 4; /* FINISHME: Stop hardcoding subimage alignment */ const uint32_t j = 4; /* FINISHME: Stop hardcoding subimage alignment */ - const uint32_t w0 = align_u32(extent->width, i); - const uint32_t h0 = align_u32(extent->height, j); - uint16_t qpitch; - uint32_t mt_width; - uint32_t mt_height; + uint16_t qpitch = min_qpitch; + uint32_t mt_width = 0; + uint32_t mt_height = 0; - if (levels == 1 && array_size == 1) { - qpitch = min_qpitch; - mt_width = w0; - mt_height = h0; - } else { - uint32_t w1 = align_u32(anv_minify(extent->width, 1), i); - uint32_t h1 = align_u32(anv_minify(extent->height, 1), j); - uint32_t w2 = align_u32(anv_minify(extent->width, 2), i); - - /* The QPitch equation is found in the Broadwell PRM >> Volume 5: Memory - * Views >> Common Surface Formats >> Surface Layout >> 2D Surfaces >> - * Surface Arrays >> For All Surface Other Than Separate Stencil Buffer: - */ - qpitch = h0 + h1 + 11 * j; - mt_width = MAX(w0, w1 + w2); - mt_height = array_size * qpitch; + switch (create_info->vk_info->imageType) { + case VK_IMAGE_TYPE_1D: + anv_finishme("VK_IMAGE_TYPE_1D"); + break; + case VK_IMAGE_TYPE_2D: { + const uint32_t w0 = align_u32(extent->width, i); + const uint32_t h0 = align_u32(extent->height, j); + + if (levels == 1 && array_size == 1) { + qpitch = min_qpitch; + mt_width = w0; + mt_height = h0; + } else { + uint32_t w1 = align_u32(anv_minify(extent->width, 1), i); + uint32_t h1 = align_u32(anv_minify(extent->height, 1), j); + uint32_t w2 = align_u32(anv_minify(extent->width, 2), i); + + /* The QPitch equation is found in the Broadwell PRM >> Volume 5: Memory + * Views >> Common Surface Formats >> Surface Layout >> 2D Surfaces >> + * Surface Arrays >> For All Surface Other Than Separate Stencil Buffer: + */ + qpitch = h0 + h1 + 11 * j; + mt_width = MAX(w0, w1 + w2); + mt_height = array_size * qpitch; + } + break; + } + case VK_IMAGE_TYPE_3D: + anv_finishme("VK_IMAGE_TYPE_3D"); + break; + default: + unreachable(!"bad VkImageType"); } assert(qpitch >= min_qpitch); -- 2.11.0