vk/format, v3dv: Add a vulkan -> pipe swizzle helper

And use it to replace the one in v3dv.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13359>
This commit is contained in:
Connor Abbott
2021-10-13 17:28:07 +02:00
committed by Marge Bot
parent 7a2e40df5e
commit 7a90aa8d2e
3 changed files with 39 additions and 31 deletions

View File

@@ -451,29 +451,6 @@ v3dv_image_type_to_view_type(VkImageType type)
}
}
static enum pipe_swizzle
vk_component_mapping_to_pipe_swizzle(VkComponentSwizzle swz)
{
assert(swz != VK_COMPONENT_SWIZZLE_IDENTITY);
switch (swz) {
case VK_COMPONENT_SWIZZLE_ZERO:
return PIPE_SWIZZLE_0;
case VK_COMPONENT_SWIZZLE_ONE:
return PIPE_SWIZZLE_1;
case VK_COMPONENT_SWIZZLE_R:
return PIPE_SWIZZLE_X;
case VK_COMPONENT_SWIZZLE_G:
return PIPE_SWIZZLE_Y;
case VK_COMPONENT_SWIZZLE_B:
return PIPE_SWIZZLE_Z;
case VK_COMPONENT_SWIZZLE_A:
return PIPE_SWIZZLE_W;
default:
unreachable("Unknown VkComponentSwizzle");
};
}
VKAPI_ATTR VkResult VKAPI_CALL
v3dv_CreateImageView(VkDevice _device,
const VkImageViewCreateInfo *pCreateInfo,
@@ -515,14 +492,8 @@ v3dv_CreateImageView(VkDevice _device,
* util_format_compose_swizzles. Would be good to check if it would be
* better to reimplement the latter using vk component
*/
image_view_swizzle[0] =
vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.r);
image_view_swizzle[1] =
vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.g);
image_view_swizzle[2] =
vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.b);
image_view_swizzle[3] =
vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle.a);
vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle,
image_view_swizzle);
}
iview->vk.format = format;

View File

@@ -339,3 +339,37 @@ vk_format_aspects(VkFormat format)
return VK_IMAGE_ASPECT_COLOR_BIT;
}
}
void
vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,
unsigned char out_swizzle[4])
{
VkComponentSwizzle swizzle[4] = { mapping.r, mapping.g, mapping.b, mapping.a };
for (unsigned i = 0; i < 4; i++) {
switch (swizzle[i]) {
case VK_COMPONENT_SWIZZLE_R:
out_swizzle[i] = PIPE_SWIZZLE_X;
break;
case VK_COMPONENT_SWIZZLE_G:
out_swizzle[i] = PIPE_SWIZZLE_Y;
break;
case VK_COMPONENT_SWIZZLE_B:
out_swizzle[i] = PIPE_SWIZZLE_Z;
break;
case VK_COMPONENT_SWIZZLE_A:
out_swizzle[i] = PIPE_SWIZZLE_W;
break;
case VK_COMPONENT_SWIZZLE_IDENTITY:
out_swizzle[i] = PIPE_SWIZZLE_X + i;
break;
case VK_COMPONENT_SWIZZLE_ZERO:
out_swizzle[i] = PIPE_SWIZZLE_0;
break;
case VK_COMPONENT_SWIZZLE_ONE:
out_swizzle[i] = PIPE_SWIZZLE_1;
break;
default:
unreachable("unknown swizzle");
}
}
}

View File

@@ -88,6 +88,9 @@ vk_format_stencil_only(VkFormat format)
return VK_FORMAT_S8_UINT;
}
void vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,
unsigned char out_swizzle[4]);
#ifdef __cplusplus
}
#endif