anv: Make anv_image_view derive from vk_image_view

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12023>
This commit is contained in:
Jason Ekstrand
2021-07-21 22:03:12 -05:00
committed by Marge Bot
parent 9cc004b3d0
commit ea410173d6
4 changed files with 41 additions and 126 deletions

View File

@@ -2421,12 +2421,9 @@ alloc_surface_state(struct anv_device *device)
}
static enum isl_channel_select
remap_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component,
remap_swizzle(VkComponentSwizzle swizzle,
struct isl_swizzle format_swizzle)
{
if (swizzle == VK_COMPONENT_SWIZZLE_IDENTITY)
swizzle = component;
switch (swizzle) {
case VK_COMPONENT_SWIZZLE_ZERO: return ISL_CHANNEL_SELECT_ZERO;
case VK_COMPONENT_SWIZZLE_ONE: return ISL_CHANNEL_SELECT_ONE;
@@ -2632,15 +2629,13 @@ anv_CreateImageView(VkDevice _device,
ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
struct anv_image_view *iview;
iview = vk_object_zalloc(&device->vk, pAllocator, sizeof(*iview),
VK_OBJECT_TYPE_IMAGE_VIEW);
iview = vk_image_view_create(&device->vk, pCreateInfo,
pAllocator, sizeof(*iview));
if (iview == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
assert(range->layerCount > 0);
assert(range->baseMipLevel < image->vk.mip_levels);
iview->image = image;
iview->n_planes = anv_image_aspect_get_planes(iview->vk.aspects);
/* Check if a conversion info was passed. */
const struct anv_format *conv_format = NULL;
@@ -2660,48 +2655,6 @@ anv_CreateImageView(VkDevice _device,
conv_format = conversion->format;
}
const VkImageUsageFlags image_usage =
vk_image_usage(&image->vk, range->aspectMask);
const VkImageViewUsageCreateInfo *usage_info =
vk_find_struct_const(pCreateInfo, IMAGE_VIEW_USAGE_CREATE_INFO);
VkImageUsageFlags view_usage = usage_info ? usage_info->usage : image_usage;
/* View usage should be a subset of image usage */
assert((view_usage & ~image_usage) == 0);
assert(view_usage & (VK_IMAGE_USAGE_SAMPLED_BIT |
VK_IMAGE_USAGE_STORAGE_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT));
uint32_t layer_count = vk_image_subresource_layer_count(&image->vk, range);
switch (image->vk.image_type) {
default:
unreachable("bad VkImageType");
case VK_IMAGE_TYPE_1D:
case VK_IMAGE_TYPE_2D:
assert(range->baseArrayLayer + layer_count - 1
<= image->vk.array_layers);
break;
case VK_IMAGE_TYPE_3D:
assert(range->baseArrayLayer + layer_count - 1
<= anv_minify(image->vk.extent.depth, range->baseMipLevel));
break;
}
iview->image = image;
/* First expand aspects to the image's ones (for example
* VK_IMAGE_ASPECT_COLOR_BIT will be converted to
* VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT |
* VK_IMAGE_ASPECT_PLANE_2_BIT for an image of format
* VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM.
*/
iview->aspects = vk_image_expand_aspect_mask(&image->vk, range->aspectMask);
iview->n_planes = anv_image_aspect_get_planes(iview->aspects);
iview->vk_format = pCreateInfo->format;
#ifdef ANDROID
/* "If image has an external format, format must be VK_FORMAT_UNDEFINED." */
assert(!image->vk.android_external_format ||
@@ -2711,74 +2664,40 @@ anv_CreateImageView(VkDevice _device,
/* Format is undefined, this can happen when using external formats. Set
* view format from the passed conversion info.
*/
if (iview->vk_format == VK_FORMAT_UNDEFINED && conv_format)
iview->vk_format = conv_format->vk_format;
iview->extent = vk_image_mip_level_extent(&image->vk, range->baseMipLevel);
if (iview->vk.format == VK_FORMAT_UNDEFINED && conv_format)
iview->vk.format = conv_format->vk_format;
/* Now go through the underlying image selected planes and map them to
* planes in the image view.
*/
anv_foreach_image_aspect_bit(iaspect_bit, image, iview->aspects) {
anv_foreach_image_aspect_bit(iaspect_bit, image, iview->vk.aspects) {
const uint32_t iplane =
anv_aspect_to_plane(image->vk.aspects, 1UL << iaspect_bit);
const uint32_t vplane =
anv_aspect_to_plane(iview->aspects, 1UL << iaspect_bit);
anv_aspect_to_plane(iview->vk.aspects, 1UL << iaspect_bit);
struct anv_format_plane format;
if (image->vk.aspects & (VK_IMAGE_ASPECT_DEPTH_BIT |
VK_IMAGE_ASPECT_STENCIL_BIT)) {
/* With depth/stencil images, we're always given the full
* depth/stencil format even if we're only taking one aspect.
*/
assert(iview->vk_format == image->vk.format);
format = anv_get_format_aspect(&device->info, iview->vk_format,
1u << iaspect_bit, image->vk.tiling);
} else {
/* With color images, we have three cases:
*
* 1. It's a single-plane image in which case vplane=0.
*
* 2. It's a YCbCr view of a multi-plane image in which case the
* client will have asked for VK_IMAGE_ASPECT_COLOR_BIT and the
* format provided will be the full planar format. In this case,
* we want all the planes.
*
* 3. It's a single-plane view of a multi-plane image in which case
* the client will have asked for VK_IMAGE_ASPECT_PLANE_N_BIT and
* will have provided a format compatible with that specific
* plane of the multi-planar format.
*
* In all three cases, the format provided by the client corresponds
* to exactly the planes we have in the view so we can just grab the
* format plane based on vplane.
*/
format = anv_get_format_plane(&device->info, iview->vk_format,
vplane, image->vk.tiling);
}
format = anv_get_format_plane(&device->info, iview->vk.format,
vplane, image->vk.tiling);
iview->planes[vplane].image_plane = iplane;
iview->planes[vplane].isl = (struct isl_view) {
.format = format.isl_format,
.base_level = range->baseMipLevel,
.levels = vk_image_subresource_level_count(&image->vk, range),
.base_array_layer = range->baseArrayLayer,
.array_len = layer_count,
.base_level = iview->vk.base_mip_level,
.levels = iview->vk.level_count,
.base_array_layer = iview->vk.base_array_layer,
.array_len = iview->vk.layer_count,
.swizzle = {
.r = remap_swizzle(pCreateInfo->components.r,
VK_COMPONENT_SWIZZLE_R, format.swizzle),
.g = remap_swizzle(pCreateInfo->components.g,
VK_COMPONENT_SWIZZLE_G, format.swizzle),
.b = remap_swizzle(pCreateInfo->components.b,
VK_COMPONENT_SWIZZLE_B, format.swizzle),
.a = remap_swizzle(pCreateInfo->components.a,
VK_COMPONENT_SWIZZLE_A, format.swizzle),
.r = remap_swizzle(iview->vk.swizzle.r, format.swizzle),
.g = remap_swizzle(iview->vk.swizzle.g, format.swizzle),
.b = remap_swizzle(iview->vk.swizzle.b, format.swizzle),
.a = remap_swizzle(iview->vk.swizzle.a, format.swizzle),
},
};
if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
iview->planes[vplane].isl.base_array_layer = 0;
iview->planes[vplane].isl.array_len = iview->extent.depth;
iview->planes[vplane].isl.array_len = iview->vk.extent.depth;
}
if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE ||
@@ -2788,9 +2707,9 @@ anv_CreateImageView(VkDevice _device,
iview->planes[vplane].isl.usage = 0;
}
if (view_usage & VK_IMAGE_USAGE_SAMPLED_BIT ||
(view_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT &&
!(iview->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV))) {
if (iview->vk.usage & VK_IMAGE_USAGE_SAMPLED_BIT ||
(iview->vk.usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT &&
!(iview->vk.aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV))) {
iview->planes[vplane].optimal_sampler_surface_state.state = alloc_surface_state(device);
iview->planes[vplane].general_sampler_surface_state.state = alloc_surface_state(device);
@@ -2821,7 +2740,7 @@ anv_CreateImageView(VkDevice _device,
}
/* NOTE: This one needs to go last since it may stomp isl_view.format */
if (view_usage & VK_IMAGE_USAGE_STORAGE_BIT) {
if (iview->vk.usage & VK_IMAGE_USAGE_STORAGE_BIT) {
if (isl_is_storage_image_format(format.isl_format)) {
iview->planes[vplane].storage_surface_state.state =
alloc_surface_state(device);
@@ -2897,7 +2816,7 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview,
}
}
vk_object_free(&device->vk, pAllocator, iview);
vk_image_view_destroy(&device->vk, pAllocator, &iview->vk);
}