anv/image: Do swizzle remapping in anv_image.c
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 27 Jan 2016 04:16:43 +0000 (20:16 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 27 Jan 2016 04:23:59 +0000 (20:23 -0800)
TODO: At some point, we really need to make an image_view_init_info that's
a flyweight and stop stuffing everything into image_view.

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

index f3fced5e70424da7e886b717f5c84d2e080162c7..8417177105c25cc690f6e303d3ffa2a267d893be 100644 (file)
@@ -453,6 +453,15 @@ has_matching_storage_typed_format(const struct anv_device *device,
            device->info.gen >= 9);
 }
 
+static VkComponentSwizzle
+remap_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component)
+{
+   if (swizzle == VK_COMPONENT_SWIZZLE_IDENTITY)
+      return component;
+   else
+      return swizzle;
+}
+
 void
 anv_image_view_init(struct anv_image_view *iview,
                     struct anv_device *device,
@@ -493,6 +502,14 @@ anv_image_view_init(struct anv_image_view *iview,
    iview->vk_format = pCreateInfo->format;
    iview->format = anv_get_isl_format(pCreateInfo->format, iview->aspect_mask,
                                       image->tiling);
+   iview->swizzle.r = remap_swizzle(pCreateInfo->components.r,
+                                    VK_COMPONENT_SWIZZLE_R);
+   iview->swizzle.g = remap_swizzle(pCreateInfo->components.g,
+                                    VK_COMPONENT_SWIZZLE_G);
+   iview->swizzle.b = remap_swizzle(pCreateInfo->components.b,
+                                    VK_COMPONENT_SWIZZLE_B);
+   iview->swizzle.a = remap_swizzle(pCreateInfo->components.a,
+                                    VK_COMPONENT_SWIZZLE_A);
 
    iview->base_layer = range->baseArrayLayer;
    iview->base_mip = range->baseMipLevel;
index 215727163edf8eeffce5fb07d1d18c64e50771b7..1b3d80e61bee6a22f887a53e9a16aa48e3426d23 100644 (file)
@@ -1566,6 +1566,7 @@ struct anv_image_view {
 
    VkImageAspectFlags aspect_mask;
    VkFormat vk_format;
+   VkComponentMapping swizzle;
    enum isl_format format;
    uint32_t base_layer;
    uint32_t base_mip;
index b3abe74090db80434c7bd63ca8e5db6f7474ed07..4c27716d18e76d20af34e70ea16412b0514eb329 100644 (file)
@@ -202,14 +202,10 @@ genX(fill_image_surface_state)(struct anv_device *device, void *state_map,
 
       .MCSEnable = false,
 #  if (ANV_IS_HASWELL)
-      .ShaderChannelSelectR = vk_to_gen_swizzle(pCreateInfo->components.r,
-                                                VK_COMPONENT_SWIZZLE_R),
-      .ShaderChannelSelectG = vk_to_gen_swizzle(pCreateInfo->components.g,
-                                                VK_COMPONENT_SWIZZLE_G),
-      .ShaderChannelSelectB = vk_to_gen_swizzle(pCreateInfo->components.b,
-                                                VK_COMPONENT_SWIZZLE_B),
-      .ShaderChannelSelectA = vk_to_gen_swizzle(pCreateInfo->components.a,
-                                                VK_COMPONENT_SWIZZLE_A),
+      .ShaderChannelSelectR = vk_to_gen_swizzle[iview->swizzle.r],
+      .ShaderChannelSelectG = vk_to_gen_swizzle[iview->swizzle.g],
+      .ShaderChannelSelectB = vk_to_gen_swizzle[iview->swizzle.b],
+      .ShaderChannelSelectA = vk_to_gen_swizzle[iview->swizzle.a],
 #  else /* XXX: Seriously? */
       .RedClearColor = 0,
       .GreenClearColor = 0,
index 6e4c3eafe111e02273965b5aa44aaf27a5e0b4d8..5b3691d22d05fdbf1dcd96d310e8c85f756ebc41 100644 (file)
@@ -224,14 +224,10 @@ genX(fill_image_surface_state)(struct anv_device *device, void *state_map,
       .GreenClearColor = 0,
       .BlueClearColor = 0,
       .AlphaClearColor = 0,
-      .ShaderChannelSelectRed = vk_to_gen_swizzle(pCreateInfo->components.r,
-                                                  VK_COMPONENT_SWIZZLE_R),
-      .ShaderChannelSelectGreen = vk_to_gen_swizzle(pCreateInfo->components.g,
-                                                    VK_COMPONENT_SWIZZLE_G),
-      .ShaderChannelSelectBlue = vk_to_gen_swizzle(pCreateInfo->components.b,
-                                                   VK_COMPONENT_SWIZZLE_B),
-      .ShaderChannelSelectAlpha = vk_to_gen_swizzle(pCreateInfo->components.a,
-                                                    VK_COMPONENT_SWIZZLE_A),
+      .ShaderChannelSelectRed = vk_to_gen_swizzle[iview->swizzle.r],
+      .ShaderChannelSelectGreen = vk_to_gen_swizzle[iview->swizzle.g],
+      .ShaderChannelSelectBlue = vk_to_gen_swizzle[iview->swizzle.b],
+      .ShaderChannelSelectAlpha = vk_to_gen_swizzle[iview->swizzle.a],
       .ResourceMinLOD = 0.0,
       .SurfaceBaseAddress = { NULL, iview->offset },
    };
index 78fe1d4da191709e2eb2838e36b1f51a7fc96594..67f798ab66ee76ee380df22bf3debdc6d24012f7 100644 (file)
@@ -58,7 +58,7 @@ anv_surface_format(const struct anv_device *device, enum isl_format format,
 }
 
 #if ANV_GEN > 7 || ANV_IS_HASWELL
-static const uint32_t vk_to_gen_swizzle_map[] = {
+static const uint32_t vk_to_gen_swizzle[] = {
    [VK_COMPONENT_SWIZZLE_ZERO]                 = SCS_ZERO,
    [VK_COMPONENT_SWIZZLE_ONE]                  = SCS_ONE,
    [VK_COMPONENT_SWIZZLE_R]                    = SCS_RED,
@@ -66,15 +66,6 @@ static const uint32_t vk_to_gen_swizzle_map[] = {
    [VK_COMPONENT_SWIZZLE_B]                    = SCS_BLUE,
    [VK_COMPONENT_SWIZZLE_A]                    = SCS_ALPHA
 };
-
-static inline uint32_t
-vk_to_gen_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component)
-{
-   if (swizzle == VK_COMPONENT_SWIZZLE_IDENTITY)
-      return vk_to_gen_swizzle_map[component];
-   else
-      return vk_to_gen_swizzle_map[swizzle];
-}
 #endif
 
 static inline uint32_t