Skip to content

Commit faa8ec4

Browse files
committed
Handle in-flight encoders properly
1 parent 3bc7a37 commit faa8ec4

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

pathfinder/gpu/vk/swap_chain.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void SwapChainVk::destroy() {
124124
vkQueueWaitIdle(device_->get_graphics_queue());
125125
vkQueueWaitIdle(device_->get_present_queue());
126126

127-
encoder_of_last_frame_.reset();
127+
encoders_in_flight_.clear();
128128

129129
// Clean up swap chain related resources.
130130
cleanup_swapchain();
@@ -239,9 +239,9 @@ void SwapChainVk::create_sync_objects() {
239239
}
240240

241241
void SwapChainVk::submit(const std::shared_ptr<CommandEncoder> &encoder) {
242-
// Cleanup last encoder.
243-
if (encoder_of_last_frame_) {
244-
encoder_of_last_frame_ = nullptr;
242+
encoders_in_flight_.push_back(encoder);
243+
if (encoders_in_flight_.size() > MAX_FRAMES_IN_FLIGHT) {
244+
encoders_in_flight_.erase(encoders_in_flight_.begin());
245245
}
246246

247247
if (encoder->submitted_) {
@@ -256,8 +256,6 @@ void SwapChainVk::submit(const std::shared_ptr<CommandEncoder> &encoder) {
256256
}
257257

258258
flush(encoder);
259-
260-
encoder_of_last_frame_ = encoder;
261259
}
262260

263261
void SwapChainVk::flush(const std::shared_ptr<CommandEncoder> &encoder) {

pathfinder/gpu/vk/swap_chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SwapChainVk : public SwapChain {
8181
std::vector<VkFence> images_in_flight_;
8282
// --------------------------------------
8383

84-
std::shared_ptr<CommandEncoder> encoder_of_last_frame_;
84+
std::vector<std::shared_ptr<CommandEncoder>> encoders_in_flight_;
8585

8686
private:
8787
void init_swapchain();

0 commit comments

Comments
 (0)