From cb208f58399f141eba33458747176b68d32f4e38 Mon Sep 17 00:00:00 2001 From: FL33TW00D Date: Fri, 17 Mar 2023 16:01:39 +0000 Subject: [PATCH 1/3] feat: unchecked msl --- wgpu-hal/src/metal/device.rs | 25 ++++++++++++++++++++++--- wgpu-hal/src/metal/mod.rs | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 52cc215126..ef81af6465 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -75,11 +75,27 @@ impl super::Device { }, }; + let mut temp_options; + let options = if !stage.module.runtime_checks { + temp_options = layout.naga_options.clone(); + if !stage.module.runtime_checks { + temp_options.bounds_check_policies = naga::proc::BoundsCheckPolicies { + index: naga::proc::BoundsCheckPolicy::Unchecked, + buffer: naga::proc::BoundsCheckPolicy::Unchecked, + image: naga::proc::BoundsCheckPolicy::Unchecked, + binding_array: naga::proc::BoundsCheckPolicy::Unchecked, + }; + } + &temp_options + } else { + &layout.naga_options + }; + let module = &stage.module.naga.module; let (source, info) = naga::back::msl::write_string( module, &stage.module.naga.info, - &layout.naga_options, + options, &pipeline_options, ) .map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("MSL: {:?}", e)))?; @@ -777,11 +793,14 @@ impl crate::Device for super::Device { unsafe fn create_shader_module( &self, - _desc: &crate::ShaderModuleDescriptor, + desc: &crate::ShaderModuleDescriptor, shader: crate::ShaderInput, ) -> Result { match shader { - crate::ShaderInput::Naga(naga) => Ok(super::ShaderModule { naga }), + crate::ShaderInput::Naga(naga) => Ok(super::ShaderModule { + naga, + runtime_checks: desc.runtime_checks, + }), crate::ShaderInput::SpirV(_) => { panic!("SPIRV_SHADER_PASSTHROUGH is not enabled for this backend") } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 57083b585d..777d0307ab 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -622,6 +622,7 @@ unsafe impl Sync for BindGroup {} #[derive(Debug)] pub struct ShaderModule { naga: crate::NagaShader, + runtime_checks: bool, } #[derive(Debug, Default)] From a350f9c4e614fc99aa8f2948f3facfd5194b662e Mon Sep 17 00:00:00 2001 From: FL33TW00D Date: Fri, 17 Mar 2023 17:27:20 +0000 Subject: [PATCH 2/3] chore: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e209fc8541..1caa7b734c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,7 @@ By @teoxoy in [#3534](https://github.com/gfx-rs/wgpu/pull/3534) #### Metal - `create_texture` returns an error if `new_texture` returns NULL. By @jinleili in [#3554](https://github.com/gfx-rs/wgpu/pull/3554) - Fix definition of `NSOperatingSystemVersion` to avoid potential crashes. By @grovesNL in [#3557](https://github.com/gfx-rs/wgpu/pull/3557) +- Fix shader bounds checking being ignored. By @FL33TW00D in [#3603](https://github.com/gfx-rs/wgpu/pull/3603) ## wgpu-0.15.0 (2023-01-25) From 955c2e6236e2bf9861bdd9c57b7d03499a2ed5b4 Mon Sep 17 00:00:00 2001 From: FL33TW00D Date: Tue, 21 Mar 2023 10:08:14 +0000 Subject: [PATCH 3/3] chore: mistake --- wgpu-hal/src/metal/device.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index ef81af6465..3f8642dd0c 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -78,14 +78,12 @@ impl super::Device { let mut temp_options; let options = if !stage.module.runtime_checks { temp_options = layout.naga_options.clone(); - if !stage.module.runtime_checks { - temp_options.bounds_check_policies = naga::proc::BoundsCheckPolicies { - index: naga::proc::BoundsCheckPolicy::Unchecked, - buffer: naga::proc::BoundsCheckPolicy::Unchecked, - image: naga::proc::BoundsCheckPolicy::Unchecked, - binding_array: naga::proc::BoundsCheckPolicy::Unchecked, - }; - } + temp_options.bounds_check_policies = naga::proc::BoundsCheckPolicies { + index: naga::proc::BoundsCheckPolicy::Unchecked, + buffer: naga::proc::BoundsCheckPolicy::Unchecked, + image: naga::proc::BoundsCheckPolicy::Unchecked, + binding_array: naga::proc::BoundsCheckPolicy::Unchecked, + }; &temp_options } else { &layout.naga_options