From 8f14bdd66cb002b2f89265b2a578ad93249089c9 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 26 Mar 2026 07:03:01 +0100 Subject: feat(cnn_v3): upgrade architecture to enc_channels=[8,16] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Double encoder capacity: enc0 4→8ch, enc1 8→16ch, bottleneck 16→16ch, dec1 32→8ch, dec0 16→4ch. Total weights 2476→7828 f16 (~15.3 KB). FiLM MLP output 40→72 params (L1: 16×40→16×72). 16-ch textures split into _lo/_hi rgba32uint pairs (enc1, bottleneck). enc0 and dec1 textures changed from rgba16float to rgba32uint (8ch). GBUF_RGBA32UINT node gains CopySrc for parity test readback. - WGSL shaders: all 5 passes rewritten for new channel counts - C++ CNNv3Effect: new weight offsets/sizes, 8ch uniform structs - Web tool (shaders.js + tester.js): matching texture formats and bindings - Parity test: readback_rgba32uint_8ch helper, updated vector counts - Training scripts: default enc_channels=[8,16], updated docstrings - Docs + architecture PNG regenerated handoff(Gemini): CNN v3 [8,16] upgrade complete. All code, tests, web tool, training scripts, and docs updated. Next: run training pass. --- cnn_v3/shaders/cnn_v3_enc0.wgsl | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'cnn_v3/shaders/cnn_v3_enc0.wgsl') diff --git a/cnn_v3/shaders/cnn_v3_enc0.wgsl b/cnn_v3/shaders/cnn_v3_enc0.wgsl index e171ca7..84d40fd 100644 --- a/cnn_v3/shaders/cnn_v3_enc0.wgsl +++ b/cnn_v3/shaders/cnn_v3_enc0.wgsl @@ -1,32 +1,42 @@ // CNN v3 — Encoder level 0 -// Conv(20->4, 3x3, zero-pad) + FiLM + ReLU +// Conv(20->8, 3x3, zero-pad) + FiLM + ReLU // // Input: feat_tex0 (rgba32uint, 8xf16), feat_tex1 (rgba32uint, 12ch u8norm) full-res -// Output: enc0_out (rgba16float, 4ch) full-res +// Output: enc0_out (rgba32uint, 8xf16) full-res // // Weight layout (f16, OIHW + bias): -// [0 .. 20*4*9) conv: w[out][in][ky][kx] -// [720 .. +4) bias: b[out] +// [0 .. 20*8*9) conv: w[out][in][ky][kx] +// [1440 .. +8) bias: b[out] #include "cnn_v3/common" const ENC0_IN: u32 = 20u; -const ENC0_OUT: u32 = 4u; +const ENC0_OUT: u32 = 8u; struct Params { weight_offset: u32, _pad: vec3u, - gamma: vec4f, - beta: vec4f, + gamma_lo: vec4f, + gamma_hi: vec4f, + beta_lo: vec4f, + beta_hi: vec4f, } @group(0) @binding(0) var feat_tex0: texture_2d; @group(0) @binding(1) var feat_tex1: texture_2d; @group(0) @binding(2) var weights: array; @group(0) @binding(3) var params: Params; -@group(0) @binding(4) var enc0_out: texture_storage_2d; +@group(0) @binding(4) var enc0_out: texture_storage_2d; + +fn film_gamma(o: u32) -> f32 { + if (o < 4u) { return params.gamma_lo[o]; } + return params.gamma_hi[o - 4u]; +} +fn film_beta(o: u32) -> f32 { + if (o < 4u) { return params.beta_lo[o]; } + return params.beta_hi[o - 4u]; +} -// Unpack all 20 feature channels at coord. Returns zeros for OOB (zero-padding). fn load_feat(coord: vec2i, dims: vec2i) -> array { if (coord.x < 0 || coord.y < 0 || coord.x >= dims.x || coord.y >= dims.y) { return array(0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.); @@ -68,8 +78,13 @@ fn enc0_main(@builtin(global_invocation_id) id: vec3u) { } } } - out[o] = max(0.0, params.gamma[o] * sum + params.beta[o]); + out[o] = max(0.0, film_gamma(o) * sum + film_beta(o)); } - textureStore(enc0_out, coord, vec4f(out[0], out[1], out[2], out[3])); + textureStore(enc0_out, coord, vec4u( + pack2x16float(vec2f(out[0], out[1])), + pack2x16float(vec2f(out[2], out[3])), + pack2x16float(vec2f(out[4], out[5])), + pack2x16float(vec2f(out[6], out[7])) + )); } -- cgit v1.2.3