Path: blob/master/thirdparty/libktx/include/ktxvulkan.h
9902 views
/* -*- tab-width: 4; -*- */1/* vi: set sw=2 ts=4 expandtab: */23#ifndef KTX_H_C54B42AEE39611E68E1E4FF8C51D1C664#define KTX_H_C54B42AEE39611E68E1E4FF8C51D1C6656/*7* Copyright 2017-2020 The Khronos Group, Inc.8* SPDX-License-Identifier: Apache-2.09*/1011/**12* @internal13* @file14* @~English15*16* @brief Declares the public functions and structures of the17* KTX Vulkan texture loading API.18*19* A separate header file is used to avoid extra dependencies for those not20* using Vulkan. The nature of the Vulkan API, rampant structures and enums,21* means that vulkan.h must be included @e before including this file. The22* alternative is duplicating unattractively large parts of it.23*24* @author Mark Callow, Edgewise Consulting25*/2627#include <ktx.h>2829#if 030/* Avoid Vulkan include file */31#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;3233#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)34#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;35#else36#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;37#endif3839VK_DEFINE_HANDLE(VkPhysicalDevice)40VK_DEFINE_HANDLE(VkDevice)41VK_DEFINE_HANDLE(VkQueue)42VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool)43VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeviceMemory)44VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImage)45VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView)46VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler)47#endif4849#ifdef __cplusplus50extern "C" {51#endif5253/**54* @struct ktxVulkanFunctions55* @~English56* @brief Struct for applications to pass Vulkan function pointers to the57* ktxTexture_VkUpload functions via a ktxVulkanDeviceInfo struct.58*59* @c vkGetInstanceProcAddr and @c vkGetDeviceProcAddr should be set, others60* are optional.61*/62typedef struct ktxVulkanFunctions {63// These are functions pointers we need to perform our vulkan duties.64PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;65PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;6667// These we optionally specify68PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;69PFN_vkAllocateMemory vkAllocateMemory;70PFN_vkBeginCommandBuffer vkBeginCommandBuffer;71PFN_vkBindBufferMemory vkBindBufferMemory;72PFN_vkBindImageMemory vkBindImageMemory;73PFN_vkCmdBlitImage vkCmdBlitImage;74PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage;75PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;76PFN_vkCreateImage vkCreateImage;77PFN_vkDestroyImage vkDestroyImage;78PFN_vkCreateBuffer vkCreateBuffer;79PFN_vkDestroyBuffer vkDestroyBuffer;80PFN_vkCreateFence vkCreateFence;81PFN_vkDestroyFence vkDestroyFence;82PFN_vkEndCommandBuffer vkEndCommandBuffer;83PFN_vkFreeCommandBuffers vkFreeCommandBuffers;84PFN_vkFreeMemory vkFreeMemory;85PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;86PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;87PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout;88PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;89PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;90PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;91PFN_vkMapMemory vkMapMemory;92PFN_vkQueueSubmit vkQueueSubmit;93PFN_vkQueueWaitIdle vkQueueWaitIdle;94PFN_vkUnmapMemory vkUnmapMemory;95PFN_vkWaitForFences vkWaitForFences;96} ktxVulkanFunctions;9798/**99* @class ktxVulkanTexture100* @~English101* @brief Struct for returning information about the Vulkan texture image102* created by the ktxTexture_VkUpload* functions.103*104* Creation of these objects is internal to the upload functions.105*/106typedef struct ktxVulkanTexture107{108PFN_vkDestroyImage vkDestroyImage; /*!< Pointer to vkDestroyImage function */109PFN_vkFreeMemory vkFreeMemory; /*!< Pointer to vkFreeMemory function */110111VkImage image; /*!< Handle to the Vulkan image created by the loader. */112VkFormat imageFormat; /*!< Format of the image data. */113VkImageLayout imageLayout; /*!< Layout of the created image. Has the same114value as @p layout parameter passed to the115loader. */116VkDeviceMemory deviceMemory; /*!< The memory (sub)allocation for the117image on the Vulkan device. Will not be118used with suballocators.*/119VkImageViewType viewType; /*!< ViewType corresponding to @p image. Reflects120the dimensionality, cubeness and arrayness121of the image. */122uint32_t width; /*!< The width of the image. */123uint32_t height; /*!< The height of the image. */124uint32_t depth; /*!< The depth of the image. */125uint32_t levelCount; /*!< The number of MIP levels in the image. */126uint32_t layerCount; /*!< The number of array layers in the image. */127uint64_t allocationId; /*!< An id referencing suballocation(s). */128} ktxVulkanTexture;129130typedef uint64_t(*ktxVulkanTexture_subAllocatorAllocMemFuncPtr)(VkMemoryAllocateInfo* allocInfo, VkMemoryRequirements* memReq, uint64_t* pageCount);131typedef VkResult(*ktxVulkanTexture_subAllocatorBindBufferFuncPtr)(VkBuffer buffer, uint64_t allocId);132typedef VkResult(*ktxVulkanTexture_subAllocatorBindImageFuncPtr)(VkImage image, uint64_t allocId);133typedef VkResult(*ktxVulkanTexture_subAllocatorMemoryMapFuncPtr)(uint64_t allocId, uint64_t pageNumber, VkDeviceSize *mapLength, void** dataPtr);134typedef void (*ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr)(uint64_t allocId, uint64_t pageNumber);135typedef void (*ktxVulkanTexture_subAllocatorFreeMemFuncPtr)(uint64_t allocId);136/**137* @class ktxVulkanTexture_subAllocatorCallbacks138* @~English139* @brief Struct that contains all callbacks necessary for suballocation.140*141* These pointers must all be provided for upload or destroy to occur using suballocator callbacks.142*/143typedef struct {144ktxVulkanTexture_subAllocatorAllocMemFuncPtr allocMemFuncPtr; /*!< Pointer to the memory procurement function. Can suballocate one or more pages. */145ktxVulkanTexture_subAllocatorBindBufferFuncPtr bindBufferFuncPtr; /*!< Pointer to bind-buffer-to-suballocation(s) function. */146ktxVulkanTexture_subAllocatorBindImageFuncPtr bindImageFuncPtr; /*!< Pointer to bind-image-to-suballocation(s) function. */147ktxVulkanTexture_subAllocatorMemoryMapFuncPtr memoryMapFuncPtr; /*!< Pointer to function for mapping the memory of a specific page. */148ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr memoryUnmapFuncPtr; /*!< Pointer to function for unmapping the memory of a specific page. */149ktxVulkanTexture_subAllocatorFreeMemFuncPtr freeMemFuncPtr; /*!< Pointer to the free procurement function. */150} ktxVulkanTexture_subAllocatorCallbacks;151152KTX_API ktx_error_code_e KTX_APIENTRY153ktxVulkanTexture_Destruct_WithSuballocator(ktxVulkanTexture* This, VkDevice device,154const VkAllocationCallbacks* pAllocator,155ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);156157KTX_API void KTX_APIENTRY158ktxVulkanTexture_Destruct(ktxVulkanTexture* This, VkDevice device,159const VkAllocationCallbacks* pAllocator);160161162/**163* @class ktxVulkanDeviceInfo164* @~English165* @brief Struct for passing information about the Vulkan device on which166* to create images to the texture image loading functions.167*168* Avoids passing a large number of parameters to each loading function.169* Use of ktxVulkanDeviceInfo_create() or ktxVulkanDeviceInfo_construct() to170* populate this structure is highly recommended.171*172* @code173ktxVulkanDeviceInfo vdi;174ktxVulkanTexture texture;175176vdi = ktxVulkanDeviceInfo_create(physicalDevice,177device,178queue,179cmdPool,180&allocator);181ktxLoadVkTextureN("texture_1.ktx", vdi, &texture, NULL, NULL);182// ...183ktxLoadVkTextureN("texture_n.ktx", vdi, &texture, NULL, NULL);184ktxVulkanDeviceInfo_destroy(vdi);185* @endcode186*/187typedef struct ktxVulkanDeviceInfo {188VkInstance instance; /*!< Instance used to communicate with vulkan. */189VkPhysicalDevice physicalDevice; /*!< Handle of the physical device. */190VkDevice device; /*!< Handle of the logical device. */191VkQueue queue; /*!< Handle to the queue to which to submit commands. */192VkCommandBuffer cmdBuffer; /*!< Handle of the cmdBuffer to use. */193/** Handle of the command pool from which to allocate the command buffer. */194VkCommandPool cmdPool;195/** Pointer to the allocator to use for the command buffer and created196* images.197*/198const VkAllocationCallbacks* pAllocator;199/** Memory properties of the Vulkan physical device. */200VkPhysicalDeviceMemoryProperties deviceMemoryProperties;201202/** The functions needed to operate functions */203ktxVulkanFunctions vkFuncs;204} ktxVulkanDeviceInfo;205206207KTX_API ktxVulkanDeviceInfo* KTX_APIENTRY208ktxVulkanDeviceInfo_CreateEx(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device,209VkQueue queue, VkCommandPool cmdPool,210const VkAllocationCallbacks* pAllocator,211const ktxVulkanFunctions* pFunctions);212213KTX_API ktxVulkanDeviceInfo* KTX_APIENTRY214ktxVulkanDeviceInfo_Create(VkPhysicalDevice physicalDevice, VkDevice device,215VkQueue queue, VkCommandPool cmdPool,216const VkAllocationCallbacks* pAllocator);217218KTX_API KTX_error_code KTX_APIENTRY219ktxVulkanDeviceInfo_Construct(ktxVulkanDeviceInfo* This,220VkPhysicalDevice physicalDevice, VkDevice device,221VkQueue queue, VkCommandPool cmdPool,222const VkAllocationCallbacks* pAllocator);223224KTX_API KTX_error_code KTX_APIENTRY225ktxVulkanDeviceInfo_ConstructEx(ktxVulkanDeviceInfo* This,226VkInstance instance,227VkPhysicalDevice physicalDevice, VkDevice device,228VkQueue queue, VkCommandPool cmdPool,229const VkAllocationCallbacks* pAllocator,230const ktxVulkanFunctions* pFunctions);231232KTX_API void KTX_APIENTRY233ktxVulkanDeviceInfo_Destruct(ktxVulkanDeviceInfo* This);234KTX_API void KTX_APIENTRY235ktxVulkanDeviceInfo_Destroy(ktxVulkanDeviceInfo* This);236KTX_API KTX_error_code KTX_APIENTRY237ktxTexture_VkUploadEx_WithSuballocator(ktxTexture* This, ktxVulkanDeviceInfo* vdi,238ktxVulkanTexture* vkTexture,239VkImageTiling tiling,240VkImageUsageFlags usageFlags,241VkImageLayout finalLayout,242ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);243KTX_API KTX_error_code KTX_APIENTRY244ktxTexture_VkUploadEx(ktxTexture* This, ktxVulkanDeviceInfo* vdi,245ktxVulkanTexture* vkTexture,246VkImageTiling tiling,247VkImageUsageFlags usageFlags,248VkImageLayout finalLayout);249KTX_API KTX_error_code KTX_APIENTRY250ktxTexture_VkUpload(ktxTexture* texture, ktxVulkanDeviceInfo* vdi,251ktxVulkanTexture *vkTexture);252KTX_API KTX_error_code KTX_APIENTRY253ktxTexture1_VkUploadEx_WithSuballocator(ktxTexture1* This, ktxVulkanDeviceInfo* vdi,254ktxVulkanTexture* vkTexture,255VkImageTiling tiling,256VkImageUsageFlags usageFlags,257VkImageLayout finalLayout,258ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);259KTX_API KTX_error_code KTX_APIENTRY260ktxTexture1_VkUploadEx(ktxTexture1* This, ktxVulkanDeviceInfo* vdi,261ktxVulkanTexture* vkTexture,262VkImageTiling tiling,263VkImageUsageFlags usageFlags,264VkImageLayout finalLayout);265KTX_API KTX_error_code KTX_APIENTRY266ktxTexture1_VkUpload(ktxTexture1* texture, ktxVulkanDeviceInfo* vdi,267ktxVulkanTexture *vkTexture);268KTX_API KTX_error_code KTX_APIENTRY269ktxTexture2_VkUploadEx_WithSuballocator(ktxTexture2* This, ktxVulkanDeviceInfo* vdi,270ktxVulkanTexture* vkTexture,271VkImageTiling tiling,272VkImageUsageFlags usageFlags,273VkImageLayout finalLayout,274ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);275KTX_API KTX_error_code KTX_APIENTRY276ktxTexture2_VkUploadEx(ktxTexture2* This, ktxVulkanDeviceInfo* vdi,277ktxVulkanTexture* vkTexture,278VkImageTiling tiling,279VkImageUsageFlags usageFlags,280VkImageLayout finalLayout);281KTX_API KTX_error_code KTX_APIENTRY282ktxTexture2_VkUpload(ktxTexture2* texture, ktxVulkanDeviceInfo* vdi,283ktxVulkanTexture *vkTexture);284285KTX_API VkFormat KTX_APIENTRY286ktxTexture_GetVkFormat(ktxTexture* This);287288KTX_API VkFormat KTX_APIENTRY289ktxTexture1_GetVkFormat(ktxTexture1* This);290291KTX_API VkFormat KTX_APIENTRY292ktxTexture2_GetVkFormat(ktxTexture2* This);293294#ifdef __cplusplus295}296#endif297298#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */299300301