Add Metal 3.0 and 3.1 detection (#5497)

This commit is contained in:
vero 2024-04-05 10:22:33 -07:00 committed by GitHub
parent b985f16ac2
commit 1c48a23cff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 36 deletions

View File

@ -179,6 +179,7 @@ Bottom level categories:
#### Metal #### Metal
- 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). - 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).
- Metal 3.0 and 3.1 detection. By @atlv24 in [#5497](https://github.com/gfx-rs/wgpu/pull/5497)
#### DX12 #### DX12

13
Cargo.lock generated
View File

@ -2088,8 +2088,7 @@ dependencies = [
[[package]] [[package]]
name = "metal" name = "metal"
version = "0.27.0" version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/gfx-rs/metal-rs?rev=ff8fd3d6dc7792852f8a015458d7e6d42d7fb352#ff8fd3d6dc7792852f8a015458d7e6d42d7fb352"
checksum = "c43f73953f8cbe511f021b58f18c3ce1c3d1ae13fe953293e13345bf83217f25"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"block", "block",
@ -2427,7 +2426,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [ dependencies = [
"malloc_buf", "malloc_buf",
"objc_exception",
] ]
[[package]] [[package]]
@ -2452,15 +2450,6 @@ version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666"
[[package]]
name = "objc_exception"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "object" name = "object"
version = "0.32.2" version = "0.32.2"

View File

@ -129,7 +129,7 @@ winit = { version = "0.29", features = ["android-native-activity"] }
# Metal dependencies # Metal dependencies
block = "0.1" block = "0.1"
core-graphics-types = "0.1" core-graphics-types = "0.1"
metal = "0.27.0" metal = { version = "0.27.0", git = "https://github.com/gfx-rs/metal-rs", rev = "ff8fd3d6dc7792852f8a015458d7e6d42d7fb352" }
objc = "0.2.5" objc = "0.2.5"
# Vulkan dependencies # Vulkan dependencies

View File

@ -208,12 +208,9 @@ fn validate_spirv(path: &Path, spirv_as: &str, spirv_val: &str) -> anyhow::Resul
buf buf
}; };
let expected_header_prefix = "; Version: "; let expected_header_prefix = "; Version: ";
let Some(version) = let Some(version) = second_line.strip_prefix(expected_header_prefix) else {
second_line.strip_prefix(expected_header_prefix) else { bail!("no {expected_header_prefix:?} header found in {path:?}");
bail!( };
"no {expected_header_prefix:?} header found in {path:?}"
);
};
let file = open_file(path)?; let file = open_file(path)?;
let mut spirv_as_cmd = EasyCommand::new(spirv_as, |cmd| { let mut spirv_as_cmd = EasyCommand::new(spirv_as, |cmd| {
cmd.stdin(Stdio::from(file)) cmd.stdin(Stdio::from(file))
@ -237,19 +234,20 @@ fn validate_metal(path: &Path, xcrun: &str) -> anyhow::Result<()> {
buf buf
}; };
let expected_header_prefix = "// language: "; let expected_header_prefix = "// language: ";
let Some(language) = let Some(language) = first_line.strip_prefix(expected_header_prefix) else {
first_line.strip_prefix(expected_header_prefix) else { bail!("no {expected_header_prefix:?} header found in {path:?}");
bail!( };
"no {expected_header_prefix:?} header found in {path:?}"
);
};
let language = language.strip_suffix('\n').unwrap_or(language); let language = language.strip_suffix('\n').unwrap_or(language);
let std_arg = if language.starts_with("metal1") || language.starts_with("metal2") {
format!("-std=macos-{language}")
} else {
format!("-std={language}")
};
let file = open_file(path)?; let file = open_file(path)?;
EasyCommand::new(xcrun, |cmd| { EasyCommand::new(xcrun, |cmd| {
cmd.stdin(Stdio::from(file)) cmd.stdin(Stdio::from(file))
.args(["-sdk", "macosx", "metal", "-mmacosx-version-min=10.11"]) .args(["-sdk", "macosx", "metal", "-mmacosx-version-min=10.11"])
.arg(format!("-std=macos-{language}")) .arg(std_arg)
.args(["-x", "metal", "-", "-o", "/dev/null"]) .args(["-x", "metal", "-", "-o", "/dev/null"])
}) })
.success() .success()
@ -337,15 +335,16 @@ fn validate_hlsl_with_fxc(
.target_profile .target_profile
.split('_') .split('_')
.nth(1) .nth(1)
.map(|segment| segment.parse::<u8>()) else { .map(|segment| segment.parse::<u8>())
bail!( else {
"expected target profile of the form \ bail!(
"expected target profile of the form \
`{{model}}_{{major}}_{{minor}}`, found invalid target \ `{{model}}_{{major}}_{{minor}}`, found invalid target \
profile {:?} in file {}", profile {:?} in file {}",
config_item.target_profile, config_item.target_profile,
file.display() file.display()
) )
}; };
// NOTE: This isn't implemented by `fxc.exe`; see // NOTE: This isn't implemented by `fxc.exe`; see
// <https://learn.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-syntax#profiles>. // <https://learn.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-syntax#profiles>.
if shader_model_major_version < 6 { if shader_model_major_version < 6 {

View File

@ -155,7 +155,7 @@ d3d12 = { path = "../d3d12/", version = "0.19.0", optional = true, features = [
# backend: Metal # backend: Metal
block = { version = "0.1", optional = true } block = { version = "0.1", optional = true }
metal = "0.27.0" metal = { version = "0.27.0", git = "https://github.com/gfx-rs/metal-rs", rev = "ff8fd3d6dc7792852f8a015458d7e6d42d7fb352" }
objc = "0.2.5" objc = "0.2.5"
core-graphics-types = "0.1" core-graphics-types = "0.1"

View File

@ -562,7 +562,11 @@ impl super::PrivateCapabilities {
Self { Self {
family_check, family_check,
msl_version: if os_is_xr || version.at_least((12, 0), (15, 0), os_is_mac) { msl_version: if os_is_xr || version.at_least((14, 0), (17, 0), os_is_mac) {
MTLLanguageVersion::V3_1
} else if version.at_least((13, 0), (16, 0), os_is_mac) {
MTLLanguageVersion::V3_0
} else if version.at_least((12, 0), (15, 0), os_is_mac) {
MTLLanguageVersion::V2_4 MTLLanguageVersion::V2_4
} else if version.at_least((11, 0), (14, 0), os_is_mac) { } else if version.at_least((11, 0), (14, 0), os_is_mac) {
MTLLanguageVersion::V2_3 MTLLanguageVersion::V2_3

View File

@ -94,6 +94,8 @@ impl super::Device {
metal::MTLLanguageVersion::V2_2 => (2, 2), metal::MTLLanguageVersion::V2_2 => (2, 2),
metal::MTLLanguageVersion::V2_3 => (2, 3), metal::MTLLanguageVersion::V2_3 => (2, 3),
metal::MTLLanguageVersion::V2_4 => (2, 4), metal::MTLLanguageVersion::V2_4 => (2, 4),
metal::MTLLanguageVersion::V3_0 => (3, 0),
metal::MTLLanguageVersion::V3_1 => (3, 1),
}, },
inline_samplers: Default::default(), inline_samplers: Default::default(),
spirv_cross_compatibility: false, spirv_cross_compatibility: false,