Skip to content

Commit

Permalink
Store Vulkan images in VK swapchain systems
Browse files Browse the repository at this point in the history
  • Loading branch information
kosude committed Dec 18, 2023
1 parent 449cf09 commit 2d8c589
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/vulkan/vk_swapchain_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ TLVK_SwapchainSystem_t *TLVK_SwapchainSystemCreate(const TLVK_RendererSystem_t *

TL_Log(debugger, "Allocated memory for Vulkan swapchain system at %p", swapchain_system);

swapchain_system->vk_image_count = 0;
swapchain_system->vk_images = NULL;

swapchain_system->renderer_system = renderer_system;

swapchain_system->vk_instance = renderer_system->vk_context->vk_instance;
Expand Down Expand Up @@ -322,6 +325,17 @@ TLVK_SwapchainSystem_t *TLVK_SwapchainSystemCreate(const TLVK_RendererSystem_t *
return NULL;
}

// retrieve image handles
devfs->vkGetSwapchainImagesKHR(renderer_system->vk_logical_device, swapchain_system->vk_swapchain, &swapchain_system->vk_image_count, NULL);
swapchain_system->vk_images = malloc(sizeof(VkImage) * swapchain_system->vk_image_count);
if (!swapchain_system->vk_images) {
TL_Fatal(debugger, "MALLOC fault in call to TLVK_SwapchainSystemCreate");
return NULL;
}
devfs->vkGetSwapchainImagesKHR(renderer_system->vk_logical_device, swapchain_system->vk_swapchain, &swapchain_system->vk_image_count,
swapchain_system->vk_images);

// debug output
if (debugger) {
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(renderer_system->vk_physical_device, &props);
Expand All @@ -331,6 +345,7 @@ TLVK_SwapchainSystem_t *TLVK_SwapchainSystemCreate(const TLVK_RendererSystem_t *

TL_Log(debugger, " For use by physical device \"%s\"", props.deviceName);
TL_Log(debugger, " With extent resolution %dx%d", extent.width, extent.height);
TL_Log(debugger, " Image count %d (from minimum of %d)", swapchain_system->vk_image_count, min_img_count);
}

return swapchain_system;
Expand All @@ -346,5 +361,7 @@ void TLVK_SwapchainSystemDestroy(TLVK_SwapchainSystem_t *const swapchain_system)
devfs->vkDestroySwapchainKHR(swapchain_system->renderer_system->vk_logical_device, swapchain_system->vk_swapchain, NULL);
vkDestroySurfaceKHR(swapchain_system->vk_instance, swapchain_system->vk_surface, NULL);

free(swapchain_system->vk_images);

free(swapchain_system);
}
6 changes: 6 additions & 0 deletions src/types/vulkan/vk_swapchain_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ typedef struct TLVK_SwapchainSystem_t {
/// @brief Vulkan window surface object:
/// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSurfaceKHR.html
VkSurfaceKHR vk_surface;

/// @brief Array of Vulkan images, retrieved from `vk_swapchain`:
/// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImage.html
VkImage *vk_images;
/// @brief Amount of elements in `vk_images`.
uint32_t vk_image_count;
} TLVK_SwapchainSystem_t;

#ifdef __cplusplus
Expand Down

0 comments on commit 2d8c589

Please sign in to comment.