screenshotting the output
This commit is contained in:
@@ -57,12 +57,10 @@ impl CompuState {
|
||||
handle
|
||||
}
|
||||
|
||||
/// Read the compute buffer back into a Vec (TODO BROKEN)
|
||||
pub fn read_compute_buffer(&mut self, handle: Arc<CompuBufferHandle>) -> Vec<u8> {
|
||||
// This is way more difficult than it should be
|
||||
//let compute_buffer : CompuBuffers = self.compute_buffers.get(handle.into()).unwrap();
|
||||
//compute_buffer.read_output_buffer().to_vec()
|
||||
unimplemented!("read_compute_buffer is not implemented")
|
||||
let mut buffer : &CompuBuffers = self.compute_buffers.get(handle.handle as usize).unwrap();
|
||||
let v = buffer.read_output_buffer();
|
||||
v.into_vec()
|
||||
}
|
||||
|
||||
/// Write to the compute buffer, ostensibly overwriting what's already there
|
||||
@@ -136,7 +134,7 @@ impl CompuState {
|
||||
|
||||
command_buffer = command_buffer
|
||||
.dispatch([size.0 / 8, size.1 / 8, 1], p, d, ()).unwrap()
|
||||
.copy_buffer_to_image(buffer.get_input_buffer(), image).unwrap();
|
||||
.copy_buffer_to_image(buffer.get_output_buffer(), image).unwrap();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ impl CompuBuffers {
|
||||
device: device.clone(),
|
||||
|
||||
handle: handle,
|
||||
io_buffers: vec![input_buffer, output_buffer],
|
||||
io_buffers: vec![output_buffer, input_buffer],
|
||||
settings_buffer: settings_buffer,
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,9 @@ impl CompuBuffers {
|
||||
pub fn read_output_buffer(&self) -> ImageBuffer<Rgba<u8>, Vec<u8>> {
|
||||
let xy = self.get_size();
|
||||
|
||||
self.io_buffers.get(1).unwrap().write().unwrap().map(|x| x);
|
||||
let data_buffer_content = self.io_buffers.get(1).unwrap().read().unwrap();
|
||||
self.io_buffers.get(0).unwrap().write().unwrap().map(|x| x);
|
||||
let data_buffer_content = self.io_buffers.get(0).unwrap().read().unwrap();
|
||||
|
||||
ImageBuffer::from_fn(xy.0, xy.1, |x, y| {
|
||||
let r = data_buffer_content[((xy.0 * y + x) * 4 + 0) as usize] as u8;
|
||||
let g = data_buffer_content[((xy.0 * y + x) * 4 + 1) as usize] as u8;
|
||||
@@ -95,10 +96,10 @@ impl CompuBuffers {
|
||||
}
|
||||
|
||||
pub fn get_input_buffer(&self) -> Arc<CpuAccessibleBuffer<[u8]>> {
|
||||
self.io_buffers.get(0).unwrap().clone()
|
||||
self.io_buffers.get(1).unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn get_output_buffer(&self) -> Arc<CpuAccessibleBuffer<[u8]>> {
|
||||
self.io_buffers.get(1).unwrap().clone()
|
||||
self.io_buffers.get(0).unwrap().clone()
|
||||
}
|
||||
}
|
||||
|
||||
28
src/main.rs
28
src/main.rs
@@ -35,6 +35,7 @@ use crate::util::load_raw;
|
||||
use crate::util::timer::Timer;
|
||||
use crate::util::vertex::{TextureVertex3D, VertexTypes};
|
||||
use crate::vkprocessor::VkProcessor;
|
||||
use std::path::Path;
|
||||
|
||||
pub mod util;
|
||||
pub mod vkprocessor;
|
||||
@@ -87,15 +88,22 @@ pub fn main() {
|
||||
let mut current_time: f32 = timer.elap_time();
|
||||
|
||||
let image_data = load_raw(String::from("funky-bird.jpg"));
|
||||
let image_dimensions_f: (f32, f32) = ((image_data.1).0 as f32, (image_data.1).1 as f32);
|
||||
let image_dimensions_f: (f32, f32) = ((image_data.1).clone().0 as f32, (image_data.1).clone().1 as f32);
|
||||
let image_dimensions_u: (u32, u32) = image_data.1;
|
||||
let compu_sprite1: CompuSprite =
|
||||
CompuSprite::new((0.0, -0.5), (0.4, 0.4), 0, image_dimensions_f,
|
||||
CompuSprite::new((0.0, -0.5), (1.0, 1.0), 0, image_dimensions_f,
|
||||
// Swap image to render the result to. Must match dimensions
|
||||
processor.new_swap_image(image_dimensions_u));
|
||||
|
||||
|
||||
// Demo gpu toolpath generation
|
||||
|
||||
// Need to
|
||||
let compute_buffer: Arc<CompuBufferHandle> =
|
||||
processor.new_compute_buffer(image_data.0, image_data.1, 4);
|
||||
processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4);
|
||||
|
||||
let first_output_buffer: Arc<CompuBufferHandle> =
|
||||
processor.new_compute_buffer(image_data.0.clone(), image_data.1.clone(), 4);
|
||||
|
||||
let compute_kernel: Arc<CompuKernelHandle> =
|
||||
processor.get_kernel_handle(String::from("simple-edge.compute"))
|
||||
@@ -123,10 +131,6 @@ pub fn main() {
|
||||
|
||||
let l = hprof::enter("Loop");
|
||||
|
||||
let mut exit = false;
|
||||
|
||||
let mut count = 0;
|
||||
|
||||
// while let true = processor.is_open() {
|
||||
//
|
||||
// // Take care of our timing
|
||||
@@ -164,6 +168,9 @@ pub fn main() {
|
||||
let mut compu_frame = CompuFrame::new();
|
||||
//compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||
compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||
|
||||
canvas_frame.draw(&compu_sprite1);
|
||||
|
||||
{
|
||||
let g = hprof::enter("Run");
|
||||
@@ -171,6 +178,7 @@ pub fn main() {
|
||||
canvas_frame,
|
||||
compu_frame);
|
||||
}
|
||||
|
||||
}
|
||||
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
|
||||
match keyboard_input.virtual_keycode.unwrap() {
|
||||
@@ -178,6 +186,12 @@ pub fn main() {
|
||||
if keyboard_input.state == ElementState::Pressed {
|
||||
// processor.save_edges_image();
|
||||
}
|
||||
},
|
||||
VirtualKeyCode::P => {
|
||||
if keyboard_input.state == ElementState::Pressed {
|
||||
let data = processor.read_compute_buffer(compute_buffer.clone());
|
||||
image::save_buffer(&Path::new("image.png"), data.as_slice(), (image_data.1).0, (image_data.1).1, image::RGBA(8));
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
||||
@@ -76,9 +76,7 @@ impl VkProcessor {
|
||||
|
||||
let capabilities = surface.capabilities(physical).unwrap();
|
||||
|
||||
|
||||
VkProcessor {
|
||||
//physical: physical.clone(),
|
||||
device: device.clone(),
|
||||
queue: queue.clone(),
|
||||
queues: queues,
|
||||
@@ -91,12 +89,6 @@ impl VkProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
/// VKProcessor controls the window. So it will let the main loop know when it is done
|
||||
pub fn is_open(&mut self) -> bool {
|
||||
// self.surface
|
||||
true
|
||||
}
|
||||
|
||||
/// Using the surface, we calculate the surface capabilities and create the swapchain and swapchain images
|
||||
pub fn create_swapchain(&mut self, instance: Arc<Instance>, surface: Arc<Surface<Window>>) {
|
||||
let (mut swapchain, images) = {
|
||||
|
||||
Reference in New Issue
Block a user