Skip to content

Commit 1b64bcb

Browse files
committed
Metal: Reduce baked version to MSL 3.1; validate minimum version
Validate the MSL version of the baked shader is <= the current version supported by the OS, and return an error so it is recompiled. Closes #109846
1 parent 4ebf67c commit 1b64bcb

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

drivers/metal/metal_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ class Defer {
102102
extern os_log_t LOG_DRIVER;
103103
// Used for dynamic tracing.
104104
extern os_log_t LOG_INTERVALS;
105+
106+
_FORCE_INLINE_ static uint32_t make_msl_version(uint32_t major, uint32_t minor = 0, uint32_t patch = 0) {
107+
return (major * 10000) + (minor * 100) + patch;
108+
}

drivers/metal/rendering_device_driver_metal.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@ static BindingInfo from_binding_info_data(const RenderingShaderContainerMetal::B
11371137
RDD::ShaderID(),
11381138
"Shader was generated with argument buffers, but device has limited support");
11391139

1140+
uint32_t msl_version = make_msl_version(device_properties->features.mslVersionMajor, device_properties->features.mslVersionMinor);
1141+
ERR_FAIL_COND_V_MSG(msl_version < mtl_reflection_data.msl_version,
1142+
RDD::ShaderID(),
1143+
"Shader was compiled with a newer version of Metal than is available on the device.");
1144+
11401145
MTLCompileOptions *options = [MTLCompileOptions new];
11411146
uint32_t major = mtl_reflection_data.msl_version / 10000;
11421147
uint32_t minor = (mtl_reflection_data.msl_version / 100) % 100;

drivers/metal/rendering_shader_container_metal.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
} break;
8080
}
8181
res.features.mslVersionMajor = 3;
82-
res.features.mslVersionMinor = 2;
82+
res.features.mslVersionMinor = 1;
8383
}
8484

8585
return &profiles.insert(key, res)->value;

0 commit comments

Comments
 (0)