From 20f3075fa88ad92b27a11ad4065f47fe955aaa92 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Mon, 1 Jul 2019 23:09:42 -0700 Subject: [PATCH] for some reason I broke it. I think it has to do with the glsl layout --- resources/images/test2.png | Bin 0 -> 4073 bytes resources/shaders/add.compute | 53 +++++++++++++++++----------------- src/main.rs | 34 ++++++++++++---------- 3 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 resources/images/test2.png diff --git a/resources/images/test2.png b/resources/images/test2.png new file mode 100644 index 0000000000000000000000000000000000000000..7b6efa96e33b3ef752d1d94ad276406bb6d2fffd GIT binary patch literal 4073 zcmX|EdpuO@*WY{3)@+rTJqR(4Z73B*B~6;x7?)0@(^ZagNmA+0#s zszaSrbm|uhgK_IZQsh#@P|^rfxg~kG&+qfTf2_~5pY^Qg`K-Oxde-y(CT-o~qA^#0 zE&u=;n_PL@002yz6=V*nAu6n&lY=_nbAdq=kk5p2_H@Q1ed#TVIWW)Nf z`Xo}d=+F+&aL16NM-TiNPEG;9G3Xhvx;%%iAK6x9$p;@4-aLz>6 zfF__2s>7&;8wMzhNclZ2wGil$!jOcz1jRX)LO>!`hiA{ixlyG`iwy{p_6yrjmkR+) zYvIpn*!MEr{ek#twPo&HKpx4gQ=M2W`n$4fq}|HW7*nwIfk#xHH;;m*{Vj8{0zigt zGXV2EWhXsa^MXAN+=|zl&VSLqaV2dfeT^?v)b3d}P@4pKIvz1jw`sk(jt;_wqQM#p&2qFj~2)9@fueGSh z^FNg_+ME2!DfV2#$hOMCiYQW_8e!;Et%^85sh4~$MwBQJys(tHcydIb7J^_1B0^SjH+KyLf}GTC zb7U_RZ;t!lAqWYzb$;t^@RyFxz`7EjQ%>AWHQ5XQS}#ql<=HO3w~Y=2{{96kEa$Tp z&=8I`j!Uf)sArSd@#fJbe&IGIF)j&$3|vZ?k01r9k~B|BUTV|cKlN!0!=p*m9tz|S z9iKqvadS%_RR%;#80f^u9EPR}rGsD#`O_KBH_bZ7L&|w#;USss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ov341L{Pu-wLC`DH4kX=!zhGCfvGSROYztu7G}04as11}Gv29Hpc4L6A)I z!l=*FUwv+7PCVcSgJ;Tj<5o7&%(|Yrl!T%mBN`*k-}Bp)5BdO=uV@(mf95({KtRvU aPj=v%6qiT!|2EHZ@J&uzcy}Fq6aE($Z0w!@ literal 0 HcmV?d00001 diff --git a/resources/shaders/add.compute b/resources/shaders/add.compute index 23788ed3..c365f341 100644 --- a/resources/shaders/add.compute +++ b/resources/shaders/add.compute @@ -2,13 +2,13 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; -layout(set = 0, binding = 0) buffer Data { - int data[]; -} data; +layout(set = 0, binding = 0) buffer wData { + int buf[]; +} write_buffer; -layout(set = 0, binding = 1) buffer Data1 { - int odata[]; -} odata; +layout(set = 0, binding = 1) buffer rData { + int buf[]; +} read_buffer; layout(set = 0, binding = 2) buffer Settings { int settings[]; @@ -39,20 +39,15 @@ void main() { uint idx = get_idx(0,0); - ivec4 p = separate(odata.odata[get_idx(0,0)]); - - ivec4 p0 = separate(odata.odata[get_idx(0, 1)]); - ivec4 p1 = separate(odata.odata[get_idx(0,-1)]); - - ivec4 p2 = separate(odata.odata[get_idx(1, 1)]); - ivec4 p3 = separate(odata.odata[get_idx(-1,-1)]); - - ivec4 p4 = separate(odata.odata[get_idx(1, 0)]); - 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)]); - + ivec4 p = separate(read_buffer.buf[get_idx(0 , 0)]); + ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]); + ivec4 p1 = separate(read_buffer.buf[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 p4 = separate(read_buffer.buf[get_idx(1 , 0)]); + ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]); + ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]); + ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]); ivec3 d0 = abs(p0.xyz - p1.xyz); ivec3 d1 = abs(p2.xyz - p3.xyz); @@ -61,17 +56,23 @@ void main() { 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.y = 0; 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); - data.data[idx] = (data.data[idx] & (~0x000000FF) ) | (p.x); - data.data[idx] = (data.data[idx] & (~0x0000FF00) ) | (p.y << 8); - data.data[idx] = (data.data[idx] & (~0x00FF0000) ) | (p.z << 16); - data.data[idx] = (data.data[idx] & (~0xFF000000) ) | (p.w << 24); + 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); + //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); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3ea31290..de55bdcc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,10 +143,10 @@ fn main() { println!("Device initialized"); let project_root = std::env::current_dir().expect("failed to get root directory"); - let mut vert_path = project_root.clone(); - vert_path.push(PathBuf::from("resources/shaders/add.compute")); + let mut compute_path = project_root.clone(); + 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 x = unsafe { @@ -165,7 +165,7 @@ fn main() { }); // 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 data_length = xy.0*xy.1*4; @@ -191,17 +191,22 @@ fn main() { 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 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() + }; + + // 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() }; @@ -216,8 +221,8 @@ 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) - .add_buffer(read_buffer).unwrap() .add_buffer(write_buffer.clone()).unwrap() + .add_buffer(read_buffer.clone()).unwrap() .add_buffer(settings_buffer.clone()).unwrap() .build().unwrap() ); @@ -237,12 +242,10 @@ fn main() { future.wait(None).unwrap(); println!("Done running kernel"); + println!("Reading output"); // The buffer is sync'd so we can just read straight from the handle 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 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())); - println!("Stdddwafasddfqwefaarting"); let mut window = RenderWindow::new( (900, 900),