diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-11 00:26:25 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-11 00:26:25 +0100 |
| commit | c49d828f101b435d73a76fcfc8444cf76aeda22f (patch) | |
| tree | 06978626cbb614f52434c4fdd40ccb197d7064c8 /workspaces/main/shaders/cnn/cnn_conv3x3.wgsl | |
| parent | 65fa059a1e5f81901735031ae329b1313ea6679d (diff) | |
opt: Move invariant in1 calculation outside CNN convolution loops
The in1 vector (uv_norm, gray, 1.0) is loop-invariant and doesn't depend on
dx/dy offset. Moving it outside the convolution loop eliminates redundant
computation and enables better SIMD optimization.
Updated both shader files and train.py code generation.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_conv3x3.wgsl')
| -rw-r--r-- | workspaces/main/shaders/cnn/cnn_conv3x3.wgsl | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl index c032767..1a5a3e1 100644 --- a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl +++ b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl @@ -19,6 +19,7 @@ fn cnn_conv3x3_7to4_src( // Normalize UV to [-1,1] let uv_norm = (uv - 0.5) * 2.0; + let in1 = vec4<f32>(uv_norm, gray, 1.0); var sum = vec4<f32>(0.0); @@ -27,7 +28,6 @@ fn cnn_conv3x3_7to4_src( for (var dx = -1; dx <= 1; dx++) { let offset = vec2<f32>(f32(dx), f32(dy)) * step; let rgbd = (textureSample(tex, samp, uv + offset) - .5) * 2.0; - let in1 = vec4<f32>(uv_norm, gray, 1.0); sum.r += dot(weights[pos+0], rgbd) + dot(weights[pos+1], in1); sum.g += dot(weights[pos+2], rgbd) + dot(weights[pos+3], in1); @@ -93,6 +93,7 @@ fn cnn_conv3x3_7to1( // Normalize UV to [-1,1] let uv_norm = (uv - 0.5) * 2.0; + let in1 = vec4<f32>(uv_norm, gray, 1.0); var sum = 0.0; @@ -101,7 +102,6 @@ fn cnn_conv3x3_7to1( for (var dx = -1; dx <= 1; dx++) { let offset = vec2<f32>(f32(dx), f32(dy)) * step; let rgbd = textureSample(tex, samp, uv + offset); - let in1 = vec4<f32>(uv_norm, gray, 1.0); sum += dot(weights[pos], rgbd) + dot(weights[pos+1], in1); pos += 2; |
