[Mesa-dev] [PATCH 18/23] anv/formats: Use the isl_channel_select enum for the swizzle

Jason Ekstrand jason at jlekstrand.net
Mon May 16 19:08:23 UTC 2016


---
 src/intel/vulkan/anv_formats.c | 18 ++++++++++++++----
 src/intel/vulkan/anv_image.c   | 18 ++++++------------
 src/intel/vulkan/anv_private.h |  8 ++++----
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index 4d5d3ce..6d677d5 100644
--- a/src/intel/vulkan/anv_formats.c
+++ b/src/intel/vulkan/anv_formats.c
@@ -25,8 +25,15 @@
 #include "brw_surface_formats.h"
 #include "vk_format_info.h"
 
-#define RGBA { 0, 1, 2, 3 }
-#define BGRA { 2, 1, 0, 3 }
+#define ISL_SWIZZLE(r, g, b, a) { \
+   ISL_CHANNEL_SELECT_##r, \
+   ISL_CHANNEL_SELECT_##g, \
+   ISL_CHANNEL_SELECT_##b, \
+   ISL_CHANNEL_SELECT_##a, \
+}
+
+#define RGBA ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA)
+#define BGRA ISL_SWIZZLE(BLUE, GREEN, RED, ALPHA)
 
 #define swiz_fmt(__vk_fmt, __hw_fmt, __swizzle)     \
    [__vk_fmt] = { \
@@ -308,13 +315,16 @@ get_image_format_properties(int gen, enum isl_format base,
     * moved, then blending won't work correctly.  The PRM tells us
     * straight-up not to render to such a surface.
     */
-   if (info->render_target <= gen && format.swizzle.a == 3) {
+   if (info->render_target <= gen &&
+       format.swizzle.a == ISL_CHANNEL_SELECT_ALPHA) {
       flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
                VK_FORMAT_FEATURE_BLIT_DST_BIT;
    }
 
-   if (info->alpha_blend <= gen && format.swizzle.a == 3)
+   if (info->alpha_blend <= gen &&
+       format.swizzle.a == ISL_CHANNEL_SELECT_ALPHA) {
       flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
+   }
 
    /* Load/store is determined based on base format.  This prevents RGB
     * formats from showing up as load/store capable.
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 75c02b3..f517aa6 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -415,18 +415,12 @@ remap_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component,
       swizzle = component;
 
    switch (swizzle) {
-   case VK_COMPONENT_SWIZZLE_ZERO:
-      return ISL_CHANNEL_SELECT_ZERO;
-   case VK_COMPONENT_SWIZZLE_ONE:
-      return ISL_CHANNEL_SELECT_ONE;
-   case VK_COMPONENT_SWIZZLE_R:
-      return ISL_CHANNEL_SELECT_RED + format_swizzle.r;
-   case VK_COMPONENT_SWIZZLE_G:
-      return ISL_CHANNEL_SELECT_RED + format_swizzle.g;
-   case VK_COMPONENT_SWIZZLE_B:
-      return ISL_CHANNEL_SELECT_RED + format_swizzle.b;
-   case VK_COMPONENT_SWIZZLE_A:
-      return ISL_CHANNEL_SELECT_RED + format_swizzle.a;
+   case VK_COMPONENT_SWIZZLE_ZERO:  return ISL_CHANNEL_SELECT_ZERO;
+   case VK_COMPONENT_SWIZZLE_ONE:   return ISL_CHANNEL_SELECT_ONE;
+   case VK_COMPONENT_SWIZZLE_R:     return format_swizzle.r;
+   case VK_COMPONENT_SWIZZLE_G:     return format_swizzle.g;
+   case VK_COMPONENT_SWIZZLE_B:     return format_swizzle.b;
+   case VK_COMPONENT_SWIZZLE_A:     return format_swizzle.a;
    default:
       unreachable("Invalid swizzle");
    }
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 040d0c7..926a71f 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1507,10 +1507,10 @@ anv_graphics_pipeline_create(VkDevice device,
                              VkPipeline *pPipeline);
 
 struct anv_format_swizzle {
-   unsigned r:2;
-   unsigned g:2;
-   unsigned b:2;
-   unsigned a:2;
+   enum isl_channel_select r:4;
+   enum isl_channel_select g:4;
+   enum isl_channel_select b:4;
+   enum isl_channel_select a:4;
 };
 
 struct anv_format {
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list