1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use gpgpu::{primitives::pixels::Rgba8Uint, ImgOps};
fn main() {
let fw = gpgpu::Framework::default();
let shader = gpgpu::Shader::from_wgsl_file(&fw, "examples/mirror-image/shader.wgsl").unwrap();
let dynamic_img = image::open("examples/mirror-image/monke.jpg").unwrap();
let rgba = dynamic_img.into_rgba8();
let (width, height) = rgba.dimensions();
let input_img = gpgpu::GpuConstImage::<Rgba8Uint>::new(&fw, width, height);
let output_img = gpgpu::GpuImage::<Rgba8Uint>::new(&fw, width, height);
input_img.write(&rgba).unwrap();
let desc = gpgpu::DescriptorSet::default()
.bind_const_image(&input_img)
.bind_image(&output_img);
let program = gpgpu::Program::new(&shader, "main").add_descriptor_set(desc);
gpgpu::Kernel::new(&fw, program).enqueue(width / 32, height / 32, 1);
let output_bytes = output_img.read_vec_blocking().unwrap();
image::save_buffer(
"examples/mirror-image/mirror-monke.png",
&output_bytes,
width,
height,
image::ColorType::Rgba8,
)
.unwrap();
}