From 2fb4d6fac58eefb34c470b226e3f1be946661bc8 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Sat, 11 Jan 2025 17:26:32 -0800 Subject: [PATCH] Fix MSL graphics shader buffer order --- src/SDL_shadercross.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/SDL_shadercross.c b/src/SDL_shadercross.c index 0e69c4e..85d38e1 100644 --- a/src/SDL_shadercross.c +++ b/src/SDL_shadercross.c @@ -1113,19 +1113,19 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV( } num_textures += (num_separate_images - num_separate_samplers); - // Storage buffers + // Uniform buffers result = spvc_resources_get_resource_list_for_type( resources, - SPVC_RESOURCE_TYPE_STORAGE_BUFFER, + SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, (const spvc_reflected_resource **)&reflected_resources, - &num_storage_buffers); + &num_uniform_buffers); if (result < 0) { SPVC_ERROR(spvc_resources_get_resource_list_for_type); spvc_context_destroy(context); return NULL; } - for (size_t i = 0; i < num_storage_buffers; i += 1) { + for (size_t i = 0; i < num_uniform_buffers; i += 1) { if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) { SDL_SetError("%s", "Shader resources must have descriptor set and binding index!"); spvc_context_destroy(context); @@ -1133,8 +1133,8 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV( } 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_SetError("%s", "Descriptor set index for graphics storage buffer must be 0 or 2!"); + if (!(descriptor_set_index == 1 || descriptor_set_index == 3)) { + SDL_SetError("%s", "Descriptor set index for graphics uniform buffer must be 1 or 3!"); spvc_context_destroy(context); return NULL; } @@ -1152,21 +1152,21 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV( return NULL; } } - num_buffers += num_storage_buffers; + num_buffers += num_uniform_buffers; - // Uniform buffers + // Storage buffers result = spvc_resources_get_resource_list_for_type( resources, - SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, + SPVC_RESOURCE_TYPE_STORAGE_BUFFER, (const spvc_reflected_resource **)&reflected_resources, - &num_uniform_buffers); + &num_storage_buffers); if (result < 0) { SPVC_ERROR(spvc_resources_get_resource_list_for_type); spvc_context_destroy(context); return NULL; } - for (size_t i = 0; i < num_uniform_buffers; i += 1) { + for (size_t i = 0; i < num_storage_buffers; i += 1) { if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) { SDL_SetError("%s", "Shader resources must have descriptor set and binding index!"); spvc_context_destroy(context); @@ -1174,8 +1174,8 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV( } 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_SetError("%s", "Descriptor set index for graphics uniform buffer must be 1 or 3!"); + if (!(descriptor_set_index == 0 || descriptor_set_index == 2)) { + SDL_SetError("%s", "Descriptor set index for graphics storage buffer must be 0 or 2!"); spvc_context_destroy(context); return NULL; } @@ -1193,7 +1193,7 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV( return NULL; } } - num_buffers += num_uniform_buffers; + num_buffers += num_storage_buffers; } if (backend == SPVC_BACKEND_MSL && shaderStage == SDL_SHADERCROSS_SHADERSTAGE_COMPUTE) {