summaryrefslogtreecommitdiff
path: root/src/gpu/effects/cnn_v2_effect.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-14 07:22:17 +0100
committerskal <pascal.massimino@gmail.com>2026-02-14 07:24:51 +0100
commit0f53ed1ed8ed7c07cd7ea8e88e21b5be5d5494e5 (patch)
tree0e1a8426c16e7c89b83038d5b90bb9d94c6d06e5 /src/gpu/effects/cnn_v2_effect.cc
parent8dd77545b5ec2f45ce46b98dd7d94a3c4a13e290 (diff)
CNN v2: bilinear mip-level sampling and UI improvements
**CNN v2 Changes:** - Replace point sampling with bilinear interpolation for mip-level features - Add linear sampler (binding 6) to static features shader - Update CNNv2Effect, cnn_test, and HTML tool **HTML Tool UI:** - Move controls to floating bottom bar in central view - Consolidate video controls + Blend/Depth/Save PNG in single container - Increase left panel width: 300px → 315px (+5%) - Remove per-frame debug messages (visualization, rendering logs) **Technical:** - WGSL: textureSample() with linear_sampler vs textureLoad() - C++: Create WGPUSampler with Linear filtering - HTML: Change sampler from 'nearest' to 'linear' handoff(Claude): CNN v2 now uses bilinear mip-level sampling across all tools
Diffstat (limited to 'src/gpu/effects/cnn_v2_effect.cc')
-rw-r--r--src/gpu/effects/cnn_v2_effect.cc36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/gpu/effects/cnn_v2_effect.cc b/src/gpu/effects/cnn_v2_effect.cc
index 366a232..d412154 100644
--- a/src/gpu/effects/cnn_v2_effect.cc
+++ b/src/gpu/effects/cnn_v2_effect.cc
@@ -19,6 +19,7 @@ CNNv2Effect::CNNv2Effect(const GpuContext& ctx)
static_params_buffer_(nullptr),
static_features_tex_(nullptr),
static_features_view_(nullptr),
+ linear_sampler_(nullptr),
layer_pipeline_(nullptr),
weights_buffer_(nullptr),
input_mip_tex_(nullptr),
@@ -36,6 +37,7 @@ CNNv2Effect::CNNv2Effect(const GpuContext& ctx, const CNNv2EffectParams& params)
static_params_buffer_(nullptr),
static_features_tex_(nullptr),
static_features_view_(nullptr),
+ linear_sampler_(nullptr),
layer_pipeline_(nullptr),
weights_buffer_(nullptr),
input_mip_tex_(nullptr),
@@ -221,6 +223,20 @@ void CNNv2Effect::create_textures() {
}
void CNNv2Effect::create_pipelines() {
+ // Create linear sampler for bilinear interpolation
+ WGPUSamplerDescriptor sampler_desc = {};
+ sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
+ sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
+ sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
+ sampler_desc.magFilter = WGPUFilterMode_Linear;
+ sampler_desc.minFilter = WGPUFilterMode_Linear;
+ sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Linear;
+ sampler_desc.lodMinClamp = 0.0f;
+ sampler_desc.lodMaxClamp = 32.0f;
+ sampler_desc.maxAnisotropy = 1;
+
+ linear_sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
+
// Static features compute pipeline
size_t shader_size = 0;
const char* static_code = (const char*)GetAsset(AssetId::ASSET_SHADER_CNN_V2_STATIC, &shader_size);
@@ -238,8 +254,8 @@ void CNNv2Effect::create_pipelines() {
shader_desc.nextInChain = &wgsl_src.chain;
// Create bind group layout for static features compute
- // Bindings: 0=input_tex, 1=input_mip1, 2=input_mip2, 3=depth_tex, 4=output, 5=params
- WGPUBindGroupLayoutEntry bgl_entries[6] = {};
+ // Bindings: 0=input_tex, 1=input_mip1, 2=input_mip2, 3=depth_tex, 4=output, 5=params, 6=linear_sampler
+ WGPUBindGroupLayoutEntry bgl_entries[7] = {};
// Binding 0: Input texture (mip 0)
bgl_entries[0].binding = 0;
@@ -278,8 +294,13 @@ void CNNv2Effect::create_pipelines() {
bgl_entries[5].buffer.type = WGPUBufferBindingType_Uniform;
bgl_entries[5].buffer.minBindingSize = sizeof(StaticFeatureParams);
+ // Binding 6: Linear sampler (for bilinear interpolation)
+ bgl_entries[6].binding = 6;
+ bgl_entries[6].visibility = WGPUShaderStage_Compute;
+ bgl_entries[6].sampler.type = WGPUSamplerBindingType_Filtering;
+
WGPUBindGroupLayoutDescriptor bgl_desc = {};
- bgl_desc.entryCount = 6;
+ bgl_desc.entryCount = 7;
bgl_desc.entries = bgl_entries;
WGPUBindGroupLayout static_bgl = wgpuDeviceCreateBindGroupLayout(ctx_.device, &bgl_desc);
@@ -398,7 +419,7 @@ void CNNv2Effect::update_bind_group(WGPUTextureView input_view) {
}
// Create bind group for static features compute
- WGPUBindGroupEntry bg_entries[6] = {};
+ WGPUBindGroupEntry bg_entries[7] = {};
// Binding 0: Input (mip 0)
bg_entries[0].binding = 0;
@@ -425,9 +446,13 @@ void CNNv2Effect::update_bind_group(WGPUTextureView input_view) {
bg_entries[5].buffer = static_params_buffer_;
bg_entries[5].size = sizeof(StaticFeatureParams);
+ // Binding 6: Linear sampler
+ bg_entries[6].binding = 6;
+ bg_entries[6].sampler = linear_sampler_;
+
WGPUBindGroupDescriptor bg_desc = {};
bg_desc.layout = wgpuComputePipelineGetBindGroupLayout(static_pipeline_, 0);
- bg_desc.entryCount = 6;
+ bg_desc.entryCount = 7;
bg_desc.entries = bg_entries;
static_bind_group_ = wgpuDeviceCreateBindGroup(ctx_.device, &bg_desc);
@@ -563,6 +588,7 @@ void CNNv2Effect::cleanup() {
if (static_bind_group_) wgpuBindGroupRelease(static_bind_group_);
if (static_params_buffer_) wgpuBufferRelease(static_params_buffer_);
if (static_pipeline_) wgpuComputePipelineRelease(static_pipeline_);
+ if (linear_sampler_) wgpuSamplerRelease(linear_sampler_);
if (layer_pipeline_) wgpuComputePipelineRelease(layer_pipeline_);
if (weights_buffer_) wgpuBufferRelease(weights_buffer_);