From df0cbb78d07ebdef5c351865e52ae9b9de9508be Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Sun, 8 Jun 2025 15:24:16 -0400 Subject: [PATCH] remap metal bindings --- .../core/shader_module/metal_shader_module.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rendering_api/metal/src/core/shader_module/metal_shader_module.m b/rendering_api/metal/src/core/shader_module/metal_shader_module.m index 3d9539d..4e5d21c 100644 --- a/rendering_api/metal/src/core/shader_module/metal_shader_module.m +++ b/rendering_api/metal/src/core/shader_module/metal_shader_module.m @@ -29,8 +29,23 @@ gnReturnCode gnCreateShaderModuleFn(struct gnShaderModule_t *module, struct gnOu spvc_context_parse_spirv(context, shaderModuleInfo.code, shaderModuleInfo.size / 4, &ir); spvc_context_create_compiler(context, SPVC_BACKEND_MSL, ir, SPVC_CAPTURE_MODE_COPY, &compiler); + spvc_compiler_create_shader_resources(compiler, &resources); + spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, &list, &count); + + for (int i = 0; i < count; i++){ + uint32_t set = spvc_compiler_get_decoration(compiler, list[i].id, SpvDecorationDescriptorSet), + binding = spvc_compiler_get_decoration(compiler, list[i].id, SpvDecorationBinding); + + if ((shaderModuleInfo.stage & GN_VERTEX_SHADER_MODULE) == GN_VERTEX_SHADER_MODULE) + binding += 1; + spvc_compiler_unset_decoration(compiler, list[i].id, SpvDecorationBinding); + spvc_compiler_set_decoration(compiler, list[i].id, SpvDecorationBinding, binding); + } + + spvc_compiler_create_compiler_options(compiler, &options); spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_MSL_VERSION, 200); + spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_MSL_ENABLE_DECORATION_BINDING, true); spvc_compiler_install_compiler_options(compiler, options); SpvExecutionModel executionModel = SpvExecutionModelVertex; @@ -40,6 +55,10 @@ gnReturnCode gnCreateShaderModuleFn(struct gnShaderModule_t *module, struct gnOu spvc_result res = spvc_compiler_compile(compiler, &result); if (res != SPVC_SUCCESS) return GN_FAILED_TO_CONVERT_SHADER_CODE; + printf("Res %s\n", result); + + + NSError* error = nil; MTLCompileOptions* mtloptions = nil;