diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 0ab34600..fa2dfbcf 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -137,8 +137,7 @@ void CompilerMSL::localize_global_variables() if (gbl_var.storage == StorageClassPrivate) { entry_func.add_local_variable(gv_id); - //iter = global_variables.erase(iter); - iter++; + iter = global_variables.erase(iter); } else iter++; @@ -164,6 +163,17 @@ void CompilerMSL::extract_global_variables_from_functions() } } } + + // Local vars that are declared in the main function and accessed directy by a function + auto &entry_func = get(entry_point); + auto iter = entry_func.local_variables.begin(); + while (iter != entry_func.local_variables.end()) + { + uint32_t gv_id = *iter; + auto &gbl_var = get(gv_id); + global_var_ids.insert(gbl_var.self); + iter++; + } std::unordered_set added_arg_ids; std::unordered_set processed_func_ids;