Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libktx/include/ktxvulkan.h
9902 views
1
/* -*- tab-width: 4; -*- */
2
/* vi: set sw=2 ts=4 expandtab: */
3
4
#ifndef KTX_H_C54B42AEE39611E68E1E4FF8C51D1C66
5
#define KTX_H_C54B42AEE39611E68E1E4FF8C51D1C66
6
7
/*
8
* Copyright 2017-2020 The Khronos Group, Inc.
9
* SPDX-License-Identifier: Apache-2.0
10
*/
11
12
/**
13
* @internal
14
* @file
15
* @~English
16
*
17
* @brief Declares the public functions and structures of the
18
* KTX Vulkan texture loading API.
19
*
20
* A separate header file is used to avoid extra dependencies for those not
21
* using Vulkan. The nature of the Vulkan API, rampant structures and enums,
22
* means that vulkan.h must be included @e before including this file. The
23
* alternative is duplicating unattractively large parts of it.
24
*
25
* @author Mark Callow, Edgewise Consulting
26
*/
27
28
#include <ktx.h>
29
30
#if 0
31
/* Avoid Vulkan include file */
32
#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
33
34
#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
35
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
36
#else
37
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
38
#endif
39
40
VK_DEFINE_HANDLE(VkPhysicalDevice)
41
VK_DEFINE_HANDLE(VkDevice)
42
VK_DEFINE_HANDLE(VkQueue)
43
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool)
44
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeviceMemory)
45
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImage)
46
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView)
47
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler)
48
#endif
49
50
#ifdef __cplusplus
51
extern "C" {
52
#endif
53
54
/**
55
* @struct ktxVulkanFunctions
56
* @~English
57
* @brief Struct for applications to pass Vulkan function pointers to the
58
* ktxTexture_VkUpload functions via a ktxVulkanDeviceInfo struct.
59
*
60
* @c vkGetInstanceProcAddr and @c vkGetDeviceProcAddr should be set, others
61
* are optional.
62
*/
63
typedef struct ktxVulkanFunctions {
64
// These are functions pointers we need to perform our vulkan duties.
65
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
66
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
67
68
// These we optionally specify
69
PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
70
PFN_vkAllocateMemory vkAllocateMemory;
71
PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
72
PFN_vkBindBufferMemory vkBindBufferMemory;
73
PFN_vkBindImageMemory vkBindImageMemory;
74
PFN_vkCmdBlitImage vkCmdBlitImage;
75
PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage;
76
PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
77
PFN_vkCreateImage vkCreateImage;
78
PFN_vkDestroyImage vkDestroyImage;
79
PFN_vkCreateBuffer vkCreateBuffer;
80
PFN_vkDestroyBuffer vkDestroyBuffer;
81
PFN_vkCreateFence vkCreateFence;
82
PFN_vkDestroyFence vkDestroyFence;
83
PFN_vkEndCommandBuffer vkEndCommandBuffer;
84
PFN_vkFreeCommandBuffers vkFreeCommandBuffers;
85
PFN_vkFreeMemory vkFreeMemory;
86
PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
87
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
88
PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout;
89
PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;
90
PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
91
PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
92
PFN_vkMapMemory vkMapMemory;
93
PFN_vkQueueSubmit vkQueueSubmit;
94
PFN_vkQueueWaitIdle vkQueueWaitIdle;
95
PFN_vkUnmapMemory vkUnmapMemory;
96
PFN_vkWaitForFences vkWaitForFences;
97
} ktxVulkanFunctions;
98
99
/**
100
* @class ktxVulkanTexture
101
* @~English
102
* @brief Struct for returning information about the Vulkan texture image
103
* created by the ktxTexture_VkUpload* functions.
104
*
105
* Creation of these objects is internal to the upload functions.
106
*/
107
typedef struct ktxVulkanTexture
108
{
109
PFN_vkDestroyImage vkDestroyImage; /*!< Pointer to vkDestroyImage function */
110
PFN_vkFreeMemory vkFreeMemory; /*!< Pointer to vkFreeMemory function */
111
112
VkImage image; /*!< Handle to the Vulkan image created by the loader. */
113
VkFormat imageFormat; /*!< Format of the image data. */
114
VkImageLayout imageLayout; /*!< Layout of the created image. Has the same
115
value as @p layout parameter passed to the
116
loader. */
117
VkDeviceMemory deviceMemory; /*!< The memory (sub)allocation for the
118
image on the Vulkan device. Will not be
119
used with suballocators.*/
120
VkImageViewType viewType; /*!< ViewType corresponding to @p image. Reflects
121
the dimensionality, cubeness and arrayness
122
of the image. */
123
uint32_t width; /*!< The width of the image. */
124
uint32_t height; /*!< The height of the image. */
125
uint32_t depth; /*!< The depth of the image. */
126
uint32_t levelCount; /*!< The number of MIP levels in the image. */
127
uint32_t layerCount; /*!< The number of array layers in the image. */
128
uint64_t allocationId; /*!< An id referencing suballocation(s). */
129
} ktxVulkanTexture;
130
131
typedef uint64_t(*ktxVulkanTexture_subAllocatorAllocMemFuncPtr)(VkMemoryAllocateInfo* allocInfo, VkMemoryRequirements* memReq, uint64_t* pageCount);
132
typedef VkResult(*ktxVulkanTexture_subAllocatorBindBufferFuncPtr)(VkBuffer buffer, uint64_t allocId);
133
typedef VkResult(*ktxVulkanTexture_subAllocatorBindImageFuncPtr)(VkImage image, uint64_t allocId);
134
typedef VkResult(*ktxVulkanTexture_subAllocatorMemoryMapFuncPtr)(uint64_t allocId, uint64_t pageNumber, VkDeviceSize *mapLength, void** dataPtr);
135
typedef void (*ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr)(uint64_t allocId, uint64_t pageNumber);
136
typedef void (*ktxVulkanTexture_subAllocatorFreeMemFuncPtr)(uint64_t allocId);
137
/**
138
* @class ktxVulkanTexture_subAllocatorCallbacks
139
* @~English
140
* @brief Struct that contains all callbacks necessary for suballocation.
141
*
142
* These pointers must all be provided for upload or destroy to occur using suballocator callbacks.
143
*/
144
typedef struct {
145
ktxVulkanTexture_subAllocatorAllocMemFuncPtr allocMemFuncPtr; /*!< Pointer to the memory procurement function. Can suballocate one or more pages. */
146
ktxVulkanTexture_subAllocatorBindBufferFuncPtr bindBufferFuncPtr; /*!< Pointer to bind-buffer-to-suballocation(s) function. */
147
ktxVulkanTexture_subAllocatorBindImageFuncPtr bindImageFuncPtr; /*!< Pointer to bind-image-to-suballocation(s) function. */
148
ktxVulkanTexture_subAllocatorMemoryMapFuncPtr memoryMapFuncPtr; /*!< Pointer to function for mapping the memory of a specific page. */
149
ktxVulkanTexture_subAllocatorMemoryUnmapFuncPtr memoryUnmapFuncPtr; /*!< Pointer to function for unmapping the memory of a specific page. */
150
ktxVulkanTexture_subAllocatorFreeMemFuncPtr freeMemFuncPtr; /*!< Pointer to the free procurement function. */
151
} ktxVulkanTexture_subAllocatorCallbacks;
152
153
KTX_API ktx_error_code_e KTX_APIENTRY
154
ktxVulkanTexture_Destruct_WithSuballocator(ktxVulkanTexture* This, VkDevice device,
155
const VkAllocationCallbacks* pAllocator,
156
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);
157
158
KTX_API void KTX_APIENTRY
159
ktxVulkanTexture_Destruct(ktxVulkanTexture* This, VkDevice device,
160
const VkAllocationCallbacks* pAllocator);
161
162
163
/**
164
* @class ktxVulkanDeviceInfo
165
* @~English
166
* @brief Struct for passing information about the Vulkan device on which
167
* to create images to the texture image loading functions.
168
*
169
* Avoids passing a large number of parameters to each loading function.
170
* Use of ktxVulkanDeviceInfo_create() or ktxVulkanDeviceInfo_construct() to
171
* populate this structure is highly recommended.
172
*
173
* @code
174
ktxVulkanDeviceInfo vdi;
175
ktxVulkanTexture texture;
176
177
vdi = ktxVulkanDeviceInfo_create(physicalDevice,
178
device,
179
queue,
180
cmdPool,
181
&allocator);
182
ktxLoadVkTextureN("texture_1.ktx", vdi, &texture, NULL, NULL);
183
// ...
184
ktxLoadVkTextureN("texture_n.ktx", vdi, &texture, NULL, NULL);
185
ktxVulkanDeviceInfo_destroy(vdi);
186
* @endcode
187
*/
188
typedef struct ktxVulkanDeviceInfo {
189
VkInstance instance; /*!< Instance used to communicate with vulkan. */
190
VkPhysicalDevice physicalDevice; /*!< Handle of the physical device. */
191
VkDevice device; /*!< Handle of the logical device. */
192
VkQueue queue; /*!< Handle to the queue to which to submit commands. */
193
VkCommandBuffer cmdBuffer; /*!< Handle of the cmdBuffer to use. */
194
/** Handle of the command pool from which to allocate the command buffer. */
195
VkCommandPool cmdPool;
196
/** Pointer to the allocator to use for the command buffer and created
197
* images.
198
*/
199
const VkAllocationCallbacks* pAllocator;
200
/** Memory properties of the Vulkan physical device. */
201
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
202
203
/** The functions needed to operate functions */
204
ktxVulkanFunctions vkFuncs;
205
} ktxVulkanDeviceInfo;
206
207
208
KTX_API ktxVulkanDeviceInfo* KTX_APIENTRY
209
ktxVulkanDeviceInfo_CreateEx(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device,
210
VkQueue queue, VkCommandPool cmdPool,
211
const VkAllocationCallbacks* pAllocator,
212
const ktxVulkanFunctions* pFunctions);
213
214
KTX_API ktxVulkanDeviceInfo* KTX_APIENTRY
215
ktxVulkanDeviceInfo_Create(VkPhysicalDevice physicalDevice, VkDevice device,
216
VkQueue queue, VkCommandPool cmdPool,
217
const VkAllocationCallbacks* pAllocator);
218
219
KTX_API KTX_error_code KTX_APIENTRY
220
ktxVulkanDeviceInfo_Construct(ktxVulkanDeviceInfo* This,
221
VkPhysicalDevice physicalDevice, VkDevice device,
222
VkQueue queue, VkCommandPool cmdPool,
223
const VkAllocationCallbacks* pAllocator);
224
225
KTX_API KTX_error_code KTX_APIENTRY
226
ktxVulkanDeviceInfo_ConstructEx(ktxVulkanDeviceInfo* This,
227
VkInstance instance,
228
VkPhysicalDevice physicalDevice, VkDevice device,
229
VkQueue queue, VkCommandPool cmdPool,
230
const VkAllocationCallbacks* pAllocator,
231
const ktxVulkanFunctions* pFunctions);
232
233
KTX_API void KTX_APIENTRY
234
ktxVulkanDeviceInfo_Destruct(ktxVulkanDeviceInfo* This);
235
KTX_API void KTX_APIENTRY
236
ktxVulkanDeviceInfo_Destroy(ktxVulkanDeviceInfo* This);
237
KTX_API KTX_error_code KTX_APIENTRY
238
ktxTexture_VkUploadEx_WithSuballocator(ktxTexture* This, ktxVulkanDeviceInfo* vdi,
239
ktxVulkanTexture* vkTexture,
240
VkImageTiling tiling,
241
VkImageUsageFlags usageFlags,
242
VkImageLayout finalLayout,
243
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);
244
KTX_API KTX_error_code KTX_APIENTRY
245
ktxTexture_VkUploadEx(ktxTexture* This, ktxVulkanDeviceInfo* vdi,
246
ktxVulkanTexture* vkTexture,
247
VkImageTiling tiling,
248
VkImageUsageFlags usageFlags,
249
VkImageLayout finalLayout);
250
KTX_API KTX_error_code KTX_APIENTRY
251
ktxTexture_VkUpload(ktxTexture* texture, ktxVulkanDeviceInfo* vdi,
252
ktxVulkanTexture *vkTexture);
253
KTX_API KTX_error_code KTX_APIENTRY
254
ktxTexture1_VkUploadEx_WithSuballocator(ktxTexture1* This, ktxVulkanDeviceInfo* vdi,
255
ktxVulkanTexture* vkTexture,
256
VkImageTiling tiling,
257
VkImageUsageFlags usageFlags,
258
VkImageLayout finalLayout,
259
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);
260
KTX_API KTX_error_code KTX_APIENTRY
261
ktxTexture1_VkUploadEx(ktxTexture1* This, ktxVulkanDeviceInfo* vdi,
262
ktxVulkanTexture* vkTexture,
263
VkImageTiling tiling,
264
VkImageUsageFlags usageFlags,
265
VkImageLayout finalLayout);
266
KTX_API KTX_error_code KTX_APIENTRY
267
ktxTexture1_VkUpload(ktxTexture1* texture, ktxVulkanDeviceInfo* vdi,
268
ktxVulkanTexture *vkTexture);
269
KTX_API KTX_error_code KTX_APIENTRY
270
ktxTexture2_VkUploadEx_WithSuballocator(ktxTexture2* This, ktxVulkanDeviceInfo* vdi,
271
ktxVulkanTexture* vkTexture,
272
VkImageTiling tiling,
273
VkImageUsageFlags usageFlags,
274
VkImageLayout finalLayout,
275
ktxVulkanTexture_subAllocatorCallbacks* subAllocatorCallbacks);
276
KTX_API KTX_error_code KTX_APIENTRY
277
ktxTexture2_VkUploadEx(ktxTexture2* This, ktxVulkanDeviceInfo* vdi,
278
ktxVulkanTexture* vkTexture,
279
VkImageTiling tiling,
280
VkImageUsageFlags usageFlags,
281
VkImageLayout finalLayout);
282
KTX_API KTX_error_code KTX_APIENTRY
283
ktxTexture2_VkUpload(ktxTexture2* texture, ktxVulkanDeviceInfo* vdi,
284
ktxVulkanTexture *vkTexture);
285
286
KTX_API VkFormat KTX_APIENTRY
287
ktxTexture_GetVkFormat(ktxTexture* This);
288
289
KTX_API VkFormat KTX_APIENTRY
290
ktxTexture1_GetVkFormat(ktxTexture1* This);
291
292
KTX_API VkFormat KTX_APIENTRY
293
ktxTexture2_GetVkFormat(ktxTexture2* This);
294
295
#ifdef __cplusplus
296
}
297
#endif
298
299
#endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */
300
301