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
use gpgpu::{primitives::pixels::Rgba8Uint, ImgOps};
fn main() {
let fw = gpgpu::Framework::default();
let shader =
gpgpu::Shader::from_wgsl_file(&fw, "examples/image-compatibility/shader.wgsl").unwrap();
let dynamic_img = image::open("examples/image-compatibility/monke.jpg").unwrap();
let rgba = dynamic_img.into_rgba8();
let (width, height) = rgba.dimensions();
let input_img = gpgpu::GpuConstImage::from_image_buffer(&fw, &rgba);
let output_img = gpgpu::GpuImage::<Rgba8Uint>::new(&fw, width, height);
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 = output_img.read_to_image_buffer_blocking().unwrap();
output
.save("examples/image-compatibility/mirror-monke.png")
.unwrap();
}