From: Jason Ekstrand Date: Mon, 30 Nov 2015 21:06:12 +0000 (-0800) Subject: vk/0.210.0: Rework texture view component mapping X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a53f23d93f7e7ee65cb4937178ea8c2c28484756;p=mesa.git vk/0.210.0: Rework texture view component mapping --- diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index 39cbb71c2d7..2f2dc11c3c2 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -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; diff --git a/src/vulkan/anv_image.c b/src/vulkan/anv_image.c index 1a500d2b4e4..0fe2df10a7a 100644 --- a/src/vulkan/anv_image.c +++ b/src/vulkan/anv_image.c @@ -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); diff --git a/src/vulkan/anv_meta.c b/src/vulkan/anv_meta.c index 143d637c55a..130557c1aa7 100644 --- a/src/vulkan/anv_meta.c +++ b/src/vulkan/anv_meta.c @@ -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, diff --git a/src/vulkan/anv_meta_clear.c b/src/vulkan/anv_meta_clear.c index 0709c41db46..ff8183a736a 100644 --- a/src/vulkan/anv_meta_clear.c +++ b/src/vulkan/anv_meta_clear.c @@ -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, diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c index 7adb4485b90..924b7303da0 100644 --- a/src/vulkan/gen7_state.c +++ b/src/vulkan/gen7_state.c @@ -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, diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c index c7dd6b3f836..12a30534bfb 100644 --- a/src/vulkan/gen8_state.c +++ b/src/vulkan/gen8_state.c @@ -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 }, };