mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 02:48:06 +02:00
radv: move radv_printf_data to radv_debug_nir
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40481>
This commit is contained in:
parent
f776a763b4
commit
7ce3b2a68e
5 changed files with 47 additions and 35 deletions
|
|
@ -21,11 +21,12 @@ VkResult
|
|||
radv_printf_data_init(struct radv_device *device)
|
||||
{
|
||||
const struct radv_physical_device *pdev = radv_device_physical(device);
|
||||
struct radv_printf_data *printf = &device->debug_nir.printf;
|
||||
|
||||
device->printf.formats = UTIL_DYNARRAY_INIT;
|
||||
printf->formats = UTIL_DYNARRAY_INIT;
|
||||
|
||||
device->printf.buffer_size = debug_get_num_option("RADV_PRINTF_BUFFER_SIZE", 0);
|
||||
if (device->printf.buffer_size < sizeof(struct radv_printf_buffer_header))
|
||||
printf->buffer_size = debug_get_num_option("RADV_PRINTF_BUFFER_SIZE", 0);
|
||||
if (printf->buffer_size < sizeof(struct radv_printf_buffer_header))
|
||||
return VK_SUCCESS;
|
||||
|
||||
VkBufferCreateInfo buffer_create_info = {
|
||||
|
|
@ -35,16 +36,16 @@ radv_printf_data_init(struct radv_device *device)
|
|||
.sType = VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO,
|
||||
.usage = VK_BUFFER_USAGE_2_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_2_SHADER_DEVICE_ADDRESS_BIT,
|
||||
},
|
||||
.size = device->printf.buffer_size,
|
||||
.size = printf->buffer_size,
|
||||
};
|
||||
|
||||
VkDevice _device = radv_device_to_handle(device);
|
||||
VkResult result = device->vk.dispatch_table.CreateBuffer(_device, &buffer_create_info, NULL, &device->printf.buffer);
|
||||
VkResult result = device->vk.dispatch_table.CreateBuffer(_device, &buffer_create_info, NULL, &printf->buffer);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
VkMemoryRequirements requirements;
|
||||
device->vk.dispatch_table.GetBufferMemoryRequirements(_device, device->printf.buffer, &requirements);
|
||||
device->vk.dispatch_table.GetBufferMemoryRequirements(_device, printf->buffer, &requirements);
|
||||
|
||||
VkMemoryAllocateInfo alloc_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
|
|
@ -54,28 +55,27 @@ radv_printf_data_init(struct radv_device *device)
|
|||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT),
|
||||
};
|
||||
|
||||
result = device->vk.dispatch_table.AllocateMemory(_device, &alloc_info, NULL, &device->printf.memory);
|
||||
result = device->vk.dispatch_table.AllocateMemory(_device, &alloc_info, NULL, &printf->memory);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
result = device->vk.dispatch_table.MapMemory(_device, device->printf.memory, 0, VK_WHOLE_SIZE, 0,
|
||||
(void **)&device->printf.data);
|
||||
result = device->vk.dispatch_table.MapMemory(_device, printf->memory, 0, VK_WHOLE_SIZE, 0, (void **)&printf->data);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
result = device->vk.dispatch_table.BindBufferMemory(_device, device->printf.buffer, device->printf.memory, 0);
|
||||
result = device->vk.dispatch_table.BindBufferMemory(_device, printf->buffer, printf->memory, 0);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
struct radv_printf_buffer_header *header = device->printf.data;
|
||||
struct radv_printf_buffer_header *header = printf->data;
|
||||
header->offset = sizeof(struct radv_printf_buffer_header);
|
||||
header->size = device->printf.buffer_size;
|
||||
header->size = printf->buffer_size;
|
||||
|
||||
VkBufferDeviceAddressInfo addr_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
|
||||
.buffer = device->printf.buffer,
|
||||
.buffer = printf->buffer,
|
||||
};
|
||||
device->printf.buffer_addr = device->vk.dispatch_table.GetBufferDeviceAddress(_device, &addr_info);
|
||||
printf->buffer_addr = device->vk.dispatch_table.GetBufferDeviceAddress(_device, &addr_info);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
|
@ -84,16 +84,17 @@ void
|
|||
radv_printf_data_finish(struct radv_device *device)
|
||||
{
|
||||
VkDevice _device = radv_device_to_handle(device);
|
||||
struct radv_printf_data *printf = &device->debug_nir.printf;
|
||||
|
||||
device->vk.dispatch_table.DestroyBuffer(_device, device->printf.buffer, NULL);
|
||||
if (device->printf.memory)
|
||||
device->vk.dispatch_table.UnmapMemory(_device, device->printf.memory);
|
||||
device->vk.dispatch_table.FreeMemory(_device, device->printf.memory, NULL);
|
||||
device->vk.dispatch_table.DestroyBuffer(_device, printf->buffer, NULL);
|
||||
if (printf->memory)
|
||||
device->vk.dispatch_table.UnmapMemory(_device, printf->memory);
|
||||
device->vk.dispatch_table.FreeMemory(_device, printf->memory, NULL);
|
||||
|
||||
util_dynarray_foreach (&device->printf.formats, struct radv_printf_format, format)
|
||||
util_dynarray_foreach (&printf->formats, struct radv_printf_format, format)
|
||||
free(format->string);
|
||||
|
||||
util_dynarray_fini(&device->printf.formats);
|
||||
util_dynarray_fini(&printf->formats);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -103,7 +104,9 @@ radv_shader_printf_enabled(nir_shader *shader)
|
|||
return false;
|
||||
|
||||
struct radv_device *device = _mesa_hash_table_search(device_ht, shader)->data;
|
||||
return !!device->printf.buffer_addr;
|
||||
struct radv_printf_data *printf = &device->debug_nir.printf;
|
||||
|
||||
return !!printf->buffer_addr;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -118,7 +121,8 @@ radv_build_printf_args(nir_builder *b, nir_def *cond, const char *format_string,
|
|||
return;
|
||||
|
||||
struct radv_device *device = _mesa_hash_table_search(device_ht, b->shader)->data;
|
||||
uint32_t format_index = util_dynarray_num_elements(&device->printf.formats, struct radv_printf_format);
|
||||
struct radv_printf_data *printf = &device->debug_nir.printf;
|
||||
uint32_t format_index = util_dynarray_num_elements(&printf->formats, struct radv_printf_format);
|
||||
|
||||
if (cond)
|
||||
nir_push_if(b, cond);
|
||||
|
|
@ -162,7 +166,7 @@ radv_build_printf_args(nir_builder *b, nir_def *cond, const char *format_string,
|
|||
nir_push_if(b, nir_elect(b, 1));
|
||||
{
|
||||
offset = nir_global_atomic(
|
||||
b, 32, nir_imm_int64(b, device->printf.buffer_addr + offsetof(struct radv_printf_buffer_header, offset)), size,
|
||||
b, 32, nir_imm_int64(b, printf->buffer_addr + offsetof(struct radv_printf_buffer_header, offset)), size,
|
||||
.atomic_op = nir_atomic_op_iadd);
|
||||
}
|
||||
nir_push_else(b, NULL);
|
||||
|
|
@ -174,11 +178,11 @@ radv_build_printf_args(nir_builder *b, nir_def *cond, const char *format_string,
|
|||
offset = nir_read_first_invocation(b, nir_if_phi(b, offset, undef));
|
||||
|
||||
nir_def *buffer_size = nir_load_global(
|
||||
b, 1, 32, nir_imm_int64(b, device->printf.buffer_addr + offsetof(struct radv_printf_buffer_header, size)));
|
||||
b, 1, 32, nir_imm_int64(b, printf->buffer_addr + offsetof(struct radv_printf_buffer_header, size)));
|
||||
|
||||
nir_push_if(b, nir_ige(b, buffer_size, nir_iadd(b, offset, size)));
|
||||
{
|
||||
nir_def *addr = nir_iadd_imm(b, nir_u2u64(b, offset), device->printf.buffer_addr);
|
||||
nir_def *addr = nir_iadd_imm(b, nir_u2u64(b, offset), printf->buffer_addr);
|
||||
|
||||
/* header */
|
||||
nir_store_global(b, nir_ior_imm(b, active_invocation_count, format_index << 16), addr);
|
||||
|
|
@ -209,7 +213,7 @@ radv_build_printf_args(nir_builder *b, nir_def *cond, const char *format_string,
|
|||
free(args);
|
||||
free(strides);
|
||||
|
||||
util_dynarray_append(&device->printf.formats, format);
|
||||
util_dynarray_append(&printf->formats, format);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -241,13 +245,15 @@ radv_build_printf(nir_builder *b, nir_def *cond, const char *format_string, ...)
|
|||
void
|
||||
radv_dump_printf_data(struct radv_device *device, FILE *out)
|
||||
{
|
||||
if (!device->printf.data)
|
||||
struct radv_printf_data *printf = &device->debug_nir.printf;
|
||||
|
||||
if (!printf->data)
|
||||
return;
|
||||
|
||||
device->vk.dispatch_table.DeviceWaitIdle(radv_device_to_handle(device));
|
||||
|
||||
struct radv_printf_buffer_header *header = device->printf.data;
|
||||
uint8_t *data = device->printf.data;
|
||||
struct radv_printf_buffer_header *header = printf->data;
|
||||
uint8_t *data = printf->data;
|
||||
|
||||
for (uint32_t offset = sizeof(struct radv_printf_buffer_header); offset < header->offset;) {
|
||||
uint32_t printf_header = *(uint32_t *)&data[offset];
|
||||
|
|
@ -255,7 +261,7 @@ radv_dump_printf_data(struct radv_device *device, FILE *out)
|
|||
|
||||
uint32_t format_index = printf_header >> 16;
|
||||
struct radv_printf_format *printf_format =
|
||||
util_dynarray_element(&device->printf.formats, struct radv_printf_format, format_index);
|
||||
util_dynarray_element(&printf->formats, struct radv_printf_format, format_index);
|
||||
|
||||
uint32_t invocation_count = printf_header & 0xFFFF;
|
||||
|
||||
|
|
@ -488,7 +494,9 @@ radv_build_is_valid_va(nir_builder *b, nir_def *addr)
|
|||
void
|
||||
radv_device_associate_nir(struct radv_device *device, nir_shader *nir)
|
||||
{
|
||||
if (!device->printf.buffer_addr && !device->valid_vas_addr)
|
||||
struct radv_printf_data *printf = &device->debug_nir.printf;
|
||||
|
||||
if (!printf->buffer_addr && !device->valid_vas_addr)
|
||||
return;
|
||||
|
||||
if (!device_ht)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ struct radv_printf_buffer_header {
|
|||
uint32_t size;
|
||||
};
|
||||
|
||||
struct radv_debug_nir {
|
||||
struct radv_printf_data printf;
|
||||
};
|
||||
|
||||
void radv_device_associate_nir(struct radv_device *device, nir_shader *nir);
|
||||
|
||||
/* shader printf */
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ struct radv_device {
|
|||
struct hash_table *rt_handles;
|
||||
simple_mtx_t rt_handles_mtx;
|
||||
|
||||
struct radv_printf_data printf;
|
||||
struct radv_debug_nir debug_nir;
|
||||
|
||||
struct radv_device_cache_key cache_key;
|
||||
blake3_hash cache_hash;
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ radv_is_cache_disabled(const struct radv_device *device, const struct vk_pipelin
|
|||
const struct radv_instance *instance = radv_physical_device_instance(pdev);
|
||||
|
||||
/* The buffer address used for debug printf is hardcoded. */
|
||||
if (device->printf.buffer_addr)
|
||||
if (device->debug_nir.printf.buffer_addr)
|
||||
return true;
|
||||
|
||||
/* The buffer address used for validating VAs is hardcoded. */
|
||||
|
|
|
|||
|
|
@ -509,7 +509,7 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st
|
|||
},
|
||||
.emit_debug_break = !!device->trap_handler_shader,
|
||||
.debug_info = !!(instance->debug_flags & RADV_DEBUG_NIR_DEBUG_INFO),
|
||||
.printf = !!device->printf.buffer_addr,
|
||||
.printf = !!device->debug_nir.printf.buffer_addr,
|
||||
};
|
||||
nir = spirv_to_nir(spirv, stage->spirv.size / 4, spec_entries, num_spec_entries, stage->stage, stage->entrypoint,
|
||||
&spirv_options, &pdev->nir_options[stage->stage]);
|
||||
|
|
@ -521,7 +521,7 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st
|
|||
|
||||
radv_device_associate_nir(device, nir);
|
||||
|
||||
if (device->printf.buffer_addr)
|
||||
if (device->debug_nir.printf.buffer_addr)
|
||||
NIR_PASS(_, nir, radv_nir_lower_printf);
|
||||
|
||||
const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue