From 494c9f58716accbada7d003d440ec5b5f4975021 Mon Sep 17 00:00:00 2001 From: Firestar99 <4696087-firestar99@users.noreply.gitlab.com> Date: Thu, 6 Apr 2023 21:06:35 +0200 Subject: [PATCH 1/2] fixed SampledImage::sample() fns being marked as unsafe --- crates/spirv-std/src/image.rs | 59 +++++++++++++++-------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/crates/spirv-std/src/image.rs b/crates/spirv-std/src/image.rs index 76f1670a34..0853d2ecd1 100644 --- a/crates/spirv-std/src/image.rs +++ b/crates/spirv-std/src/image.rs @@ -979,38 +979,29 @@ impl< > { /// Sample texels at `coord` from the sampled image with an implicit lod. - /// - /// # Safety - /// Sampling with a type (`S`) that doesn't match the image's image format - /// will result in undefined behaviour. #[crate::macros::gpu_only] - pub unsafe fn sample( - &self, - coord: impl ImageCoordinate, - ) -> SampledType::Vec4 + pub fn sample(&self, coord: impl ImageCoordinate) -> SampledType::Vec4 where F: Float, { let mut result = Default::default(); - asm!( - "%sampledImage = OpLoad typeof*{1} {1}", - "%coord = OpLoad typeof*{2} {2}", - "%result = OpImageSampleImplicitLod typeof*{0} %sampledImage %coord", - "OpStore {0} %result", - in(reg) &mut result, - in(reg) self, - in(reg) &coord - ); + unsafe { + asm!( + "%sampledImage = OpLoad typeof*{1} {1}", + "%coord = OpLoad typeof*{2} {2}", + "%result = OpImageSampleImplicitLod typeof*{0} %sampledImage %coord", + "OpStore {0} %result", + in(reg) &mut result, + in(reg) self, + in(reg) &coord + ); + } result } /// Sample texels at `coord` from the sampled image with an explicit lod. - /// - /// # Safety - /// Sampling with a type (`S`) that doesn't match the image's image format - /// will result in undefined behaviour. #[crate::macros::gpu_only] - pub unsafe fn sample_by_lod( + pub fn sample_by_lod( &self, coord: impl ImageCoordinate, lod: f32, @@ -1019,17 +1010,19 @@ impl< F: Float, { let mut result = Default::default(); - asm!( - "%sampledImage = OpLoad typeof*{1} {1}", - "%coord = OpLoad typeof*{2} {2}", - "%lod = OpLoad typeof*{3} {3}", - "%result = OpImageSampleExplicitLod typeof*{0} %sampledImage %coord Lod %lod", - "OpStore {0} %result", - in(reg) &mut result, - in(reg) self, - in(reg) &coord, - in(reg) &lod, - ); + unsafe { + asm!( + "%sampledImage = OpLoad typeof*{1} {1}", + "%coord = OpLoad typeof*{2} {2}", + "%lod = OpLoad typeof*{3} {3}", + "%result = OpImageSampleExplicitLod typeof*{0} %sampledImage %coord Lod %lod", + "OpStore {0} %result", + in(reg) &mut result, + in(reg) self, + in(reg) &coord, + in(reg) &lod, + ); + } result } } From fba2ceb9e73bbf2ad62e285d9d4b8b97d6b25369 Mon Sep 17 00:00:00 2001 From: Firestar99 <4696087-firestar99@users.noreply.gitlab.com> Date: Thu, 6 Apr 2023 21:10:55 +0200 Subject: [PATCH 2/2] PR#1029 changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6b468914f..617f14eaf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed 🛠 - [PR#1011](https://github.com/EmbarkStudios/rust-gpu/pull/1011) made `NonWritable` all read-only storage buffers (i.e. those typed `&T`, where `T` doesn't have interior mutability) +- [PR#1029](https://github.com/EmbarkStudios/rust-gpu/pull/1029) fixed SampledImage::sample() fns being unnecessarily marked as unsafe ### Fixed 🩹 - [PR#1025](https://github.com/EmbarkStudios/rust-gpu/pull/1025) fixed [#1024](https://github.com/EmbarkStudios/rust-gpu/issues/1024) by keeping checked arithmetic "zombie" `bool`s disjoint from normal `bool` (`false`) consts