anv/image: Do swizzle remapping in anv_image.c
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.
diff --git a/src/vulkan/anv_image.c b/src/vulkan/anv_image.c
index f3fced5..8417177 100644
--- a/src/vulkan/anv_image.c
+++ b/src/vulkan/anv_image.c
@@ -453,6 +453,15 @@
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 @@
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;
diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h
index 2157271..1b3d80e 100644
--- a/src/vulkan/anv_private.h
+++ b/src/vulkan/anv_private.h
@@ -1566,6 +1566,7 @@
VkImageAspectFlags aspect_mask;
VkFormat vk_format;
+ VkComponentMapping swizzle;
enum isl_format format;
uint32_t base_layer;
uint32_t base_mip;
diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c
index b3abe74..4c27716 100644
--- a/src/vulkan/gen7_state.c
+++ b/src/vulkan/gen7_state.c
@@ -202,14 +202,10 @@
.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,
diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c
index 6e4c3ea..5b3691d 100644
--- a/src/vulkan/gen8_state.c
+++ b/src/vulkan/gen8_state.c
@@ -224,14 +224,10 @@
.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 },
};
diff --git a/src/vulkan/genX_state_util.h b/src/vulkan/genX_state_util.h
index 78fe1d4..67f798a 100644
--- a/src/vulkan/genX_state_util.h
+++ b/src/vulkan/genX_state_util.h
@@ -58,7 +58,7 @@
}
#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 @@
[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