remap metal bindings

This commit is contained in:
Greg Wells
2025-06-08 15:24:16 -04:00
parent 0a2c1089c5
commit df0cbb78d0

View File

@@ -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_parse_spirv(context, shaderModuleInfo.code, shaderModuleInfo.size / 4, &ir);
spvc_context_create_compiler(context, SPVC_BACKEND_MSL, ir, SPVC_CAPTURE_MODE_COPY, &compiler); 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_create_compiler_options(compiler, &options);
spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_MSL_VERSION, 200); 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); spvc_compiler_install_compiler_options(compiler, options);
SpvExecutionModel executionModel = SpvExecutionModelVertex; SpvExecutionModel executionModel = SpvExecutionModelVertex;
@@ -40,6 +55,10 @@ gnReturnCode gnCreateShaderModuleFn(struct gnShaderModule_t *module, struct gnOu
spvc_result res = spvc_compiler_compile(compiler, &result); spvc_result res = spvc_compiler_compile(compiler, &result);
if (res != SPVC_SUCCESS) if (res != SPVC_SUCCESS)
return GN_FAILED_TO_CONVERT_SHADER_CODE; return GN_FAILED_TO_CONVERT_SHADER_CODE;
printf("Res %s\n", result);
NSError* error = nil; NSError* error = nil;
MTLCompileOptions* mtloptions = nil; MTLCompileOptions* mtloptions = nil;