|
| 1 | +From 9545b9f927099c74212485c391a21e02efb2793d Mon Sep 17 00:00:00 2001 |
| 2 | +From: lfdevs <109842948+lfdevs@users.noreply.github.com> |
| 3 | +Date: Sat, 11 Apr 2026 09:09:03 +0800 |
| 4 | +Subject: [PATCH] turnip/autotune: don't fail device init when CP group is |
| 5 | + missing |
| 6 | + |
| 7 | +Note: This is a temporary fix patch, and upstream will fix this issue soon: |
| 8 | +https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40823 |
| 9 | + |
| 10 | +After MR !37802, tu_autotune initialization treats missing CP perf counters |
| 11 | +as a fatal error and returns VK_ERROR_INITIALIZATION_FAILED. On newer A8xx |
| 12 | +devices where perf counter mappings may be incomplete, this breaks device |
| 13 | +creation and causes all Vulkan apps (including vulkaninfo) to fail. |
| 14 | + |
| 15 | +Make preempt latency tracking initialization degrade gracefully instead of |
| 16 | +failing device creation: |
| 17 | +- only probe CP counters when preempt tracking is supported |
| 18 | +- if CP group/countables/counters are missing, log a warning |
| 19 | +- disable PREEMPT_OPTIMIZE in both supported and active autotune config |
| 20 | +- continue initialization with VK_SUCCESS |
| 21 | + |
| 22 | +This keeps optional preempt optimization disabled on unsupported hardware |
| 23 | +while preserving normal Vulkan device creation. |
| 24 | +--- |
| 25 | + src/freedreno/vulkan/tu_autotune.cc | 47 ++++++++++++++++++----------- |
| 26 | + 1 file changed, 30 insertions(+), 17 deletions(-) |
| 27 | + |
| 28 | +diff --git a/src/freedreno/vulkan/tu_autotune.cc b/src/freedreno/vulkan/tu_autotune.cc |
| 29 | +index e1e4666768c..080ffdadf10 100644 |
| 30 | +--- a/src/freedreno/vulkan/tu_autotune.cc |
| 31 | ++++ b/src/freedreno/vulkan/tu_autotune.cc |
| 32 | +@@ -1632,24 +1632,28 @@ tu_autotune::tu_autotune(struct tu_device *device, VkResult &result) |
| 33 | + { |
| 34 | + tu_bo_suballocator_init(&suballoc, device, 128 * 1024, TU_BO_ALLOC_INTERNAL_RESOURCE, "autotune_suballoc"); |
| 35 | + |
| 36 | +- uint32_t group_count; |
| 37 | +- const struct fd_perfcntr_group *groups = fd_perfcntrs(&device->physical_device->dev_id, &group_count); |
| 38 | ++ auto disable_preempt_optimize_with_reason = [&](const char *reason) { |
| 39 | ++ mesa_logw("autotune: %s, disabling preempt_optimize", reason); |
| 40 | ++ supported_mod_flags &= ~(uint32_t) mod_flag::PREEMPT_OPTIMIZE; |
| 41 | ++ disable_preempt_optimize(); |
| 42 | ++ }; |
| 43 | + |
| 44 | +- for (uint32_t i = 0; i < group_count; i++) { |
| 45 | +- if (strcmp(groups[i].name, "CP") == 0) { |
| 46 | +- cp_group = &groups[i]; |
| 47 | +- break; |
| 48 | ++ if (supports_preempt_latency_tracking()) { |
| 49 | ++ uint32_t group_count; |
| 50 | ++ const struct fd_perfcntr_group *groups = fd_perfcntrs(&device->physical_device->dev_id, &group_count); |
| 51 | ++ |
| 52 | ++ for (uint32_t i = 0; i < group_count; i++) { |
| 53 | ++ if (strcmp(groups[i].name, "CP") == 0) { |
| 54 | ++ cp_group = &groups[i]; |
| 55 | ++ break; |
| 56 | ++ } |
| 57 | + } |
| 58 | +- } |
| 59 | + |
| 60 | +- if (!cp_group) { |
| 61 | +- mesa_loge("autotune: CP group not found"); |
| 62 | +- result = VK_ERROR_INITIALIZATION_FAILED; |
| 63 | +- return; |
| 64 | +- } else if (cp_group->num_countables < 5) { |
| 65 | +- mesa_loge("autotune: CP group has too few countables"); |
| 66 | +- result = VK_ERROR_INITIALIZATION_FAILED; |
| 67 | +- return; |
| 68 | ++ if (!cp_group) { |
| 69 | ++ disable_preempt_optimize_with_reason("CP group not found"); |
| 70 | ++ } else if (cp_group->num_countables < 5) { |
| 71 | ++ disable_preempt_optimize_with_reason("CP group has too few countables"); |
| 72 | ++ } |
| 73 | + } |
| 74 | + |
| 75 | + auto get_perfcntr_countable = [](const struct fd_perfcntr_group *group, |
| 76 | +@@ -1667,9 +1671,18 @@ tu_autotune::tu_autotune(struct tu_device *device, VkResult &result) |
| 77 | + auto preemption_latency_countable = get_perfcntr_countable(cp_group, "PERF_CP_PREEMPTION_REACTION_DELAY"); |
| 78 | + auto always_count_countable = get_perfcntr_countable(cp_group, "PERF_CP_ALWAYS_COUNT"); |
| 79 | + |
| 80 | ++ if (!preemption_latency_countable || !always_count_countable) { |
| 81 | ++ disable_preempt_optimize_with_reason("required CP countables missing for preemption tracking"); |
| 82 | ++ } |
| 83 | ++ |
| 84 | ++ if (!supports_preempt_latency_tracking()) { |
| 85 | ++ result = VK_SUCCESS; |
| 86 | ++ return; |
| 87 | ++ } |
| 88 | ++ |
| 89 | + if (cp_group->num_counters < 2) { |
| 90 | +- mesa_loge("autotune: CP group has too few counters for preemption latency tracking"); |
| 91 | +- result = VK_ERROR_INITIALIZATION_FAILED; |
| 92 | ++ disable_preempt_optimize_with_reason("CP group has too few counters for preemption latency tracking"); |
| 93 | ++ result = VK_SUCCESS; |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | +-- |
| 98 | +2.47.3 |
| 99 | + |
0 commit comments