screenshotting the output

master
mitchellhansen 4 years ago
parent 5916b0d947
commit 67efffa139

@ -6,14 +6,14 @@ edition = "2018"
[dependencies]
#vulkano = "0.13.0"
vulkano = {path = "../vulkano/vulkano"}
vulkano = "0.19.0"
#vulkano = {path = "../vulkano/vulkano"}
#vulkano-shaders = "0.14.0"
vulkano-shaders = {path = "../vulkano/vulkano-shaders"}
vulkano-shaders = "0.19.0"
#vulkano-shaders = {path = "../vulkano/vulkano-shaders"}
#vulkano-win = "0.14.0"
vulkano-win= {path = "../vulkano/vulkano-win"}
vulkano-win = "0.19.0"
#vulkano-win= {path = "../vulkano/vulkano-win"}
#shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"}
shade_runner = {path = "../shade_runner"}

@ -8,15 +8,16 @@ Creation-Date: 2020-02-03T22:11:42-08:00
=== Trac3r : A program to convert images to 2D toolpaths ===
TODO:
[x] Text rendering is half implemented.
[ ] Pathfinder vulkan backend implementation
[ ] Currently using local copies of a few libraries:
[X] Text rendering is mocked.
[?] Pathfinder vulkan backend implementation
* Kinda big meh on this. It's very much oneshot based
and not incredibly compatible with vulkano...
[ ] Investigate lyon maybe
[X] Currently using local copies of a few libraries:
[x] shade_runner ( not gonna happen, my fork has diverged too far )
vulkano/vulkano-win
vulkano/vulkano-shaders
vulkano/vulkano
[*] Get a new GPU
[*] Figure out how to make this POS stable (semi stable)
[ ] Make a toolpath
[X] Read from GPU?
[ ] Figure out a way to vectorize the simple edge
--------------------

@ -60,11 +60,19 @@ void main() {
else {
//p.w = 125;
}
//write_buffer.buf[0] = write_buffer.buf[0];
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
//write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) & 0x0;
//write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (255 <<16);
//write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | 10;
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | 125;
// write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | 125;
}

@ -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()
}
}

@ -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) = {

Loading…
Cancel
Save