anv/sparse: add INTEL_DEBUG=sparse

This pollutes stderr a lot, but I've used it countless times while
developing this code.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23045>
This commit is contained in:
Paulo Zanoni
2023-07-20 14:30:16 -07:00
committed by Marge Bot
parent 2bdd01187d
commit 7e2d8cced3
2 changed files with 163 additions and 5 deletions

View File

@@ -1368,6 +1368,15 @@ anv_queue_submit_sparse_bind_locked(struct anv_queue *queue,
assert(submit->command_buffer_count == 0);
if (INTEL_DEBUG(DEBUG_SPARSE)) {
fprintf(stderr, "[sparse submission, buffers:%u opaque_images:%u "
"images:%u waits:%u signals:%u]\n",
submit->buffer_bind_count,
submit->image_opaque_bind_count,
submit->image_bind_count,
submit->wait_count, submit->signal_count);
}
/* TODO: make both the syncs and signals be passed as part of the vm_bind
* ioctl so they can be waited asynchronously. For now this doesn't matter
* as we're doing synchronous vm_bind, but later when we make it async this

View File

@@ -35,6 +35,130 @@
* to which buffers).
*/
__attribute__((format(printf, 1, 2)))
static void
sparse_debug(const char *format, ...)
{
if (!INTEL_DEBUG(DEBUG_SPARSE))
return;
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
static void
dump_anv_vm_bind(struct anv_device *device,
struct anv_sparse_binding_data *sparse,
const struct anv_vm_bind *bind)
{
if (!INTEL_DEBUG(DEBUG_SPARSE))
return;
sparse_debug("[%s] ", bind->op == ANV_VM_BIND ? " bind " : "unbind");
if (bind->bo)
sparse_debug("bo:%04u ", bind->bo->gem_handle);
else
sparse_debug("bo:---- ");
sparse_debug("res_offset:%08"PRIx64" size:%08"PRIx64" "
"mem_offset:%08"PRIx64"\n",
bind->address - sparse->address, bind->size,
bind->bo_offset);
}
static void
dump_vk_sparse_memory_bind(const VkSparseMemoryBind *bind)
{
if (!INTEL_DEBUG(DEBUG_SPARSE))
return;
if (bind->memory != VK_NULL_HANDLE) {
struct anv_bo *bo = anv_device_memory_from_handle(bind->memory)->bo;
sparse_debug("bo:%04u ", bo->gem_handle);
} else {
sparse_debug("bo:---- ");
}
sparse_debug("res_offset:%08"PRIx64" size:%08"PRIx64" "
"mem_offset:%08"PRIx64" flags:0x%08x\n",
bind->resourceOffset, bind->size, bind->memoryOffset,
bind->flags);
}
static void
dump_anv_image(struct anv_image *i)
{
if (!INTEL_DEBUG(DEBUG_SPARSE))
return;
sparse_debug("anv_image:\n");
sparse_debug("- format: %d\n", i->vk.format);
sparse_debug("- extent: [%d, %d, %d]\n",
i->vk.extent.width, i->vk.extent.height, i->vk.extent.depth);
sparse_debug("- mip_levels: %d array_layers: %d samples: %d\n",
i->vk.mip_levels, i->vk.array_layers, i->vk.samples);
sparse_debug("- n_planes: %d\n", i->n_planes);
sparse_debug("- disjoint: %d\n", i->disjoint);
}
static void
dump_isl_surf(struct isl_surf *s)
{
if (!INTEL_DEBUG(DEBUG_SPARSE))
return;
sparse_debug("isl_surf:\n");
const char *dim_s = s->dim == ISL_SURF_DIM_1D ? "1D" :
s->dim == ISL_SURF_DIM_2D ? "2D" :
s->dim == ISL_SURF_DIM_3D ? "3D" :
"(ERROR)";
sparse_debug("- dim: %s\n", dim_s);
sparse_debug("- tiling: %d (%s)\n", s->tiling,
isl_tiling_to_name(s->tiling));
sparse_debug("- format: %s\n", isl_format_get_short_name(s->format));
sparse_debug("- image_alignment_el: [%d, %d, %d]\n",
s->image_alignment_el.w, s->image_alignment_el.h,
s->image_alignment_el.d);
sparse_debug("- logical_level0_px: [%d, %d, %d, %d]\n",
s->logical_level0_px.w,
s->logical_level0_px.h,
s->logical_level0_px.d,
s->logical_level0_px.a);
sparse_debug("- phys_level0_sa: [%d, %d, %d, %d]\n",
s->phys_level0_sa.w,
s->phys_level0_sa.h,
s->phys_level0_sa.d,
s->phys_level0_sa.a);
sparse_debug("- levels: %d samples: %d\n", s->levels, s->samples);
sparse_debug("- size_B: %"PRIu64" alignment_B: %u\n",
s->size_B, s->alignment_B);
sparse_debug("- row_pitch_B: %u\n", s->row_pitch_B);
sparse_debug("- array_pitch_el_rows: %u\n", s->array_pitch_el_rows);
const struct isl_format_layout *layout = isl_format_get_layout(s->format);
sparse_debug("- format layout:\n");
sparse_debug(" - format:%d bpb:%d bw:%d bh:%d bd:%d\n",
layout->format, layout->bpb, layout->bw, layout->bh,
layout->bd);
struct isl_tile_info tile_info;
isl_surf_get_tile_info(s, &tile_info);
sparse_debug("- tile info:\n");
sparse_debug(" - format_bpb: %d\n", tile_info.format_bpb);
sparse_debug(" - logical_extent_el: [%d, %d, %d, %d]\n",
tile_info.logical_extent_el.w,
tile_info.logical_extent_el.h,
tile_info.logical_extent_el.d,
tile_info.logical_extent_el.a);
sparse_debug(" - phys_extent_B: [%d, %d]\n",
tile_info.phys_extent_B.w,
tile_info.phys_extent_B.h);
}
static VkOffset3D
vk_offset3d_px_to_el(const VkOffset3D offset_px,
const struct isl_format_layout *layout)
@@ -178,6 +302,7 @@ anv_init_sparse_bindings(struct anv_device *device,
.size = size,
.op = ANV_VM_BIND,
};
dump_anv_vm_bind(device, sparse, &bind);
int rc = device->kmd_backend->vm_bind(device, 1, &bind);
if (rc) {
anv_vma_free(device, sparse->vma_heap, sparse->address, sparse->size);
@@ -195,6 +320,9 @@ anv_free_sparse_bindings(struct anv_device *device,
if (!sparse->address)
return VK_SUCCESS;
sparse_debug("%s: address:0x%016"PRIx64" size:0x%08"PRIx64"\n",
__func__, sparse->address, sparse->size);
struct anv_vm_bind unbind = {
.bo = 0,
.address = sparse->address,
@@ -202,6 +330,7 @@ anv_free_sparse_bindings(struct anv_device *device,
.size = sparse->size,
.op = ANV_VM_UNBIND,
};
dump_anv_vm_bind(device, sparse, &unbind);
int ret = device->kmd_backend->vm_bind(device, 1, &unbind);
if (ret)
return vk_errorf(device, VK_ERROR_UNKNOWN,
@@ -395,21 +524,26 @@ anv_sparse_calc_miptail_properties(struct anv_device *device,
*imageMipTailSize = tile_size;
*imageMipTailOffset = binding_plane_offset + miptail_offset;
*imageMipTailStride = layer1_offset;
return;
goto out_debug;
out_no_miptail:
*imageMipTailFirstLod = image->vk.mip_levels;
*imageMipTailSize = 0;
*imageMipTailOffset = 0;
*imageMipTailStride = 0;
return;
goto out_debug;
out_everything_is_miptail:
*imageMipTailFirstLod = 0;
*imageMipTailSize = surf->size_B;
*imageMipTailOffset = binding_plane_offset;
*imageMipTailStride = 0;
return;
out_debug:
sparse_debug("miptail first_lod:%d size:%"PRIu64" offset:%"PRIu64" "
"stride:%"PRIu64"\n",
*imageMipTailFirstLod, *imageMipTailSize,
*imageMipTailOffset, *imageMipTailStride);
}
static struct anv_vm_bind
@@ -443,6 +577,7 @@ anv_sparse_bind_resource_memory(struct anv_device *device,
{
struct anv_vm_bind bind = vk_bind_to_anv_vm_bind(sparse, vk_bind);
dump_anv_vm_bind(device, sparse, &bind);
int rc = device->kmd_backend->vm_bind(device, 1, &bind);
if (rc) {
return vk_errorf(device, VK_ERROR_OUT_OF_DEVICE_MEMORY,
@@ -480,6 +615,16 @@ anv_sparse_bind_image_memory(struct anv_queue *queue,
struct isl_tile_info tile_info;
isl_surf_get_tile_info(surf, &tile_info);
sparse_debug("\n=== [%s:%d] [%s] BEGIN\n", __FILE__, __LINE__, __func__);
sparse_debug("--> mip_level:%d array_layer:%d\n",
mip_level, array_layer);
sparse_debug("aspect:0x%x plane:%d\n", aspect, plane);
sparse_debug("binding offset: [%d, %d, %d] extent: [%d, %d, %d]\n",
bind->offset.x, bind->offset.y, bind->offset.z,
bind->extent.width, bind->extent.height, bind->extent.depth);
dump_anv_image(image);
dump_isl_surf(surf);
VkExtent3D block_shape_px =
anv_sparse_calc_block_shape(device->physical, surf);
VkExtent3D block_shape_el = vk_extent3d_px_to_el(block_shape_px, layout);
@@ -567,8 +712,10 @@ anv_sparse_bind_image_memory(struct anv_queue *queue,
assert(opaque_bind.size % block_size_B == 0);
assert(num_binds < binds_array_len);
binds[num_binds++] = vk_bind_to_anv_vm_bind(sparse_data,
&opaque_bind);
binds[num_binds] = vk_bind_to_anv_vm_bind(sparse_data,
&opaque_bind);
dump_anv_vm_bind(device, sparse_data, &binds[num_binds]);
num_binds++;
}
}
@@ -586,6 +733,8 @@ anv_sparse_bind_image_memory(struct anv_queue *queue,
STACK_ARRAY_FINISH(binds);
sparse_debug("\n=== [%s:%d] [%s] END num_binds:%d\n",
__FILE__, __LINE__, __func__, num_binds);
return ret;
}