Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix swapchain image wrappers lifetime #1424

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions framework/encode/vulkan_handle_wrapper_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ CreateWrappedHandle<DeviceWrapper, SwapchainKHRWrapper, ImageWrapper>(VkDevice,
CreateWrappedNonDispatchHandle<ImageWrapper>(handle, get_id);
wrapper = GetWrapper<ImageWrapper>(*handle);
wrapper->is_swapchain_image = true;
wrapper->parent_swapchains.insert(co_parent);
parent_wrapper->child_images.push_back(wrapper);
}
}
Expand Down Expand Up @@ -613,8 +614,12 @@ inline void DestroyWrappedHandle<SwapchainKHRWrapper>(VkSwapchainKHR handle)

for (auto image_wrapper : wrapper->child_images)
{
RemoveWrapper<ImageWrapper>(image_wrapper);
delete image_wrapper;
image_wrapper->parent_swapchains.erase(handle);
if (image_wrapper->parent_swapchains.empty())
{
RemoveWrapper<ImageWrapper>(image_wrapper);
delete image_wrapper;
}
}

RemoveWrapper<SwapchainKHRWrapper>(wrapper);
Expand Down
25 changes: 13 additions & 12 deletions framework/encode/vulkan_handle_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,19 @@ struct ImageWrapper : public HandleWrapper<VkImage>
const void* bind_pnext{ nullptr };
HandleUnwrapMemory bind_pnext_memory; // Global HandleUnwrapMemory could be reset anytime, so it should have its own
// HandleUnwrapMemory.
format::HandleId bind_memory_id{ format::kNullHandleId };
VkDeviceSize bind_offset{ 0 };
uint32_t queue_family_index{ 0 };
VkImageType image_type{ VK_IMAGE_TYPE_2D };
VkFormat format{ VK_FORMAT_UNDEFINED };
VkExtent3D extent{ 0, 0, 0 };
uint32_t mip_levels{ 0 };
uint32_t array_layers{ 0 };
VkSampleCountFlagBits samples{};
VkImageTiling tiling{};
VkImageLayout current_layout{ VK_IMAGE_LAYOUT_UNDEFINED };
bool is_swapchain_image{ false };
format::HandleId bind_memory_id{ format::kNullHandleId };
VkDeviceSize bind_offset{ 0 };
uint32_t queue_family_index{ 0 };
VkImageType image_type{ VK_IMAGE_TYPE_2D };
VkFormat format{ VK_FORMAT_UNDEFINED };
VkExtent3D extent{ 0, 0, 0 };
uint32_t mip_levels{ 0 };
uint32_t array_layers{ 0 };
VkSampleCountFlagBits samples{};
VkImageTiling tiling{};
VkImageLayout current_layout{ VK_IMAGE_LAYOUT_UNDEFINED };
bool is_swapchain_image{ false };
std::set<VkSwapchainKHR> parent_swapchains;
};

struct BufferViewWrapper : public HandleWrapper<VkBufferView>
Expand Down
Loading