fix race condition in vulkan encoder

This commit is contained in:
Patrick Nicolas
2026-04-02 14:39:48 +02:00
parent 706f76b18d
commit cd9b3fc031
2 changed files with 4 additions and 0 deletions
+3
View File
@@ -616,6 +616,7 @@ std::optional<wivrn::video_encoder::data> wivrn::video_encoder_vulkan::encode(ui
return data{
.encoder = this,
.span = std::span(((uint8_t *)mapped), size),
.mem = std::shared_ptr<void>(&slot_item.busy, [](std::atomic_bool * busy) {*busy = false; busy->notify_all(); }),
.prefer_control = slot_item.idr,
};
}
@@ -950,6 +951,8 @@ void wivrn::video_encoder_vulkan::post_submit(uint8_t slot)
{
auto & slot_item = slot_data[slot];
const auto & prev_slot = slot_data[(slot + num_slots - 1) % num_slots];
slot_item.busy.wait(true);
slot_item.busy = true;
const bool need_transfer = *slot_item.transfer_cmd_buf and slot_item.host_buffer;
// Issue encode command, and if necessary transfer command
vk.device.resetFences(*slot_item.fence);
+1
View File
@@ -56,6 +56,7 @@ class video_encoder_vulkan : public video_encoder
buffer_allocation host_buffer;
vk::DeviceSize copy_size;
bool idr = false;
std::atomic_bool busy = false;
};
std::array<slot_item, num_slots> slot_data;