Skip to content

Commit

Permalink
Add Metal 3.0 and 3.1 detection (#5497)
Browse files Browse the repository at this point in the history
  • Loading branch information
atlv24 authored Apr 5, 2024
1 parent b985f16 commit 1c48a23
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Bottom level categories:
#### 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).
- Metal 3.0 and 3.1 detection. By @atlv24 in [#5497](https://github.com/gfx-rs/wgpu/pull/5497)

#### DX12

Expand Down
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ winit = { version = "0.29", features = ["android-native-activity"] }
# Metal dependencies
block = "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"

# Vulkan dependencies
Expand Down
41 changes: 20 additions & 21 deletions naga/xtask/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,9 @@ fn validate_spirv(path: &Path, spirv_as: &str, spirv_val: &str) -> anyhow::Resul
buf
};
let expected_header_prefix = "; Version: ";
let Some(version) =
second_line.strip_prefix(expected_header_prefix) else {
bail!(
"no {expected_header_prefix:?} header found in {path:?}"
);
};
let Some(version) = second_line.strip_prefix(expected_header_prefix) else {
bail!("no {expected_header_prefix:?} header found in {path:?}");
};
let file = open_file(path)?;
let mut spirv_as_cmd = EasyCommand::new(spirv_as, |cmd| {
cmd.stdin(Stdio::from(file))
Expand All @@ -237,19 +234,20 @@ fn validate_metal(path: &Path, xcrun: &str) -> anyhow::Result<()> {
buf
};
let expected_header_prefix = "// language: ";
let Some(language) =
first_line.strip_prefix(expected_header_prefix) else {
bail!(
"no {expected_header_prefix:?} header found in {path:?}"
);
};
let Some(language) = first_line.strip_prefix(expected_header_prefix) else {
bail!("no {expected_header_prefix:?} header found in {path:?}");
};
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)?;
EasyCommand::new(xcrun, |cmd| {
cmd.stdin(Stdio::from(file))
.args(["-sdk", "macosx", "metal", "-mmacosx-version-min=10.11"])
.arg(format!("-std=macos-{language}"))
.arg(std_arg)
.args(["-x", "metal", "-", "-o", "/dev/null"])
})
.success()
Expand Down Expand Up @@ -337,15 +335,16 @@ fn validate_hlsl_with_fxc(
.target_profile
.split('_')
.nth(1)
.map(|segment| segment.parse::<u8>()) else {
bail!(
"expected target profile of the form \
.map(|segment| segment.parse::<u8>())
else {
bail!(
"expected target profile of the form \
`{{model}}_{{major}}_{{minor}}`, found invalid target \
profile {:?} in file {}",
config_item.target_profile,
file.display()
)
};
config_item.target_profile,
file.display()
)
};
// NOTE: This isn't implemented by `fxc.exe`; see
// <https://learn.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-syntax#profiles>.
if shader_model_major_version < 6 {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ d3d12 = { path = "../d3d12/", version = "0.19.0", optional = true, features = [
# backend: Metal
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"
core-graphics-types = "0.1"

Expand Down
6 changes: 5 additions & 1 deletion wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,11 @@ impl super::PrivateCapabilities {

Self {
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
} else if version.at_least((11, 0), (14, 0), os_is_mac) {
MTLLanguageVersion::V2_3
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl super::Device {
metal::MTLLanguageVersion::V2_2 => (2, 2),
metal::MTLLanguageVersion::V2_3 => (2, 3),
metal::MTLLanguageVersion::V2_4 => (2, 4),
metal::MTLLanguageVersion::V3_0 => (3, 0),
metal::MTLLanguageVersion::V3_1 => (3, 1),
},
inline_samplers: Default::default(),
spirv_cross_compatibility: false,
Expand Down

0 comments on commit 1c48a23

Please sign in to comment.