From ea410173d68bc2f9848c123f089117f4947c1ab3 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 21 Jul 2021 22:03:12 -0500 Subject: [PATCH] anv: Make anv_image_view derive from vk_image_view Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_cmd_buffer.c | 4 +- src/intel/vulkan/anv_image.c | 131 +++++++------------------------------ src/intel/vulkan/anv_private.h | 8 +-- src/intel/vulkan/genX_cmd_buffer.c | 24 +++---- 4 files changed, 41 insertions(+), 126 deletions(-) diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 08cfad7..ece9dd3 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -1332,8 +1332,8 @@ anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer) const struct anv_image_view *iview = cmd_buffer->state.attachments[subpass->depth_stencil_attachment->attachment].image_view; - assert(iview->aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | - VK_IMAGE_ASPECT_STENCIL_BIT)); + assert(iview->vk.aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | + VK_IMAGE_ASPECT_STENCIL_BIT)); return iview; } diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 6e2ef8b..eb136db 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -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); } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 9da83af..a5ed4c1 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -4348,14 +4348,10 @@ anv_image_aspects_compatible(VkImageAspectFlags aspects1, } struct anv_image_view { - struct vk_object_base base; + struct vk_image_view vk; const struct anv_image *image; /**< VkImageViewCreateInfo::image */ - VkImageAspectFlags aspects; - VkFormat vk_format; - VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */ - unsigned n_planes; struct { uint32_t image_plane; @@ -4782,7 +4778,7 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(anv_event, base, VkEvent, VK_OBJECT_TYPE_EVENT) VK_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, base, VkFramebuffer, VK_OBJECT_TYPE_FRAMEBUFFER) VK_DEFINE_NONDISP_HANDLE_CASTS(anv_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE) -VK_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, base, VkImageView, +VK_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, vk.base, VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW); VK_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache, base, VkPipelineCache, VK_OBJECT_TYPE_PIPELINE_CACHE) diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index b177fff..da793ab 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -384,8 +384,8 @@ anv_can_fast_clear_color_view(struct anv_device * device, */ if (render_area.offset.x != 0 || render_area.offset.y != 0 || - render_area.extent.width != iview->extent.width || - render_area.extent.height != iview->extent.height) + render_area.extent.width != iview->vk.extent.width || + render_area.extent.height != iview->vk.extent.height) return false; /* On Broadwell and earlier, we can only handle 0/1 clear colors */ @@ -401,7 +401,7 @@ anv_can_fast_clear_color_view(struct anv_device * device, if (isl_color_value_requires_conversion(clear_color, &iview->image->planes[0].primary_surface.isl, &iview->planes[0].isl)) { - anv_perf_warn(device, &iview->base, + anv_perf_warn(device, &iview->vk.base, "Cannot fast-clear to colors which would require " "format conversion on resolve"); return false; @@ -1607,7 +1607,7 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer, att_state->clear_value = begin->pClearValues[i]; struct anv_image_view *iview = state->attachments[i].image_view; - anv_assert(iview->vk_format == pass_att->format); + anv_assert(iview->vk.format == pass_att->format); const uint32_t num_layers = iview->planes[0].isl.array_len; att_state->pending_clear_views = (1 << num_layers) - 1; @@ -2723,7 +2723,7 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer, case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: assert(shader->stage == MESA_SHADER_FRAGMENT); assert(desc->image_view != NULL); - if ((desc->image_view->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) == 0) { + if ((desc->image_view->vk.aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) == 0) { /* For depth and stencil input attachments, we treat it like any * old texture that a user may have bound. */ @@ -2762,7 +2762,7 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer, "corresponding SPIR-V format enum."); vk_debug_report(&cmd_buffer->device->physical->instance->vk, VK_DEBUG_REPORT_ERROR_BIT_EXT, - &desc->image_view->base, + &desc->image_view->vk.base, __LINE__, 0, "anv", "Bound a image to a descriptor where the " "descriptor does not have NonReadable " @@ -6342,7 +6342,7 @@ cmd_buffer_end_subpass(struct anv_cmd_buffer *cmd_buffer) * with depth. */ const struct isl_view *ds_view = &iview->planes[0].isl; - if (iview->aspects & VK_IMAGE_ASPECT_DEPTH_BIT) { + if (iview->vk.aspects & VK_IMAGE_ASPECT_DEPTH_BIT) { genX(cmd_buffer_mark_image_written)(cmd_buffer, iview->image, VK_IMAGE_ASPECT_DEPTH_BIT, att_state->aux_usage, @@ -6350,7 +6350,7 @@ cmd_buffer_end_subpass(struct anv_cmd_buffer *cmd_buffer) ds_view->base_array_layer, fb->layers); } - if (iview->aspects & VK_IMAGE_ASPECT_STENCIL_BIT) { + if (iview->vk.aspects & VK_IMAGE_ASPECT_STENCIL_BIT) { /* Even though stencil may be plane 1, it always shares a * base_level with depth. */ @@ -6405,8 +6405,8 @@ cmd_buffer_end_subpass(struct anv_cmd_buffer *cmd_buffer) enum isl_aux_usage dst_aux_usage = cmd_buffer->state.attachments[dst_att].aux_usage; - assert(src_iview->aspects == VK_IMAGE_ASPECT_COLOR_BIT && - dst_iview->aspects == VK_IMAGE_ASPECT_COLOR_BIT); + assert(src_iview->vk.aspects == VK_IMAGE_ASPECT_COLOR_BIT && + dst_iview->vk.aspects == VK_IMAGE_ASPECT_COLOR_BIT); anv_image_msaa_resolve(cmd_buffer, src_iview->image, src_aux_usage, @@ -6492,8 +6492,8 @@ cmd_buffer_end_subpass(struct anv_cmd_buffer *cmd_buffer) */ if (dst_iview->image->vk.image_type != VK_IMAGE_TYPE_3D && render_area.offset.x == 0 && render_area.offset.y == 0 && - render_area.extent.width == dst_iview->extent.width && - render_area.extent.height == dst_iview->extent.height) + render_area.extent.width == dst_iview->vk.extent.width && + render_area.extent.height == dst_iview->vk.extent.height) dst_initial_layout = VK_IMAGE_LAYOUT_UNDEFINED; transition_depth_buffer(cmd_buffer, dst_iview->image, -- 2.7.4