diff options
author | Jason Ekstrand <[email protected]> | 2016-01-26 20:16:43 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2016-01-26 20:23:59 -0800 |
commit | 9bc72a9213432622364bdeb0ddd053a494896a6e (patch) | |
tree | af885c5a657c407a9f6f1e4f62d63eb4d156ca66 | |
parent | 7d84fe9b1f35da32c435c23eb07dfac4cbde7502 (diff) |
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.
-rw-r--r-- | src/vulkan/anv_image.c | 17 | ||||
-rw-r--r-- | src/vulkan/anv_private.h | 1 | ||||
-rw-r--r-- | src/vulkan/gen7_state.c | 12 | ||||
-rw-r--r-- | src/vulkan/gen8_state.c | 12 | ||||
-rw-r--r-- | src/vulkan/genX_state_util.h | 11 |
5 files changed, 27 insertions, 26 deletions
diff --git a/src/vulkan/anv_image.c b/src/vulkan/anv_image.c index f3fced5e704..8417177105c 100644 --- a/src/vulkan/anv_image.c +++ b/src/vulkan/anv_image.c @@ -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; diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 215727163ed..1b3d80e61be 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -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; diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c index b3abe74090d..4c27716d18e 100644 --- a/src/vulkan/gen7_state.c +++ b/src/vulkan/gen7_state.c @@ -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, diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c index 6e4c3eafe11..5b3691d22d0 100644 --- a/src/vulkan/gen8_state.c +++ b/src/vulkan/gen8_state.c @@ -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 }, }; diff --git a/src/vulkan/genX_state_util.h b/src/vulkan/genX_state_util.h index 78fe1d4da19..67f798ab66e 100644 --- a/src/vulkan/genX_state_util.h +++ b/src/vulkan/genX_state_util.h @@ -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 |