From 754ebf34cbb6280ef77421e1ca54d35d727dc6f7 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 18 Nov 2023 17:37:57 +0100 Subject: debug and better search --- flowy/src/main.rs | 16 +++++++++++++--- flowy/src/motion/debug.wgsl | 2 +- flowy/src/motion/enc.rs | 2 +- flowy/src/motion/enc.wgsl | 35 ++++++++++++++++++++++------------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/flowy/src/main.rs b/flowy/src/main.rs index 6620ed8..8529f2c 100644 --- a/flowy/src/main.rs +++ b/flowy/src/main.rs @@ -5,7 +5,8 @@ use log::{debug, info}; use motion::{dec::MotionDecoder, enc::MotionEncoder, CommonBuffers, Params}; use pollster::FutureExt; use std::{ - io::{stdin, stdout, Read, Write}, + io::{stdin, stdout, ErrorKind, Read, Write}, + process::exit, time::Instant, }; use wgpu::{ @@ -86,9 +87,16 @@ fn main() { debug: fparams.debug == 2, preview: fparams.debug > 0, }; - eprintln!("{params:?} {rp:?}"); + debug!("{params:?} {rp:?}"); debug!("read"); - stdin().read_exact(&mut buffer).unwrap(); + match stdin().read_exact(&mut buffer) { + Ok(_) => (), + Err(e) if e.kind() == ErrorKind::UnexpectedEof => { + break; + } + Err(e) => Err(e).unwrap(), + } + framework.next_frame_manual(); debug!("upload"); @@ -120,4 +128,6 @@ fn main() { stdout().write_all(&buffer).unwrap(); i += 1; } + eprintln!("done"); + exit(0); } diff --git a/flowy/src/motion/debug.wgsl b/flowy/src/motion/debug.wgsl index 3e740f6..7da5c57 100644 --- a/flowy/src/motion/debug.wgsl +++ b/flowy/src/motion/debug.wgsl @@ -25,7 +25,7 @@ struct BlockOffset { for (var x = 0; x < params.block_size.x; x++) { for (var y = 0; y < params.block_size.y; y++) { let base = uv + vec2(x, y); - let col = vec4(colormap_vec(vec2(bl.offset) * 0.05),1.); + let col = vec4(colormap_vec(vec2(bl.offset) * 0.08),1.); textureStore(out, base, col); } } diff --git a/flowy/src/motion/enc.rs b/flowy/src/motion/enc.rs index 56b459b..d3e8a81 100644 --- a/flowy/src/motion/enc.rs +++ b/flowy/src/motion/enc.rs @@ -38,7 +38,7 @@ impl MotionEncoder { block_size: [params.block_width as i32, params.block_height as i32], output_stride: (params.width / params.block_width) as u32, search_radius: 16, - skip_threshold: 0.07, + skip_threshold: 0.1, ..Default::default() }; diff --git a/flowy/src/motion/enc.wgsl b/flowy/src/motion/enc.wgsl index 6ba3081..80618b7 100644 --- a/flowy/src/motion/enc.wgsl +++ b/flowy/src/motion/enc.wgsl @@ -24,19 +24,28 @@ var best_tint: vec3 = vec3(0.); @compute @workgroup_size(1)fn main(@builtin(global_invocation_id) global_id: vec3) { let uv = vec2(global_id.xy) * params.block_size; - test_offset(uv, vec2(0, 0)); - - do_dist(uv, 32); - do_dist(uv, 16); - do_dist(uv, 10); - do_dist(uv, 8); - do_dist(uv, 6); - do_dist(uv, 3); - do_dist(uv, 4); - do_dist(uv, 2); - do_dist(uv, 1); - - apply_tint(uv); + loop { + test_offset(uv, vec2(0, 0)); + if best_error < params.skip_threshold { break; } + apply_tint(uv); + if best_error < params.skip_threshold { break; } + best_tint = vec3(0.); + + do_dist(uv, 32); + do_dist(uv, 16); + do_dist(uv, 10); + do_dist(uv, 8); + if best_error < params.skip_threshold { break; } + do_dist(uv, 6); + do_dist(uv, 3); + do_dist(uv, 4); + do_dist(uv, 2); + do_dist(uv, 1); + if best_error < params.skip_threshold { break; } + + apply_tint(uv); + break; + } offsets[global_id.x + global_id.y * params.offsets_stride] = BlockOffset(best_error, best_offset, best_tint); } -- cgit v1.2.3-70-g09d2