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

Support for external allocators: #748

Merged
merged 15 commits into from
Sep 16, 2023
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
42 changes: 38 additions & 4 deletions include/ktxvulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ typedef struct ktxVulkanTexture
VkImageLayout imageLayout; /*!< Layout of the created image. Has the same
value as @p layout parameter passed to the
loader. */
VkDeviceMemory deviceMemory; /*!< The memory allocated for the image on
the Vulkan device. */
VkDeviceMemory deviceMemory; /*!< The memory (sub)allocation for the
image on the Vulkan device. Will not be
used with suballocators.*/
VkImageViewType viewType; /*!< ViewType corresponding to @p image. Reflects
the dimensionality, cubeness and arrayness
of the image. */
Expand All @@ -124,15 +125,41 @@ typedef struct ktxVulkanTexture
uint32_t depth; /*!< The depth of the image. */
uint32_t levelCount; /*!< The number of MIP levels in the image. */
uint32_t layerCount; /*!< The number of array layers in the image. */
uint64_t allocationId; /*!< An id referencing suballocation(s). */
} ktxVulkanTexture;

typedef uint64_t(*ktxVulkanTexture_subAllocatorAllocMemFuncPtr)(VkMemoryAllocateInfo* allocInfo, VkMemoryRequirements* memReq, uint64_t* pageCount);
typedef VkResult(*ktxVulkanTexture_subAllocatorBindBufferFuncPtr)(VkBuffer buffer, uint64_t allocId);
typedef VkResult(*ktxVulkanTexture_subAllocatorBindImageFuncPtr)(VkImage image, uint64_t allocId);
typedef VkResult(*ktxVulkanTexture_subAllocatorMemoryMapFuncPtr)(uint64_t allocId, uint64_t pageNumber, VkDeviceSize *mapLength, void** dataPtr);
typedef void (*ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr)(uint64_t allocId, uint64_t pageNumber);
typedef void (*ktxVulkanTexture_subAllocatorFreeMemFuncPtr)(uint64_t allocId);
/**
* @class ktxVulkanTexture_subAllocatorCallbacks
* @~English
* @brief Struct that contains all callbacks necessary for suballocation.
*
* These pointers must all be provided for upload or destroy to occur using suballocator callbacks.
*/
typedef struct {
ktxVulkanTexture_subAllocatorAllocMemFuncPtr allocMemFuncPtr; /*!< Pointer to the memory procurement function. Can suballocate one or more pages. */
ktxVulkanTexture_subAllocatorBindBufferFuncPtr bindBufferFuncPtr; /*!< Pointer to bind-buffer-to-suballocation(s) function. */
ktxVulkanTexture_subAllocatorBindImageFuncPtr bindImageFuncPtr; /*!< Pointer to bind-image-to-suballocation(s) function. */
ktxVulkanTexture_subAllocatorMemoryMapFuncPtr memoryMapFuncPtr; /*!< Pointer to function for mapping the memory of a specific page. */
ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr memoryUnmapFuncPtr; /*!< Pointer to function for unmapping the memory of a specific page. */
ktxVulkanTexture_subAllocatorFreeMemFuncPtr freeMemFuncPtr; /*!< Pointer to the free procurement function. */
} ktxVulkanTexture_subAllocatorCallbacks;

KTX_API ktx_error_code_e KTX_APIENTRY
ktxVulkanTexture_Destruct_WithSuballocator(ktxVulkanTexture* This, VkDevice device,
const VkAllocationCallbacks* pAllocator,
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);

KTX_API void KTX_APIENTRY
ktxVulkanTexture_Destruct(ktxVulkanTexture* This, VkDevice device,
const VkAllocationCallbacks* pAllocator);




/**
* @class ktxVulkanDeviceInfo
* @~English
Expand Down Expand Up @@ -208,6 +235,13 @@ ktxVulkanDeviceInfo_Destruct(ktxVulkanDeviceInfo* This);
KTX_API void KTX_APIENTRY
ktxVulkanDeviceInfo_Destroy(ktxVulkanDeviceInfo* This);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_VkUploadEx_WithSuballocator(ktxTexture* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
VkImageUsageFlags usageFlags,
VkImageLayout finalLayout,
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);
KTX_API KTX_error_code KTX_APIENTRY
ktxTexture_VkUploadEx(ktxTexture* This, ktxVulkanDeviceInfo* vdi,
ktxVulkanTexture* vkTexture,
VkImageTiling tiling,
Expand Down
302 changes: 228 additions & 74 deletions lib/vkloader.c

Large diffs are not rendered by default.

Loading