From: Chad Versace Date: Fri, 22 Jan 2016 22:48:36 +0000 (-0800) Subject: anv/state: Dedupe code for lowering surface format X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6a03c69adb646b6f7c11acc888550c1fb68b5a5d;p=mesa.git anv/state: Dedupe code for lowering surface format Add helper anv_surface_format(). --- diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c index eff5dd20eb7..55cff90a723 100644 --- a/src/vulkan/gen7_state.c +++ b/src/vulkan/gen7_state.c @@ -153,6 +153,7 @@ genX(fill_image_surface_state)(struct anv_device *device, void *state_map, ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange; + bool is_storage = (usage == VK_IMAGE_USAGE_STORAGE_BIT); struct anv_surface *surface = anv_image_get_surface_for_aspect_mask(image, range->aspectMask); @@ -170,9 +171,7 @@ genX(fill_image_surface_state)(struct anv_device *device, void *state_map, .SurfaceType = anv_surftype(image, pCreateInfo->viewType, usage == VK_IMAGE_USAGE_STORAGE_BIT), .SurfaceArray = image->array_size > 1, - .SurfaceFormat = (usage != VK_IMAGE_USAGE_STORAGE_BIT ? iview->format : - isl_lower_storage_image_format( - &device->isl_dev, iview->format)), + .SurfaceFormat = anv_surface_format(device, iview->format, is_storage), .SurfaceVerticalAlignment = anv_valign[image_align_sa.height], .SurfaceHorizontalAlignment = anv_halign[image_align_sa.width], diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c index 9d56ecd1845..01099f4e3d9 100644 --- a/src/vulkan/gen8_state.c +++ b/src/vulkan/gen8_state.c @@ -164,6 +164,7 @@ genX(fill_image_surface_state)(struct anv_device *device, void *state_map, ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange; + bool is_storage = (usage == VK_IMAGE_USAGE_STORAGE_BIT); struct anv_surface *surface = anv_image_get_surface_for_aspect_mask(image, range->aspectMask); @@ -180,12 +181,9 @@ genX(fill_image_surface_state)(struct anv_device *device, void *state_map, get_halign_valign(&surface->isl, &halign, &valign); struct GENX(RENDER_SURFACE_STATE) template = { - .SurfaceType = anv_surftype(image, pCreateInfo->viewType, - usage == VK_IMAGE_USAGE_STORAGE_BIT), + .SurfaceType = anv_surftype(image, pCreateInfo->viewType, is_storage), .SurfaceArray = image->array_size > 1, - .SurfaceFormat = (usage != VK_IMAGE_USAGE_STORAGE_BIT ? iview->format : - isl_lower_storage_image_format( - &device->isl_dev, iview->format)), + .SurfaceFormat = anv_surface_format(device, iview->format, is_storage), .SurfaceVerticalAlignment = valign, .SurfaceHorizontalAlignment = halign, .TileMode = isl_to_gen_tiling[surface->isl.tiling], diff --git a/src/vulkan/genX_state_util.h b/src/vulkan/genX_state_util.h index 215e9ba30eb..78fe1d4da19 100644 --- a/src/vulkan/genX_state_util.h +++ b/src/vulkan/genX_state_util.h @@ -46,6 +46,17 @@ anv_surftype(const struct anv_image *image, VkImageViewType view_type, } } +static enum isl_format +anv_surface_format(const struct anv_device *device, enum isl_format format, + bool storage) +{ + if (storage) { + return isl_lower_storage_image_format(&device->isl_dev, format); + } else { + return format; + } +} + #if ANV_GEN > 7 || ANV_IS_HASWELL static const uint32_t vk_to_gen_swizzle_map[] = { [VK_COMPONENT_SWIZZLE_ZERO] = SCS_ZERO,