From 96a349b9874c6cdaac525ba062a0f4f90c9bc3ed Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 10 Feb 2026 10:27:44 +0100 Subject: feat: Add coordinate-aware CNN layer 0 for position-dependent stylization - Implement CoordConv2d custom layer accepting (x,y) patch center - Split layer 0 weights: rgba_weights (9x mat4x4) + coord_weights (mat2x4) - Add *_with_coord() functions to 3x3/5x5/7x7 convolution shaders - Update training script to generate coordinate grid and export split weights - Regenerate placeholder weights with new format Size impact: +32B coord weights + ~100B shader code = +132B total All 36 tests passing (100%) handoff(Claude): CNN coordinate awareness implemented, ready for training Co-Authored-By: Claude Sonnet 4.5 --- workspaces/main/shaders/cnn/cnn_conv7x7.wgsl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'workspaces/main/shaders/cnn/cnn_conv7x7.wgsl') diff --git a/workspaces/main/shaders/cnn/cnn_conv7x7.wgsl b/workspaces/main/shaders/cnn/cnn_conv7x7.wgsl index ba28d64..e68d644 100644 --- a/workspaces/main/shaders/cnn/cnn_conv7x7.wgsl +++ b/workspaces/main/shaders/cnn/cnn_conv7x7.wgsl @@ -24,3 +24,30 @@ fn cnn_conv7x7( return sum; } + +fn cnn_conv7x7_with_coord( + tex: texture_2d, + samp: sampler, + uv: vec2, + resolution: vec2, + rgba_weights: array, 49>, + coord_weights: mat2x4, + bias: vec4 +) -> vec4 { + let step = 1.0 / resolution; + var sum = bias; + + sum += coord_weights * uv; + + var idx = 0; + for (var dy = -3; dy <= 3; dy++) { + for (var dx = -3; dx <= 3; dx++) { + let offset = vec2(f32(dx), f32(dy)) * step; + let rgba = textureSample(tex, samp, uv + offset); + sum += rgba_weights[idx] * rgba; + idx++; + } + } + + return sum; +} -- cgit v1.2.3