diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 04:37:50 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 04:37:50 -0500 |
| commit | c50059aaba339cded3cbe5e8a3ca12aa44fd98ec (patch) | |
| tree | 50fefc25f0c0b91788399a9a1aff65edc7cececb /runtime/src | |
| parent | 12f0c70d92f71f8c8c9b1132f5fb3a3125cbfd1c (diff) | |
| parent | 1c5463b430d23a6e63d410ceb390f448b02be482 (diff) | |
Merge pull request #1230 from totonii
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/vulkan_backend.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 084e000e1..45851e527 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -1054,15 +1054,21 @@ public: | |||
| 1054 | VkCommandBuffer command_buffer = VK_NULL_HANDLE; | 1054 | VkCommandBuffer command_buffer = VK_NULL_HANDLE; |
| 1055 | std::function<void(bool)> bindless_commit; | 1055 | std::function<void(bool)> bindless_commit; |
| 1056 | // Lock hierarchy: resource_mutex_ -> tracker_mutex_ -> submit_mutex_. | 1056 | // Lock hierarchy: resource_mutex_ -> tracker_mutex_ -> submit_mutex_. |
| 1057 | // Shared read-lock allows concurrent prepare() lookups; when depth24_ is active, tracker_mutex_ is also | 1057 | // Shared read-lock allows concurrent prepare() across queues; tracker_mutex_ is acquired lazily during |
| 1058 | // acquired before prepare() so Depth24Converter::prepare/collect/retire stay serialized per execution. | 1058 | // prepare() only if a list actually converts a depth24_as_float copy, and otherwise right before |
| 1059 | // Otherwise tracker_mutex_ is held from emit() through submit() so emit order == submit order across queues. | 1059 | // bindless_prepare_/emit() through submit() so bindless flushes, layout emits, and submissions stay in order. |
| 1060 | std::shared_lock resource_lock(context_.resource_mutex_); | 1060 | std::shared_lock resource_lock(context_.resource_mutex_); |
| 1061 | std::unique_lock tracker_lock(context_.tracker_mutex_, std::defer_lock); | 1061 | std::unique_lock tracker_lock(context_.tracker_mutex_, std::defer_lock); |
| 1062 | if (context_.depth24_) { | 1062 | // Declared after tracker_lock so any early return after depth24_->prepare() retires uncommitted scratch/pools |
| 1063 | tracker_lock.lock(); | 1063 | // with ticket 0 while tracker_lock is still held. |
| 1064 | context_.depth24_->collect(); | 1064 | struct Depth24Guard { |
| 1065 | } | 1065 | Depth24Converter* d24 = nullptr; |
| 1066 | VkSemaphore progress = VK_NULL_HANDLE; | ||
| 1067 | bool active = false; | ||
| 1068 | ~Depth24Guard() { | ||
| 1069 | if (active && d24) d24->retire(progress, 0); | ||
| 1070 | } | ||
| 1071 | } depth24_guard{context_.depth24_.get(), progress_, false}; | ||
| 1066 | bindless_commit = context_.bindless_commit_; | 1072 | bindless_commit = context_.bindless_commit_; |
| 1067 | std::vector<PreparedList> prepared(lists.size()); | 1073 | std::vector<PreparedList> prepared(lists.size()); |
| 1068 | ReplayFunctions replay = context_.replay_; | 1074 | ReplayFunctions replay = context_.replay_; |
| @@ -1086,6 +1092,17 @@ public: | |||
| 1086 | context_.predicate_reducer_->capture(cb, p); | 1092 | context_.predicate_reducer_->capture(cb, p); |
| 1087 | }; | 1093 | }; |
| 1088 | } | 1094 | } |
| 1095 | if (context_.depth24_) { | ||
| 1096 | replay.depth24_prepare = [this, &tracker_lock, &depth24_guard](Depth24Job& job, | ||
| 1097 | std::vector<Depth24Job>& parts) { | ||
| 1098 | if (!tracker_lock.owns_lock()) tracker_lock.lock(); | ||
| 1099 | if (!depth24_guard.active) { | ||
| 1100 | context_.depth24_->collect(); | ||
| 1101 | depth24_guard.active = true; | ||
| 1102 | } | ||
| 1103 | return context_.depth24_->prepare(job, parts); | ||
| 1104 | }; | ||
| 1105 | } | ||
| 1089 | const auto& occlusion_memory = context_.occlusion_resolve_memory_; | 1106 | const auto& occlusion_memory = context_.occlusion_resolve_memory_; |
| 1090 | const bool can_resolve_occlusion = occlusion_memory.memoryTypeCount != 0; | 1107 | const bool can_resolve_occlusion = occlusion_memory.memoryTypeCount != 0; |
| 1091 | if (can_resolve_occlusion) { | 1108 | if (can_resolve_occlusion) { |
| @@ -1148,16 +1165,20 @@ public: | |||
| 1148 | discard(); | 1165 | discard(); |
| 1149 | return ReplayResult::unsupported; | 1166 | return ReplayResult::unsupported; |
| 1150 | } | 1167 | } |
| 1168 | if (!tracker_lock.owns_lock()) tracker_lock.lock(); | ||
| 1151 | if (context_.bindless_prepare_ && !context_.bindless_prepare_(command_buffer)) { | 1169 | if (context_.bindless_prepare_ && !context_.bindless_prepare_(command_buffer)) { |
| 1152 | const bool ended = context_.vk.vkEndCommandBuffer(command_buffer) == VK_SUCCESS; | 1170 | const bool ended = context_.vk.vkEndCommandBuffer(command_buffer) == VK_SUCCESS; |
| 1153 | resource_lock.unlock(); | 1171 | resource_lock.unlock(); |
| 1154 | if (tracker_lock.owns_lock()) tracker_lock.unlock(); | ||
| 1155 | const bool submitted = ended && submit(command_buffer, VK_NULL_HANDLE, 0); | 1172 | const bool submitted = ended && submit(command_buffer, VK_NULL_HANDLE, 0); |
| 1156 | if (!submitted) discard(); | 1173 | if (!submitted) discard(); |
| 1174 | if (depth24_guard.active) { | ||
| 1175 | context_.depth24_->retire(progress_, 0); | ||
| 1176 | depth24_guard.active = false; | ||
| 1177 | } | ||
| 1178 | tracker_lock.unlock(); | ||
| 1157 | if (bindless_commit) bindless_commit(submitted); | 1179 | if (bindless_commit) bindless_commit(submitted); |
| 1158 | return ReplayResult::unsupported; | 1180 | return ReplayResult::unsupported; |
| 1159 | } | 1181 | } |
| 1160 | if (!tracker_lock.owns_lock()) tracker_lock.lock(); | ||
| 1161 | auto next_tracker = context_.tracker_; | 1182 | auto next_tracker = context_.tracker_; |
| 1162 | bool wrote_readback = false; | 1183 | bool wrote_readback = false; |
| 1163 | VkPipelineStageFlags2 readback_stages = 0; | 1184 | VkPipelineStageFlags2 readback_stages = 0; |
| @@ -1209,7 +1230,10 @@ public: | |||
| 1209 | } else { | 1230 | } else { |
| 1210 | discard(); | 1231 | discard(); |
| 1211 | } | 1232 | } |
| 1212 | if (context_.depth24_) context_.depth24_->retire(progress_, submitted ? submitted_ : 0); | 1233 | if (depth24_guard.active) { |
| 1234 | context_.depth24_->retire(progress_, submitted ? submitted_ : 0); | ||
| 1235 | depth24_guard.active = false; | ||
| 1236 | } | ||
| 1213 | tracker_lock.unlock(); | 1237 | tracker_lock.unlock(); |
| 1214 | if (bindless_commit) bindless_commit(submitted); | 1238 | if (bindless_commit) bindless_commit(submitted); |
| 1215 | return submitted ? ReplayResult::success : ReplayResult::unsupported; | 1239 | return submitted ? ReplayResult::success : ReplayResult::unsupported; |