From ffc08351e1f559b46a57ba2b808c280afc646fe1 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Thu, 10 Dec 2020 11:57:46 -0800 Subject: [PATCH] anv: Add anv_surface_is_valid() Current code checks for surface validity with `surface.isl.size_B > 0`. Replace the checks with anv_surface_is_valid(). This prepares for adding new members to anv_surface that may be accidentally used as a validity-indicator. Reviewed-by: Jason Ekstrand Part-of: --- src/intel/vulkan/anv_blorp.c | 2 +- src/intel/vulkan/anv_image.c | 8 ++++---- src/intel/vulkan/anv_private.h | 7 ++++++- src/intel/vulkan/genX_cmd_buffer.c | 6 +++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c index 530cc4e04c6..ebeb9014f8f 100644 --- a/src/intel/vulkan/anv_blorp.c +++ b/src/intel/vulkan/anv_blorp.c @@ -276,7 +276,7 @@ get_blorp_surf_for_anv_shadow_image(const struct anv_device *device, { uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect); - if (image->planes[plane].shadow_surface.isl.size_B == 0) + if (!anv_surface_is_valid(&image->planes[plane].shadow_surface)) return false; *blorp_surf = (struct blorp_surf) { diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 08e6a972435..b88c2e367a5 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -375,7 +375,7 @@ add_aux_surface_if_supported(struct anv_device *device, bool ok; /* The aux surface must not be already added. */ - assert(image->planes[plane].aux_surface.isl.size_B == 0); + assert(!anv_surface_is_valid(&image->planes[plane].aux_surface)); if ((isl_extra_usage_flags & ISL_SURF_USAGE_DISABLE_AUX_BIT)) return VK_SUCCESS; @@ -639,7 +639,7 @@ check_surfaces(const struct anv_image *image, const struct anv_surface *primary_surface = &plane->primary_surface; const struct anv_surface *aux_surface = &plane->aux_surface; uintmax_t last_surface_offset = MAX2(primary_surface->offset, aux_surface->offset); - uintmax_t last_surface_size = aux_surface->isl.size_B > 0 + uintmax_t last_surface_size = anv_surface_is_valid(aux_surface) ? aux_surface->isl.size_B : primary_surface->isl.size_B; uintmax_t last_surface_end = last_surface_offset + last_surface_size; @@ -1857,7 +1857,7 @@ anv_image_fill_surface_state(struct anv_device *device, * the primary surface. The shadow surface will be tiled, unlike the main * surface, so it should get significantly better performance. */ - if (image->planes[plane].shadow_surface.isl.size_B > 0 && + if (anv_surface_is_valid(&image->planes[plane].shadow_surface) && isl_format_is_compressed(view.format) && (flags & ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL)) { assert(isl_format_is_compressed(surface->isl.format)); @@ -1869,7 +1869,7 @@ anv_image_fill_surface_state(struct anv_device *device, /* For texturing from stencil on gen7, we have to sample from a shadow * surface because we don't support W-tiling in the sampler. */ - if (image->planes[plane].shadow_surface.isl.size_B > 0 && + if (anv_surface_is_valid(&image->planes[plane].shadow_surface) && aspect == VK_IMAGE_ASPECT_STENCIL_BIT) { assert(device->info.gen == 7); assert(view_usage & ISL_SURF_USAGE_TEXTURE_BIT); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 38ce4329c00..8fb8ce9fa16 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -3711,7 +3711,6 @@ anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm); * Subsurface of an anv_image. */ struct anv_surface { - /** Valid only if isl_surf::size_B > 0. */ struct isl_surf isl; /** @@ -3720,6 +3719,12 @@ struct anv_surface { uint32_t offset; }; +static inline bool MUST_CHECK +anv_surface_is_valid(const struct anv_surface *surface) +{ + return surface->isl.size_B > 0; +} + struct anv_image { struct vk_object_base base; diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 27a3d57cebf..eddc8e1e47f 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -663,7 +663,7 @@ transition_stencil_buffer(struct anv_cmd_buffer *cmd_buffer, * destinations, we can update it as part of the transfer op. For the other * layouts, we delay the copy until a transition into some other layout. */ - if (image->planes[plane].shadow_surface.isl.size_B > 0 && + if (anv_surface_is_valid(&image->planes[plane].shadow_surface) && vk_image_layout_stencil_write_optimal(initial_layout) && !vk_image_layout_stencil_write_optimal(final_layout)) { anv_image_copy_to_shadow(cmd_buffer, image, @@ -1144,7 +1144,7 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer, uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect); - if (image->planes[plane].shadow_surface.isl.size_B > 0 && + if (anv_surface_is_valid(&image->planes[plane].shadow_surface) && final_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { /* This surface is a linear compressed image with a tiled shadow surface * for texturing. The client is about to use it in READ_ONLY_OPTIMAL so @@ -6021,7 +6021,7 @@ cmd_buffer_end_subpass(struct anv_cmd_buffer *cmd_buffer) uint32_t plane = anv_image_aspect_to_plane(image->aspects, VK_IMAGE_ASPECT_STENCIL_BIT); - if (image->planes[plane].shadow_surface.isl.size_B > 0 && + if (anv_surface_is_valid(&image->planes[plane].shadow_surface) && att_state->current_stencil_layout == VK_IMAGE_LAYOUT_GENERAL) { assert(image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT); anv_image_copy_to_shadow(cmd_buffer, image,