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 <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8097>
This commit is contained in:
Chad Versace
2020-12-10 11:57:46 -08:00
committed by chadversary
parent 3e6d3bca1d
commit ffc08351e1
4 changed files with 14 additions and 9 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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;

View File

@@ -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,