mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-25 08:14:12 +00:00
feat: add image fetch (#480)
This commit is contained in:
parent
2d6a677563
commit
c53c351987
@ -587,3 +587,14 @@ pub fn main(input: Input<glam::Vec2>, image: UniformConstant<StorageImage2d>) {
|
||||
}
|
||||
"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_fetch() {
|
||||
val(r#"
|
||||
#[spirv(fragment)]
|
||||
pub fn main(image: UniformConstant<Image2d>, mut output: Output<glam::Vec4>) {
|
||||
let texel = image.fetch(glam::IVec2::new(0, 1));
|
||||
*output = texel;
|
||||
}
|
||||
"#);
|
||||
}
|
||||
|
@ -42,6 +42,27 @@ impl Image2d {
|
||||
result
|
||||
}
|
||||
}
|
||||
/// Fetch a single texel with a sampler set at compile time
|
||||
#[spirv_std_macros::gpu_only]
|
||||
pub fn fetch<I>(&self, coordinate: impl Vector<I>) -> Vec4
|
||||
where
|
||||
I: Integer,
|
||||
{
|
||||
let mut result = Vec4::default();
|
||||
unsafe {
|
||||
asm! {
|
||||
"%image = OpLoad _ {this}",
|
||||
"%coordinate = OpLoad _ {coordinate}",
|
||||
"%result = OpImageFetch typeof*{result} %image %coordinate",
|
||||
"OpStore {result} %result",
|
||||
this = in(reg) self,
|
||||
coordinate = in(reg) &coordinate,
|
||||
result = in(reg) &mut result,
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[spirv(image_type(
|
||||
|
Loading…
Reference in New Issue
Block a user