diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gpu/effects/cnn_v2_effect.cc | 36 | ||||
| -rw-r--r-- | src/gpu/effects/cnn_v2_effect.h | 1 |
2 files changed, 32 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_); diff --git a/src/gpu/effects/cnn_v2_effect.h b/src/gpu/effects/cnn_v2_effect.h index 8a2e1b6..d530d3b 100644 --- a/src/gpu/effects/cnn_v2_effect.h +++ b/src/gpu/effects/cnn_v2_effect.h @@ -64,6 +64,7 @@ private: WGPUBuffer static_params_buffer_; WGPUTexture static_features_tex_; WGPUTextureView static_features_view_; + WGPUSampler linear_sampler_; // CNN layers (storage buffer architecture) WGPUComputePipeline layer_pipeline_; // Single pipeline for all layers |
