Fix Metal GPU backend shader compile errors in certain language environments
This patch fixes an issue where Blender 3.5 alpha with the Metal GPU backend enabled on Japanese macOS fails to compile shaders and crashes on startup. In a Japanese environment, `defaultCStringEncoding` is the legacy MacJapanese encoding, and it erroneously converts backslashes (0x5c) to Yen symbols (¥). Therefore, Metal shader compile fails with the following log and Blender crashes. ``` 2022-12-29 13:50:10.200 Blender[13404:246707] Compile Error - Metal Shader Library (Stage: 0), error Error Domain=MTLLibraryErrorDomain Code=3 "program_source:225:74: error: non-ASCII characters are not allowed outside of literals and identifiers template<typename T, access A = access::sample> struct STRUCT_NAME { ¥ ^ program_source:226:14: error: no template named 'TEX_TYPE' thread TEX_TYPE<T, A> *texture; ¥ ^ program_source:226:39: error: non-ASCII characters are not allowed outside of literals and identifiers thread TEX_TYPE<T, A> *texture; ¥ ^ program_source:227:29: error: non-ASCII characters are not allowed outside of literals and identifiers thread sampler *samp; ¥ ^ ... ``` We can use `stringWithUTF8String` instead. Reviewed By: fclem, MichaelPW Differential Revision: https://developer.blender.org/D16881
This commit is contained in:
parent
b44a8f6749
commit
48b82a6ea3
|
@ -1049,12 +1049,10 @@ bool MTLShader::generate_msl_from_glsl(const shader::ShaderCreateInfo *info)
|
|||
#endif
|
||||
|
||||
/* Set MSL source NSString's. Required by Metal API. */
|
||||
NSString *msl_final_vert = [NSString stringWithCString:ss_vertex.str().c_str()
|
||||
encoding:[NSString defaultCStringEncoding]];
|
||||
NSString *msl_final_vert = [NSString stringWithUTF8String:ss_vertex.str().c_str()];
|
||||
NSString *msl_final_frag = (msl_iface.uses_transform_feedback) ?
|
||||
(@"") :
|
||||
([NSString stringWithCString:ss_fragment.str().c_str()
|
||||
encoding:[NSString defaultCStringEncoding]]);
|
||||
([NSString stringWithUTF8String:ss_fragment.str().c_str()]);
|
||||
|
||||
this->shader_source_from_msl(msl_final_vert, msl_final_frag);
|
||||
shader_debug_printf("[METAL] BSL Converted into MSL\n");
|
||||
|
|
Loading…
Reference in New Issue