From 0faf4917b9165df47401486dfb4eb307ddc0e0e6 Mon Sep 17 00:00:00 2001 From: Mark Callow <2244683+MarkCallow@users.noreply.github.com> Date: Sun, 17 Sep 2023 16:28:38 +0900 Subject: [PATCH] Return KTX_NOT_FOUND when a GPU proc is not found. (#770) Fixes #768. --- include/ktx.h | 2 +- lib/gl_funcs.c | 4 ++-- lib/glloader.c | 6 +++++- lib/strings.c | 2 +- lib/vkloader.c | 26 +++++++++++++++----------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/ktx.h b/include/ktx.h index 7017a35fa5..fd321c3014 100644 --- a/include/ktx.h +++ b/include/ktx.h @@ -177,7 +177,7 @@ typedef enum ktx_error_code_e { KTX_GL_ERROR, /*!< GL operations resulted in an error. */ KTX_INVALID_OPERATION, /*!< The operation is not allowed in the current state. */ KTX_INVALID_VALUE, /*!< A parameter value was not valid */ - KTX_NOT_FOUND, /*!< Requested key was not found */ + KTX_NOT_FOUND, /*!< Requested metadata key or required dynamically loaded GPU function was not found. */ KTX_OUT_OF_MEMORY, /*!< Not enough memory to complete the operation. */ KTX_TRANSCODE_FAILED, /*!< Transcoding of block compressed texture failed. */ KTX_UNKNOWN_FILE_FORMAT, /*!< The file not a KTX file */ diff --git a/lib/gl_funcs.c b/lib/gl_funcs.c index a312962223..c937eb1ff9 100644 --- a/lib/gl_funcs.c +++ b/lib/gl_funcs.c @@ -102,7 +102,7 @@ struct glFuncPtrs gl; *(void **)(&gl.func) = LoadProcAddr(ktxOpenGLModuleHandle, #func); \ if ( !gl.func && required ) { \ fprintf(stderr, noloadmsg, #func); \ - return KTX_FALSE; \ + return KTX_NOT_FOUND; \ } #else #define GL_FUNCTION(type, func, required) \ @@ -112,7 +112,7 @@ struct glFuncPtrs gl; gl.func = (type)LoadProcAddr(ktxOpenGLModuleHandle, #func); \ if ( !gl.func && required) { \ fprintf(stderr, noloadmsg, #func); \ - return KTX_FALSE; \ + return KTX_NOT_FOUND; \ } #endif diff --git a/lib/glloader.c b/lib/glloader.c index 7d0845078a..c0f7ca6cfe 100644 --- a/lib/glloader.c +++ b/lib/glloader.c @@ -890,6 +890,8 @@ ktxTexture_GLUploadPrivate(ktxTexture* This, ktx_glformatinfo* formatInfo, * glGenTextures or gl*TexImage*. The GL error * will be returned in @p *glerror, if glerror * is not @c NULL. + * @exception KTX_NOT_FOUND A dynamically loaded OpenGL {,ES} function + * required by the loader was not found. * @exception KTX_UNSUPPORTED_TEXTURE_TYPE The type of texture is not supported * by the current OpenGL context. */ @@ -974,6 +976,8 @@ ktxTexture1_GLUpload(ktxTexture1* This, GLuint* pTexture, GLenum* pTarget, * glGenTextures or gl*TexImage*. The GL error * will be returned in @p *glerror, if glerror * is not @c NULL. + * @exception KTX_NOT_FOUND A dynamically loaded OpenGL {,ES} function + * required by the loader was not found. * @exception KTX_UNSUPPORTED_TEXTURE_TYPE The type of texture is not supported * by the current OpenGL context. */ @@ -1041,7 +1045,7 @@ ktxTexture2_GLUpload(ktxTexture2* This, GLuint* pTexture, GLenum* pTarget, * @~English * @brief Create a GL texture object from a ktxTexture1 object. * - * In ordert to ensure that the GL uploader is not linked into an application unless explicitly called, + * In order to ensure that the GL uploader is not linked into an application unless explicitly called, * this is not a virtual function. It determines the texture type then dispatches to the correct function. * * @copydetails ktxTexture1::ktxTexture1_GLUpload diff --git a/lib/strings.c b/lib/strings.c index c635201161..1545341bd3 100644 --- a/lib/strings.c +++ b/lib/strings.c @@ -31,7 +31,7 @@ static const char* const errorStrings[] = { "GL error occurred.", /* KTX_GL_ERROR */ "Operation not allowed in the current state.", /* KTX_INVALID_OPERATION */ "Invalid parameter value.", /* KTX_INVALID_VALUE */ - "Key not found.", /* KTX_NOT_FOUND */ + "Metadata key or loader-required GPU function not found.", /* KTX_NOT_FOUND */ "Out of memory.", /* KTX_OUT_OF_MEMORY */ "Transcoding of block compressed texture failed.",/* KTX_TRANSCODE_FAILED */ "Not a KTX file.", /* KTX_UNKNOWN_FILE_FORMAT */ diff --git a/lib/vkloader.c b/lib/vkloader.c index ddda30ce70..9bb4832bb3 100644 --- a/lib/vkloader.c +++ b/lib/vkloader.c @@ -89,12 +89,12 @@ generateMipmaps(ktxVulkanTexture* vkTexture, ktxVulkanDeviceInfo* vdi, * @brief Create a ktxVulkanDeviceInfo object. * * Allocates CPU memory for a ktxVulkanDeviceInfo object then calls - * ktxVulkanDeviceInfo_construct(). See it for documentation of the + * ktxVulkanDeviceInfo\_Construct(). See it for documentation of the * parameters. * * @return a pointer to the constructed ktxVulkanDeviceInfo. * - * @sa ktxVulkanDeviceInfo_construct(), ktxVulkanDeviceInfo_destroy() + * @sa ktxVulkanDeviceInfo\_Construct(), ktxVulkanDeviceInfo\_Destroy() */ ktxVulkanDeviceInfo* ktxVulkanDeviceInfo_Create(VkPhysicalDevice physicalDevice, VkDevice device, @@ -111,12 +111,12 @@ ktxVulkanDeviceInfo_Create(VkPhysicalDevice physicalDevice, VkDevice device, * @brief Create a ktxVulkanDeviceInfo object. * * Allocates CPU memory for a ktxVulkanDeviceInfo object then calls - * ktxVulkanDeviceInfo_construct(). See it for documentation of the + * ktxVulkanDeviceInfo\_Construct(). See it for documentation of the * parameters. * * @return a pointer to the constructed ktxVulkanDeviceInfo. * - * @sa ktxVulkanDeviceInfo_construct(), ktxVulkanDeviceInfo_destroy() + * @sa ktxVulkanDeviceInfo\_Construct(), ktxVulkanDeviceInfo\_Destroy() */ ktxVulkanDeviceInfo* ktxVulkanDeviceInfo_CreateEx(VkInstance instance, @@ -164,10 +164,14 @@ ktxVulkanDeviceInfo_CreateEx(VkInstance instance, * Pass a valid ktxVulkanDeviceInfo* to any Vulkan KTX image loading * function to provide it with the information. * - * @returns KTX_SUCCESS on success, KTX_OUT_OF_MEMORY if a command buffer could - * not be allocated. + * @returns KTX\_SUCCESS on success, other KTX\_\* enum values on error. * - * @sa ktxVulkanDeviceInfo_destruct() + * @exception KTX_NOT_FOUND A dynamically loaded Vulkan function + * required by the loader was not found. + * + * @exception KTX_OUT_OF_MEMORY A command buffer could not be allocated. + * + * @sa ktxVulkanDeviceInfo\_Destruct() * * @param This pointer to the ktxVulkanDeviceInfo object to * initialize. @@ -217,7 +221,7 @@ do { \ if ((member).fun == NULL) { \ (member).fun = (PFN_##fun)ktxLoadVulkanFunction(#fun); \ if ((member).fun == NULL) { \ - return KTX_FALSE; \ + return KTX_NOT_FOUND; \ }\ } \ } while (0) @@ -227,7 +231,7 @@ do { \ if ((member).fun == NULL) { \ (member).fun = (PFN_##fun)((member).vkGetInstanceProcAddr)((instance), #fun); \ if ((member).fun == NULL) { \ - return KTX_FALSE; \ + return KTX_NOT_FOUND; \ }\ } \ } while (0) @@ -237,7 +241,7 @@ do { \ if ((member).fun == NULL) { \ (member).fun = (PFN_##fun)((member).vkGetDeviceProcAddr)((device), #fun); \ if ((member).fun == NULL) { \ - return KTX_FALSE; \ + return KTX_NOT_FOUND; \ }\ } \ } while (0) @@ -369,7 +373,7 @@ ktxVulkanDeviceInfo_Destruct(ktxVulkanDeviceInfo* This) * @~English * @brief Destroy a ktxVulkanDeviceInfo object. * - * Calls ktxVulkanDeviceInfo_destruct() then frees the ktxVulkanDeviceInfo. + * Calls ktxVulkanDeviceInfo\_Destruct() then frees the ktxVulkanDeviceInfo. * * @param This pointer to the ktxVulkanDeviceInfo to destroy. */