Skip to content

Commit

Permalink
metal: Set preserveInvariance for shader options
Browse files Browse the repository at this point in the history
This fixes, for example, depth prepass resulting in ever so slightly
different depth values for later render passes.
  • Loading branch information
scoopr committed Jan 10, 2022
1 parent f8a63c4 commit e052572
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,11 @@ impl super::PrivateCapabilities {
supports_depth_clip_control: device
.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1)
|| os_is_mac,
supports_preserve_invariance: if os_is_mac {
Self::version_at_least(major, minor, 11, 0)
} else {
Self::version_at_least(major, minor, 13, 0)
},
}
}

Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ impl super::Device {
let options = mtl::CompileOptions::new();
options.set_language_version(self.shared.private_caps.msl_version);

if self.shared.private_caps.supports_preserve_invariance {
// TODO: Workaround until naga supports [[invariant]]
options.set_preserve_invariance(true);
}

let library = self
.shared
.device
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ struct PrivateCapabilities {
supports_arrays_of_textures_write: bool,
supports_mutability: bool,
supports_depth_clip_control: bool,
supports_preserve_invariance: bool,
}

#[derive(Clone, Debug)]
Expand Down

0 comments on commit e052572

Please sign in to comment.