So it seems like we are constrained to a fixed size buffer?

master
mitchellhansen 5 years ago
parent 20f3075fa8
commit ceb138c391

@ -61,18 +61,18 @@ void main() {
p.y = 0;
p.z = 255;
}
p.x = 0;
p.y = 0;
p.x = 125;
p.y = 255;
p.z = 255;
// p.z = max(p.z - (d0.x + d0.y + d0.z + d1.x + d1.y + d1.z)/5, 0);
write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
write_buffer.buf[0] = (read_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
//write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
//write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
//write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
//read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
//read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
//read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
//read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
// read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
// read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
// read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
// read_buffer.buf[idx] = (read_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
}

@ -29,7 +29,7 @@ use vulkano::pipeline::ComputePipeline;
use vulkano::sync::GpuFuture;
use vulkano::sync;
use std::sync::Arc;
use std::fs;
use std::{fs, mem, iter, ptr};
use std::path::PathBuf;
use std::result;
@ -40,6 +40,7 @@ use na::DimAdd;
use std::time::{SystemTime, Duration};
use shade_runner as sr;
use std::ffi::CStr;
use std::ptr::write;
mod slider;
mod timer;
@ -165,7 +166,7 @@ fn main() {
});
// Load up the input image, determine some details
let mut img = image::open("resources/images/test2.png").unwrap();
let mut img = image::open("resources/images/test.png").unwrap();
let xy = img.dimensions();
let data_length = xy.0*xy.1*4;
@ -192,22 +193,38 @@ fn main() {
println!("Allocating Buffers...");
{
//CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
// Pull out the image data and place it in a buffer for the kernel to write to and for us to read from
let write_buffer = {
let mut buff = image_buffer.iter();
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
//CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
let data_iter = (0..data_length).map(|n| *(buff.next().unwrap()));
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap();
unsafe {
let uninitialized =
CpuAccessibleBuffer::raw(device, data_length as usize, BufferUsage::all(), iter::empty()).unwrap();
{
let mut mapping = uninitialized.write().unwrap();
ptr::write(&mut *mapping, image_buffer.as_slice())
}
uninitialized
}
};
// Pull out the image data and place it in a buffer for the kernel to read from
let read_buffer = {
let mut buff = image_buffer.iter();
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
// let q = ImmutableBuffer::from_data(image_buffer.clone(), BufferUsage::all(), queue.clone()).unwrap();
// q.1.flush();
// q.0
// let mut buff = image_buffer.iter();
// let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
//CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
};
// A buffer to hold many i32 values to use as settings
@ -220,12 +237,12 @@ fn main() {
println!("Done");
// Create the data descriptor set for our previously created shader pipeline
let mut set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
let mut set = PersistentDescriptorSet::start(pipeline.clone(), 0)
.add_buffer(write_buffer.clone()).unwrap()
.add_buffer(read_buffer.clone()).unwrap()
.add_buffer(settings_buffer.clone()).unwrap()
.build().unwrap()
);
.add_buffer(settings_buffer.clone()).unwrap();
let mut set = Arc::new(set.build().unwrap());
println!("Running Kernel...");
// The command buffer I think pretty much serves to define what runs where for how many times

Loading…
Cancel
Save