[Mesa-dev] [PATCH 11/11] anv: Add a new anv_surface_state struct
Jason Ekstrand
jason at jlekstrand.net
Wed Jul 12 00:04:40 UTC 2017
This struct represents a full surface state including the addresses of
the referenced main and auxiliary surfaces (if any). This makes
relocation setup substantially simpler and allows us to move 100% of the
surface state setup logic into anv_image where it belongs. Before, we
were manually fishing data out of surface states when emitting
relocations so we knew how to offset aux address. It's best to keep all
of the surface state emit logic together. This also gets us closer, at
least cosmetically, to a world of no relocations where addresses are
placed in surface states up-front.
---
src/intel/vulkan/anv_blorp.c | 4 +-
src/intel/vulkan/anv_image.c | 68 +++++++++++++++++-----------
src/intel/vulkan/anv_private.h | 35 ++++++++++-----
src/intel/vulkan/genX_cmd_buffer.c | 91 ++++++++++++++------------------------
4 files changed, 101 insertions(+), 97 deletions(-)
diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index 459d57e..16f7f42 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -994,7 +994,7 @@ clear_color_attachment(struct anv_cmd_buffer *cmd_buffer,
uint32_t binding_table;
VkResult result =
- binding_table_for_surface_state(cmd_buffer, att_state->color_rt_state,
+ binding_table_for_surface_state(cmd_buffer, att_state->color.state,
&binding_table);
if (result != VK_SUCCESS)
return;
@@ -1606,7 +1606,7 @@ ccs_resolve_attachment(struct anv_cmd_buffer *cmd_buffer,
cmd_buffer->state.pending_pipe_bits |=
ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT | ANV_PIPE_CS_STALL_BIT;
- anv_ccs_resolve(cmd_buffer, att_state->color_rt_state, image,
+ anv_ccs_resolve(cmd_buffer, att_state->color.state, image,
iview->isl.base_level, fb->layers, resolve_op);
cmd_buffer->state.pending_pipe_bits |=
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 82c4718..1036821 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -563,7 +563,7 @@ anv_image_view_fill_state(struct anv_device *device,
enum isl_aux_usage aux_usage,
const union isl_color_value *clear_color,
enum anv_image_view_state_flags flags,
- struct anv_state *state,
+ struct anv_surface_state *state_inout,
struct brw_image_param *image_param_out)
{
const struct anv_surface *surface =
@@ -584,6 +584,10 @@ anv_image_view_fill_state(struct anv_device *device,
if (!clear_color)
clear_color = &default_clear_color;
+ const uint64_t address = iview->image->offset + surface->offset;
+ const uint64_t aux_address = (aux_usage == ISL_AUX_USAGE_NONE) ?
+ 0 : iview->image->offset + iview->image->aux_surface.offset;
+
if (view_usage == ISL_SURF_USAGE_STORAGE_BIT &&
!(flags & ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY) &&
!isl_has_matching_typed_storage_image_format(&device->info,
@@ -593,11 +597,14 @@ anv_image_view_fill_state(struct anv_device *device,
* the shader.
*/
assert(aux_usage == ISL_AUX_USAGE_NONE);
- isl_buffer_fill_state(&device->isl_dev, state->map,
+ isl_buffer_fill_state(&device->isl_dev, state_inout->state.map,
+ .address = address,
.size = surface->isl.size,
.format = ISL_FORMAT_RAW,
.stride = 1,
.mocs = device->default_mocs);
+ state_inout->address = address,
+ state_inout->aux_address = 0;
} else {
if (view_usage == ISL_SURF_USAGE_STORAGE_BIT &&
!(flags & ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY)) {
@@ -610,16 +617,32 @@ anv_image_view_fill_state(struct anv_device *device,
view.format);
}
- isl_surf_fill_state(&device->isl_dev, state->map,
+ isl_surf_fill_state(&device->isl_dev, state_inout->state.map,
.surf = &surface->isl,
.view = &view,
+ .address = address,
.clear_color = *clear_color,
.aux_surf = &iview->image->aux_surface.isl,
.aux_usage = aux_usage,
+ .aux_address = aux_address,
.mocs = device->default_mocs);
+ state_inout->address = address;
+ if (device->info.gen >= 8) {
+ state_inout->aux_address = aux_address;
+ } else {
+ /* On gen7 and prior, the bottom 12 bits of the MCS base address are
+ * used to store other information. This should be ok, however,
+ * because surface buffer addresses are always 4K page alinged.
+ */
+ 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;
+ }
}
- anv_state_flush(device, *state);
+ anv_state_flush(device, state_inout->state);
if (image_param_out) {
assert(view_usage == ISL_SURF_USAGE_STORAGE_BIT);
@@ -666,12 +689,7 @@ anv_CreateImageView(VkDevice _device,
break;
}
- const struct anv_surface *surface =
- anv_image_get_surface_for_aspect_mask(image, range->aspectMask);
-
iview->image = image;
- iview->bo = image->bo;
- iview->offset = image->offset + surface->offset;
iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask;
iview->vk_format = pCreateInfo->format;
@@ -724,26 +742,26 @@ anv_CreateImageView(VkDevice _device,
if (image->usage & VK_IMAGE_USAGE_SAMPLED_BIT ||
(image->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT &&
!(iview->aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT))) {
- iview->optimal_sampler_surface_state = alloc_surface_state(device);
- iview->general_sampler_surface_state = alloc_surface_state(device);
+ iview->optimal_sampler_surface_state.state = alloc_surface_state(device);
+ iview->general_sampler_surface_state.state = alloc_surface_state(device);
- iview->general_sampler_aux_usage =
+ enum isl_aux_usage general_aux_usage =
anv_layout_to_aux_usage(&device->info, image, iview->aspect_mask,
VK_IMAGE_LAYOUT_GENERAL);
- iview->optimal_sampler_aux_usage =
+ enum isl_aux_usage optimal_aux_usage =
anv_layout_to_aux_usage(&device->info, image, iview->aspect_mask,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
anv_image_view_fill_state(device, iview,
ISL_SURF_USAGE_TEXTURE_BIT,
- iview->optimal_sampler_aux_usage, NULL,
+ optimal_aux_usage, NULL,
ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL,
&iview->optimal_sampler_surface_state,
NULL);
anv_image_view_fill_state(device, iview,
ISL_SURF_USAGE_TEXTURE_BIT,
- iview->general_sampler_aux_usage, NULL,
+ general_aux_usage, NULL,
0,
&iview->general_sampler_surface_state,
NULL);
@@ -751,8 +769,8 @@ anv_CreateImageView(VkDevice _device,
/* NOTE: This one needs to go last since it may stomp isl_view.format */
if (image->usage & VK_IMAGE_USAGE_STORAGE_BIT) {
- iview->storage_surface_state = alloc_surface_state(device);
- iview->writeonly_storage_surface_state = alloc_surface_state(device);
+ iview->storage_surface_state.state = alloc_surface_state(device);
+ iview->writeonly_storage_surface_state.state = alloc_surface_state(device);
anv_image_view_fill_state(device, iview,
ISL_SURF_USAGE_STORAGE_BIT,
@@ -784,24 +802,24 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview,
if (!iview)
return;
- if (iview->optimal_sampler_surface_state.alloc_size > 0) {
+ if (iview->optimal_sampler_surface_state.state.alloc_size > 0) {
anv_state_pool_free(&device->surface_state_pool,
- iview->optimal_sampler_surface_state);
+ iview->optimal_sampler_surface_state.state);
}
- if (iview->general_sampler_surface_state.alloc_size > 0) {
+ if (iview->general_sampler_surface_state.state.alloc_size > 0) {
anv_state_pool_free(&device->surface_state_pool,
- iview->general_sampler_surface_state);
+ iview->general_sampler_surface_state.state);
}
- if (iview->storage_surface_state.alloc_size > 0) {
+ if (iview->storage_surface_state.state.alloc_size > 0) {
anv_state_pool_free(&device->surface_state_pool,
- iview->storage_surface_state);
+ iview->storage_surface_state.state);
}
- if (iview->writeonly_storage_surface_state.alloc_size > 0) {
+ if (iview->writeonly_storage_surface_state.state.alloc_size > 0) {
anv_state_pool_free(&device->surface_state_pool,
- iview->writeonly_storage_surface_state);
+ iview->writeonly_storage_surface_state.state);
}
vk_free2(&device->alloc, pAllocator, iview);
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 569e256..453615a 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1470,6 +1470,23 @@ void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
const struct anv_dynamic_state *src,
uint32_t copy_mask);
+struct anv_surface_state {
+ struct anv_state state;
+ /** Address of the surface referred to by this state
+ *
+ * This address is relative to the start of the BO.
+ */
+ uint64_t address;
+ /* Address of the aux surface, if any
+ *
+ * This field is 0 if and only if no aux surface exists.
+ *
+ * This address is relative to the start of the BO. On gen7, the bottom 12
+ * bits of this address include extra aux information.
+ */
+ uint64_t aux_address;
+};
+
/**
* Attachment state when recording a renderpass instance.
*
@@ -1478,8 +1495,8 @@ void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
struct anv_attachment_state {
enum isl_aux_usage aux_usage;
enum isl_aux_usage input_aux_usage;
- struct anv_state color_rt_state;
- struct anv_state input_att_state;
+ struct anv_surface_state color;
+ struct anv_surface_state input;
VkImageLayout current_layout;
VkImageAspectFlags pending_clear_aspects;
@@ -2133,8 +2150,6 @@ anv_get_levelCount(const struct anv_image *image,
struct anv_image_view {
const struct anv_image *image; /**< VkImageViewCreateInfo::image */
- struct anv_bo *bo;
- uint32_t offset; /**< Offset into bo. */
struct isl_view isl;
@@ -2146,23 +2161,21 @@ struct anv_image_view {
* RENDER_SURFACE_STATE when using image as a sampler surface with an image
* layout of SHADER_READ_ONLY_OPTIMAL or DEPTH_STENCIL_READ_ONLY_OPTIMAL.
*/
- enum isl_aux_usage optimal_sampler_aux_usage;
- struct anv_state optimal_sampler_surface_state;
+ struct anv_surface_state optimal_sampler_surface_state;
/**
* RENDER_SURFACE_STATE when using image as a sampler surface with an image
* layout of GENERAL.
*/
- enum isl_aux_usage general_sampler_aux_usage;
- struct anv_state general_sampler_surface_state;
+ struct anv_surface_state general_sampler_surface_state;
/**
* RENDER_SURFACE_STATE when using image as a storage image. Separate states
* for write-only and readable, using the real format for write-only and the
* lowered format for readable.
*/
- struct anv_state storage_surface_state;
- struct anv_state writeonly_storage_surface_state;
+ struct anv_surface_state storage_surface_state;
+ struct anv_surface_state writeonly_storage_surface_state;
struct brw_image_param storage_image_param;
};
@@ -2178,7 +2191,7 @@ void anv_image_view_fill_state(struct anv_device *device,
enum isl_aux_usage aux_usage,
const union isl_color_value *clear_color,
enum anv_image_view_state_flags flags,
- struct anv_state *state,
+ struct anv_surface_state *state_inout,
struct brw_image_param *image_param_out);
struct anv_image_create_info {
diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index 3ab90f5..552b4f1 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -179,34 +179,20 @@ add_surface_state_reloc(struct anv_cmd_buffer *cmd_buffer,
}
static void
-add_image_relocs(struct anv_cmd_buffer * const cmd_buffer,
- const struct anv_image * const image,
- const VkImageAspectFlags aspect_mask,
- const enum isl_aux_usage aux_usage,
- const struct anv_state state)
+add_image_relocs(struct anv_cmd_buffer *cmd_buffer,
+ const struct anv_image *image,
+ struct anv_surface_state state)
{
const struct isl_device *isl_dev = &cmd_buffer->device->isl_dev;
- const uint32_t surf_offset = image->offset +
- anv_image_get_surface_for_aspect_mask(image, aspect_mask)->offset;
- add_surface_state_reloc(cmd_buffer, state, image->bo, surf_offset);
-
- if (aux_usage != ISL_AUX_USAGE_NONE) {
- uint32_t aux_offset = image->offset + image->aux_surface.offset;
-
- /* On gen7 and prior, the bottom 12 bits of the MCS base address are
- * used to store other information. This should be ok, however, because
- * surface buffer addresses are always 4K page alinged.
- */
- assert((aux_offset & 0xfff) == 0);
- uint32_t *aux_addr_dw = state.map + isl_dev->ss.aux_addr_offset;
- aux_offset += *aux_addr_dw & 0xfff;
+ add_surface_state_reloc(cmd_buffer, state.state, image->bo, state.address);
+ if (state.aux_address) {
VkResult result =
anv_reloc_list_add(&cmd_buffer->surface_relocs,
&cmd_buffer->pool->alloc,
- state.offset + isl_dev->ss.aux_addr_offset,
- image->bo, aux_offset);
+ state.state.offset + isl_dev->ss.aux_addr_offset,
+ image->bo, state.aux_address);
if (result != VK_SUCCESS)
anv_batch_set_error(&cmd_buffer->batch, result);
}
@@ -467,13 +453,13 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer,
for (uint32_t i = 0; i < pass->attachment_count; ++i) {
if (vk_format_is_color(pass->attachments[i].format)) {
- state->attachments[i].color_rt_state = next_state;
+ state->attachments[i].color.state = next_state;
next_state.offset += ss_stride;
next_state.map += ss_stride;
}
if (need_input_attachment_state(&pass->attachments[i])) {
- state->attachments[i].input_att_state = next_state;
+ state->attachments[i].input.state = next_state;
next_state.offset += ss_stride;
next_state.map += ss_stride;
}
@@ -544,12 +530,11 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer,
state->attachments[i].aux_usage,
&clear_color,
0,
- &state->attachments[i].color_rt_state,
+ &state->attachments[i].color,
NULL);
- add_image_relocs(cmd_buffer, iview->image, iview->aspect_mask,
- state->attachments[i].aux_usage,
- state->attachments[i].color_rt_state);
+ add_image_relocs(cmd_buffer, iview->image,
+ state->attachments[i].color);
} else {
/* This field will be initialized after the first subpass
* transition.
@@ -565,12 +550,11 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer,
state->attachments[i].input_aux_usage,
&clear_color,
0,
- &state->attachments[i].input_att_state,
+ &state->attachments[i].input,
NULL);
- add_image_relocs(cmd_buffer, iview->image, iview->aspect_mask,
- state->attachments[i].input_aux_usage,
- state->attachments[i].input_att_state);
+ add_image_relocs(cmd_buffer, iview->image,
+ state->attachments[i].input);
}
}
}
@@ -1168,7 +1152,7 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
if (att == VK_ATTACHMENT_UNUSED) {
surface_state = cmd_buffer->state.null_surface_state;
} else {
- surface_state = cmd_buffer->state.attachments[att].color_rt_state;
+ surface_state = cmd_buffer->state.attachments[att].color.state;
}
} else {
surface_state = cmd_buffer->state.null_surface_state;
@@ -1190,18 +1174,13 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: {
- enum isl_aux_usage aux_usage;
- if (desc->layout == VK_IMAGE_LAYOUT_GENERAL) {
- surface_state = desc->image_view->general_sampler_surface_state;
- aux_usage = desc->image_view->general_sampler_aux_usage;
- } else {
- surface_state = desc->image_view->optimal_sampler_surface_state;
- aux_usage = desc->image_view->optimal_sampler_aux_usage;
- }
+ struct anv_surface_state sstate =
+ (desc->layout == VK_IMAGE_LAYOUT_GENERAL) ?
+ desc->image_view->general_sampler_surface_state :
+ desc->image_view->optimal_sampler_surface_state;
+ surface_state = sstate.state;
assert(surface_state.alloc_size);
- add_image_relocs(cmd_buffer, desc->image_view->image,
- desc->image_view->aspect_mask,
- aux_usage, surface_state);
+ add_image_relocs(cmd_buffer, desc->image_view->image, sstate);
break;
}
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
@@ -1210,18 +1189,13 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
/* For depth and stencil input attachments, we treat it like any
* old texture that a user may have bound.
*/
- enum isl_aux_usage aux_usage;
- if (desc->layout == VK_IMAGE_LAYOUT_GENERAL) {
- surface_state = desc->image_view->general_sampler_surface_state;
- aux_usage = desc->image_view->general_sampler_aux_usage;
- } else {
- surface_state = desc->image_view->optimal_sampler_surface_state;
- aux_usage = desc->image_view->optimal_sampler_aux_usage;
- }
+ struct anv_surface_state sstate =
+ (desc->layout == VK_IMAGE_LAYOUT_GENERAL) ?
+ desc->image_view->general_sampler_surface_state :
+ desc->image_view->optimal_sampler_surface_state;
+ surface_state = sstate.state;
assert(surface_state.alloc_size);
- add_image_relocs(cmd_buffer, desc->image_view->image,
- desc->image_view->aspect_mask,
- aux_usage, surface_state);
+ add_image_relocs(cmd_buffer, desc->image_view->image, sstate);
} else {
/* For color input attachments, we create the surface state at
* vkBeginRenderPass time so that we can include aux and clear
@@ -1230,18 +1204,17 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
assert(binding->input_attachment_index < subpass->input_count);
const unsigned subpass_att = binding->input_attachment_index;
const unsigned att = subpass->input_attachments[subpass_att].attachment;
- surface_state = cmd_buffer->state.attachments[att].input_att_state;
+ surface_state = cmd_buffer->state.attachments[att].input.state;
}
break;
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
- surface_state = (binding->write_only)
+ struct anv_surface_state sstate = (binding->write_only)
? desc->image_view->writeonly_storage_surface_state
: desc->image_view->storage_surface_state;
+ surface_state = sstate.state;
assert(surface_state.alloc_size);
- add_image_relocs(cmd_buffer, desc->image_view->image,
- desc->image_view->aspect_mask,
- desc->image_view->image->aux_usage, surface_state);
+ add_image_relocs(cmd_buffer, desc->image_view->image, sstate);
struct brw_image_param *image_param =
&cmd_buffer->state.push_constants[stage]->images[image++];
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list