https://github.com/libsdl-org/SDL_shadercross/commit/3bd0b01ab8f4baa52250dbe565c67b39dc12e657
From 3bd0b01ab8f4baa52250dbe565c67b39dc12e657 Mon Sep 17 00:00:00 2001
From: Evan Hemsley <[EMAIL REDACTED]>
Date: Sat, 11 Jan 2025 18:08:28 -0800
Subject: [PATCH] Fix MSL graphics shader buffer order (#87)
---
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 efc15c4..96df4dd 100644
--- a/src/SDL_shadercross.c
+++ b/src/SDL_shadercross.c
@@ -1117,19 +1117,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);
@@ -1137,8 +1137,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;
}
@@ -1156,21 +1156,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);
@@ -1178,8 +1178,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;
}
@@ -1197,7 +1197,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) {