Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed SampledImage::sample() fns being unnecessarily marked as unsafe #1029

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 26 additions & 33 deletions crates/spirv-std/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F>(
&self,
coord: impl ImageCoordinate<F, DIM, ARRAYED>,
) -> SampledType::Vec4
pub fn sample<F>(&self, coord: impl ImageCoordinate<F, DIM, ARRAYED>) -> 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<F>(
pub fn sample_by_lod<F>(
&self,
coord: impl ImageCoordinate<F, DIM, ARRAYED>,
lod: f32,
Expand All @@ -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
}
}
Expand Down