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

Safeness bug in StorageImage2d::write #453

Merged
merged 3 commits into from
Mar 1, 2021
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
4 changes: 3 additions & 1 deletion crates/spirv-builder/src/test/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ fn image_write() {
#[spirv(fragment)]
pub fn main(input: Input<glam::Vec2>, image: UniformConstant<StorageImage2d>) {
let texels = *input;
image.write(glam::UVec2::new(0, 1), texels);
unsafe {
image.write(glam::UVec2::new(0, 1), texels);
}
}
"#);
}
20 changes: 9 additions & 11 deletions crates/spirv-std/src/textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,20 @@ impl StorageImage2d {

/// Write a texel to an image without a sampler.
#[spirv_std_macros::gpu_only]
pub fn write<I, V, V2, const N: usize>(&self, coordinate: V, texels: V2)
pub unsafe fn write<I, V, V2, const N: usize>(&self, coordinate: V, texels: V2)
where
I: Integer,
V: Vector<I, N>,
V2: Vector<f32, N>,
{
unsafe {
asm! {
"%image = OpLoad _ {this}",
"%coordinate = OpLoad _ {coordinate}",
"%texels = OpLoad _ {texels}",
"OpImageWrite %image %coordinate %texels",
this = in(reg) self,
coordinate = in(reg) &coordinate,
texels = in(reg) &texels,
}
asm! {
"%image = OpLoad _ {this}",
"%coordinate = OpLoad _ {coordinate}",
"%texels = OpLoad _ {texels}",
"OpImageWrite %image %coordinate %texels",
this = in(reg) self,
coordinate = in(reg) &coordinate,
texels = in(reg) &texels,
}
}
}
Expand Down