From: Jason Ekstrand Date: Thu, 31 May 2018 00:16:52 +0000 (-0700) Subject: anv: Use full anv_addresses in anv_surface_state X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=de1c5c1b503fb190e5d169654ce207777e699195;p=mesa.git anv: Use full anv_addresses in anv_surface_state This refactors surface state filling to work entirely in terms of anv_addresses instead of offsets. This should make things simpler for when we go to soft-pin image buffers. Among other things, add_image_view_relocs now only cares about the addresses in the surface state and doesn't really need the image view anymore. Reviewed-by: Scott D Phillips --- diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 42496b6414c..52882080fd0 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1067,20 +1067,10 @@ anv_image_fill_surface_state(struct anv_device *device, if (!clear_color) clear_color = &default_clear_color; - const uint64_t address = image->planes[plane].bo_offset + surface->offset; - const uint64_t aux_address = aux_usage == ISL_AUX_USAGE_NONE ? - 0 : (image->planes[plane].bo_offset + aux_surface->offset); - - struct anv_address clear_address = { .bo = NULL }; - state_inout->clear_address = 0; - - if (device->info.gen >= 10 && aux_usage != ISL_AUX_USAGE_NONE) { - if (aux_usage == ISL_AUX_USAGE_HIZ) { - clear_address = (struct anv_address) { .bo = &device->hiz_clear_bo }; - } else { - clear_address = anv_image_get_clear_color_addr(device, image, aspect); - } - } + const struct anv_address address = { + .bo = image->planes[plane].bo, + .offset = image->planes[plane].bo_offset + surface->offset, + }; if (view_usage == ISL_SURF_USAGE_STORAGE_BIT && !(flags & ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY) && @@ -1092,14 +1082,14 @@ anv_image_fill_surface_state(struct anv_device *device, */ assert(aux_usage == ISL_AUX_USAGE_NONE); isl_buffer_fill_state(&device->isl_dev, state_inout->state.map, - .address = address, + .address = anv_address_physical(address), .size = surface->isl.size, .format = ISL_FORMAT_RAW, .stride = 1, .mocs = device->default_mocs); state_inout->address = address, - state_inout->aux_address = 0; - state_inout->clear_address = 0; + state_inout->aux_address = ANV_NULL_ADDRESS; + state_inout->clear_address = ANV_NULL_ADDRESS; } else { if (view_usage == ISL_SURF_USAGE_STORAGE_BIT && !(flags & ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY)) { @@ -1165,20 +1155,43 @@ anv_image_fill_surface_state(struct anv_device *device, } } + state_inout->address = anv_address_add(address, offset_B); + + struct anv_address aux_address = ANV_NULL_ADDRESS; + if (aux_usage != ISL_AUX_USAGE_NONE) { + aux_address = (struct anv_address) { + .bo = image->planes[plane].bo, + .offset = image->planes[plane].bo_offset + aux_surface->offset, + }; + } + state_inout->aux_address = aux_address; + + struct anv_address clear_address = ANV_NULL_ADDRESS; + if (device->info.gen >= 10 && aux_usage != ISL_AUX_USAGE_NONE) { + if (aux_usage == ISL_AUX_USAGE_HIZ) { + clear_address = (struct anv_address) { + .bo = &device->hiz_clear_bo, + .offset = 0, + }; + } else { + clear_address = anv_image_get_clear_color_addr(device, image, aspect); + } + } + state_inout->clear_address = clear_address; + isl_surf_fill_state(&device->isl_dev, state_inout->state.map, .surf = isl_surf, .view = &view, - .address = address + offset_B, + .address = anv_address_physical(state_inout->address), .clear_color = *clear_color, .aux_surf = &aux_surface->isl, .aux_usage = aux_usage, - .aux_address = aux_address, - .clear_address = clear_address.offset, - .use_clear_address = clear_address.bo != NULL, + .aux_address = anv_address_physical(aux_address), + .clear_address = anv_address_physical(clear_address), + .use_clear_address = !anv_address_is_null(clear_address), .mocs = device->default_mocs, .x_offset_sa = tile_x_sa, .y_offset_sa = tile_y_sa); - state_inout->address = address + offset_B; /* With the exception of gen8, the bottom 12 bits of the MCS base address * are used to store other information. This should be ok, however, @@ -1186,15 +1199,14 @@ anv_image_fill_surface_state(struct anv_device *device, */ uint32_t *aux_addr_dw = state_inout->state.map + device->isl_dev.ss.aux_addr_offset; - assert((aux_address & 0xfff) == 0); - assert(aux_address == (*aux_addr_dw & 0xfffff000)); - state_inout->aux_address = *aux_addr_dw; + assert((aux_address.offset & 0xfff) == 0); + state_inout->aux_address.offset |= *aux_addr_dw & 0xfff; if (device->info.gen >= 10 && clear_address.bo) { uint32_t *clear_addr_dw = state_inout->state.map + device->isl_dev.ss.clear_color_state_offset; assert((clear_address.offset & 0x3f) == 0); - state_inout->clear_address = *clear_addr_dw; + state_inout->clear_address.offset |= *clear_addr_dw & 0x3f; } } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index bcd2197e7f9..a18a1d1bede 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1778,20 +1778,20 @@ struct anv_surface_state { * * This address is relative to the start of the BO. */ - uint64_t address; + struct anv_address address; /* Address of the aux surface, if any * - * This field is 0 if and only if no aux surface exists. + * This field is ANV_NULL_ADDRESS if and only if no aux surface exists. * - * This address is relative to the start of the BO. With the exception of - * gen8, the bottom 12 bits of this address include extra aux information. + * With the exception of gen8, the bottom 12 bits of this address' offset + * include extra aux information. */ - uint64_t aux_address; + struct anv_address aux_address; /* Address of the clear color, if any * * This address is relative to the start of the BO. */ - uint64_t clear_address; + struct anv_address clear_address; }; /** diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index afccad8ef80..ad792658a83 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -180,34 +180,31 @@ add_surface_state_reloc(struct anv_cmd_buffer *cmd_buffer, static void add_image_view_relocs(struct anv_cmd_buffer *cmd_buffer, - const struct anv_image_view *image_view, - const uint32_t plane, struct anv_surface_state state) { const struct isl_device *isl_dev = &cmd_buffer->device->isl_dev; - const struct anv_image *image = image_view->image; - uint32_t image_plane = image_view->planes[plane].image_plane; + assert(!anv_address_is_null(state.address)); add_surface_state_reloc(cmd_buffer, state.state, - image->planes[image_plane].bo, state.address); + state.address.bo, state.address.offset); - if (state.aux_address) { + if (!anv_address_is_null(state.aux_address)) { VkResult result = anv_reloc_list_add(&cmd_buffer->surface_relocs, &cmd_buffer->pool->alloc, state.state.offset + isl_dev->ss.aux_addr_offset, - image->planes[image_plane].bo, state.aux_address); + state.aux_address.bo, state.aux_address.offset); if (result != VK_SUCCESS) anv_batch_set_error(&cmd_buffer->batch, result); } - if (state.clear_address) { + if (!anv_address_is_null(state.clear_address)) { VkResult result = anv_reloc_list_add(&cmd_buffer->surface_relocs, &cmd_buffer->pool->alloc, state.state.offset + isl_dev->ss.clear_color_state_offset, - image->planes[image_plane].bo, state.clear_address); + state.clear_address.bo, state.clear_address.offset); if (result != VK_SUCCESS) anv_batch_set_error(&cmd_buffer->batch, result); } @@ -1271,8 +1268,7 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer, &state->attachments[i].color, NULL); - add_image_view_relocs(cmd_buffer, iview, 0, - state->attachments[i].color); + add_image_view_relocs(cmd_buffer, state->attachments[i].color); } else { depth_stencil_attachment_compute_aux_usage(cmd_buffer->device, state, i, @@ -1291,8 +1287,7 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer, &state->attachments[i].input, NULL); - add_image_view_relocs(cmd_buffer, iview, 0, - state->attachments[i].input); + add_image_view_relocs(cmd_buffer, state->attachments[i].input); } } } @@ -2050,8 +2045,7 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer, desc->image_view->planes[binding->plane].optimal_sampler_surface_state; surface_state = sstate.state; assert(surface_state.alloc_size); - add_image_view_relocs(cmd_buffer, desc->image_view, - binding->plane, sstate); + add_image_view_relocs(cmd_buffer, sstate); break; } case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: @@ -2066,8 +2060,7 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer, desc->image_view->planes[binding->plane].optimal_sampler_surface_state; surface_state = sstate.state; assert(surface_state.alloc_size); - add_image_view_relocs(cmd_buffer, desc->image_view, - binding->plane, sstate); + add_image_view_relocs(cmd_buffer, sstate); } else { /* For color input attachments, we create the surface state at * vkBeginRenderPass time so that we can include aux and clear @@ -2086,8 +2079,7 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer, : desc->image_view->planes[binding->plane].storage_surface_state; surface_state = sstate.state; assert(surface_state.alloc_size); - add_image_view_relocs(cmd_buffer, desc->image_view, - binding->plane, sstate); + add_image_view_relocs(cmd_buffer, sstate); struct brw_image_param *image_param = &cmd_buffer->state.push_constants[stage]->images[image++];