From 88b4eed4f6d3b795ce4bdc0b188da01fdf5209af Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Sat, 4 Apr 2026 00:15:26 +0300 Subject: [PATCH] anv: rework debug flag Making it easier to use. Signed-off-by: Lionel Landwerlin Reviewed-by: Kenneth Graunke Part-of: --- src/intel/vulkan/anv_batch_chain.c | 2 +- src/intel/vulkan/anv_descriptor_set.c | 2 +- src/intel/vulkan/anv_formats.c | 4 ++-- src/intel/vulkan/anv_instance.c | 13 +++++++++-- .../vulkan/anv_nir_apply_pipeline_layout.c | 6 ++--- src/intel/vulkan/anv_physical_device.c | 22 +++++++++---------- src/intel/vulkan/anv_private.h | 9 ++++---- src/intel/vulkan/anv_slab_bo.c | 2 +- src/intel/vulkan/genX_cmd_compute.c | 3 +-- src/intel/vulkan/genX_cmd_draw.c | 4 ++-- src/intel/vulkan/genX_gfx_state.c | 5 ++--- src/intel/vulkan/xe/anv_kmd_backend.c | 2 +- 12 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index cb914663981..91afbe5b485 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -1079,7 +1079,7 @@ anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer) * actual ExecuteCommands implementation. */ const uint32_t length = cmd_buffer->batch.next - cmd_buffer->batch.start; - if (!(cmd_buffer->device->physical->instance->debug & ANV_DEBUG_NO_SECONDARY_CALL)) { + if (!ANV_DEBUG(NO_SECONDARY_CALL)) { cmd_buffer->exec_mode = ANV_CMD_BUFFER_EXEC_MODE_CALL_AND_RETURN; void *jump_addr = diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c index 289789f91eb..246d64eed5b 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -448,7 +448,7 @@ anv_descriptor_requires_bindless(const struct anv_physical_device *pdevice, const struct anv_descriptor_set_layout *set, const struct anv_descriptor_set_binding_layout *binding) { - if (pdevice->instance->debug & ANV_DEBUG_BINDLESS) + if (ANV_DEBUG(BINDLESS)) return anv_descriptor_supports_bindless(pdevice, set, binding); if (set->vk.flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR) diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 22666449987..5a5afdc1f4e 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -813,11 +813,11 @@ anv_get_color_format_features(const struct anv_physical_device *physical_device, if (anv_format->flags & ANV_FORMAT_FLAG_CAN_VIDEO && !(create_flags & VK_IMAGE_CREATE_DISJOINT_BIT)) { - flags |= (physical_device->instance->debug & ANV_DEBUG_VIDEO_DECODE) ? + flags |= ANV_DEBUG(VIDEO_DECODE) ? VK_FORMAT_FEATURE_2_VIDEO_DECODE_OUTPUT_BIT_KHR | VK_FORMAT_FEATURE_2_VIDEO_DECODE_DPB_BIT_KHR : 0; - flags |= (physical_device->instance->debug & ANV_DEBUG_VIDEO_ENCODE) ? + flags |= ANV_DEBUG(VIDEO_ENCODE) ? VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR | VK_FORMAT_FEATURE_2_VIDEO_ENCODE_DPB_BIT_KHR : 0; } diff --git a/src/intel/vulkan/anv_instance.c b/src/intel/vulkan/anv_instance.c index aa270a39efb..e47474c3996 100644 --- a/src/intel/vulkan/anv_instance.c +++ b/src/intel/vulkan/anv_instance.c @@ -105,6 +105,14 @@ static const struct debug_control debug_control[] = { { NULL, 0 } }; +enum anv_debug anv_debug; + +static void +process_anv_debug_variable_once(void) +{ + anv_debug = parse_debug_string(os_get_option("ANV_DEBUG"), debug_control); +} + VkResult anv_EnumerateInstanceVersion( uint32_t* pApiVersion) { @@ -327,8 +335,9 @@ VkResult anv_CreateInstance( anv_init_dri_options(instance); - instance->debug = parse_debug_string(os_get_option("ANV_DEBUG"), - debug_control); + static once_flag process_anv_debug_variable_flag = ONCE_FLAG_INIT; + call_once(&process_anv_debug_variable_flag, + process_anv_debug_variable_once); process_intel_debug_variable(); instance->vk.enable_debug_logging = INTEL_DEBUG(DEBUG_PERF); diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c index d404a9ea9bb..b2ff12c9023 100644 --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c @@ -2265,8 +2265,7 @@ binding_should_use_surface_binding_table(const struct apply_pipeline_layout_stat if ((bind_layout->data & ANV_DESCRIPTOR_BTI_SURFACE_STATE) == 0) return false; - if ((state->pdevice->instance->debug & ANV_DEBUG_BINDLESS) && - (bind_layout->data & ANV_DESCRIPTOR_SURFACE)) + if (ANV_DEBUG(BINDLESS) && (bind_layout->data & ANV_DESCRIPTOR_SURFACE)) return false; if (state->set[set].binding[binding].properties & @@ -2283,8 +2282,7 @@ binding_should_use_sampler_binding_table(const struct apply_pipeline_layout_stat if ((binding->data & ANV_DESCRIPTOR_BTI_SAMPLER_STATE) == 0) return false; - if ((state->pdevice->instance->debug & ANV_DEBUG_BINDLESS) && - (binding->data & ANV_DESCRIPTOR_SAMPLER)) + if (ANV_DEBUG(BINDLESS) && (binding->data & ANV_DESCRIPTOR_SAMPLER)) return false; return true; diff --git a/src/intel/vulkan/anv_physical_device.c b/src/intel/vulkan/anv_physical_device.c index c00d27eb190..67582f09eb3 100644 --- a/src/intel/vulkan/anv_physical_device.c +++ b/src/intel/vulkan/anv_physical_device.c @@ -138,9 +138,8 @@ get_device_extensions(const struct anv_physical_device *device, !intel_use_jay_any_stage(&device->info); const bool hw_video_encode_supported = device->info.verx10 < 125; const bool video_encode_enabled = hw_video_encode_supported && - (device->instance->debug & ANV_DEBUG_VIDEO_ENCODE); - const bool video_decode_enabled = device->instance->debug & ANV_DEBUG_VIDEO_DECODE; - + ANV_DEBUG(VIDEO_ENCODE); + const bool video_decode_enabled = ANV_DEBUG(VIDEO_DECODE); *ext = (struct vk_device_extension_table) { .KHR_8bit_storage = true, @@ -201,7 +200,7 @@ get_device_extensions(const struct anv_physical_device *device, device->perf && (intel_perf_has_hold_preemption(device->perf) || INTEL_DEBUG(DEBUG_NO_OACONFIG)) && - !(device->instance->debug & ANV_DEBUG_NO_SECONDARY_CALL), + !ANV_DEBUG(NO_SECONDARY_CALL), .KHR_pipeline_binary = true, .KHR_pipeline_executable_properties = true, .KHR_pipeline_library = true, @@ -309,7 +308,7 @@ get_device_extensions(const struct anv_physical_device *device, VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR, .EXT_global_priority_query = device->max_context_priority >= VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR, - .EXT_graphics_pipeline_library = !(device->instance->debug & ANV_DEBUG_NO_GPL), + .EXT_graphics_pipeline_library = !ANV_DEBUG(NO_GPL), .EXT_hdr_metadata = true, .EXT_host_image_copy = true, .EXT_host_query_reset = true, @@ -2387,7 +2386,7 @@ anv_physical_device_init_uuids(struct anv_physical_device *device) _mesa_blake3_init(&blake3_ctx); _mesa_blake3_update(&blake3_ctx, build_id_data(note), build_id_len); brw_device_blake3_update(&blake3_ctx, &device->info); - bool always_use_bindless = !!(device->instance->debug & ANV_DEBUG_BINDLESS); + bool always_use_bindless = ANV_DEBUG(BINDLESS); _mesa_blake3_update(&blake3_ctx, &always_use_bindless, sizeof(always_use_bindless)); _mesa_blake3_final(&blake3_ctx, blake3); @@ -2566,8 +2565,7 @@ anv_physical_device_init_queue_families(struct anv_physical_device *pdevice) .engine_class = compute_class, }; } - if (v_count > 0 && ((pdevice->instance->debug & ANV_DEBUG_VIDEO_DECODE) || - (pdevice->instance->debug & ANV_DEBUG_VIDEO_ENCODE))) { + if (v_count > 0 && (ANV_DEBUG(VIDEO_DECODE) || ANV_DEBUG(VIDEO_ENCODE))) { /* HEVC support on Gfx9 is only available on VCS0. So limit the number of video queues * to the first VCS engine instance. * @@ -2580,9 +2578,9 @@ anv_physical_device_init_queue_families(struct anv_physical_device *pdevice) */ /* TODO: enable protected content on video queue */ pdevice->queue.families[family_count++] = (struct anv_queue_family) { - .queueFlags = ((pdevice->instance->debug & ANV_DEBUG_VIDEO_DECODE) ? + .queueFlags = (ANV_DEBUG(VIDEO_DECODE) ? VK_QUEUE_VIDEO_DECODE_BIT_KHR : 0) | - ((pdevice->instance->debug & ANV_DEBUG_VIDEO_ENCODE) ? + (ANV_DEBUG(VIDEO_ENCODE) ? VK_QUEUE_VIDEO_ENCODE_BIT_KHR : 0), .queueCount = pdevice->info.ver == 9 ? MIN2(1, v_count) : v_count, .engine_class = INTEL_ENGINE_CLASS_VIDEO, @@ -2816,9 +2814,9 @@ anv_physical_device_try_create(struct vk_instance *vk_instance, device->uses_relocs = device->info.kmd_type != INTEL_KMD_TYPE_XE; /* While xe.ko can use both vm_bind and TR-TT, i915.ko only has TR-TT. */ - if (!(instance->debug & ANV_DEBUG_NO_SPARSE)) { + if (!ANV_DEBUG(NO_SPARSE)) { if (device->info.kmd_type == INTEL_KMD_TYPE_XE) { - if (instance->debug & ANV_DEBUG_SPARSE_TRTT) + if (ANV_DEBUG(SPARSE_TRTT)) device->sparse_type = ANV_SPARSE_TYPE_TRTT; else device->sparse_type = ANV_SPARSE_TYPE_VM_BIND; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index ffb44022ba8..bd11bde2505 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1801,14 +1801,16 @@ enum anv_debug { ANV_DEBUG_DESCRIPTOR_DIRTY = BITFIELD_BIT(9), }; +extern enum anv_debug anv_debug; + +#define ANV_DEBUG(name) unlikely(anv_debug & ANV_DEBUG_##name) + struct anv_instance { struct vk_instance vk; struct driOptionCache dri_options; struct driOptionCache available_dri_options; - enum anv_debug debug; - int mesh_conv_prim_attrs_to_vert_attrs; bool enable_tbimr; bool enable_vf_distribution; @@ -6940,8 +6942,7 @@ anv_cmd_buffer_dirty_descriptors(struct anv_cmd_buffer* cmd_buffer, const char* reason) { cmd_buffer->state.descriptors_dirty |= stages; - if (unlikely(cmd_buffer->device->physical->instance->debug & - ANV_DEBUG_DESCRIPTOR_DIRTY)) + if (ANV_DEBUG(DESCRIPTOR_DIRTY)) anv_cmd_buffer_descriptor_buffer_debug(cmd_buffer, stages, reason); } diff --git a/src/intel/vulkan/anv_slab_bo.c b/src/intel/vulkan/anv_slab_bo.c index 0a7af377cfc..aaa55e716aa 100644 --- a/src/intel/vulkan/anv_slab_bo.c +++ b/src/intel/vulkan/anv_slab_bo.c @@ -340,7 +340,7 @@ anv_slab_bo_init(struct anv_device *device) unsigned num_slab_orders_per_allocator = (max_slab_order - min_slab_order) / num_slab_allocator; - if (unlikely(device->physical->instance->debug & ANV_DEBUG_NO_SLAB)) + if (ANV_DEBUG(NO_SLAB)) return true; /* feature requirement */ diff --git a/src/intel/vulkan/genX_cmd_compute.c b/src/intel/vulkan/genX_cmd_compute.c index 44e5c0d881b..fab710ef5a1 100644 --- a/src/intel/vulkan/genX_cmd_compute.c +++ b/src/intel/vulkan/genX_cmd_compute.c @@ -643,11 +643,10 @@ emit_cs_walker(struct anv_cmd_buffer *cmd_buffer, bool is_unaligned_size_x, uint32_t unaligned_invocations_x) { struct anv_device *device = cmd_buffer->device; - struct anv_instance *instance = device->physical->instance; bool is_indirect = !anv_address_is_null(indirect_addr); struct mi_builder b; - if (unlikely(instance->debug & ANV_DEBUG_SHADER_HASH)) { + if (ANV_DEBUG(SHADER_HASH)) { mi_builder_init(&b, device->info, &cmd_buffer->batch); mi_builder_set_mocs(&b, isl_mocs(&device->isl_dev, 0, false)); mi_store(&b, mi_mem32(device->workaround_address), diff --git a/src/intel/vulkan/genX_cmd_draw.c b/src/intel/vulkan/genX_cmd_draw.c index 0ef07099c42..c3e02d25e74 100644 --- a/src/intel/vulkan/genX_cmd_draw.c +++ b/src/intel/vulkan/genX_cmd_draw.c @@ -1079,13 +1079,13 @@ cmd_buffer_pre_draw_wa(struct anv_cmd_buffer *cmd_buffer) UNUSED struct anv_gfx_dynamic_state *hw_state = &gfx->dyn_state; struct mi_builder b; - if (unlikely(instance->debug & ANV_DEBUG_SHADER_HASH)) { + if (ANV_DEBUG(SHADER_HASH)) { mi_builder_init(&b, device->info, &cmd_buffer->batch); mi_builder_set_mocs(&b, isl_mocs(&device->isl_dev, 0, false)); } #define DEBUG_SHADER_HASH(stage) do { \ - if (unlikely(instance->debug & ANV_DEBUG_SHADER_HASH)) { \ + if (ANV_DEBUG(SHADER_HASH)) { \ mi_store(&b, \ mi_mem32(device->workaround_address), \ mi_imm(gfx->shaders[stage]->prog_data->source_hash)); \ diff --git a/src/intel/vulkan/genX_gfx_state.c b/src/intel/vulkan/genX_gfx_state.c index e65c46fda62..1b3a963f4ce 100644 --- a/src/intel/vulkan/genX_gfx_state.c +++ b/src/intel/vulkan/genX_gfx_state.c @@ -3605,7 +3605,6 @@ cmd_buffer_gfx_state_emission(struct anv_cmd_buffer *cmd_buffer) { struct anv_batch *batch = &cmd_buffer->batch; struct anv_device *device = cmd_buffer->device; - struct anv_instance *instance = device->physical->instance; struct anv_cmd_graphics_state *gfx = &cmd_buffer->state.gfx; const struct vk_dynamic_graphics_state *dyn = &cmd_buffer->vk.dynamic_graphics_state; @@ -3615,7 +3614,7 @@ cmd_buffer_gfx_state_emission(struct anv_cmd_buffer *cmd_buffer) #define DEBUG_SHADER_HASH(stage) do { \ if (unlikely( \ - (instance->debug & ANV_DEBUG_SHADER_HASH) && \ + ANV_DEBUG(SHADER_HASH) && \ anv_gfx_has_stage(gfx, stage))) { \ mi_store(&b, \ mi_mem32(device->workaround_address), \ @@ -3624,7 +3623,7 @@ cmd_buffer_gfx_state_emission(struct anv_cmd_buffer *cmd_buffer) } while (0) struct mi_builder b; - if (unlikely(instance->debug & ANV_DEBUG_SHADER_HASH)) { + if (ANV_DEBUG(SHADER_HASH)) { mi_builder_init(&b, device->info, &cmd_buffer->batch); mi_builder_set_mocs(&b, isl_mocs(&device->isl_dev, 0, false)); } diff --git a/src/intel/vulkan/xe/anv_kmd_backend.c b/src/intel/vulkan/xe/anv_kmd_backend.c index e56b9005551..06dbd5a4dd5 100644 --- a/src/intel/vulkan/xe/anv_kmd_backend.c +++ b/src/intel/vulkan/xe/anv_kmd_backend.c @@ -38,7 +38,7 @@ is_slab_parent_memory_mapped_placeable(struct anv_device *device, { if ((alloc_flags & ANV_BO_ALLOC_SLAB_PARENT) == false) return false; - if (device->physical->instance->debug & ANV_DEBUG_NO_SLAB) + if (ANV_DEBUG(NO_SLAB)) return false; if (!device->vk.enabled_features.memoryMapPlaced) return false;