diff options
author | Chad Versace <[email protected]> | 2016-01-22 14:48:36 -0800 |
---|---|---|
committer | Chad Versace <[email protected]> | 2016-01-22 16:49:17 -0800 |
commit | 6a03c69adb646b6f7c11acc888550c1fb68b5a5d (patch) | |
tree | 346f30f91e5e985bae3a96a7416f19a093e26f9f | |
parent | 11d5c1905ce3856a3832718bbcb0c65928a3b26b (diff) |
anv/state: Dedupe code for lowering surface format
Add helper anv_surface_format().
-rw-r--r-- | src/vulkan/gen7_state.c | 5 | ||||
-rw-r--r-- | src/vulkan/gen8_state.c | 8 | ||||
-rw-r--r-- | src/vulkan/genX_state_util.h | 11 |
3 files changed, 16 insertions, 8 deletions
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, |