anv/state: Dedupe code for lowering surface format
authorChad Versace <chad.versace@intel.com>
Fri, 22 Jan 2016 22:48:36 +0000 (14:48 -0800)
committerChad Versace <chad.versace@intel.com>
Sat, 23 Jan 2016 00:49:17 +0000 (16:49 -0800)
Add helper anv_surface_format().

src/vulkan/gen7_state.c
src/vulkan/gen8_state.c
src/vulkan/genX_state_util.h

index eff5dd20eb740c9d5a51cedd2d6ad4f75aa3d62e..55cff90a723da300c77d8ba3843e2502ac18d4a8 100644 (file)
@@ -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],
 
index 9d56ecd18450de85f0939853199c91fb93f97046..01099f4e3d95777dc0821295efcd42d706e6192e 100644 (file)
@@ -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],
index 215e9ba30eb6565696db1c3972eed2fa996e164d..78fe1d4da191709e2eb2838e36b1f51a7fc96594 100644 (file)
@@ -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,