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>) {...@@ -278,9 +278,9 @@ fn xf_chroma_op(@builtin(global_invocation_id) gid: vec3<u32>) {
278// 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 order278// 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
279// p[5] = (skip_r, skip_g, skip_b, skip_a): 1 keeps that source channel untouched279// p[5] = (skip_r, skip_g, skip_b, skip_a): 1 keeps that source channel untouched
280// ============================================================================280// ============================================================================
281// Maps `p` inside the quad (a = bl, b = br, c = tr, d = tl) to bilinear (u, v) in [0, 1]; NaN when unsolvable.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>) -> vec2<f32> {282fn inv_bilinear(p: vec2<f32>, a: vec2<f32>, b: vec2<f32>, c: vec2<f32>, d: vec2<f32>) -> vec3<f32> {
283 let nan = vec2<f32>(bitcast<f32>(0x7fc00000u));283 let invalid = vec3<f32>(0.0, 0.0, 0.0);
284 let e = b - a;284 let e = b - a;
285 let f = d - a;285 let f = d - a;
286 let g = a - b + c - d;286 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<...@@ -290,27 +290,29 @@ fn inv_bilinear(p: vec2<f32>, a: vec2<f32>, b: vec2<f32>, c: vec2<f32>, d: vec2<
290 let k0 = h.x * e.y - h.y * e.x;290 let k0 = h.x * e.y - h.y * e.x;
291 var v = 0.0;291 var v = 0.0;
292 if (abs(k2) < 1e-5) {292 if (abs(k2) < 1e-5) {
293 if (abs(k1) < 1e-6) { return nan; }293 if (abs(k1) < 1e-6) { return invalid; }
294 v = -k0 / k1;294 v = -k0 / k1;
295 } else {295 } else {
296 let w = k1 * k1 - 4.0 * k0 * k2;296 let w = k1 * k1 - 4.0 * k0 * k2;
297 if (w < 0.0) { return nan; }297 if (w < 0.0) { return invalid; }
298 let r = sqrt(w);298 let r = sqrt(w);
299 v = (-k1 - r) * 0.5 / k2;299 v = (-k1 - r) * 0.5 / k2;
300 let uu = bilinear_u(h, e, f, g, v);300 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)) {
302 v = (-k1 + r) * 0.5 / k2;302 v = (-k1 + r) * 0.5 / k2;
303 }303 }
304 }304 }
305 // Solve u from whichever axis has the larger denominator: vertical top/bottom edges zero the x one.305 // 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);
307}308}
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> {
310 let dx = e.x + g.x * v;311 let dx = e.x + g.x * v;
311 let dy = e.y + g.y * v;312 let dy = e.y + g.y * v;
312 if (max(abs(dx), abs(dy)) < 1e-6) { return bitcast<f32>(0x7fc00000u); }313 if (max(abs(dx), abs(dy)) < 1e-6) { return vec2<f32>(0.0, 0.0); }
313 return select((h.y - f.y * v) / dy, (h.x - f.x * v) / dx, abs(dx) >= abs(dy));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);
314}316}
315317
316@compute @workgroup_size(8, 8)318@compute @workgroup_size(8, 8)
...@@ -337,7 +339,7 @@ fn homography_op(@builtin(global_invocation_id) gid: vec3<u32>) {...@@ -337,7 +339,7 @@ fn homography_op(@builtin(global_invocation_id) gid: vec3<u32>) {
337 if (u.p[3].w > 0.5) {339 if (u.p[3].w > 0.5) {
338 let uv = inv_bilinear(fu, u.p[6].xy, u.p[6].zw, u.p[7].xy, u.p[7].zw);340 let uv = inv_bilinear(fu, u.p[6].xy, u.p[6].zw, u.p[7].xy, u.p[7].zw);
339 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);341 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;
341 } else {343 } else {
342 let sx = u.p[0].x * fu.x + u.p[0].y * fu.y + u.p[0].z;344 let sx = u.p[0].x * fu.x + u.p[0].y * fu.y + u.p[0].z;
343 let sy = u.p[0].w * fu.x + u.p[1].x * fu.y + u.p[1].y;345 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 {...@@ -67,7 +67,10 @@ impl Fission {
67 let slot = Arc::clone(&gpu_error);67 let slot = Arc::clone(&gpu_error);
68 device.on_uncaptured_error(Arc::new(move |e: wgpu::Error| {68 device.on_uncaptured_error(Arc::new(move |e: wgpu::Error| {
69 console_error(&format!("GPU error: {e}"));69 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 }
71 }));74 }));
72 let slot = Arc::clone(&gpu_error);75 let slot = Arc::clone(&gpu_error);
73 device.set_device_lost_callback(move |reason, message| {76 device.set_device_lost_callback(move |reason, message| {