vk/0.210.0: Rework texture view component mapping
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 30 Nov 2015 21:06:12 +0000 (13:06 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 30 Nov 2015 21:06:12 +0000 (13:06 -0800)
include/vulkan/vulkan.h
src/vulkan/anv_image.c
src/vulkan/anv_meta.c
src/vulkan/anv_meta_clear.c
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index 39cbb71c2d7b370b8657be1fa6e531097d5d2044..2f2dc11c3c283368e15790bfca4ce06610c9c2b8 100644 (file)
@@ -467,18 +467,19 @@ typedef enum VkImageViewType {
     VK_IMAGE_VIEW_TYPE_MAX_ENUM = 0x7FFFFFFF
 } VkImageViewType;
 
-typedef enum {
-    VK_CHANNEL_SWIZZLE_ZERO = 0,
-    VK_CHANNEL_SWIZZLE_ONE = 1,
-    VK_CHANNEL_SWIZZLE_R = 2,
-    VK_CHANNEL_SWIZZLE_G = 3,
-    VK_CHANNEL_SWIZZLE_B = 4,
-    VK_CHANNEL_SWIZZLE_A = 5,
-    VK_CHANNEL_SWIZZLE_BEGIN_RANGE = VK_CHANNEL_SWIZZLE_ZERO,
-    VK_CHANNEL_SWIZZLE_END_RANGE = VK_CHANNEL_SWIZZLE_A,
-    VK_CHANNEL_SWIZZLE_NUM = (VK_CHANNEL_SWIZZLE_A - VK_CHANNEL_SWIZZLE_ZERO + 1),
-    VK_CHANNEL_SWIZZLE_MAX_ENUM = 0x7FFFFFFF
-} VkChannelSwizzle;
+typedef enum VkComponentSwizzle {
+    VK_COMPONENT_SWIZZLE_IDENTITY = 0,
+    VK_COMPONENT_SWIZZLE_ZERO = 1,
+    VK_COMPONENT_SWIZZLE_ONE = 2,
+    VK_COMPONENT_SWIZZLE_R = 3,
+    VK_COMPONENT_SWIZZLE_G = 4,
+    VK_COMPONENT_SWIZZLE_B = 5,
+    VK_COMPONENT_SWIZZLE_A = 6,
+    VK_COMPONENT_SWIZZLE_BEGIN_RANGE = VK_COMPONENT_SWIZZLE_IDENTITY,
+    VK_COMPONENT_SWIZZLE_END_RANGE = VK_COMPONENT_SWIZZLE_A,
+    VK_COMPONENT_SWIZZLE_RANGE_SIZE = (VK_COMPONENT_SWIZZLE_A - VK_COMPONENT_SWIZZLE_IDENTITY + 1),
+    VK_COMPONENT_SWIZZLE_MAX_ENUM = 0x7FFFFFFF
+} VkComponentSwizzle;
 
 typedef enum {
     VK_SHADER_STAGE_VERTEX = 0,
@@ -1493,12 +1494,12 @@ typedef struct {
     VkDeviceSize                                depthPitch;
 } VkSubresourceLayout;
 
-typedef struct {
-    VkChannelSwizzle                            r;
-    VkChannelSwizzle                            g;
-    VkChannelSwizzle                            b;
-    VkChannelSwizzle                            a;
-} VkChannelMapping;
+typedef struct VkComponentMapping {
+    VkComponentSwizzle                          r;
+    VkComponentSwizzle                          g;
+    VkComponentSwizzle                          b;
+    VkComponentSwizzle                          a;
+} VkComponentMapping;
 
 typedef struct {
     VkImageAspectFlags                          aspectMask;
@@ -1514,7 +1515,7 @@ typedef struct {
     VkImage                                     image;
     VkImageViewType                             viewType;
     VkFormat                                    format;
-    VkChannelMapping                            channels;
+    VkComponentMapping                          components;
     VkImageSubresourceRange                     subresourceRange;
     VkImageViewCreateFlags                      flags;
 } VkImageViewCreateInfo;
index 1a500d2b4e44dba462492ecf22c77b91dc1d16d8..0fe2df10a7a66d5d329b71818c04ee357a478fb4 100644 (file)
@@ -474,14 +474,14 @@ anv_validate_CreateImageView(VkDevice _device,
    view_format_info = anv_format_for_vk_format(pCreateInfo->format);
 
    /* Validate channel swizzles. */
-   assert(pCreateInfo->channels.r >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE);
-   assert(pCreateInfo->channels.r <= VK_CHANNEL_SWIZZLE_END_RANGE);
-   assert(pCreateInfo->channels.g >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE);
-   assert(pCreateInfo->channels.g <= VK_CHANNEL_SWIZZLE_END_RANGE);
-   assert(pCreateInfo->channels.b >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE);
-   assert(pCreateInfo->channels.b <= VK_CHANNEL_SWIZZLE_END_RANGE);
-   assert(pCreateInfo->channels.a >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE);
-   assert(pCreateInfo->channels.a <= VK_CHANNEL_SWIZZLE_END_RANGE);
+   assert(pCreateInfo->components.r >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
+   assert(pCreateInfo->components.r <= VK_COMPONENT_SWIZZLE_END_RANGE);
+   assert(pCreateInfo->components.g >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
+   assert(pCreateInfo->components.g <= VK_COMPONENT_SWIZZLE_END_RANGE);
+   assert(pCreateInfo->components.b >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
+   assert(pCreateInfo->components.b <= VK_COMPONENT_SWIZZLE_END_RANGE);
+   assert(pCreateInfo->components.a >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE);
+   assert(pCreateInfo->components.a <= VK_COMPONENT_SWIZZLE_END_RANGE);
 
    /* Validate subresource. */
    assert(subresource->aspectMask != 0);
index 143d637c55a8c3d33d7b4aced0d931d3d264a3de..130557c1aa739e69b996876d631da4d939baf152 100644 (file)
@@ -698,12 +698,6 @@ do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
          .image = src_image,
          .viewType = VK_IMAGE_VIEW_TYPE_2D,
          .format = copy_format,
-         .channels = {
-            VK_CHANNEL_SWIZZLE_R,
-            VK_CHANNEL_SWIZZLE_G,
-            VK_CHANNEL_SWIZZLE_B,
-            VK_CHANNEL_SWIZZLE_A
-         },
          .subresourceRange = {
             .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
             .baseMipLevel = 0,
@@ -721,12 +715,6 @@ do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
          .image = dest_image,
          .viewType = VK_IMAGE_VIEW_TYPE_2D,
          .format = copy_format,
-         .channels = {
-            .r = VK_CHANNEL_SWIZZLE_R,
-            .g = VK_CHANNEL_SWIZZLE_G,
-            .b = VK_CHANNEL_SWIZZLE_B,
-            .a = VK_CHANNEL_SWIZZLE_A,
-         },
          .subresourceRange = {
             .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
             .baseMipLevel = 0,
@@ -858,12 +846,6 @@ void anv_CmdCopyImage(
             .image = srcImage,
             .viewType = src_iview_type,
             .format = src_image->format->vk_format,
-            .channels = {
-               VK_CHANNEL_SWIZZLE_R,
-               VK_CHANNEL_SWIZZLE_G,
-               VK_CHANNEL_SWIZZLE_B,
-               VK_CHANNEL_SWIZZLE_A
-            },
             .subresourceRange = {
                .aspectMask = 1 << pRegions[r].srcSubresource.aspect,
                .baseMipLevel = pRegions[r].srcSubresource.mipLevel,
@@ -908,12 +890,6 @@ void anv_CmdCopyImage(
                .image = destImage,
                .viewType = VK_IMAGE_VIEW_TYPE_2D,
                .format = dest_image->format->vk_format,
-               .channels = {
-                  VK_CHANNEL_SWIZZLE_R,
-                  VK_CHANNEL_SWIZZLE_G,
-                  VK_CHANNEL_SWIZZLE_B,
-                  VK_CHANNEL_SWIZZLE_A
-               },
                .subresourceRange = {
                   .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
                   .baseMipLevel = pRegions[r].destSubresource.mipLevel,
@@ -970,12 +946,6 @@ void anv_CmdBlitImage(
             .image = srcImage,
             .viewType = src_iview_type,
             .format = src_image->format->vk_format,
-            .channels = {
-               VK_CHANNEL_SWIZZLE_R,
-               VK_CHANNEL_SWIZZLE_G,
-               VK_CHANNEL_SWIZZLE_B,
-               VK_CHANNEL_SWIZZLE_A
-            },
             .subresourceRange = {
                .aspectMask = 1 << pRegions[r].srcSubresource.aspect,
                .baseMipLevel = pRegions[r].srcSubresource.mipLevel,
@@ -1010,12 +980,6 @@ void anv_CmdBlitImage(
             .image = destImage,
             .viewType = VK_IMAGE_VIEW_TYPE_2D,
             .format = dest_image->format->vk_format,
-            .channels = {
-               VK_CHANNEL_SWIZZLE_R,
-               VK_CHANNEL_SWIZZLE_G,
-               VK_CHANNEL_SWIZZLE_B,
-               VK_CHANNEL_SWIZZLE_A
-            },
             .subresourceRange = {
                .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
                .baseMipLevel = pRegions[r].destSubresource.mipLevel,
@@ -1133,12 +1097,6 @@ void anv_CmdCopyBufferToImage(
                .image = anv_image_to_handle(src_image),
                .viewType = VK_IMAGE_VIEW_TYPE_2D,
                .format = proxy_format,
-               .channels = {
-                  VK_CHANNEL_SWIZZLE_R,
-                  VK_CHANNEL_SWIZZLE_G,
-                  VK_CHANNEL_SWIZZLE_B,
-                  VK_CHANNEL_SWIZZLE_A
-               },
                .subresourceRange = {
                   .aspectMask = 1 << proxy_aspect,
                   .baseMipLevel = 0,
@@ -1156,12 +1114,6 @@ void anv_CmdCopyBufferToImage(
                .image = anv_image_to_handle(dest_image),
                .viewType = VK_IMAGE_VIEW_TYPE_2D,
                .format = proxy_format,
-               .channels = {
-                  VK_CHANNEL_SWIZZLE_R,
-                  VK_CHANNEL_SWIZZLE_G,
-                  VK_CHANNEL_SWIZZLE_B,
-                  VK_CHANNEL_SWIZZLE_A
-               },
                .subresourceRange = {
                   .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
                   .baseMipLevel = pRegions[r].imageSubresource.mipLevel,
@@ -1233,12 +1185,6 @@ void anv_CmdCopyImageToBuffer(
             .image = srcImage,
             .viewType = src_iview_type,
             .format = src_image->format->vk_format,
-            .channels = {
-               VK_CHANNEL_SWIZZLE_R,
-               VK_CHANNEL_SWIZZLE_G,
-               VK_CHANNEL_SWIZZLE_B,
-               VK_CHANNEL_SWIZZLE_A
-            },
             .subresourceRange = {
                .aspectMask = 1 << pRegions[r].imageSubresource.aspect,
                .baseMipLevel = pRegions[r].imageSubresource.mipLevel,
@@ -1279,12 +1225,6 @@ void anv_CmdCopyImageToBuffer(
                .image = anv_image_to_handle(dest_image),
                .viewType = VK_IMAGE_VIEW_TYPE_2D,
                .format = dest_format,
-               .channels = {
-                  VK_CHANNEL_SWIZZLE_R,
-                  VK_CHANNEL_SWIZZLE_G,
-                  VK_CHANNEL_SWIZZLE_B,
-                  VK_CHANNEL_SWIZZLE_A
-               },
                .subresourceRange = {
                   .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
                   .baseMipLevel = 0,
index 0709c41db4644d23040024b61b2fbb0d3b343571..ff8183a736a383200e89fa90c55755c6a9bcbf88 100644 (file)
@@ -701,12 +701,6 @@ void anv_CmdClearColorImage(
                   .image = _image,
                   .viewType = VK_IMAGE_VIEW_TYPE_2D,
                   .format = image->format->vk_format,
-                  .channels = {
-                     VK_CHANNEL_SWIZZLE_R,
-                     VK_CHANNEL_SWIZZLE_G,
-                     VK_CHANNEL_SWIZZLE_B,
-                     VK_CHANNEL_SWIZZLE_A
-                  },
                   .subresourceRange = {
                      .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
                      .baseMipLevel = pRanges[r].baseMipLevel + l,
index 7adb4485b901ec3b3f984cc223acafd06ab83ef0..924b7303da05a59ea38982b19599372a4212080a 100644 (file)
@@ -182,15 +182,24 @@ static const uint8_t anv_valign[] = {
     [4] = VALIGN_4,
 };
 
-static const uint32_t vk_to_gen_swizzle[] = {
-   [VK_CHANNEL_SWIZZLE_ZERO]                 = SCS_ZERO,
-   [VK_CHANNEL_SWIZZLE_ONE]                  = SCS_ONE,
-   [VK_CHANNEL_SWIZZLE_R]                    = SCS_RED,
-   [VK_CHANNEL_SWIZZLE_G]                    = SCS_GREEN,
-   [VK_CHANNEL_SWIZZLE_B]                    = SCS_BLUE,
-   [VK_CHANNEL_SWIZZLE_A]                    = SCS_ALPHA
+static const uint32_t vk_to_gen_swizzle_map[] = {
+   [VK_COMPONENT_SWIZZLE_ZERO]                 = SCS_ZERO,
+   [VK_COMPONENT_SWIZZLE_ONE]                  = SCS_ONE,
+   [VK_COMPONENT_SWIZZLE_R]                    = SCS_RED,
+   [VK_COMPONENT_SWIZZLE_G]                    = SCS_GREEN,
+   [VK_COMPONENT_SWIZZLE_B]                    = SCS_BLUE,
+   [VK_COMPONENT_SWIZZLE_A]                    = SCS_ALPHA
 };
 
+static 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];
+}
+
 GENX_FUNC(GEN7, GEN75) void
 genX(image_view_init)(struct anv_image_view *iview,
                       struct anv_device *device,
@@ -263,10 +272,14 @@ genX(image_view_init)(struct anv_image_view *iview,
 
       .MCSEnable = false,
 #  if (ANV_IS_HASWELL)
-      .ShaderChannelSelectR = vk_to_gen_swizzle[pCreateInfo->channels.r],
-      .ShaderChannelSelectG = vk_to_gen_swizzle[pCreateInfo->channels.g],
-      .ShaderChannelSelectB = vk_to_gen_swizzle[pCreateInfo->channels.b],
-      .ShaderChannelSelectA = vk_to_gen_swizzle[pCreateInfo->channels.a],
+      .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),
 #  else /* XXX: Seriously? */
       .RedClearColor = 0,
       .GreenClearColor = 0,
index c7dd6b3f836ef4141f3f005b986e2199c5cee0d9..12a30534bfbc4f57a51af44ebfc456d2ae3d39d0 100644 (file)
@@ -87,6 +87,24 @@ alloc_surface_state(struct anv_device *device,
       }
 }
 
+static const uint32_t vk_to_gen_swizzle_map[] = {
+   [VK_COMPONENT_SWIZZLE_ZERO]                 = SCS_ZERO,
+   [VK_COMPONENT_SWIZZLE_ONE]                  = SCS_ONE,
+   [VK_COMPONENT_SWIZZLE_R]                    = SCS_RED,
+   [VK_COMPONENT_SWIZZLE_G]                    = SCS_GREEN,
+   [VK_COMPONENT_SWIZZLE_B]                    = SCS_BLUE,
+   [VK_COMPONENT_SWIZZLE_A]                    = SCS_ALPHA
+};
+
+static 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];
+}
+
 void
 genX(image_view_init)(struct anv_image_view *iview,
                       struct anv_device *device,
@@ -156,15 +174,6 @@ genX(image_view_init)(struct anv_image_view *iview,
       unreachable(!"bad VkImageType");
    }
 
-   static const uint32_t vk_to_gen_swizzle[] = {
-      [VK_CHANNEL_SWIZZLE_ZERO]                 = SCS_ZERO,
-      [VK_CHANNEL_SWIZZLE_ONE]                  = SCS_ONE,
-      [VK_CHANNEL_SWIZZLE_R]                    = SCS_RED,
-      [VK_CHANNEL_SWIZZLE_G]                    = SCS_GREEN,
-      [VK_CHANNEL_SWIZZLE_B]                    = SCS_BLUE,
-      [VK_CHANNEL_SWIZZLE_A]                    = SCS_ALPHA
-   };
-
    static const uint8_t isl_to_gen_tiling[] = {
       [ISL_TILING_LINEAR]  = LINEAR,
       [ISL_TILING_X]       = XMAJOR,
@@ -212,10 +221,14 @@ genX(image_view_init)(struct anv_image_view *iview,
       .GreenClearColor = 0,
       .BlueClearColor = 0,
       .AlphaClearColor = 0,
-      .ShaderChannelSelectRed = vk_to_gen_swizzle[pCreateInfo->channels.r],
-      .ShaderChannelSelectGreen = vk_to_gen_swizzle[pCreateInfo->channels.g],
-      .ShaderChannelSelectBlue = vk_to_gen_swizzle[pCreateInfo->channels.b],
-      .ShaderChannelSelectAlpha = vk_to_gen_swizzle[pCreateInfo->channels.a],
+      .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),
       .ResourceMinLOD = 0.0,
       .SurfaceBaseAddress = { NULL, iview->offset },
    };