authoravatarclover caruso<git@paperclover.net>2026-12-01 09:30:52-08:00
committeravatarclover caruso<git@paperclover.net>2026-12-01 09:32:42-08:00
log0c69df72d003d84bba40b1fa5d0450ffe981478c
treed4d4424380ff669ec50d766c32cd70e25cd9507d
parent31e3b7db401ce05ebf42d82fec9a028d294f4989
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

web/wgsl: remove compile-time NaN bitcast in transform.wgsl (fixes Chrome Tint validation) and keep first GPU error


2 files changed, 17 insertions(+), 12 deletions(-)

crates/engine/src/shaders/transform.wgsl+13-11
......@@ -278,9 +278,9 @@ fn xf_chroma_op(@builtin(global_invocation_id) gid: vec3<u32>) {
278278// p[3].w = 1 selects bilinear mapping: p[6], p[7] = output quad (bl br / tr tl), p[8], p[9] = source-UV quad in the same order
279279// p[5] = (skip_r, skip_g, skip_b, skip_a): 1 keeps that source channel untouched
280280// ============================================================================
281// Maps `p` inside the quad (a = bl, b = br, c = tr, d = tl) to bilinear (u, v) in [0, 1]; NaN when unsolvable.
282fn inv_bilinear(p: vec2<f32>, a: vec2<f32>, b: vec2<f32>, c: vec2<f32>, d: vec2<f32>) -> vec2<f32> {
283 let nan = vec2<f32>(bitcast<f32>(0x7fc00000u));
281// Maps `p` inside the quad (a = bl, b = br, c = tr, d = tl) to bilinear (u, v, valid); valid == 0.0 when unsolvable.
282fn inv_bilinear(p: vec2<f32>, a: vec2<f32>, b: vec2<f32>, c: vec2<f32>, d: vec2<f32>) -> vec3<f32> {
283 let invalid = vec3<f32>(0.0, 0.0, 0.0);
284284 let e = b - a;
285285 let f = d - a;
286286 let g = a - b + c - d;
......@@ -290,27 +290,29 @@ fn inv_bilinear(p: vec2<f32>, a: vec2<f32>, b: vec2<f32>, c: vec2<f32>, d: vec2<
290290 let k0 = h.x * e.y - h.y * e.x;
291291 var v = 0.0;
292292 if (abs(k2) < 1e-5) {
293 if (abs(k1) < 1e-6) { return nan; }
293 if (abs(k1) < 1e-6) { return invalid; }
294294 v = -k0 / k1;
295295 } else {
296296 let w = k1 * k1 - 4.0 * k0 * k2;
297 if (w < 0.0) { return nan; }
297 if (w < 0.0) { return invalid; }
298298 let r = sqrt(w);
299299 v = (-k1 - r) * 0.5 / k2;
300300 let uu = bilinear_u(h, e, f, g, v);
301 if (!(uu >= 0.0 && uu <= 1.0 && v >= 0.0 && v <= 1.0)) {
301 if (!(uu.y > 0.5 && uu.x >= 0.0 && uu.x <= 1.0 && v >= 0.0 && v <= 1.0)) {
302302 v = (-k1 + r) * 0.5 / k2;
303303 }
304304 }
305305 // Solve u from whichever axis has the larger denominator: vertical top/bottom edges zero the x one.
306 return vec2<f32>(bilinear_u(h, e, f, g, v), v);
306 let u_res = bilinear_u(h, e, f, g, v);
307 return vec3<f32>(u_res.x, v, u_res.y);
307308}
308309
309fn bilinear_u(h: vec2<f32>, e: vec2<f32>, f: vec2<f32>, g: vec2<f32>, v: f32) -> f32 {
310fn bilinear_u(h: vec2<f32>, e: vec2<f32>, f: vec2<f32>, g: vec2<f32>, v: f32) -> vec2<f32> {
310311 let dx = e.x + g.x * v;
311312 let dy = e.y + g.y * v;
312 if (max(abs(dx), abs(dy)) < 1e-6) { return bitcast<f32>(0x7fc00000u); }
313 return select((h.y - f.y * v) / dy, (h.x - f.x * v) / dx, abs(dx) >= abs(dy));
313 if (max(abs(dx), abs(dy)) < 1e-6) { return vec2<f32>(0.0, 0.0); }
314 let u_val = select((h.y - f.y * v) / dy, (h.x - f.x * v) / dx, abs(dx) >= abs(dy));
315 return vec2<f32>(u_val, 1.0);
314316}
315317
316318@compute @workgroup_size(8, 8)
......@@ -337,7 +339,7 @@ fn homography_op(@builtin(global_invocation_id) gid: vec3<u32>) {
337339 if (u.p[3].w > 0.5) {
338340 let uv = inv_bilinear(fu, u.p[6].xy, u.p[6].zw, u.p[7].xy, u.p[7].zw);
339341 s_fu = mix(mix(u.p[8].xy, u.p[8].zw, uv.x), mix(u.p[9].zw, u.p[9].xy, uv.x), uv.y);
340 valid = all(uv == uv);
342 valid = uv.z > 0.5;
341343 } else {
342344 let sx = u.p[0].x * fu.x + u.p[0].y * fu.y + u.p[0].z;
343345 let sy = u.p[0].w * fu.x + u.p[1].x * fu.y + u.p[1].y;
crates/web/src/lib.rs+4-1
......@@ -67,7 +67,10 @@ impl Fission {
6767 let slot = Arc::clone(&gpu_error);
6868 device.on_uncaptured_error(Arc::new(move |e: wgpu::Error| {
6969 console_error(&format!("GPU error: {e}"));
70 *slot.lock().unwrap() = Some(e.to_string());
70 let mut guard = slot.lock().unwrap();
71 if guard.is_none() {
72 *guard = Some(e.to_string());
73 }
7174 }));
7275 let slot = Arc::clone(&gpu_error);
7376 device.set_device_lost_callback(move |reason, message| {