intel/isl: Add an isl_swizzle structure and use it for isl_view swizzles
[mesa.git] / src / intel / vulkan / anv_image.c
index 7fd826846d86d343fc340c6f6b85f6bb0ed1886c..63b8c86f5c33c1c82491ec9c4dad3aeb5606ee62 100644 (file)
@@ -345,7 +345,7 @@ alloc_surface_state(struct anv_device *device,
 
 static enum isl_channel_select
 remap_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component,
-              struct anv_format_swizzle format_swizzle)
+              struct isl_swizzle format_swizzle)
 {
    if (swizzle == VK_COMPONENT_SWIZZLE_IDENTITY)
       swizzle = component;
@@ -414,15 +414,15 @@ anv_image_view_init(struct anv_image_view *iview,
       .levels = anv_get_levelCount(image, range),
       .base_array_layer = range->baseArrayLayer,
       .array_len = anv_get_layerCount(image, range),
-      .channel_select = {
-         remap_swizzle(pCreateInfo->components.r,
-                       VK_COMPONENT_SWIZZLE_R, format.swizzle),
-         remap_swizzle(pCreateInfo->components.g,
-                       VK_COMPONENT_SWIZZLE_G, format.swizzle),
-         remap_swizzle(pCreateInfo->components.b,
-                       VK_COMPONENT_SWIZZLE_B, format.swizzle),
-         remap_swizzle(pCreateInfo->components.a,
-                       VK_COMPONENT_SWIZZLE_A, format.swizzle),
+      .swizzle = {
+         .r = remap_swizzle(pCreateInfo->components.r,
+                            VK_COMPONENT_SWIZZLE_R, format.swizzle),
+         .g = remap_swizzle(pCreateInfo->components.g,
+                            VK_COMPONENT_SWIZZLE_G, format.swizzle),
+         .b = remap_swizzle(pCreateInfo->components.b,
+                            VK_COMPONENT_SWIZZLE_B, format.swizzle),
+         .a = remap_swizzle(pCreateInfo->components.a,
+                            VK_COMPONENT_SWIZZLE_A, format.swizzle),
       },
    };
 
@@ -456,7 +456,18 @@ anv_image_view_init(struct anv_image_view *iview,
       iview->sampler_surface_state.alloc_size = 0;
    }
 
-   if (image->usage & usage_mask & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
+   /* This is kind-of hackish.  It is possible, due to get_full_usage above,
+    * to get a surface state with a non-renderable format but with
+    * VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT.  This happens in particular for
+    * formats which aren't renderable but where we want to use Vulkan copy
+    * commands so VK_IMAGE_USAGE_TRANSFER_DST_BIT is set.  In the case of a
+    * copy, meta will use a format that we can render to, but most of the rest
+    * of the time, we don't want to create those surface states.  Once we
+    * start using blorp for copies, this problem will go away and we can
+    * remove a lot of hacks.
+    */
+   if ((image->usage & usage_mask & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) &&
+       isl_format_supports_rendering(&device->info, isl_view.format)) {
       iview->color_rt_surface_state = alloc_surface_state(device, cmd_buffer);
 
       isl_view.usage = cube_usage | ISL_SURF_USAGE_RENDER_TARGET_BIT;