Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ CMakeSettings.json
/interface/java_binding/build/
/interface/java_binding/target/
/interface/java_binding/libktx.iml

# CLion
Comment thread
MarkCallow marked this conversation as resolved.
.idea
cmake-build-*
63 changes: 63 additions & 0 deletions include/ktxvulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,42 @@ VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler)
extern "C" {
#endif

typedef struct ktxVulkanFunctions {
// These are functions pointers we need to perform our vulkan duties.
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;

// These we optionally specify
PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
PFN_vkAllocateMemory vkAllocateMemory;
PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
PFN_vkBindBufferMemory vkBindBufferMemory;
PFN_vkBindImageMemory vkBindImageMemory;
PFN_vkCmdBlitImage vkCmdBlitImage;
PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage;
PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
PFN_vkCreateImage vkCreateImage;
PFN_vkDestroyImage vkDestroyImage;
PFN_vkCreateBuffer vkCreateBuffer;
PFN_vkDestroyBuffer vkDestroyBuffer;
PFN_vkCreateFence vkCreateFence;
PFN_vkDestroyFence vkDestroyFence;
PFN_vkEndCommandBuffer vkEndCommandBuffer;
PFN_vkFreeCommandBuffers vkFreeCommandBuffers;
PFN_vkFreeMemory vkFreeMemory;
PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout;
PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;
PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
PFN_vkMapMemory vkMapMemory;
PFN_vkQueueSubmit vkQueueSubmit;
PFN_vkQueueWaitIdle vkQueueWaitIdle;
PFN_vkUnmapMemory vkUnmapMemory;
PFN_vkWaitForFences vkWaitForFences;
} ktxVulkanFunctions;

/**
* @class ktxVulkanTexture
* @brief Struct for returning information about the Vulkan texture image
Expand All @@ -62,6 +98,9 @@ extern "C" {
*/
typedef struct ktxVulkanTexture
{
PFN_vkDestroyImage vkDestroyImage; /*!< Pointer to vkDestroyImage function */
PFN_vkFreeMemory vkFreeMemory; /*!< Pointer to vkFreeMemory function */

VkImage image; /*!< Handle to the Vulkan image created by the loader. */
VkFormat imageFormat; /*!< Format of the image data. */
VkImageLayout imageLayout; /*!< Layout of the created image. Has the same
Expand All @@ -83,6 +122,9 @@ KTX_API void KTX_APIENTRY
ktxVulkanTexture_Destruct(ktxVulkanTexture* This, VkDevice device,
const VkAllocationCallbacks* pAllocator);




/**
* @class ktxVulkanDeviceInfo
* @brief Struct for passing information about the Vulkan device on which
Expand All @@ -108,6 +150,7 @@ ktxVulkanTexture_Destruct(ktxVulkanTexture* This, VkDevice device,
* @endcode
*/
typedef struct ktxVulkanDeviceInfo {
VkInstance instance; /*!< Instance used to communicate with vulkan. */
VkPhysicalDevice physicalDevice; /*!< Handle of the physical device. */
VkDevice device; /*!< Handle of the logical device. */
VkQueue queue; /*!< Handle to the queue to which to submit commands. */
Expand All @@ -120,17 +163,37 @@ typedef struct ktxVulkanDeviceInfo {
const VkAllocationCallbacks* pAllocator;
/** Memory properties of the Vulkan physical device. */
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;

/** The functions needed to operate functions */
ktxVulkanFunctions vkFuncs;
} ktxVulkanDeviceInfo;


KTX_API ktxVulkanDeviceInfo* KTX_APIENTRY
ktxVulkanDeviceInfo_CreateEx(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device,
VkQueue queue, VkCommandPool cmdPool,
const VkAllocationCallbacks* pAllocator,
const ktxVulkanFunctions* pFunctions);

KTX_API ktxVulkanDeviceInfo* KTX_APIENTRY
ktxVulkanDeviceInfo_Create(VkPhysicalDevice physicalDevice, VkDevice device,
VkQueue queue, VkCommandPool cmdPool,
const VkAllocationCallbacks* pAllocator);

KTX_API KTX_error_code KTX_APIENTRY
ktxVulkanDeviceInfo_Construct(ktxVulkanDeviceInfo* This,
VkPhysicalDevice physicalDevice, VkDevice device,
VkQueue queue, VkCommandPool cmdPool,
const VkAllocationCallbacks* pAllocator);

KTX_API KTX_error_code KTX_APIENTRY
ktxVulkanDeviceInfo_ConstructEx(ktxVulkanDeviceInfo* This,
VkInstance instance,
VkPhysicalDevice physicalDevice, VkDevice device,
VkQueue queue, VkCommandPool cmdPool,
const VkAllocationCallbacks* pAllocator,
const ktxVulkanFunctions* pFunctions);

KTX_API void KTX_APIENTRY
ktxVulkanDeviceInfo_Destruct(ktxVulkanDeviceInfo* This);
KTX_API void KTX_APIENTRY
Expand Down
44 changes: 0 additions & 44 deletions lib/vk_funclist.inl

This file was deleted.

80 changes: 14 additions & 66 deletions lib/vk_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

#include "vk_funcs.h"

#if defined(KTX_USE_FUNCPTRS_FOR_VULKAN)

#if WINDOWS
#define WINDOWS_LEAN_AND_MEAN
Expand All @@ -72,50 +71,6 @@ void* ktxVulkanModuleHandle;
#error "Don\'t know how to load symbols on this OS."
#endif

#if 0
static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
#endif

/* Define pointers for functions libktx is using. */
#define VK_FUNCTION(fun) PFN_##fun ktx_##fun;

#include "vk_funclist.inl"

#undef VK_FUNCTION

#if 0
// The Vulkan spec. recommends using vkGetInstanceProcAddr over dlsym
// (or whatever). Doing so would require a backward incompatible
// change to the libktx API to provide the VkInstance. We have no
// choice but dlsym. We can't use vkGetDeviceProcAddr because libktx
// also uses none-device-level functions.
#define VK_FUNCTION(fun) \
if ( !(ktx_##fun = (PFN_##fun)vkGetInstanceProcAddr(instance, #fun )) ) { \
fprintf(stderr, "Could not load Vulkan command: %s!\n", #fun); \
return KTX_FALSE; \
}
#else
#if defined(__GNUC__)
// This strange casting is because dlsym returns a void* thus is not
// compatible with ISO C which forbids conversion of object pointers
// to function pointers. The cast masks the conversion from the
// compiler thus no warning even though -pedantic is set. Since the
// platform supports dlsym, conversion to function pointers must
// work, despite the mandated ISO C warning.
#define VK_FUNCTION(fun) \
if (!(*(void **)(&ktx_##fun) = LoadProcAddr(ktxVulkanModuleHandle, #fun))) { \
fprintf(stderr, "Could not load Vulkan command: %s!\n", #fun); \
return KTX_FALSE; \
}
#else
#define VK_FUNCTION(fun) \
if ((ktx_##fun=(PFN_##fun)LoadProcAddr(ktxVulkanModuleHandle, #fun)) == 0) { \
fprintf(stderr, "Could not load Vulkan command: %s!\n", #fun); \
return KTX_FALSE; \
}
#endif
#endif

#if WINDOWS
#define VULKANLIB "vulkan-1.dll"
static HMODULE
Expand Down Expand Up @@ -153,30 +108,23 @@ ktxLoadVulkanLibrary(void)
#endif
}

#if 0
vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)LoadProcAddr(ktxVulkanLibrary,
"vkGetInstanceProcAddr");
if (!vkGetInstanceProcAddr) {
fprintf(stderr, "Could not load Vulkan command: %s!\n",
"vkGetInstanceProcAddr");
return(KTX_FALSE);
}
#endif

#include "vk_funclist.inl"

return KTX_SUCCESS;
}

#undef VK_FUNCTION
PFN_vkVoidFunction
ktxLoadVulkanFunction(const char* pName) {
ktx_error_code_e rc = ktxLoadVulkanLibrary();
if (rc != KTX_SUCCESS) {
return NULL;
}

PFN_vkVoidFunction pfn = LoadProcAddr(ktxVulkanModuleHandle, pName);
if (pfn == NULL) {
fprintf(stderr, "Couldn't load Vulkan command: %s\n", pName);
return NULL;
}
return pfn;
}

#else

extern
#if defined(__GNUC__)
__attribute__((unused))
#endif
int keepISOCompilersHappy;

#endif /* !KTX_OMIT_VULKAN && KTX_USE_FUNCPTRS_FOR_VULKAN */
53 changes: 3 additions & 50 deletions lib/vk_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,12 @@
#ifndef _VK_FUNCS_H_
#define _VK_FUNCS_H_

#if !defined(KTX_USE_FUNCPTRS_FOR_VULKAN)
#define KTX_USE_FUNCPTRS_FOR_VULKAN 1
#endif

#if defined(KTX_USE_FUNCPTRS_FOR_VULKAN)
#define VK_NO_PROTOTYPES
#endif

#include "vulkan/vk_platform.h"
#include "vulkan/vulkan_core.h"
#include "ktx.h"

#if defined(KTX_USE_FUNCPTRS_FOR_VULKAN)

#if WINDOWS
#define WINDOWS_LEAN_AND_MEAN
Expand All @@ -43,51 +36,11 @@ extern HMODULE ktxVulkanModuleHandle;
extern void* ktxVulkanModuleHandle;
#endif

extern ktx_error_code_e ktxLoadVulkanLibrary(void);

/* Declare pointers for functions libktx is using. */
#define VK_FUNCTION(fun) extern PFN_##fun ktx_##fun;

#include "vk_funclist.inl"

#undef VK_FUNCTION

/*
* Define prefixed names to prevent collisions with other libraries or apps
* finding our pointers when searching the module for function addresses.
*/
#define vkAllocateCommandBuffers ktx_vkAllocateCommandBuffers
#define vkAllocateMemory ktx_vkAllocateMemory
#define vkBeginCommandBuffer ktx_vkBeginCommandBuffer
#define vkBindBufferMemory ktx_vkBindBufferMemory
#define vkBindImageMemory ktx_vkBindImageMemory
#define vkCmdBlitImage ktx_vkCmdBlitImage
#define vkCmdCopyBufferToImage ktx_vkCmdCopyBufferToImage
#define vkCmdPipelineBarrier ktx_vkCmdPipelineBarrier
#define vkCreateBuffer ktx_vkCreateBuffer
#define vkCreateFence ktx_vkCreateFence
#define vkCreateImage ktx_vkCreateImage
#define vkDestroyBuffer ktx_vkDestroyBuffer
#define vkDestroyFence ktx_vkDestroyFence
#define vkDestroyImage ktx_vkDestroyImage
#define vkEndCommandBuffer ktx_vkEndCommandBuffer
#define vkFreeCommandBuffers ktx_vkFreeCommandBuffers
#define vkFreeMemory ktx_vkFreeMemory
#define vkGetBufferMemoryRequirements ktx_vkGetBufferMemoryRequirements
#define vkGetImageMemoryRequirements ktx_vkGetImageMemoryRequirements
#define vkGetImageSubresourceLayout ktx_vkGetImageSubresourceLayout
#define vkGetPhysicalDeviceImageFormatProperties ktx_vkGetPhysicalDeviceImageFormatProperties
#define vkGetPhysicalDeviceFormatProperties ktx_vkGetPhysicalDeviceFormatProperties
#define vkGetPhysicalDeviceMemoryProperties ktx_vkGetPhysicalDeviceMemoryProperties
#define vkMapMemory ktx_vkMapMemory
#define vkQueueSubmit ktx_vkQueueSubmit
#define vkQueueWaitIdle ktx_vkQueueWaitIdle
#define vkUnmapMemory ktx_vkUnmapMemory
#define vkWaitForFences ktx_vkWaitForFences
ktx_error_code_e ktxLoadVulkanLibrary(void);

#undef VK_FUNCTION
// This is used to load instance functions through libktx's methods.
PFN_vkVoidFunction ktxLoadVulkanFunction(const char* pName);

#endif /* KTX_USE_FUNCPTRS_FOR_VULKAN */

#endif /* _VK_FUNCS_H_ */

Loading