diff --git a/src/intel/compiler/brw_compiler.h b/src/intel/compiler/brw_compiler.h index 02fb7371733..c4f137c5f95 100644 --- a/src/intel/compiler/brw_compiler.h +++ b/src/intel/compiler/brw_compiler.h @@ -463,7 +463,6 @@ enum brw_shader_reloc_id { BRW_SHADER_RELOC_EMBEDDED_SAMPLER_HANDLE + BRW_MAX_EMBEDDED_SAMPLERS - 1, BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_LOW, BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_HIGH, - BRW_SHADER_RELOC_PRINTF_BASE_IDENTIFIER, BRW_SHADER_RELOC_PRINTF_BUFFER_SIZE, }; diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c index 2e02be36601..a2b03b86bbc 100644 --- a/src/intel/vulkan/anv_pipeline_cache.c +++ b/src/intel/vulkan/anv_pipeline_cache.c @@ -201,46 +201,6 @@ anv_shader_bin_rewrite_embedded_samplers(struct anv_device *device, reloc_values, rv_count); } -static uint32_t -brw_stage_prog_data_printf_num_args(const struct brw_stage_prog_data *prog_data) -{ - uint32_t count = 0; - for (unsigned i = 0; i < prog_data->printf_info_count; i++) - count += prog_data->printf_info[i].num_args; - return count; -} - -static uint32_t -brw_stage_prog_data_printf_string_size(const struct brw_stage_prog_data *prog_data) -{ - uint32_t size = 0; - for (unsigned i = 0; i < prog_data->printf_info_count; i++) - size += prog_data->printf_info[i].string_size; - return size; -} - -static void -copy_uprintf(u_printf_info *out_infos, - unsigned *out_arg_sizes, - char *out_strings, - const struct brw_stage_prog_data *prog_data) -{ - for (unsigned i = 0; i < prog_data->printf_info_count; i++) { - out_infos[i] = prog_data->printf_info[i]; - out_infos[i].arg_sizes = out_arg_sizes; - memcpy(out_infos[i].arg_sizes, - prog_data->printf_info[i].arg_sizes, - sizeof(out_infos[i].arg_sizes[0]) * prog_data->printf_info[i].num_args); - out_infos[i].strings = out_strings; - memcpy(out_infos[i].strings, - prog_data->printf_info[i].strings, - prog_data->printf_info[i].string_size); - - out_arg_sizes += prog_data->printf_info[i].num_args; - out_strings += prog_data->printf_info[i].string_size; - } -} - static struct anv_shader_bin * anv_shader_bin_create(struct anv_device *device, gl_shader_stage stage, @@ -278,15 +238,6 @@ anv_shader_bin_create(struct anv_device *device, bind_map->kernel_arg_count); VK_MULTIALLOC_DECL(&ma, struct anv_embedded_sampler *, embedded_samplers, bind_map->embedded_sampler_count); - VK_MULTIALLOC_DECL(&ma, u_printf_info, printf_infos, - INTEL_DEBUG(DEBUG_SHADER_PRINT) ? - prog_data_in->printf_info_count : 0); - VK_MULTIALLOC_DECL(&ma, unsigned, arg_sizes, - INTEL_DEBUG(DEBUG_SHADER_PRINT) ? - brw_stage_prog_data_printf_num_args(prog_data_in) : 0); - VK_MULTIALLOC_DECL(&ma, char, strings, - INTEL_DEBUG(DEBUG_SHADER_PRINT) ? - brw_stage_prog_data_printf_string_size(prog_data_in) : 0); if (!vk_multialloc_zalloc(&ma, &device->vk.alloc, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE)) @@ -364,41 +315,22 @@ anv_shader_bin_create(struct anv_device *device, }; } - if (INTEL_DEBUG(DEBUG_SHADER_PRINT) && prog_data_in->printf_info_count > 0) { - assert(device->printf.bo != NULL); + if (INTEL_DEBUG(DEBUG_SHADER_PRINT)) { + struct anv_bo *bo = device->printf.bo; + assert(bo != NULL); - copy_uprintf(printf_infos, arg_sizes, strings, prog_data_in); - - simple_mtx_lock(&device->printf.mutex); - - uint32_t base_printf_idx = - util_dynarray_num_elements(&device->printf.prints, u_printf_info*); - for (uint32_t i = 0; i < prog_data_in->printf_info_count; i++) { - util_dynarray_append(&device->printf.prints, u_printf_info *, - &printf_infos[i]); - } - - simple_mtx_unlock(&device->printf.mutex); - - /* u_printf expects the string IDs to start at 1. */ - reloc_values[rv_count++] = (struct brw_shader_reloc_value) { - .id = BRW_SHADER_RELOC_PRINTF_BASE_IDENTIFIER, - .value = base_printf_idx, - }; reloc_values[rv_count++] = (struct brw_shader_reloc_value) { .id = BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_LOW, - .value = device->printf.bo->offset & 0xffffffff, + .value = bo->offset & 0xffffffff, }; reloc_values[rv_count++] = (struct brw_shader_reloc_value) { .id = BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_HIGH, - .value = device->printf.bo->offset >> 32, + .value = bo->offset >> 32, }; reloc_values[rv_count++] = (struct brw_shader_reloc_value) { .id = BRW_SHADER_RELOC_PRINTF_BUFFER_SIZE, .value = anv_printf_buffer_size(), }; - } else if (prog_data_in->printf_info_count > 0) { - unreachable("shader with printf intrinsics requires INTEL_DEBUG=shader-print"); } brw_write_shader_relocs(&device->physical->compiler->isa, @@ -412,7 +344,6 @@ anv_shader_bin_create(struct anv_device *device, prog_data_in->num_relocs); prog_data->relocs = prog_data_relocs; prog_data->param = prog_data_param; - prog_data->printf_info = printf_infos; shader->prog_data = prog_data; shader->prog_data_size = prog_data_size; @@ -479,8 +410,6 @@ anv_shader_bin_serialize(struct vk_pipeline_cache_object *object, blob_write_bytes(blob, shader->prog_data->relocs, shader->prog_data->num_relocs * sizeof(shader->prog_data->relocs[0])); - u_printf_serialize_info(blob, shader->prog_data->printf_info, - shader->prog_data->printf_info_count); blob_write_uint32(blob, shader->num_stats); blob_write_bytes(blob, shader->stats, @@ -559,10 +488,6 @@ anv_shader_bin_deserialize(struct vk_pipeline_cache *cache, sizeof(prog_data.base.relocs[0])); void *mem_ctx = ralloc_context(NULL); - prog_data.base.printf_info = - u_printf_deserialize_info(mem_ctx, blob, - &prog_data.base.printf_info_count); - uint32_t num_stats = blob_read_uint32(blob); const struct brw_compile_stats *stats = blob_read_bytes(blob, num_stats * sizeof(stats[0])); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 8587a76d004..6061765b82a 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2138,20 +2138,7 @@ struct anv_device { struct hash_table *map; } embedded_samplers; - struct { - /** - * Mutex for the printfs array - */ - simple_mtx_t mutex; - /** - * Buffer in which the shader printfs are stored - */ - struct anv_bo *bo; - /** - * Array of pointers to u_printf_info - */ - struct util_dynarray prints; - } printf; + struct u_printf_ctx printf; struct { simple_mtx_t mutex; @@ -2321,7 +2308,6 @@ VkResult anv_device_wait(struct anv_device *device, struct anv_bo *bo, VkResult anv_device_print_init(struct anv_device *device); void anv_device_print_fini(struct anv_device *device); -void anv_device_print_shader_prints(struct anv_device *device); void anv_dump_bvh_to_files(struct anv_device *device); @@ -2350,9 +2336,6 @@ anv_queue_post_submit(struct anv_queue *queue, VkResult submit_result) result = vk_queue_set_lost(&queue->vk, "sync wait failed"); } - if (INTEL_DEBUG(DEBUG_SHADER_PRINT)) - anv_device_print_shader_prints(queue->device); - #if ANV_SUPPORT_RT && !ANV_SUPPORT_RT_GRL /* The recorded bvh is dumped to files upon command buffer completion */ if (INTEL_DEBUG(DEBUG_BVH_ANY)) diff --git a/src/intel/vulkan/anv_util.c b/src/intel/vulkan/anv_util.c index 7509ad5e2cc..1e6063938d1 100644 --- a/src/intel/vulkan/anv_util.c +++ b/src/intel/vulkan/anv_util.c @@ -27,6 +27,7 @@ #include #include #include +#include "util/u_printf.h" #include #include "anv_private.h" @@ -180,6 +181,7 @@ anv_gfx_state_bit_to_str(enum anv_gfx_state_bits state) VkResult anv_device_print_init(struct anv_device *device) { + struct anv_bo *bo; VkResult result = anv_device_alloc_bo(device, "printf", anv_printf_buffer_size(), @@ -188,15 +190,11 @@ anv_device_print_init(struct anv_device *device) ANV_BO_ALLOC_HOST_COHERENT | ANV_BO_ALLOC_NO_LOCAL_MEM, 0 /* explicit_address */, - &device->printf.bo); + &bo); if (result != VK_SUCCESS) return result; - util_dynarray_init(&device->printf.prints, ralloc_context(NULL)); - simple_mtx_init(&device->printf.mutex, mtx_plain); - - *((uint32_t *)device->printf.bo->map) = 4; - + u_printf_init(&device->printf, bo, (uint32_t*)bo->map); return VK_SUCCESS; } @@ -204,30 +202,9 @@ void anv_device_print_fini(struct anv_device *device) { anv_device_release_bo(device, device->printf.bo); - util_dynarray_fini(&device->printf.prints); - simple_mtx_destroy(&device->printf.mutex); + u_printf_destroy(&device->printf); } -void -anv_device_print_shader_prints(struct anv_device *device) -{ - simple_mtx_lock(&device->printf.mutex); - - uint32_t *size = device->printf.bo->map; - - u_printf_ptr(stdout, - device->printf.bo->map + sizeof(uint32_t), - *size - 4, - util_dynarray_begin(&device->printf.prints), - util_dynarray_num_elements(&device->printf.prints, u_printf_info*)); - - /* Reset */ - *size = 4; - - simple_mtx_unlock(&device->printf.mutex); -} - - static void create_directory(const char *dir, const char *sub_dir) { diff --git a/src/intel/vulkan/i915/anv_device.c b/src/intel/vulkan/i915/anv_device.c index 818b514ca1c..1c5bbf23ba5 100644 --- a/src/intel/vulkan/i915/anv_device.c +++ b/src/intel/vulkan/i915/anv_device.c @@ -22,6 +22,7 @@ #include "i915/anv_device.h" #include "anv_private.h" +#include "vk_debug_utils.h" #include "common/i915/intel_defines.h" #include "common/i915/intel_gem.h" @@ -374,6 +375,12 @@ anv_i915_device_check_status(struct vk_device *vk_device) result = anv_gem_context_get_reset_stats(device, device->context_id); } + if (result != VK_SUCCESS) + return result; + + if (INTEL_DEBUG(DEBUG_SHADER_PRINT)) + result = vk_check_printf_status(vk_device, &device->printf); + return result; } diff --git a/src/intel/vulkan/xe/anv_device.c b/src/intel/vulkan/xe/anv_device.c index df6173a283a..2b32c9639f1 100644 --- a/src/intel/vulkan/xe/anv_device.c +++ b/src/intel/vulkan/xe/anv_device.c @@ -22,6 +22,7 @@ #include "xe/anv_device.h" #include "anv_private.h" +#include "vk_debug_utils.h" #include "drm-uapi/gpu_scheduler.h" #include "drm-uapi/xe_drm.h" @@ -208,5 +209,11 @@ anv_xe_device_check_status(struct vk_device *vk_device) } } + if (result != VK_SUCCESS) + return result; + + if (INTEL_DEBUG(DEBUG_SHADER_PRINT)) + result = vk_check_printf_status(vk_device, &device->printf); + return result; }