#![recursion_limit="1024"] #[macro_use] extern crate gl_struct; extern crate glfw; extern crate rand; use gl_struct::*; use gl_struct::glsl_type::*; glsl! {$ pub mod QRDecomp { @Compute #version 460 #define I (mat4(vec4(1,0,0,0),vec4(0,1,0,0),vec4(0,0,1,0),vec4(0,0,0,1))) #define EPSILON 0.0001 layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; layout(std140) buffer mat_input { readonly restrict mat4 mats[]; }; layout(std140) buffer rot_out { writeonly restrict mat4 rot[]; }; layout(std140) buffer upper_triangular_out { writeonly restrict mat4 ut[]; }; layout(std140) buffer mat_output { writeonly restrict mat4 result[]; }; mat4 hausdorf(vec4 v) { float l2 = dot(v,v); return l2==0 ? I : I - (2/l2)*outerProduct(v,v); } void qr(in mat4 A, out mat4 Q, out mat4 R) { Q = I; R = A; for(uint i=0; i<4; i++) { vec4 a = R[i]; for(uint j=0; j f32 {rand::random::()} let count = 10000; let mats = (0..count).map( |_| { let rand = [[rf(),rf(),rf(),rf()],[rf(),rf(),rf(),rf()],[rf(),rf(),rf(),rf()],[rf(),rf(),rf(),rf()]]; //now make a positive semidefinite matrix let mut m = [[0.0;4];4]; for i in 0..4 { for j in 0..4 { m[j][i] = 0.0; for k in 0..4 { m[j][i] += rand[i][k]*rand[j][k]; } } } m.into() } ).collect::>(); let mut mat_buf: Buffer<[mat4], _> = Buffer::readonly_from(&gl_provider, mats.into_boxed_slice()); let mut q_buf = mat_buf.clone(); let mut r_buf = mat_buf.clone(); let mut res_buf = mat_buf.clone(); let start = ::std::time::Instant::now(); decomposer.compute(mat_buf.len() as u32, 1, 1, &mut mat_buf, &mut q_buf, &mut r_buf, &mut res_buf); let (b1, _b2, _b3, b4) = (mat_buf.into_box(), q_buf.into_box(), r_buf.into_box(), res_buf.into_box()); println!("{:?}", ::std::time::Instant::now() - start); for i in 0..count { // println!("{:?}", b1[i].value[0]); // println!("{:?}", b1[i].value[1]); // println!("{:?}", b1[i].value[2]); // println!("{:?}", b1[i].value[3]); println!("{} {:?} == {:?}", b1[i].value == b4[i].value, b1[i].value, b4[i].value); // println!("{} {:?} {:?} == {:?}", b1[i].value == b4[i].value, b3[i].value, b1[i].value, b4[i].value); println!(); } }