SDL_gpu_shadercross: Link SPIRV-Cross instead of using SDL_LoadObject

From f335050e192a0b5eea7d28018aebe233f7a87996 Mon Sep 17 00:00:00 2001
From: cosmonaut <[EMAIL REDACTED]>
Date: Mon, 4 Nov 2024 11:31:53 -0800
Subject: [PATCH] Link SPIRV-Cross instead of using SDL_LoadObject

---
 CMakeLists.txt            |   2 +
 src/SDL_gpu_shadercross.c | 372 ++++++++++++--------------------------
 2 files changed, 114 insertions(+), 260 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5964cfd..8e6e6b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -122,9 +122,11 @@ if(SDLGPUSHADERCROSS_STATIC)
 	)
 endif()
 
+find_package(spirv_cross_c_shared REQUIRED)
 foreach(target IN LISTS SDL3_gpu_shadercross_targets)
 	sdl_add_warning_options(${target} WARNING_AS_ERROR ${SDLGPUSHADERCROSS_WERROR})
 	target_compile_features(${target} PRIVATE c_std_99)
+	target_link_libraries(${target} PRIVATE spirv-cross-c-shared)
 endforeach()
 
 if(NOT TARGET SDL3_gpu_shadercross::SDL3_gpu_shadercross)
diff --git a/src/SDL_gpu_shadercross.c b/src/SDL_gpu_shadercross.c
index bd41126..dd7a7e4 100644
--- a/src/SDL_gpu_shadercross.c
+++ b/src/SDL_gpu_shadercross.c
@@ -764,78 +764,8 @@ SDL_GPUComputePipeline *SDL_ShaderCross_CompileComputePipelineFromHLSL(
 
 #include "spirv_cross_c.h"
 
-#ifndef SDL_GPU_SHADERCROSS_STATIC
-
-#ifndef SDL_GPU_SPIRV_CROSS_DLL
-#if defined(_WIN32)
-#define SDL_GPU_SPIRV_CROSS_DLL "spirv-cross-c-shared.dll"
-#define SDL_GPU_SPIRV_CROSS_DLL_2 "libspirv-cross-c-shared.dll"
-#elif defined(__APPLE__)
-#define SDL_GPU_SPIRV_CROSS_DLL "libspirv-cross-c-shared.0.dylib"
-#else
-#define SDL_GPU_SPIRV_CROSS_DLL "libspirv-cross-c-shared.so.0"
-#endif
-#endif /* SDL_GPU_SPIRV_CROSS_DLL */
-
-static SDL_SharedObject *spirvcross_dll = NULL;
-
-typedef spvc_result (*pfn_spvc_context_create)(spvc_context *context);
-typedef void (*pfn_spvc_context_destroy)(spvc_context);
-typedef spvc_result (*pfn_spvc_context_parse_spirv)(spvc_context, const SpvId *, size_t, spvc_parsed_ir *);
-typedef spvc_result (*pfn_spvc_context_create_compiler)(spvc_context, spvc_backend, spvc_parsed_ir, spvc_capture_mode, spvc_compiler *);
-typedef spvc_result (*pfn_spvc_compiler_create_compiler_options)(spvc_compiler, spvc_compiler_options *);
-typedef spvc_result (*pfn_spvc_compiler_options_set_uint)(spvc_compiler_options, spvc_compiler_option, unsigned);
-typedef spvc_result (*pfn_spvc_compiler_create_shader_resources)(spvc_compiler, spvc_resources *);
-typedef spvc_result (*pfn_spvc_compiler_msl_add_resource_binding)(spvc_compiler, const spvc_msl_resource_binding *);
-typedef spvc_result (*pfn_spvc_compiler_has_decoration)(spvc_compiler, SpvId, SpvDecoration);
-typedef spvc_result (*pfn_spvc_compiler_get_decoration)(spvc_compiler, SpvId, SpvDecoration);
-typedef spvc_result (*pfn_spvc_compiler_install_compiler_options)(spvc_compiler, spvc_compiler_options);
-typedef spvc_result (*pfn_spvc_compiler_compile)(spvc_compiler, const char **);
-typedef spvc_result (*pfn_spvc_resources_get_resource_list_for_type)(spvc_resources, spvc_resource_type, const spvc_reflected_resource **, size_t *);
-typedef const char *(*pfn_spvc_context_get_last_error_string)(spvc_context);
-typedef SpvExecutionModel (*pfn_spvc_compiler_get_execution_model)(spvc_compiler compiler);
-typedef const char *(*pfn_spvc_compiler_get_cleansed_entry_point_name)(spvc_compiler compiler, const char *name, SpvExecutionModel model);
-
-static pfn_spvc_context_create SDL_spvc_context_create = NULL;
-static pfn_spvc_context_destroy SDL_spvc_context_destroy = NULL;
-static pfn_spvc_context_parse_spirv SDL_spvc_context_parse_spirv = NULL;
-static pfn_spvc_context_create_compiler SDL_spvc_context_create_compiler = NULL;
-static pfn_spvc_compiler_create_compiler_options SDL_spvc_compiler_create_compiler_options = NULL;
-static pfn_spvc_compiler_options_set_uint SDL_spvc_compiler_options_set_uint = NULL;
-static pfn_spvc_compiler_create_shader_resources SDL_spvc_compiler_create_shader_resources = NULL;
-static pfn_spvc_compiler_msl_add_resource_binding SDL_spvc_compiler_msl_add_resource_binding = NULL;
-static pfn_spvc_compiler_has_decoration SDL_spvc_compiler_has_decoration = NULL;
-static pfn_spvc_compiler_get_decoration SDL_spvc_compiler_get_decoration = NULL;
-static pfn_spvc_compiler_install_compiler_options SDL_spvc_compiler_install_compiler_options = NULL;
-static pfn_spvc_compiler_compile SDL_spvc_compiler_compile = NULL;
-static pfn_spvc_resources_get_resource_list_for_type SDL_spvc_resources_get_resource_list_for_type = NULL;
-static pfn_spvc_context_get_last_error_string SDL_spvc_context_get_last_error_string = NULL;
-static pfn_spvc_compiler_get_execution_model SDL_spvc_compiler_get_execution_model = NULL;
-static pfn_spvc_compiler_get_cleansed_entry_point_name SDL_spvc_compiler_get_cleansed_entry_point_name = NULL;
-
-#else /* SDL_GPU_SHADERCROSS_STATIC */
-
-#define SDL_spvc_context_create                         spvc_context_create
-#define SDL_spvc_context_destroy                        spvc_context_destroy
-#define SDL_spvc_context_parse_spirv                    spvc_context_parse_spirv
-#define SDL_spvc_context_create_compiler                spvc_context_create_compiler
-#define SDL_spvc_compiler_create_compiler_options       spvc_compiler_create_compiler_options
-#define SDL_spvc_compiler_options_set_uint              spvc_compiler_options_set_uint
-#define SDL_spvc_compiler_create_shader_resources       spvc_compiler_create_shader_resources
-#define SDL_spvc_compiler_msl_add_resource_binding      spvc_compiler_msl_add_resource_binding
-#define SDL_spvc_compiler_has_decoration                spvc_compiler_has_decoration
-#define SDL_spvc_compiler_get_decoration                spvc_compiler_get_decoration
-#define SDL_spvc_compiler_install_compiler_options      spvc_compiler_install_compiler_options
-#define SDL_spvc_compiler_compile                       spvc_compiler_compile
-#define SDL_spvc_resources_get_resource_list_for_type   spvc_resources_get_resource_list_for_type
-#define SDL_spvc_context_get_last_error_string          spvc_context_get_last_error_string
-#define SDL_spvc_compiler_get_execution_model           spvc_compiler_get_execution_model
-#define SDL_spvc_compiler_get_cleansed_entry_point_name spvc_compiler_get_cleansed_entry_point_name
-
-#endif /* SDL_GPU_SHADERCROSS_STATIC */
-
 #define SPVC_ERROR(func) \
-    SDL_SetError(#func " failed: %s", SDL_spvc_context_get_last_error_string(context))
+    SDL_SetError(#func " failed: %s", spvc_context_get_last_error_string(context))
 
 typedef struct SPIRVTranspileContext {
     spvc_context context;
@@ -846,7 +776,7 @@ typedef struct SPIRVTranspileContext {
 static void SDL_ShaderCross_INTERNAL_DestroyTranspileContext(
     SPIRVTranspileContext *context)
 {
-    SDL_spvc_context_destroy(context->context);
+    spvc_context_destroy(context->context);
     SDL_free(context);
 }
 
@@ -868,40 +798,40 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
     const char *cleansed_entrypoint;
 
     /* Create the SPIRV-Cross context */
-    result = SDL_spvc_context_create(&context);
+    result = spvc_context_create(&context);
     if (result < 0) {
         SDL_SetError("spvc_context_create failed: %X", result);
         return NULL;
     }
 
     /* Parse the SPIR-V into IR */
-    result = SDL_spvc_context_parse_spirv(context, (const SpvId *)code, codeSize / sizeof(SpvId), &ir);
+    result = spvc_context_parse_spirv(context, (const SpvId *)code, codeSize / sizeof(SpvId), &ir);
     if (result < 0) {
         SPVC_ERROR(spvc_context_parse_spirv);
-        SDL_spvc_context_destroy(context);
+        spvc_context_destroy(context);
         return NULL;
     }
 
     /* Create the cross-compiler */
-    result = SDL_spvc_context_create_compiler(context, backend, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler);
+    result = spvc_context_create_compiler(context, backend, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler);
     if (result < 0) {
         SPVC_ERROR(spvc_context_create_compiler);
-        SDL_spvc_context_destroy(context);
+        spvc_context_destroy(context);
         return NULL;
     }
 
     /* Set up the cross-compiler options */
-    result = SDL_spvc_compiler_create_compiler_options(compiler, &options);
+    result = spvc_compiler_create_compiler_options(compiler, &options);
     if (result < 0) {
         SPVC_ERROR(spvc_compiler_create_compiler_options);
-        SDL_spvc_context_destroy(context);
+        spvc_context_destroy(context);
         return NULL;
     }
 
     if (backend == SPVC_BACKEND_HLSL) {
-        SDL_spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_HLSL_SHADER_MODEL, shadermodel);
-        SDL_spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_HLSL_NONWRITABLE_UAV_TEXTURE_AS_SRV, 1);
-        SDL_spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_HLSL_FLATTEN_MATRIX_VERTEX_INPUT_SEMANTICS, 1);
+        spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_HLSL_SHADER_MODEL, shadermodel);
+        spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_HLSL_NONWRITABLE_UAV_TEXTURE_AS_SRV, 1);
+        spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_HLSL_FLATTEN_MATRIX_VERTEX_INPUT_SEMANTICS, 1);
     }
 
     SpvExecutionModel executionModel;
@@ -922,171 +852,171 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
         size_t num_storage_buffers;
         size_t num_uniform_buffers;
 
-        result = SDL_spvc_compiler_create_shader_resources(compiler, &resources);
+        result = spvc_compiler_create_shader_resources(compiler, &resources);
         if (result < 0) {
             SPVC_ERROR(spvc_compiler_create_shader_resources);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         // Combined texture-samplers
-        result = SDL_spvc_resources_get_resource_list_for_type(
+        result = spvc_resources_get_resource_list_for_type(
             resources,
             SPVC_RESOURCE_TYPE_SAMPLED_IMAGE,
             (const spvc_reflected_resource **)&reflected_resources,
             &num_texture_samplers);
         if (result < 0) {
             SPVC_ERROR(spvc_resources_get_resource_list_for_type);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         spvc_msl_resource_binding binding;
         for (size_t i = 0; i < num_texture_samplers; i += 1) {
-            if (!SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
+            if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
             if (!(descriptor_set_index == 0 || descriptor_set_index == 2)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics texture-sampler must be 0 or 2!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int binding_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
+            unsigned int binding_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
 
             binding.stage = executionModel;
             binding.desc_set = descriptor_set_index;
             binding.binding = binding_index;
             binding.msl_texture = binding_index;
             binding.msl_sampler = binding_index;
-            result = SDL_spvc_compiler_msl_add_resource_binding(compiler, &binding);
+            result = spvc_compiler_msl_add_resource_binding(compiler, &binding);
             if (result < 0) {
                 SPVC_ERROR(spvc_compiler_msl_add_resource_binding);
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
         }
 
         // Storage textures
-        result = SDL_spvc_resources_get_resource_list_for_type(
+        result = spvc_resources_get_resource_list_for_type(
             resources,
             SPVC_RESOURCE_TYPE_STORAGE_IMAGE,
             (const spvc_reflected_resource **)&reflected_resources,
             &num_storage_textures);
         if (result < 0) {
             SPVC_ERROR(spvc_resources_get_resource_list_for_type);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         for (size_t i = 0; i < num_storage_textures; i += 1) {
-            if (!SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
+            if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
             if (!(descriptor_set_index == 0 || descriptor_set_index == 2)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics storage texture must be 0 or 2!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int binding_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
+            unsigned int binding_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
 
             binding.stage = executionModel;
             binding.desc_set = descriptor_set_index;
             binding.binding = binding_index;
             binding.msl_texture = num_texture_samplers + binding_index;
-            SDL_spvc_compiler_msl_add_resource_binding(compiler, &binding);
+            spvc_compiler_msl_add_resource_binding(compiler, &binding);
             if (result < 0) {
                 SPVC_ERROR(spvc_compiler_msl_add_resource_binding);
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
         }
 
         // Storage buffers
-        result = SDL_spvc_resources_get_resource_list_for_type(
+        result = spvc_resources_get_resource_list_for_type(
             resources,
             SPVC_RESOURCE_TYPE_STORAGE_BUFFER,
             (const spvc_reflected_resource **)&reflected_resources,
             &num_storage_buffers);
         if (result < 0) {
             SPVC_ERROR(spvc_resources_get_resource_list_for_type);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         for (size_t i = 0; i < num_storage_buffers; i += 1) {
-            if (!SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
+            if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
             if (!(descriptor_set_index == 0 || descriptor_set_index == 2)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics storage buffer must be 0 or 2!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int binding_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
+            unsigned int binding_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
 
             binding.stage = executionModel;
             binding.desc_set = descriptor_set_index;
             binding.binding = binding_index;
             binding.msl_buffer = binding_index;
-            SDL_spvc_compiler_msl_add_resource_binding(compiler, &binding);
+            spvc_compiler_msl_add_resource_binding(compiler, &binding);
             if (result < 0) {
                 SPVC_ERROR(spvc_compiler_msl_add_resource_binding);
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
         }
 
         // Uniform buffers
-        result = SDL_spvc_resources_get_resource_list_for_type(
+        result = spvc_resources_get_resource_list_for_type(
             resources,
             SPVC_RESOURCE_TYPE_UNIFORM_BUFFER,
             (const spvc_reflected_resource **)&reflected_resources,
             &num_uniform_buffers);
         if (result < 0) {
             SPVC_ERROR(spvc_resources_get_resource_list_for_type);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         for (size_t i = 0; i< num_uniform_buffers; i += 1) {
-            if (!SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
+            if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
             if (!(descriptor_set_index == 1 || descriptor_set_index == 3)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics uniform buffer must be 1 or 3!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int binding_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
+            unsigned int binding_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
 
             binding.stage = executionModel;
             binding.desc_set = descriptor_set_index;
             binding.binding = binding_index;
             binding.msl_buffer = num_storage_buffers + binding_index;
-            SDL_spvc_compiler_msl_add_resource_binding(compiler, &binding);
+            spvc_compiler_msl_add_resource_binding(compiler, &binding);
             if (result < 0) {
                 SPVC_ERROR(spvc_compiler_msl_add_resource_binding);
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
         }
@@ -1100,10 +1030,10 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
         size_t num_storage_buffers; // total storage buffers
         size_t num_uniform_buffers;
 
-        result = SDL_spvc_compiler_create_shader_resources(compiler, &resources);
+        result = spvc_compiler_create_shader_resources(compiler, &resources);
         if (result < 0) {
             SPVC_ERROR(spvc_compiler_create_shader_resources);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
@@ -1112,87 +1042,87 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
         unsigned int num_buffers = 0;
 
         // Combined texture-samplers
-        result = SDL_spvc_resources_get_resource_list_for_type(
+        result = spvc_resources_get_resource_list_for_type(
             resources,
             SPVC_RESOURCE_TYPE_SAMPLED_IMAGE,
             (const spvc_reflected_resource **)&reflected_resources,
             &num_texture_samplers);
         if (result < 0) {
             SPVC_ERROR(spvc_resources_get_resource_list_for_type);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         for (size_t i = 0; i < num_texture_samplers; i += 1) {
-            if (!SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
+            if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
             if (descriptor_set_index != 0) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute texture-sampler must be 0!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int binding_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
+            unsigned int binding_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
 
             binding.stage = executionModel;
             binding.desc_set = descriptor_set_index;
             binding.binding = binding_index;
             binding.msl_texture = num_textures;
             binding.msl_sampler = num_textures;
-            result = SDL_spvc_compiler_msl_add_resource_binding(compiler, &binding);
+            result = spvc_compiler_msl_add_resource_binding(compiler, &binding);
             if (result < 0) {
                 SPVC_ERROR(spvc_compiler_msl_add_resource_binding);
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
             num_textures += 1;
         }
 
         // Storage textures
-        result = SDL_spvc_resources_get_resource_list_for_type(
+        result = spvc_resources_get_resource_list_for_type(
             resources,
             SPVC_RESOURCE_TYPE_STORAGE_IMAGE,
             (const spvc_reflected_resource **)&reflected_resources,
             &num_storage_textures);
         if (result < 0) {
             SPVC_ERROR(spvc_resources_get_resource_list_for_type);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         // Readonly storage textures
         for (size_t i = 0; i < num_storage_textures; i += 1) {
-            if (!SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
+            if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
             if (!(descriptor_set_index == 0 || descriptor_set_index == 1)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute storage texture must be 0 or 1!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
             // Skip readwrite textures
             if (descriptor_set_index != 0) { continue; }
 
-            unsigned int binding_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
+            unsigned int binding_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
 
             binding.stage = executionModel;
             binding.desc_set = descriptor_set_index;
             binding.binding = binding_index;
             binding.msl_texture = num_textures + binding_index;
-            SDL_spvc_compiler_msl_add_resource_binding(compiler, &binding);
+            spvc_compiler_msl_add_resource_binding(compiler, &binding);
             if (result < 0) {
                 SPVC_ERROR(spvc_compiler_msl_add_resource_binding);
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
@@ -1201,21 +1131,21 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
 
         // Readwrite storage textures
         for (size_t i = 0; i < num_storage_textures; i += 1) {
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
 
             // Skip readonly textures
             if (descriptor_set_index != 1) { continue; }
 
-            unsigned int binding_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
+            unsigned int binding_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding);
 
             binding.stage = executionModel;
             binding.desc_set = descriptor_set_index;
             binding.binding = binding_index;
             binding.msl_texture = num_textures + binding_index;
-            SDL_spvc_compiler_msl_add_resource_binding(compiler, &binding);
+            spvc_compiler_msl_add_resource_binding(compiler, &binding);
             if (result < 0) {
                 SPVC_ERROR(spvc_compiler_msl_add_resource_binding);
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
@@ -1223,45 +1153,45 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
         }
 
         // Storage buffers
-        result = SDL_spvc_resources_get_resource_list_for_type(
+        result = spvc_resources_get_resource_list_for_type(
             resources,
             SPVC_RESOURCE_TYPE_STORAGE_BUFFER,
             (const spvc_reflected_resource **)&reflected_resources,
             &num_storage_buffers);
         if (result < 0) {
             SPVC_ERROR(spvc_resources_get_resource_list_for_type);
-            SDL_spvc_context_destroy(context);
+            spvc_context_destroy(context);
             return NULL;
         }
 
         // Readonly storage buffers
         for (size_t i = 0; i < num_storage_buffers; i += 1) {
-            if (!SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !SDL_spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
+            if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
-            unsigned int descriptor_set_index = SDL_spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
+            unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
             if (!(descriptor_set_index == 0 || descriptor_set_index == 1)) {
                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute storage buffer must be 0 or 1!");
-                SDL_spvc_context_destroy(context);
+                spvc_context_destroy(context);
                 return NULL;
             }
 
             // Skip readwrite buffers
             if (descriptor_set_index != 0) { continue; }
 
-            unsigned int binding_index = SDL_spvc_compil

(Patch may be truncated, please check the link at the top of this post.)