Skip to content

Commit f5071b2

Browse files
authored
Set the minimum required Metal version (#9425)
1 parent 0fa13ee commit f5071b2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

filament/backend/src/metal/MetalShaderCompiler.mm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,22 @@ bool isReady() const noexcept {
111111
id<MTLLibrary> library = nil;
112112
switch (program.getShaderLanguage()) {
113113
case ShaderLanguage::MSL: {
114-
// By default, Metal uses the most recent language version.
115114
MTLCompileOptions* options = [MTLCompileOptions new];
116115
options.fastMathEnabled = YES;
116+
// The docs for MTLCompileOptions say that Metal uses the most
117+
// recent language version if it is not specified, but this is
118+
// not always true: it is possible for the environment to be set
119+
// up in a way where an older version is used by default. So we
120+
// explicitly set the minimum version we require.
121+
#if defined(FILAMENT_IOS)
122+
options.languageVersion = MTLLanguageVersion2_0;
123+
#else
124+
if (@available(macOS 11.0, *)) {
125+
options.languageVersion = MTLLanguageVersion2_3;
126+
} else {
127+
options.languageVersion = MTLLanguageVersion2_2;
128+
}
129+
#endif
117130

118131
assert_invariant(source[source.size() - 1] == '\0');
119132
// the shader string is null terminated and the length includes the null character

0 commit comments

Comments
 (0)