for some reason I broke it. I think it has to do with the glsl layout
This commit is contained in:
BIN
resources/images/test2.png
Normal file
BIN
resources/images/test2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||||
|
|
||||||
layout(set = 0, binding = 0) buffer Data {
|
layout(set = 0, binding = 0) buffer wData {
|
||||||
int data[];
|
int buf[];
|
||||||
} data;
|
} write_buffer;
|
||||||
|
|
||||||
layout(set = 0, binding = 1) buffer Data1 {
|
layout(set = 0, binding = 1) buffer rData {
|
||||||
int odata[];
|
int buf[];
|
||||||
} odata;
|
} read_buffer;
|
||||||
|
|
||||||
layout(set = 0, binding = 2) buffer Settings {
|
layout(set = 0, binding = 2) buffer Settings {
|
||||||
int settings[];
|
int settings[];
|
||||||
@@ -39,20 +39,15 @@ void main() {
|
|||||||
|
|
||||||
uint idx = get_idx(0,0);
|
uint idx = get_idx(0,0);
|
||||||
|
|
||||||
ivec4 p = separate(odata.odata[get_idx(0,0)]);
|
ivec4 p = separate(read_buffer.buf[get_idx(0 , 0)]);
|
||||||
|
ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]);
|
||||||
ivec4 p0 = separate(odata.odata[get_idx(0, 1)]);
|
ivec4 p1 = separate(read_buffer.buf[get_idx(0 ,-1)]);
|
||||||
ivec4 p1 = separate(odata.odata[get_idx(0,-1)]);
|
ivec4 p2 = separate(read_buffer.buf[get_idx(1 , 1)]);
|
||||||
|
ivec4 p3 = separate(read_buffer.buf[get_idx(-1,-1)]);
|
||||||
ivec4 p2 = separate(odata.odata[get_idx(1, 1)]);
|
ivec4 p4 = separate(read_buffer.buf[get_idx(1 , 0)]);
|
||||||
ivec4 p3 = separate(odata.odata[get_idx(-1,-1)]);
|
ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]);
|
||||||
|
ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]);
|
||||||
ivec4 p4 = separate(odata.odata[get_idx(1, 0)]);
|
ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]);
|
||||||
ivec4 p5 = separate(odata.odata[get_idx(-1,0)]);
|
|
||||||
|
|
||||||
ivec4 p6 = separate(odata.odata[get_idx(1,-1)]);
|
|
||||||
ivec4 p7 = separate(odata.odata[get_idx(-1,1)]);
|
|
||||||
|
|
||||||
|
|
||||||
ivec3 d0 = abs(p0.xyz - p1.xyz);
|
ivec3 d0 = abs(p0.xyz - p1.xyz);
|
||||||
ivec3 d1 = abs(p2.xyz - p3.xyz);
|
ivec3 d1 = abs(p2.xyz - p3.xyz);
|
||||||
@@ -61,17 +56,23 @@ void main() {
|
|||||||
|
|
||||||
ivec3 m = max(max(max(d0, d1), d2), d3);
|
ivec3 m = max(max(max(d0, d1), d2), d3);
|
||||||
|
|
||||||
if ((m.x + m.y + m.z) > 150){
|
if ((m.x + m.y + m.z) > 1){
|
||||||
p.x = 0;
|
p.x = 0;
|
||||||
p.y = 0;
|
p.y = 0;
|
||||||
p.z = 255;
|
p.z = 255;
|
||||||
}
|
}
|
||||||
|
p.x = 0;
|
||||||
|
p.y = 0;
|
||||||
|
p.z = 255;
|
||||||
// p.z = max(p.z - (d0.x + d0.y + d0.z + d1.x + d1.y + d1.z)/5, 0);
|
// p.z = max(p.z - (d0.x + d0.y + d0.z + d1.x + d1.y + d1.z)/5, 0);
|
||||||
|
|
||||||
data.data[idx] = (data.data[idx] & (~0x000000FF) ) | (p.x);
|
write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
|
||||||
data.data[idx] = (data.data[idx] & (~0x0000FF00) ) | (p.y << 8);
|
write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
|
||||||
data.data[idx] = (data.data[idx] & (~0x00FF0000) ) | (p.z << 16);
|
write_buffer.buf[idx] = (read_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
|
||||||
data.data[idx] = (data.data[idx] & (~0xFF000000) ) | (p.w << 24);
|
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);
|
||||||
}
|
}
|
||||||
34
src/main.rs
34
src/main.rs
@@ -143,10 +143,10 @@ fn main() {
|
|||||||
println!("Device initialized");
|
println!("Device initialized");
|
||||||
|
|
||||||
let project_root = std::env::current_dir().expect("failed to get root directory");
|
let project_root = std::env::current_dir().expect("failed to get root directory");
|
||||||
let mut vert_path = project_root.clone();
|
let mut compute_path = project_root.clone();
|
||||||
vert_path.push(PathBuf::from("resources/shaders/add.compute"));
|
compute_path.push(PathBuf::from("resources/shaders/add.compute"));
|
||||||
|
|
||||||
let shader = sr::load_compute(vert_path).expect("Failed to compile");
|
let shader = sr::load_compute(compute_path).expect("Failed to compile");
|
||||||
let vulkano_entry = sr::parse_compute(&shader).expect("failed to parse");
|
let vulkano_entry = sr::parse_compute(&shader).expect("failed to parse");
|
||||||
|
|
||||||
let x = unsafe {
|
let x = unsafe {
|
||||||
@@ -165,7 +165,7 @@ fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Load up the input image, determine some details
|
// Load up the input image, determine some details
|
||||||
let mut img = image::open("resources/images/test.png").unwrap();
|
let mut img = image::open("resources/images/test2.png").unwrap();
|
||||||
let xy = img.dimensions();
|
let xy = img.dimensions();
|
||||||
let data_length = xy.0*xy.1*4;
|
let data_length = xy.0*xy.1*4;
|
||||||
|
|
||||||
@@ -191,17 +191,22 @@ fn main() {
|
|||||||
|
|
||||||
println!("Allocating Buffers...");
|
println!("Allocating Buffers...");
|
||||||
{
|
{
|
||||||
// Pull out the image data and place it in a buffer for the kernel to read from
|
|
||||||
let read_buffer = {
|
|
||||||
let q = ImmutableBuffer::from_data(image_buffer.clone(), BufferUsage::all(), queue.clone()).unwrap();
|
|
||||||
q.1.flush();
|
|
||||||
q.0
|
|
||||||
};
|
|
||||||
|
|
||||||
// Pull out the image data and place it in a buffer for the kernel to write to and for us to read from
|
// 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 write_buffer = {
|
||||||
let mut buff = image_buffer.iter();
|
let mut buff = image_buffer.iter();
|
||||||
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
|
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()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pull out the image data and place it in a buffer for the kernel to read from
|
||||||
|
let read_buffer = {
|
||||||
|
// 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()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -216,8 +221,8 @@ fn main() {
|
|||||||
println!("Done");
|
println!("Done");
|
||||||
// Create the data descriptor set for our previously created shader pipeline
|
// Create the data descriptor set for our previously created shader pipeline
|
||||||
let mut set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
|
let mut set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
|
||||||
.add_buffer(read_buffer).unwrap()
|
|
||||||
.add_buffer(write_buffer.clone()).unwrap()
|
.add_buffer(write_buffer.clone()).unwrap()
|
||||||
|
.add_buffer(read_buffer.clone()).unwrap()
|
||||||
.add_buffer(settings_buffer.clone()).unwrap()
|
.add_buffer(settings_buffer.clone()).unwrap()
|
||||||
.build().unwrap()
|
.build().unwrap()
|
||||||
);
|
);
|
||||||
@@ -237,12 +242,10 @@ fn main() {
|
|||||||
future.wait(None).unwrap();
|
future.wait(None).unwrap();
|
||||||
|
|
||||||
println!("Done running kernel");
|
println!("Done running kernel");
|
||||||
|
println!("Reading output");
|
||||||
// The buffer is sync'd so we can just read straight from the handle
|
// The buffer is sync'd so we can just read straight from the handle
|
||||||
let data_buffer_content = write_buffer.read().unwrap();
|
let data_buffer_content = write_buffer.read().unwrap();
|
||||||
|
|
||||||
let p = image::load_from_memory(data_buffer_content.as_slice()).unwrap();
|
|
||||||
|
|
||||||
println!("done2");
|
|
||||||
for y in 0 .. xy.1 {
|
for y in 0 .. xy.1 {
|
||||||
for x in 0 .. xy.0 {
|
for x in 0 .. xy.0 {
|
||||||
|
|
||||||
@@ -261,10 +264,9 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("done3");
|
println!("Saving output");
|
||||||
img.save(format!("output/{}.png", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()));
|
img.save(format!("output/{}.png", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()));
|
||||||
|
|
||||||
println!("Stdddwafasddfqwefaarting");
|
|
||||||
|
|
||||||
let mut window = RenderWindow::new(
|
let mut window = RenderWindow::new(
|
||||||
(900, 900),
|
(900, 900),
|
||||||
|
|||||||
Reference in New Issue
Block a user