Module: Mesa Branch: main Commit: d7ef1331b5e625b39d3cbbcab41808dd8c36cff0 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d7ef1331b5e625b39d3cbbcab41808dd8c36cff0
Author: Chia-I Wu <[email protected]> Date: Thu Jan 26 09:42:06 2023 -0800 turnip: make debug_flags a global variable Add tu_env as a global variable and add tu_env_init to initialize it. Add TU_DEBUG macro to check debug flags. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20946> --- src/freedreno/vulkan/tu_clear_blit.c | 8 ++-- src/freedreno/vulkan/tu_cmd_buffer.c | 20 ++++----- src/freedreno/vulkan/tu_descriptor_set.c | 8 ++-- src/freedreno/vulkan/tu_device.c | 59 ++++----------------------- src/freedreno/vulkan/tu_device.h | 30 -------------- src/freedreno/vulkan/tu_drm.c | 5 +-- src/freedreno/vulkan/tu_image.c | 8 ++-- src/freedreno/vulkan/tu_kgsl.c | 5 +-- src/freedreno/vulkan/tu_lrz.c | 8 ++-- src/freedreno/vulkan/tu_nir_lower_multiview.c | 2 +- src/freedreno/vulkan/tu_pass.c | 4 +- src/freedreno/vulkan/tu_pipeline.c | 4 +- src/freedreno/vulkan/tu_shader.c | 4 +- src/freedreno/vulkan/tu_util.c | 58 ++++++++++++++++++++++++-- src/freedreno/vulkan/tu_util.h | 40 +++++++++++++++++- 15 files changed, 136 insertions(+), 127 deletions(-) diff --git a/src/freedreno/vulkan/tu_clear_blit.c b/src/freedreno/vulkan/tu_clear_blit.c index 2577bd68e18..bfb53ef36a5 100644 --- a/src/freedreno/vulkan/tu_clear_blit.c +++ b/src/freedreno/vulkan/tu_clear_blit.c @@ -3073,8 +3073,7 @@ tu_begin_load_store_cond_exec(struct tu_cmd_buffer *cmd, { tu_cond_exec_start(cs, CP_COND_REG_EXEC_0_MODE(PRED_TEST)); - if (!unlikely(cmd->device->physical_device->instance->debug_flags & - TU_DEBUG_LOG_SKIP_GMEM_OPS)) + if (!TU_DEBUG(LOG_SKIP_GMEM_OPS)) return; uint64_t result_iova; @@ -3096,8 +3095,7 @@ tu_end_load_store_cond_exec(struct tu_cmd_buffer *cmd, { tu_cond_exec_end(cs); - if (!unlikely(cmd->device->physical_device->instance->debug_flags & - TU_DEBUG_LOG_SKIP_GMEM_OPS)) + if (!TU_DEBUG(LOG_SKIP_GMEM_OPS)) return; uint64_t result_iova; @@ -3294,7 +3292,7 @@ tu_attachment_store_unaligned(struct tu_cmd_buffer *cmd, uint32_t a) const VkRect2D *render_area = &cmd->state.render_area; /* Unaligned store is incredibly rare in CTS, we have to force it to test. */ - if (unlikely(cmd->device->physical_device->instance->debug_flags & TU_DEBUG_UNALIGNED_STORE)) + if (TU_DEBUG(UNALIGNED_STORE)) return true; uint32_t x1 = render_area->offset.x; diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index 0151b40a5e5..cd19e2a52af 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -138,10 +138,10 @@ tu6_emit_flushes(struct tu_cmd_buffer *cmd_buffer, enum tu_cmd_flush_bits flushes = cache->flush_bits; cache->flush_bits = 0; - if (unlikely(cmd_buffer->device->physical_device->instance->debug_flags & TU_DEBUG_FLUSHALL)) + if (TU_DEBUG(FLUSHALL)) flushes |= TU_CMD_FLAG_ALL_FLUSH | TU_CMD_FLAG_ALL_INVALIDATE; - if (unlikely(cmd_buffer->device->physical_device->instance->debug_flags & TU_DEBUG_SYNCDRAW)) + if (TU_DEBUG(SYNCDRAW)) flushes |= TU_CMD_FLAG_WAIT_MEM_WRITES | TU_CMD_FLAG_WAIT_FOR_IDLE | TU_CMD_FLAG_WAIT_FOR_ME; @@ -193,7 +193,7 @@ void tu_emit_cache_flush_renderpass(struct tu_cmd_buffer *cmd_buffer) { if (!cmd_buffer->state.renderpass_cache.flush_bits && - likely(!cmd_buffer->device->physical_device->instance->debug_flags)) + likely(!tu_env.debug)) return; tu6_emit_flushes(cmd_buffer, &cmd_buffer->draw_cs, &cmd_buffer->state.renderpass_cache); @@ -682,7 +682,7 @@ static bool use_sysmem_rendering(struct tu_cmd_buffer *cmd, struct tu_renderpass_result **autotune_result) { - if (unlikely(cmd->device->physical_device->instance->debug_flags & TU_DEBUG_SYSMEM)) + if (TU_DEBUG(SYSMEM)) return true; /* can't fit attachments into gmem */ @@ -716,7 +716,7 @@ use_sysmem_rendering(struct tu_cmd_buffer *cmd, !cmd->state.tiling->binning_possible) return true; - if (unlikely(cmd->device->physical_device->instance->debug_flags & TU_DEBUG_GMEM)) + if (TU_DEBUG(GMEM)) return false; bool use_sysmem = tu_autotune_use_bypass(&cmd->device->autotune, @@ -1847,7 +1847,7 @@ tu_BeginCommandBuffer(VkCommandBuffer commandBuffer, vk_find_struct_const(pBeginInfo->pInheritanceInfo->pNext, COMMAND_BUFFER_INHERITANCE_RENDERING_INFO); - if (unlikely(cmd_buffer->device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { rendering_info = vk_get_command_buffer_inheritance_rendering_info(cmd_buffer->vk.level, pBeginInfo); @@ -4282,7 +4282,7 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer, { TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer); - if (unlikely(cmd->device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { vk_common_CmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); return; @@ -4405,7 +4405,7 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer, } } - if (unlikely(cmd->device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { const VkRenderingSelfDependencyInfoMESA *self_dependency = vk_find_struct_const(pRenderingInfo->pNext, RENDERING_SELF_DEPENDENCY_INFO_MESA); if (self_dependency && @@ -4496,7 +4496,7 @@ tu_CmdNextSubpass2(VkCommandBuffer commandBuffer, { TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer); - if (unlikely(cmd->device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { vk_common_CmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo); return; @@ -5860,7 +5860,7 @@ tu_CmdEndRenderPass2(VkCommandBuffer commandBuffer, { TU_FROM_HANDLE(tu_cmd_buffer, cmd_buffer, commandBuffer); - if (unlikely(cmd_buffer->device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { vk_common_CmdEndRenderPass2(commandBuffer, pSubpassEndInfo); return; } diff --git a/src/freedreno/vulkan/tu_descriptor_set.c b/src/freedreno/vulkan/tu_descriptor_set.c index d4becab491f..9c99ca712b2 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.c +++ b/src/freedreno/vulkan/tu_descriptor_set.c @@ -42,7 +42,7 @@ descriptor_size(struct tu_device *dev, { switch (type) { case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: - if (unlikely(dev->instance->debug_flags & TU_DEBUG_DYNAMIC)) + if (TU_DEBUG(DYNAMIC)) return A6XX_TEX_CONST_DWORDS * 4; /* Input attachment doesn't use descriptor sets at all */ @@ -1186,7 +1186,7 @@ tu_GetDescriptorEXT( break; case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: /* nothing in descriptor set - framebuffer state is used instead */ - if (unlikely(device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { write_image_descriptor(pDescriptor, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorInfo->data.pInputAttachmentImage); } @@ -1347,7 +1347,7 @@ tu_update_descriptor_sets(const struct tu_device *device, break; case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: /* nothing in descriptor set - framebuffer state is used instead */ - if (unlikely(device->instance->debug_flags & TU_DEBUG_DYNAMIC)) + if (TU_DEBUG(DYNAMIC)) write_image_descriptor(ptr, writeset->descriptorType, writeset->pImageInfo + j); break; default: @@ -1676,7 +1676,7 @@ tu_update_descriptor_set_with_template( break; case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: /* nothing in descriptor set - framebuffer state is used instead */ - if (unlikely(device->instance->debug_flags & TU_DEBUG_DYNAMIC)) + if (TU_DEBUG(DYNAMIC)) write_image_descriptor(ptr, templ->entry[i].descriptor_type, src); break; default: diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index f3dd819afc6..de1372b4310 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -56,7 +56,7 @@ tu_device_get_cache_uuid(struct tu_physical_device *device, void *uuid) * shader hash instead, since the compiler is only created with the logical * device. */ - uint64_t driver_flags = device->instance->debug_flags & TU_DEBUG_NOMULTIPOS; + uint64_t driver_flags = tu_env.debug & TU_DEBUG_NOMULTIPOS; uint16_t family = fd_dev_gpu_id(&device->dev_id); memset(uuid, 0, VK_UUID_SIZE); @@ -145,7 +145,7 @@ get_device_extensions(const struct tu_physical_device *device, .KHR_maintenance3 = true, .KHR_maintenance4 = true, .KHR_multiview = true, - .KHR_performance_query = device->instance->debug_flags & TU_DEBUG_PERFC, + .KHR_performance_query = TU_DEBUG(PERFC), .KHR_pipeline_executable_properties = true, .KHR_push_descriptor = true, .KHR_relaxed_block_layout = true, @@ -391,37 +391,6 @@ tu_destroy_physical_device(struct vk_physical_device *device) vk_free(&device->instance->alloc, device); } -static const struct debug_control tu_debug_options[] = { - { "startup", TU_DEBUG_STARTUP }, - { "nir", TU_DEBUG_NIR }, - { "nobin", TU_DEBUG_NOBIN }, - { "sysmem", TU_DEBUG_SYSMEM }, - { "gmem", TU_DEBUG_GMEM }, - { "forcebin", TU_DEBUG_FORCEBIN }, - { "layout", TU_DEBUG_LAYOUT }, - { "noubwc", TU_DEBUG_NOUBWC }, - { "nomultipos", TU_DEBUG_NOMULTIPOS }, - { "nolrz", TU_DEBUG_NOLRZ }, - { "nolrzfc", TU_DEBUG_NOLRZFC }, - { "perf", TU_DEBUG_PERF }, - { "perfc", TU_DEBUG_PERFC }, - { "flushall", TU_DEBUG_FLUSHALL }, - { "syncdraw", TU_DEBUG_SYNCDRAW }, - { "rast_order", TU_DEBUG_RAST_ORDER }, - { "unaligned_store", TU_DEBUG_UNALIGNED_STORE }, - { "log_skip_gmem_ops", TU_DEBUG_LOG_SKIP_GMEM_OPS }, - { "dynamic", TU_DEBUG_DYNAMIC }, - { "bos", TU_DEBUG_BOS }, - { NULL, 0 } -}; - -const char * -tu_get_debug_option_name(int id) -{ - assert(id < ARRAY_SIZE(tu_debug_options) - 1); - return tu_debug_options[id].string; -} - static const driOptionDescription tu_dri_options[] = { DRI_CONF_SECTION_PERFORMANCE DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0) @@ -464,6 +433,8 @@ tu_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, struct tu_instance *instance; VkResult result; + tu_env_init(); + assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO); if (pAllocator == NULL) @@ -498,18 +469,7 @@ tu_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, #endif instance->vk.physical_devices.destroy = tu_destroy_physical_device; - instance->debug_flags = - parse_debug_string(os_get_option("TU_DEBUG"), tu_debug_options); - -#ifdef DEBUG - /* Enable startup debugging by default on debug drivers. You almost always - * want to see your startup failures in that case, and it's hard to set - * this env var on android. - */ - instance->debug_flags |= TU_DEBUG_STARTUP; -#endif - - if (instance->debug_flags & TU_DEBUG_STARTUP) + if (TU_DEBUG(STARTUP)) mesa_logi("Created an instance"); VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false)); @@ -1501,8 +1461,7 @@ tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, A6XX_TEX_CONST_DWORDS * 4; properties->robustStorageBufferDescriptorSize = properties->storageBufferDescriptorSize; - properties->inputAttachmentDescriptorSize = - (pdevice->instance->debug_flags & TU_DEBUG_DYNAMIC) ? + properties->inputAttachmentDescriptorSize = TU_DEBUG(DYNAMIC) ? A6XX_TEX_CONST_DWORDS * 4 : 0; properties->maxSamplerDescriptorBufferRange = ~0ull; @@ -2082,7 +2041,7 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice, u_rwlock_init(&device->dma_bo_lock); pthread_mutex_init(&device->submit_mutex, NULL); - if (device->instance->debug_flags & TU_DEBUG_BOS) + if (TU_DEBUG(BOS)) device->bo_sizes = _mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal); #ifndef TU_USE_KGSL @@ -2922,7 +2881,7 @@ tu_CreateFramebuffer(VkDevice _device, { TU_FROM_HANDLE(tu_device, device, _device); - if (unlikely(device->instance->debug_flags & TU_DEBUG_DYNAMIC)) + if (TU_DEBUG(DYNAMIC)) return vk_common_CreateFramebuffer(_device, pCreateInfo, pAllocator, pFramebuffer); @@ -2984,7 +2943,7 @@ tu_DestroyFramebuffer(VkDevice _device, { TU_FROM_HANDLE(tu_device, device, _device); - if (unlikely(device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { vk_common_DestroyFramebuffer(_device, _fb, pAllocator); return; } diff --git a/src/freedreno/vulkan/tu_device.h b/src/freedreno/vulkan/tu_device.h index 2aa326e1b9d..809b81d176d 100644 --- a/src/freedreno/vulkan/tu_device.h +++ b/src/freedreno/vulkan/tu_device.h @@ -35,31 +35,6 @@ /* extra space in vsc draw/prim streams */ #define VSC_PAD 0x40 -enum tu_debug_flags -{ - TU_DEBUG_STARTUP = 1 << 0, - TU_DEBUG_NIR = 1 << 1, - TU_DEBUG_NOBIN = 1 << 3, - TU_DEBUG_SYSMEM = 1 << 4, - TU_DEBUG_FORCEBIN = 1 << 5, - TU_DEBUG_NOUBWC = 1 << 6, - TU_DEBUG_NOMULTIPOS = 1 << 7, - TU_DEBUG_NOLRZ = 1 << 8, - TU_DEBUG_PERFC = 1 << 9, - TU_DEBUG_FLUSHALL = 1 << 10, - TU_DEBUG_SYNCDRAW = 1 << 11, - /* bit 12 is available */ - TU_DEBUG_GMEM = 1 << 13, - TU_DEBUG_RAST_ORDER = 1 << 14, - TU_DEBUG_UNALIGNED_STORE = 1 << 15, - TU_DEBUG_LAYOUT = 1 << 16, - TU_DEBUG_LOG_SKIP_GMEM_OPS = 1 << 17, - TU_DEBUG_PERF = 1 << 18, - TU_DEBUG_NOLRZFC = 1 << 19, - TU_DEBUG_DYNAMIC = 1 << 20, - TU_DEBUG_BOS = 1 << 21, -}; - enum global_shader { GLOBAL_SH_VS_BLIT, GLOBAL_SH_VS_CLEAR, @@ -148,8 +123,6 @@ struct tu_instance struct driOptionCache dri_options; struct driOptionCache available_dri_options; - enum tu_debug_flags debug_flags; - bool dont_care_as_load; /* Conservative LRZ (default true) invalidates LRZ on draws with @@ -439,9 +412,6 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler, base, VkSampler, uint64_t tu_get_system_heap_size(void); -const char * -tu_get_debug_option_name(int id); - VkResult tu_physical_device_init(struct tu_physical_device *device, struct tu_instance *instance); diff --git a/src/freedreno/vulkan/tu_drm.c b/src/freedreno/vulkan/tu_drm.c index 250ff53a954..d757a92f6c3 100644 --- a/src/freedreno/vulkan/tu_drm.c +++ b/src/freedreno/vulkan/tu_drm.c @@ -859,7 +859,7 @@ tu_physical_device_try_create(struct vk_instance *vk_instance, drmFreeVersion(version); - if (instance->debug_flags & TU_DEBUG_STARTUP) + if (TU_DEBUG(STARTUP)) mesa_logi("Found compatible device '%s'.", path); device->instance = instance; @@ -1303,8 +1303,7 @@ tu_queue_submit(struct vk_queue *vk_queue, struct vk_queue_submit *submit) submit->perf_pass_index : ~0; struct tu_queue_submit submit_req; - if (unlikely(queue->device->physical_device->instance->debug_flags & - TU_DEBUG_LOG_SKIP_GMEM_OPS)) { + if (TU_DEBUG(LOG_SKIP_GMEM_OPS)) { tu_dbg_log_gmem_load_store_skips(queue->device); } diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c index 15a0649a2dc..f5e4e3fb43c 100644 --- a/src/freedreno/vulkan/tu_image.c +++ b/src/freedreno/vulkan/tu_image.c @@ -510,7 +510,7 @@ tu_image_init(struct tu_device *device, struct tu_image *image, /* expect UBWC enabled if we asked for it */ if (modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED) assert(ubwc_enabled); - else if (device->physical_device->instance->debug_flags & TU_DEBUG_NOUBWC) + else if (TU_DEBUG(NOUBWC)) ubwc_enabled = false; /* Non-UBWC tiled R8G8 is probably buggy since media formats are always @@ -574,7 +574,7 @@ tu_image_init(struct tu_device *device, struct tu_image *image, return vk_error(device, VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT); } - if (device->instance->debug_flags & TU_DEBUG_LAYOUT) + if (TU_DEBUG(LAYOUT)) fdl_dump_layout(layout); /* fdl6_layout can't take explicit offset without explicit pitch @@ -593,7 +593,7 @@ tu_image_init(struct tu_device *device, struct tu_image *image, } const struct util_format_description *desc = util_format_description(image->layout[0].format); - if (util_format_has_depth(desc) && !(device->instance->debug_flags & TU_DEBUG_NOLRZ)) + if (util_format_has_depth(desc) && !TU_DEBUG(NOLRZ)) { /* Depth plane is the first one */ struct fdl_layout *layout = &image->layout[0]; @@ -630,7 +630,7 @@ tu_image_init(struct tu_device *device, struct tu_image *image, /* Fast-clear buffer cannot be larger than 512 bytes (HW limitation) */ bool has_lrz_fc = image->lrz_fc_size <= 512 && device->physical_device->info->a6xx.enable_lrz_fast_clear && - !unlikely(device->physical_device->instance->debug_flags & TU_DEBUG_NOLRZFC); + !TU_DEBUG(NOLRZFC); if (has_lrz_fc || device->physical_device->info->a6xx.has_lrz_dir_tracking) { image->lrz_fc_offset = image->total_size; diff --git a/src/freedreno/vulkan/tu_kgsl.c b/src/freedreno/vulkan/tu_kgsl.c index 8344d8c9f81..20e9690467f 100644 --- a/src/freedreno/vulkan/tu_kgsl.c +++ b/src/freedreno/vulkan/tu_kgsl.c @@ -263,7 +263,7 @@ tu_enumerate_devices(struct vk_instance *vk_instance) /* kgsl version check? */ - if (instance->debug_flags & TU_DEBUG_STARTUP) + if (TU_DEBUG(STARTUP)) mesa_logi("Found compatible device '%s'.", path); device->instance = instance; @@ -377,8 +377,7 @@ tu_QueueSubmit2(VkQueue _queue, TU_FROM_HANDLE(tu_syncobj, fence, _fence); VkResult result = VK_SUCCESS; - if (unlikely(queue->device->physical_device->instance->debug_flags & - TU_DEBUG_LOG_SKIP_GMEM_OPS)) { + if (TU_DEBUG(LOG_SKIP_GMEM_OPS)) { tu_dbg_log_gmem_load_store_skips(queue->device); } diff --git a/src/freedreno/vulkan/tu_lrz.c b/src/freedreno/vulkan/tu_lrz.c index 1553d7ec63f..6a04e3e0dc1 100644 --- a/src/freedreno/vulkan/tu_lrz.c +++ b/src/freedreno/vulkan/tu_lrz.c @@ -111,8 +111,7 @@ tu_lrz_init_state(struct tu_cmd_buffer *cmd, const struct tu_image_view *view) { if (!view->image->lrz_height) { - assert((cmd->device->instance->debug_flags & TU_DEBUG_NOLRZ) || - !vk_format_has_depth(att->format)); + assert(TU_DEBUG(NOLRZ) || !vk_format_has_depth(att->format)); return; } @@ -161,7 +160,7 @@ tu_lrz_init_secondary(struct tu_cmd_buffer *cmd, if (!has_gpu_tracking) return; - if (cmd->device->instance->debug_flags & TU_DEBUG_NOLRZ) + if (TU_DEBUG(NOLRZ)) return; if (!vk_format_has_depth(att->format)) @@ -575,8 +574,7 @@ tu6_calculate_lrz_state(struct tu_cmd_buffer *cmd, /* If depth test is disabled we shouldn't touch LRZ. * Same if there is no depth attachment. */ - if (a == VK_ATTACHMENT_UNUSED || !z_test_enable || - (cmd->device->instance->debug_flags & TU_DEBUG_NOLRZ)) + if (a == VK_ATTACHMENT_UNUSED || !z_test_enable || TU_DEBUG(NOLRZ)) return gras_lrz_cntl; if (!cmd->state.lrz.gpu_dir_tracking && !cmd->state.attachments) { diff --git a/src/freedreno/vulkan/tu_nir_lower_multiview.c b/src/freedreno/vulkan/tu_nir_lower_multiview.c index 6b4ea3020ee..81374431f82 100644 --- a/src/freedreno/vulkan/tu_nir_lower_multiview.c +++ b/src/freedreno/vulkan/tu_nir_lower_multiview.c @@ -99,7 +99,7 @@ tu_nir_lower_multiview(nir_shader *nir, uint32_t mask, struct tu_device *dev) /* In addition to the generic checks done by NIR, check that we don't * overflow VPC with the extra copies of gl_Position. */ - if (likely(!(dev->physical_device->instance->debug_flags & TU_DEBUG_NOMULTIPOS)) && + if (!TU_DEBUG(NOMULTIPOS) && num_views <= max_views_for_multipos && num_outputs + (num_views - 1) <= 32 && nir_can_lower_multiview(nir)) { /* It appears that the multiview mask is ignored when multi-position diff --git a/src/freedreno/vulkan/tu_pass.c b/src/freedreno/vulkan/tu_pass.c index 0aad74ad347..e6256e68bc0 100644 --- a/src/freedreno/vulkan/tu_pass.c +++ b/src/freedreno/vulkan/tu_pass.c @@ -761,7 +761,7 @@ tu_CreateRenderPass2(VkDevice _device, { TU_FROM_HANDLE(tu_device, device, _device); - if (unlikely(device->instance->debug_flags & TU_DEBUG_DYNAMIC)) + if (TU_DEBUG(DYNAMIC)) return vk_common_CreateRenderPass2(_device, pCreateInfo, pAllocator, pRenderPass); @@ -957,7 +957,7 @@ tu_DestroyRenderPass(VkDevice _device, { TU_FROM_HANDLE(tu_device, device, _device); - if (unlikely(device->instance->debug_flags & TU_DEBUG_DYNAMIC)) { + if (TU_DEBUG(DYNAMIC)) { vk_common_DestroyRenderPass(_device, _pass, pAllocator); return; } diff --git a/src/freedreno/vulkan/tu_pipeline.c b/src/freedreno/vulkan/tu_pipeline.c index bb4114466cd..427ef801112 100644 --- a/src/freedreno/vulkan/tu_pipeline.c +++ b/src/freedreno/vulkan/tu_pipeline.c @@ -4662,7 +4662,7 @@ tu_pipeline_builder_parse_rasterization_order( bool raster_order_attachment_access = pipeline->blend.raster_order_attachment_access || pipeline->ds.raster_order_attachment_access || - unlikely(builder->device->physical_device->instance->debug_flags & TU_DEBUG_RAST_ORDER); + TU_DEBUG(RAST_ORDER); /* VK_EXT_blend_operation_advanced would also require ordered access * when implemented in the future. @@ -4957,7 +4957,7 @@ tu_pipeline_builder_init_graphics( const VkPipelineRenderingCreateInfo *rendering_info = vk_find_struct_const(create_info->pNext, PIPELINE_RENDERING_CREATE_INFO); - if (unlikely(dev->instance->debug_flags & TU_DEBUG_DYNAMIC) && !rendering_info) + if (TU_DEBUG(DYNAMIC) && !rendering_info) rendering_info = vk_get_pipeline_rendering_create_info(create_info); /* Get multiview_mask, which is only used for shaders */ diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c index ce8a6e3bd59..1f414f87c10 100644 --- a/src/freedreno/vulkan/tu_shader.c +++ b/src/freedreno/vulkan/tu_shader.c @@ -90,7 +90,7 @@ tu_spirv_to_nir(struct tu_device *dev, if (result != VK_SUCCESS) return NULL; - if (unlikely(dev->physical_device->instance->debug_flags & TU_DEBUG_NIR)) { + if (TU_DEBUG(NIR)) { fprintf(stderr, "translated nir:\n"); nir_print_shader(nir, stderr); } @@ -361,7 +361,7 @@ build_bindless(struct tu_device *dev, nir_builder *b, /* input attachments use non bindless workaround */ if (bind_layout->type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT && - likely(!(dev->instance->debug_flags & TU_DEBUG_DYNAMIC))) { + !TU_DEBUG(DYNAMIC)) { const struct glsl_type *glsl_type = glsl_without_array(var->type); uint32_t idx = var->data.index * 2; diff --git a/src/freedreno/vulkan/tu_util.c b/src/freedreno/vulkan/tu_util.c index 537bf6e0e98..07a9df29d4f 100644 --- a/src/freedreno/vulkan/tu_util.c +++ b/src/freedreno/vulkan/tu_util.c @@ -15,6 +15,57 @@ #include "tu_device.h" #include "tu_pass.h" +static const struct debug_control tu_debug_options[] = { + { "startup", TU_DEBUG_STARTUP }, + { "nir", TU_DEBUG_NIR }, + { "nobin", TU_DEBUG_NOBIN }, + { "sysmem", TU_DEBUG_SYSMEM }, + { "gmem", TU_DEBUG_GMEM }, + { "forcebin", TU_DEBUG_FORCEBIN }, + { "layout", TU_DEBUG_LAYOUT }, + { "noubwc", TU_DEBUG_NOUBWC }, + { "nomultipos", TU_DEBUG_NOMULTIPOS }, + { "nolrz", TU_DEBUG_NOLRZ }, + { "nolrzfc", TU_DEBUG_NOLRZFC }, + { "perf", TU_DEBUG_PERF }, + { "perfc", TU_DEBUG_PERFC }, + { "flushall", TU_DEBUG_FLUSHALL }, + { "syncdraw", TU_DEBUG_SYNCDRAW }, + { "rast_order", TU_DEBUG_RAST_ORDER }, + { "unaligned_store", TU_DEBUG_UNALIGNED_STORE }, + { "log_skip_gmem_ops", TU_DEBUG_LOG_SKIP_GMEM_OPS }, + { "dynamic", TU_DEBUG_DYNAMIC }, + { "bos", TU_DEBUG_BOS }, + { NULL, 0 } +}; + +struct tu_env tu_env; + +static void +tu_env_init_once(void) +{ + tu_env.debug = parse_debug_string(os_get_option("TU_DEBUG"), + tu_debug_options); + +#ifdef DEBUG + /* Enable startup debugging by default on debug drivers. You almost always + * want to see your startup failures in that case, and it's hard to set + * this env var on android. + */ + tu_env.debug |= TU_DEBUG_STARTUP; +#endif + + if (TU_DEBUG(STARTUP)) + mesa_logi("TU_DEBUG=0x%x", tu_env.debug); +} + +void +tu_env_init(void) +{ + static once_flag once = ONCE_FLAG_INIT; + call_once(&once, tu_env_init_once); +} + void PRINTFLIKE(3, 4) __tu_finishme(const char *file, int line, const char *format, ...) { @@ -126,7 +177,7 @@ tu_tiling_config_update_tile_layout(struct tu_framebuffer *fb, if (!pass->gmem_pixels[gmem_layout]) return; - if (unlikely(dev->physical_device->instance->debug_flags & TU_DEBUG_FORCEBIN)) { + if (TU_DEBUG(FORCEBIN)) { /* start with 2x2 tiles */ tiling->tile_count.width = 2; tiling->tile_count.height = 2; @@ -255,10 +306,9 @@ tu_tiling_config_update_binning(struct tu_tiling_config *tiling, const struct tu if (tiling->binning_possible) { tiling->binning = (tiling->tile_count.width * tiling->tile_count.height) > 2; - if (unlikely(device->physical_device->instance->debug_flags & TU_DEBUG_FORCEBIN)) + if (TU_DEBUG(FORCEBIN)) tiling->binning = true; - if (unlikely(device->physical_device->instance->debug_flags & - TU_DEBUG_NOBIN)) + if (TU_DEBUG(NOBIN)) tiling->binning = false; } else { tiling->binning = false; diff --git a/src/freedreno/vulkan/tu_util.h b/src/freedreno/vulkan/tu_util.h index 41b7eda42af..b4603f6d61f 100644 --- a/src/freedreno/vulkan/tu_util.h +++ b/src/freedreno/vulkan/tu_util.h @@ -18,6 +18,42 @@ #include "vk_util.h" +#define TU_DEBUG(name) unlikely(tu_env.debug & TU_DEBUG_##name) + +enum tu_debug_flags +{ + TU_DEBUG_STARTUP = 1 << 0, + TU_DEBUG_NIR = 1 << 1, + TU_DEBUG_NOBIN = 1 << 3, + TU_DEBUG_SYSMEM = 1 << 4, + TU_DEBUG_FORCEBIN = 1 << 5, + TU_DEBUG_NOUBWC = 1 << 6, + TU_DEBUG_NOMULTIPOS = 1 << 7, + TU_DEBUG_NOLRZ = 1 << 8, + TU_DEBUG_PERFC = 1 << 9, + TU_DEBUG_FLUSHALL = 1 << 10, + TU_DEBUG_SYNCDRAW = 1 << 11, + /* bit 12 is available */ + TU_DEBUG_GMEM = 1 << 13, + TU_DEBUG_RAST_ORDER = 1 << 14, + TU_DEBUG_UNALIGNED_STORE = 1 << 15, + TU_DEBUG_LAYOUT = 1 << 16, + TU_DEBUG_LOG_SKIP_GMEM_OPS = 1 << 17, + TU_DEBUG_PERF = 1 << 18, + TU_DEBUG_NOLRZFC = 1 << 19, + TU_DEBUG_DYNAMIC = 1 << 20, + TU_DEBUG_BOS = 1 << 21, +}; + +struct tu_env { + uint32_t debug; +}; + +extern struct tu_env tu_env; + +void +tu_env_init(void); + /* Whenever we generate an error, pass it through this function. Useful for * debugging, where we can break on it. Only call at error site, not when * propagating errors. Might be useful to plug in a stack trace here. @@ -37,7 +73,7 @@ __vk_startup_errorf(struct tu_instance *instance, */ #define vk_startup_errorf(instance, error, format, ...) \ __vk_startup_errorf(instance, error, \ - instance->debug_flags & TU_DEBUG_STARTUP, \ + TU_DEBUG(STARTUP), \ __FILE__, __LINE__, format, ##__VA_ARGS__) void @@ -391,7 +427,7 @@ void tu_dbg_log_gmem_load_store_skips(struct tu_device *device); #define perf_debug(device, fmt, ...) do { \ - if (unlikely((device)->instance->debug_flags & TU_DEBUG_PERF)) \ + if (TU_DEBUG(PERF)) \ mesa_log(MESA_LOG_WARN, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__); \ } while(0)
