[Mesa-dev] [PATCH v4 08/23] anv: Use an anv_address in anv_buffer_view
Jason Ekstrand
jason at jlekstrand.net
Thu May 31 15:46:29 UTC 2018
Instead of storing a BO and offset separately, use an anv_address. This
changes anv_fill_buffer_surface_state to use anv_address and we now call
anv_address_physical and pass that into ISL.
---
src/intel/vulkan/anv_descriptor_set.c | 8 +++++---
src/intel/vulkan/anv_device.c | 5 +++--
src/intel/vulkan/anv_image.c | 13 ++++++++-----
src/intel/vulkan/anv_private.h | 8 ++++----
src/intel/vulkan/genX_cmd_buffer.c | 29 ++++++++++++++++-------------
5 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c
index 67511e4..0380e13 100644
--- a/src/intel/vulkan/anv_descriptor_set.c
+++ b/src/intel/vulkan/anv_descriptor_set.c
@@ -745,9 +745,11 @@ anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
&set->buffer_views[bind_layout->buffer_index + element];
bview->format = anv_isl_format_for_descriptor_type(type);
- bview->bo = buffer->bo;
- bview->offset = buffer->offset + offset;
bview->range = anv_buffer_get_range(buffer, offset, range);
+ bview->address = (struct anv_address) {
+ .bo = buffer->bo,
+ .offset = buffer->offset + offset,
+ };
/* If we're writing descriptors through a push command, we need to
* allocate the surface state from the command buffer. Otherwise it will
@@ -758,7 +760,7 @@ anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
anv_fill_buffer_surface_state(device, bview->surface_state,
bview->format,
- bview->offset, bview->range, 1);
+ bview->address, bview->range, 1);
*desc = (struct anv_descriptor) {
.type = type,
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 276e32b..3deeea5 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -2711,10 +2711,11 @@ void anv_DestroyBuffer(
void
anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state,
enum isl_format format,
- uint32_t offset, uint32_t range, uint32_t stride)
+ struct anv_address address,
+ uint32_t range, uint32_t stride)
{
isl_buffer_fill_state(&device->isl_dev, state.map,
- .address = offset,
+ .address = anv_address_physical(address),
.mocs = device->default_mocs,
.size = range,
.format = format,
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 5288208..090d061 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -1467,18 +1467,21 @@ anv_CreateBufferView(VkDevice _device,
VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_TILING_LINEAR);
const uint32_t format_bs = isl_format_get_layout(view->format)->bpb / 8;
- view->bo = buffer->bo;
- view->offset = buffer->offset + pCreateInfo->offset;
view->range = anv_buffer_get_range(buffer, pCreateInfo->offset,
pCreateInfo->range);
view->range = align_down_npot_u32(view->range, format_bs);
+ view->address = (struct anv_address) {
+ .bo = buffer->bo,
+ .offset = buffer->offset + pCreateInfo->offset,
+ };
+
if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
view->surface_state = alloc_surface_state(device);
anv_fill_buffer_surface_state(device, view->surface_state,
view->format,
- view->offset, view->range, format_bs);
+ view->address, view->range, format_bs);
} else {
view->surface_state = (struct anv_state){ 0 };
}
@@ -1495,14 +1498,14 @@ anv_CreateBufferView(VkDevice _device,
anv_fill_buffer_surface_state(device, view->storage_surface_state,
storage_format,
- view->offset, view->range,
+ view->address, view->range,
(storage_format == ISL_FORMAT_RAW ? 1 :
isl_format_get_layout(storage_format)->bpb / 8));
/* Write-only accesses should use the original format. */
anv_fill_buffer_surface_state(device, view->writeonly_storage_surface_state,
view->format,
- view->offset, view->range,
+ view->address, view->range,
isl_format_get_layout(view->format)->bpb / 8);
isl_buffer_fill_image_param(&device->isl_dev,
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index a18a1d1..95d3e4d 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1388,10 +1388,10 @@ struct anv_descriptor_set {
struct anv_buffer_view {
enum isl_format format; /**< VkBufferViewCreateInfo::format */
- struct anv_bo *bo;
- uint32_t offset; /**< Offset into bo. */
uint64_t range; /**< VkBufferViewCreateInfo::range */
+ struct anv_address address;
+
struct anv_state surface_state;
struct anv_state storage_surface_state;
struct anv_state writeonly_storage_surface_state;
@@ -2993,8 +2993,8 @@ anv_sanitize_image_offset(const VkImageType imageType,
void anv_fill_buffer_surface_state(struct anv_device *device,
struct anv_state state,
enum isl_format format,
- uint32_t offset, uint32_t range,
- uint32_t stride);
+ struct anv_address address,
+ uint32_t range, uint32_t stride);
static inline void
anv_clear_color_from_att_state(union isl_color_value *clear_color,
diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index ad79265..97fb8ea 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -1978,7 +1978,9 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
const enum isl_format format =
anv_isl_format_for_descriptor_type(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
anv_fill_buffer_surface_state(cmd_buffer->device, surface_state,
- format, bo_offset, 12, 1);
+ format,
+ cmd_buffer->state.compute.num_workgroups,
+ 12, 1);
bt_map[0] = surface_state.offset + state_offset;
add_surface_state_reloc(cmd_buffer, surface_state, bo, bo_offset);
@@ -2095,8 +2097,8 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
surface_state = desc->buffer_view->surface_state;
assert(surface_state.alloc_size);
add_surface_state_reloc(cmd_buffer, surface_state,
- desc->buffer_view->bo,
- desc->buffer_view->offset);
+ desc->buffer_view->address.bo,
+ desc->buffer_view->address.offset);
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
@@ -2110,16 +2112,20 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
/* Clamp the range to the buffer size */
uint32_t range = MIN2(desc->range, desc->buffer->size - offset);
+ struct anv_address address = {
+ .bo = desc->buffer->bo,
+ .offset = desc->buffer->offset + offset,
+ };
+
surface_state =
anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
enum isl_format format =
anv_isl_format_for_descriptor_type(desc->type);
anv_fill_buffer_surface_state(cmd_buffer->device, surface_state,
- format, offset, range, 1);
+ format, address, range, 1);
add_surface_state_reloc(cmd_buffer, surface_state,
- desc->buffer->bo,
- desc->buffer->offset + offset);
+ address.bo, address.offset);
break;
}
@@ -2129,8 +2135,8 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
: desc->buffer_view->storage_surface_state;
assert(surface_state.alloc_size);
add_surface_state_reloc(cmd_buffer, surface_state,
- desc->buffer_view->bo,
- desc->buffer_view->offset);
+ desc->buffer_view->address.bo,
+ desc->buffer_view->address.offset);
struct brw_image_param *image_param =
&cmd_buffer->state.push_constants[stage]->images[image++];
@@ -2389,11 +2395,8 @@ cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer,
if (desc->type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
read_len = MIN2(range->length,
DIV_ROUND_UP(desc->buffer_view->range, 32) - range->start);
- read_addr = (struct anv_address) {
- .bo = desc->buffer_view->bo,
- .offset = desc->buffer_view->offset +
- range->start * 32,
- };
+ read_addr = anv_address_add(desc->buffer_view->address,
+ range->start * 32);
} else {
assert(desc->type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC);
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list