diff --git a/src/gallium/drivers/crocus/crocus_context.c b/src/gallium/drivers/crocus/crocus_context.c index 49a158da690..526ffd00b64 100644 --- a/src/gallium/drivers/crocus/crocus_context.c +++ b/src/gallium/drivers/crocus/crocus_context.c @@ -34,6 +34,7 @@ #include "crocus_resource.h" #include "crocus_screen.h" #include "common/i915/intel_defines.h" +#include "common/intel_debug_identifier.h" #include "common/intel_sample_positions.h" /** diff --git a/src/gallium/drivers/crocus/crocus_screen.c b/src/gallium/drivers/crocus/crocus_screen.c index 81c107386ab..5ecc1c3a5cb 100644 --- a/src/gallium/drivers/crocus/crocus_screen.c +++ b/src/gallium/drivers/crocus/crocus_screen.c @@ -53,6 +53,7 @@ #include "crocus_resource.h" #include "crocus_screen.h" #include "intel/compiler/elk/elk_compiler.h" +#include "intel/common/intel_debug_identifier.h" #include "intel/common/intel_gem.h" #include "intel/common/intel_l3_config.h" #include "intel/common/intel_uuid.h" diff --git a/src/gallium/drivers/iris/i915/iris_kmd_backend.c b/src/gallium/drivers/iris/i915/iris_kmd_backend.c index 6fcec1cd185..ea8bdb81a9e 100644 --- a/src/gallium/drivers/iris/i915/iris_kmd_backend.c +++ b/src/gallium/drivers/iris/i915/iris_kmd_backend.c @@ -24,6 +24,7 @@ #include +#include "common/intel_debug_identifier.h" #include "common/intel_gem.h" #include "common/i915/intel_gem.h" #include "dev/intel_debug.h" diff --git a/src/gallium/drivers/iris/iris_screen.c b/src/gallium/drivers/iris/iris_screen.c index bf8a569aada..9ed07fff44e 100644 --- a/src/gallium/drivers/iris/iris_screen.c +++ b/src/gallium/drivers/iris/iris_screen.c @@ -54,6 +54,7 @@ #include "iris_resource.h" #include "iris_screen.h" #include "compiler/glsl_types.h" +#include "intel/common/intel_debug_identifier.h" #include "intel/common/intel_gem.h" #include "intel/common/intel_l3_config.h" #include "intel/common/intel_uuid.h" diff --git a/src/gallium/drivers/iris/xe/iris_kmd_backend.c b/src/gallium/drivers/iris/xe/iris_kmd_backend.c index 064361842a5..135994e211f 100644 --- a/src/gallium/drivers/iris/xe/iris_kmd_backend.c +++ b/src/gallium/drivers/iris/xe/iris_kmd_backend.c @@ -24,6 +24,7 @@ #include +#include "common/intel_debug_identifier.h" #include "common/intel_gem.h" #include "dev/intel_debug.h" #include "iris/iris_bufmgr.h" diff --git a/src/intel/common/intel_debug_identifier.c b/src/intel/common/intel_debug_identifier.c new file mode 100644 index 00000000000..a327dc904fb --- /dev/null +++ b/src/intel/common/intel_debug_identifier.c @@ -0,0 +1,141 @@ +/** + * \file intel_debug_identifier.c + * + * + */ + +#include +#include +#include + +#include "git_sha1.h" + +#include "common/intel_debug_identifier.h" +#include "dev/intel_debug.h" +#include "util/macros.h" +#include "util/u_math.h" + +static uint64_t debug_identifier[4] = { + 0xffeeddccbbaa9988, + 0x7766554433221100, + 0xffeeddccbbaa9988, + 0x7766554433221100, +}; + +void * +intel_debug_identifier(void) +{ + return debug_identifier; +} + +uint32_t +intel_debug_identifier_size(void) +{ + return sizeof(debug_identifier); +} + +uint32_t +intel_debug_write_identifiers(void *_output, + uint32_t output_size, + const char *driver_name) +{ + void *output = _output, *output_end = _output + output_size; + + assert(output_size > intel_debug_identifier_size()); + + memcpy(output, intel_debug_identifier(), intel_debug_identifier_size()); + output += intel_debug_identifier_size(); + + for (uint32_t id = INTEL_DEBUG_BLOCK_TYPE_DRIVER; id < INTEL_DEBUG_BLOCK_TYPE_MAX; id++) { + switch (id) { + case INTEL_DEBUG_BLOCK_TYPE_DRIVER: { + struct intel_debug_block_driver driver_desc = { + .base = { + .type = id, + }, + }; + int len = snprintf(output + sizeof(driver_desc), + output_end - (output + sizeof(driver_desc)), + "%s " PACKAGE_VERSION " build " MESA_GIT_SHA1, + driver_name); + driver_desc.base.length = sizeof(driver_desc) + len + 1; + memcpy(output, &driver_desc, sizeof(driver_desc)); + output += driver_desc.base.length; + break; + } + + case INTEL_DEBUG_BLOCK_TYPE_FRAME: { + struct intel_debug_block_frame frame_desc = { + .base = { + .type = INTEL_DEBUG_BLOCK_TYPE_FRAME, + .length = sizeof(frame_desc), + }, + }; + memcpy(output, &frame_desc, sizeof(frame_desc)); + output += sizeof(frame_desc); + break; + } + + default: + unreachable("Missing identifier write"); + } + + assert(output < output_end); + } + + struct intel_debug_block_base end = { + .type = INTEL_DEBUG_BLOCK_TYPE_END, + .length = sizeof(end), + }; + memcpy(output, &end, sizeof(end)); + output += sizeof(end); + + assert(output < output_end); + + /* Add at least a full aligned uint64_t of zero padding at the end + * to make the identifiers easier to spot. + */ + const unsigned unpadded_len = output - _output; + const unsigned padding = align(unpadded_len + 8, 8) - unpadded_len; + memset(output, 0, padding); + output += padding; + + assert(output < output_end); + + /* Return the how many bytes where written, so that the rest of the buffer + * can be used for other things. + */ + return output - _output; +} + +void * +intel_debug_get_identifier_block(void *_buffer, + uint32_t buffer_size, + enum intel_debug_block_type type) +{ + void *buffer = _buffer + intel_debug_identifier_size(), + *end_buffer = _buffer + buffer_size; + + while (buffer < end_buffer) { + struct intel_debug_block_base *item = buffer; + + if (item->type == type) + return item; + if (item->type == INTEL_DEBUG_BLOCK_TYPE_END) + return NULL; + + buffer += item->length; + } + + return NULL; +} + +/** + * Check if in valid frame range for batch dumping + */ +bool +intel_debug_batch_in_range(uint64_t frame_id) +{ + return frame_id >= intel_debug_batch_frame_start && + frame_id < intel_debug_batch_frame_stop; +} diff --git a/src/intel/common/intel_debug_identifier.h b/src/intel/common/intel_debug_identifier.h new file mode 100644 index 00000000000..7371cb489fe --- /dev/null +++ b/src/intel/common/intel_debug_identifier.h @@ -0,0 +1,62 @@ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +/** + * \file intel_debug_identifier.h + * + * Debug identifier to put into the driver debug buffers. Helps figure out + * information about the driver that generated a hang. + */ + +/* Below is a list of structure located in the identifier buffer. The driver + * can fill those in for debug purposes. + */ + +enum intel_debug_block_type { + /* End of the debug blocks */ + INTEL_DEBUG_BLOCK_TYPE_END = 1, + + /* Driver identifier (struct intel_debug_block_driver) */ + INTEL_DEBUG_BLOCK_TYPE_DRIVER, + + /* Frame identifier (struct intel_debug_block_frame) */ + INTEL_DEBUG_BLOCK_TYPE_FRAME, + + /* Internal, never to be written out */ + INTEL_DEBUG_BLOCK_TYPE_MAX, +}; + +struct intel_debug_block_base { + uint32_t type; /* enum intel_debug_block_type */ + uint32_t length; /* inclusive of this structure size */ +}; + +struct intel_debug_block_driver { + struct intel_debug_block_base base; + uint8_t description[]; +}; + +struct intel_debug_block_frame { + struct intel_debug_block_base base; + uint64_t frame_id; +}; + +extern void *intel_debug_identifier(void); +extern uint32_t intel_debug_identifier_size(void); + +extern uint32_t intel_debug_write_identifiers(void *output, + uint32_t output_size, + const char *driver_name); + +extern void *intel_debug_get_identifier_block(void *buffer, + uint32_t buffer_size, + enum intel_debug_block_type type); + +bool intel_debug_batch_in_range(uint64_t frame_id); + +#ifdef __cplusplus +} +#endif diff --git a/src/intel/common/meson.build b/src/intel/common/meson.build index 0628e6cae4f..88985063589 100644 --- a/src/intel/common/meson.build +++ b/src/intel/common/meson.build @@ -36,6 +36,8 @@ files_libintel_common = files( 'intel_bind_timeline.c', 'intel_bind_timeline.h', 'intel_buffer_alloc.h', + 'intel_debug_identifier.h', + 'intel_debug_identifier.c', 'intel_engine.c', 'intel_engine.h', 'intel_gem.c', diff --git a/src/intel/dev/intel_debug.c b/src/intel/dev/intel_debug.c index b1a9c7a0721..83a66ddf41f 100644 --- a/src/intel/dev/intel_debug.c +++ b/src/intel/dev/intel_debug.c @@ -34,7 +34,6 @@ #include #include "dev/intel_debug.h" -#include "git_sha1.h" #include "util/macros.h" #include "util/u_debug.h" #include "util/u_math.h" @@ -186,8 +185,8 @@ intel_debug_flag_for_shader_stage(gl_shader_stage stage) DEBUG_MS_SIMD32 | \ DEBUG_RT_SIMD32) -static uint64_t intel_debug_batch_frame_start = 0; -static uint64_t intel_debug_batch_frame_stop = -1; +uint64_t intel_debug_batch_frame_start = 0; +uint64_t intel_debug_batch_frame_stop = -1; uint32_t intel_debug_bkp_before_draw_count = 0; uint32_t intel_debug_bkp_after_draw_count = 0; @@ -235,128 +234,3 @@ process_intel_debug_variable(void) call_once(&process_intel_debug_variable_flag, process_intel_debug_variable_once); } - -static uint64_t debug_identifier[4] = { - 0xffeeddccbbaa9988, - 0x7766554433221100, - 0xffeeddccbbaa9988, - 0x7766554433221100, -}; - -void * -intel_debug_identifier(void) -{ - return debug_identifier; -} - -uint32_t -intel_debug_identifier_size(void) -{ - return sizeof(debug_identifier); -} - -uint32_t -intel_debug_write_identifiers(void *_output, - uint32_t output_size, - const char *driver_name) -{ - void *output = _output, *output_end = _output + output_size; - - assert(output_size > intel_debug_identifier_size()); - - memcpy(output, intel_debug_identifier(), intel_debug_identifier_size()); - output += intel_debug_identifier_size(); - - for (uint32_t id = INTEL_DEBUG_BLOCK_TYPE_DRIVER; id < INTEL_DEBUG_BLOCK_TYPE_MAX; id++) { - switch (id) { - case INTEL_DEBUG_BLOCK_TYPE_DRIVER: { - struct intel_debug_block_driver driver_desc = { - .base = { - .type = id, - }, - }; - int len = snprintf(output + sizeof(driver_desc), - output_end - (output + sizeof(driver_desc)), - "%s " PACKAGE_VERSION " build " MESA_GIT_SHA1, - driver_name); - driver_desc.base.length = sizeof(driver_desc) + len + 1; - memcpy(output, &driver_desc, sizeof(driver_desc)); - output += driver_desc.base.length; - break; - } - - case INTEL_DEBUG_BLOCK_TYPE_FRAME: { - struct intel_debug_block_frame frame_desc = { - .base = { - .type = INTEL_DEBUG_BLOCK_TYPE_FRAME, - .length = sizeof(frame_desc), - }, - }; - memcpy(output, &frame_desc, sizeof(frame_desc)); - output += sizeof(frame_desc); - break; - } - - default: - unreachable("Missing identifier write"); - } - - assert(output < output_end); - } - - struct intel_debug_block_base end = { - .type = INTEL_DEBUG_BLOCK_TYPE_END, - .length = sizeof(end), - }; - memcpy(output, &end, sizeof(end)); - output += sizeof(end); - - assert(output < output_end); - - /* Add at least a full aligned uint64_t of zero padding at the end - * to make the identifiers easier to spot. - */ - const unsigned unpadded_len = output - _output; - const unsigned padding = ALIGN(unpadded_len + 8, 8) - unpadded_len; - memset(output, 0, padding); - output += padding; - - assert(output < output_end); - - /* Return the how many bytes where written, so that the rest of the buffer - * can be used for other things. - */ - return output - _output; -} - -void * -intel_debug_get_identifier_block(void *_buffer, - uint32_t buffer_size, - enum intel_debug_block_type type) -{ - void *buffer = _buffer + intel_debug_identifier_size(), - *end_buffer = _buffer + buffer_size; - - while (buffer < end_buffer) { - struct intel_debug_block_base *item = buffer; - - if (item->type == type) - return item; - if (item->type == INTEL_DEBUG_BLOCK_TYPE_END) - return NULL; - - buffer += item->length; - } - - return NULL; -} - -/** - * Check if in valid frame range for batch dumping - */ -bool -intel_debug_batch_in_range(uint64_t frame_id) -{ - return frame_id >= intel_debug_batch_frame_start && - frame_id < intel_debug_batch_frame_stop; -} diff --git a/src/intel/dev/intel_debug.h b/src/intel/dev/intel_debug.h index aedcc18b2c2..a9ecd4083be 100644 --- a/src/intel/dev/intel_debug.h +++ b/src/intel/dev/intel_debug.h @@ -110,6 +110,8 @@ extern uint64_t intel_debug; extern uint64_t intel_simd; extern uint32_t intel_debug_bkp_before_draw_count; extern uint32_t intel_debug_bkp_after_draw_count; +extern uint64_t intel_debug_batch_frame_start; +extern uint64_t intel_debug_batch_frame_stop; #define INTEL_SIMD(type, size) (!!(intel_simd & (DEBUG_ ## type ## _SIMD ## size))) @@ -163,52 +165,6 @@ extern uint64_t intel_debug_flag_for_shader_stage(gl_shader_stage stage); extern void process_intel_debug_variable(void); -/* Below is a list of structure located in the identifier buffer. The driver - * can fill those in for debug purposes. - */ - -enum intel_debug_block_type { - /* End of the debug blocks */ - INTEL_DEBUG_BLOCK_TYPE_END = 1, - - /* Driver identifier (struct intel_debug_block_driver) */ - INTEL_DEBUG_BLOCK_TYPE_DRIVER, - - /* Frame identifier (struct intel_debug_block_frame) */ - INTEL_DEBUG_BLOCK_TYPE_FRAME, - - /* Internal, never to be written out */ - INTEL_DEBUG_BLOCK_TYPE_MAX, -}; - -struct intel_debug_block_base { - uint32_t type; /* enum intel_debug_block_type */ - uint32_t length; /* inclusive of this structure size */ -}; - -struct intel_debug_block_driver { - struct intel_debug_block_base base; - uint8_t description[]; -}; - -struct intel_debug_block_frame { - struct intel_debug_block_base base; - uint64_t frame_id; -}; - -extern void *intel_debug_identifier(void); -extern uint32_t intel_debug_identifier_size(void); - -extern uint32_t intel_debug_write_identifiers(void *output, - uint32_t output_size, - const char *driver_name); - -extern void *intel_debug_get_identifier_block(void *buffer, - uint32_t buffer_size, - enum intel_debug_block_type type); - -bool intel_debug_batch_in_range(uint64_t frame_id); - #ifdef __cplusplus } #endif diff --git a/src/intel/tools/aubinator_error_decode.c b/src/intel/tools/aubinator_error_decode.c index 92e6e20138f..5f932c6a656 100644 --- a/src/intel/tools/aubinator_error_decode.c +++ b/src/intel/tools/aubinator_error_decode.c @@ -40,6 +40,7 @@ #include "aubinator_error_decode_lib.h" #include "aubinator_error_decode_xe.h" +#include "common/intel_debug_identifier.h" #include "compiler/brw_compiler.h" #include "compiler/elk/elk_compiler.h" #include "decoder/intel_decoder.h" diff --git a/src/intel/tools/intel_dump_gpu.c b/src/intel/tools/intel_dump_gpu.c index b1764c8e1cd..46cf4467598 100644 --- a/src/intel/tools/intel_dump_gpu.c +++ b/src/intel/tools/intel_dump_gpu.c @@ -46,6 +46,7 @@ #include "c11/threads.h" #include "dev/intel_debug.h" #include "dev/intel_device_info.h" +#include "common/intel_debug_identifier.h" #include "common/intel_gem.h" #include "util/macros.h" #include "util/u_math.h" diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index bb986847a08..bd516408f09 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -32,6 +32,8 @@ #include "anv_private.h" #include "anv_measure.h" +#include "common/intel_debug_identifier.h" + #include "genxml/gen9_pack.h" #include "genxml/genX_bits.h" diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index a61a4ebc67e..571ef69b835 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -59,6 +59,7 @@ #include "vk_deferred_operation.h" #include "vk_drm_syncobj.h" #include "common/intel_aux_map.h" +#include "common/intel_debug_identifier.h" #include "common/intel_uuid.h" #include "perf/intel_perf.h" diff --git a/src/intel/vulkan/anv_utrace.c b/src/intel/vulkan/anv_utrace.c index 14fdff22743..5c749676cb2 100644 --- a/src/intel/vulkan/anv_utrace.c +++ b/src/intel/vulkan/anv_utrace.c @@ -24,6 +24,7 @@ #include "anv_private.h" #include "anv_internal_kernels.h" +#include "common/intel_debug_identifier.h" #include "ds/intel_tracepoints.h" #include "genxml/gen9_pack.h" #include "perf/intel_perf.h" diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index ab8e5d5fc6c..ec8d243613f 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -29,6 +29,8 @@ #include "vk_semaphore.h" #include "vk_util.h" +#include "common/intel_debug_identifier.h" + static PFN_vkVoidFunction anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) { diff --git a/src/intel/vulkan_hasvk/anv_batch_chain.c b/src/intel/vulkan_hasvk/anv_batch_chain.c index ec775611765..de0a55b1b54 100644 --- a/src/intel/vulkan_hasvk/anv_batch_chain.c +++ b/src/intel/vulkan_hasvk/anv_batch_chain.c @@ -32,6 +32,8 @@ #include "anv_private.h" #include "anv_measure.h" +#include "common/intel_debug_identifier.h" + #include "genxml/gen8_pack.h" #include "genxml/genX_bits.h" #include "perf/intel_perf.h" diff --git a/src/intel/vulkan_hasvk/anv_device.c b/src/intel/vulkan_hasvk/anv_device.c index 3762c1f6f1e..fc6e156e03a 100644 --- a/src/intel/vulkan_hasvk/anv_device.c +++ b/src/intel/vulkan_hasvk/anv_device.c @@ -55,6 +55,7 @@ #include "vk_deferred_operation.h" #include "vk_drm_syncobj.h" #include "common/i915/intel_defines.h" +#include "common/intel_debug_identifier.h" #include "common/intel_uuid.h" #include "perf/intel_perf.h" diff --git a/src/intel/vulkan_hasvk/anv_wsi.c b/src/intel/vulkan_hasvk/anv_wsi.c index 93b7539fe23..e743bd41705 100644 --- a/src/intel/vulkan_hasvk/anv_wsi.c +++ b/src/intel/vulkan_hasvk/anv_wsi.c @@ -29,6 +29,8 @@ #include "vk_semaphore.h" #include "vk_util.h" +#include "common/intel_debug_identifier.h" + static PFN_vkVoidFunction anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) {