Skip to content

Commit 1c48a23

Browse files
authored
Add Metal 3.0 and 3.1 detection (#5497)
1 parent b985f16 commit 1c48a23

File tree

7 files changed

+31
-36
lines changed

7 files changed

+31
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Bottom level categories:
179179
#### Metal
180180

181181
- Don't depend on bind group and bind group layout entry order in HAL. This caused incorrect severely incorrect command execution and, in some cases, crashes. By @ErichDonGubler in [#5421](https://github.com/gfx-rs/wgpu/pull/5421).
182+
- Metal 3.0 and 3.1 detection. By @atlv24 in [#5497](https://github.com/gfx-rs/wgpu/pull/5497)
182183

183184
#### DX12
184185

Cargo.lock

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ winit = { version = "0.29", features = ["android-native-activity"] }
129129
# Metal dependencies
130130
block = "0.1"
131131
core-graphics-types = "0.1"
132-
metal = "0.27.0"
132+
metal = { version = "0.27.0", git = "https://github.com/gfx-rs/metal-rs", rev = "ff8fd3d6dc7792852f8a015458d7e6d42d7fb352" }
133133
objc = "0.2.5"
134134

135135
# Vulkan dependencies

naga/xtask/src/validate.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,9 @@ fn validate_spirv(path: &Path, spirv_as: &str, spirv_val: &str) -> anyhow::Resul
208208
buf
209209
};
210210
let expected_header_prefix = "; Version: ";
211-
let Some(version) =
212-
second_line.strip_prefix(expected_header_prefix) else {
213-
bail!(
214-
"no {expected_header_prefix:?} header found in {path:?}"
215-
);
216-
};
211+
let Some(version) = second_line.strip_prefix(expected_header_prefix) else {
212+
bail!("no {expected_header_prefix:?} header found in {path:?}");
213+
};
217214
let file = open_file(path)?;
218215
let mut spirv_as_cmd = EasyCommand::new(spirv_as, |cmd| {
219216
cmd.stdin(Stdio::from(file))
@@ -237,19 +234,20 @@ fn validate_metal(path: &Path, xcrun: &str) -> anyhow::Result<()> {
237234
buf
238235
};
239236
let expected_header_prefix = "// language: ";
240-
let Some(language) =
241-
first_line.strip_prefix(expected_header_prefix) else {
242-
bail!(
243-
"no {expected_header_prefix:?} header found in {path:?}"
244-
);
245-
};
237+
let Some(language) = first_line.strip_prefix(expected_header_prefix) else {
238+
bail!("no {expected_header_prefix:?} header found in {path:?}");
239+
};
246240
let language = language.strip_suffix('\n').unwrap_or(language);
247-
241+
let std_arg = if language.starts_with("metal1") || language.starts_with("metal2") {
242+
format!("-std=macos-{language}")
243+
} else {
244+
format!("-std={language}")
245+
};
248246
let file = open_file(path)?;
249247
EasyCommand::new(xcrun, |cmd| {
250248
cmd.stdin(Stdio::from(file))
251249
.args(["-sdk", "macosx", "metal", "-mmacosx-version-min=10.11"])
252-
.arg(format!("-std=macos-{language}"))
250+
.arg(std_arg)
253251
.args(["-x", "metal", "-", "-o", "/dev/null"])
254252
})
255253
.success()
@@ -337,15 +335,16 @@ fn validate_hlsl_with_fxc(
337335
.target_profile
338336
.split('_')
339337
.nth(1)
340-
.map(|segment| segment.parse::<u8>()) else {
341-
bail!(
342-
"expected target profile of the form \
338+
.map(|segment| segment.parse::<u8>())
339+
else {
340+
bail!(
341+
"expected target profile of the form \
343342
`{{model}}_{{major}}_{{minor}}`, found invalid target \
344343
profile {:?} in file {}",
345-
config_item.target_profile,
346-
file.display()
347-
)
348-
};
344+
config_item.target_profile,
345+
file.display()
346+
)
347+
};
349348
// NOTE: This isn't implemented by `fxc.exe`; see
350349
// <https://learn.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-syntax#profiles>.
351350
if shader_model_major_version < 6 {

wgpu-hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ d3d12 = { path = "../d3d12/", version = "0.19.0", optional = true, features = [
155155
# backend: Metal
156156
block = { version = "0.1", optional = true }
157157

158-
metal = "0.27.0"
158+
metal = { version = "0.27.0", git = "https://github.com/gfx-rs/metal-rs", rev = "ff8fd3d6dc7792852f8a015458d7e6d42d7fb352" }
159159
objc = "0.2.5"
160160
core-graphics-types = "0.1"
161161

wgpu-hal/src/metal/adapter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,11 @@ impl super::PrivateCapabilities {
562562

563563
Self {
564564
family_check,
565-
msl_version: if os_is_xr || version.at_least((12, 0), (15, 0), os_is_mac) {
565+
msl_version: if os_is_xr || version.at_least((14, 0), (17, 0), os_is_mac) {
566+
MTLLanguageVersion::V3_1
567+
} else if version.at_least((13, 0), (16, 0), os_is_mac) {
568+
MTLLanguageVersion::V3_0
569+
} else if version.at_least((12, 0), (15, 0), os_is_mac) {
566570
MTLLanguageVersion::V2_4
567571
} else if version.at_least((11, 0), (14, 0), os_is_mac) {
568572
MTLLanguageVersion::V2_3

wgpu-hal/src/metal/device.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ impl super::Device {
9494
metal::MTLLanguageVersion::V2_2 => (2, 2),
9595
metal::MTLLanguageVersion::V2_3 => (2, 3),
9696
metal::MTLLanguageVersion::V2_4 => (2, 4),
97+
metal::MTLLanguageVersion::V3_0 => (3, 0),
98+
metal::MTLLanguageVersion::V3_1 => (3, 1),
9799
},
98100
inline_samplers: Default::default(),
99101
spirv_cross_compatibility: false,

0 commit comments

Comments
 (0)