From c4cfc8459dbc6fde74d5553519dc3fcb1afccad0 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 14 Feb 2026 12:38:59 +0100 Subject: Refactor: factorize common WGPU patterns into helper functions Add texture creation helpers (gpu_create_texture_2d, gpu_create_storage_texture_2d, gpu_create_mip_view) and extend BindGroupLayoutBuilder with uint_texture and storage_texture methods. Refactored files: - cnn_v2_effect.cc: Use texture helpers (~70% code reduction in create_textures) - rotating_cube_effect.cc: Use BindGroupLayoutBuilder and texture helpers - circle_mask_effect.cc: Use BindGroupBuilder Benefits: - Improved code readability - Reduced boilerplate for texture/bind group creation - Consistent patterns across effects Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/bind_group_builder.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/gpu/bind_group_builder.h') diff --git a/src/gpu/bind_group_builder.h b/src/gpu/bind_group_builder.h index d63f6e2..abce9dc 100644 --- a/src/gpu/bind_group_builder.h +++ b/src/gpu/bind_group_builder.h @@ -55,6 +55,28 @@ public: return *this; } + BindGroupLayoutBuilder& uint_texture(uint32_t binding, WGPUShaderStageFlags vis) { + WGPUBindGroupLayoutEntry e{}; + e.binding = binding; + e.visibility = vis; + e.texture.sampleType = WGPUTextureSampleType_Uint; + e.texture.viewDimension = WGPUTextureViewDimension_2D; + entries_.push_back(e); + return *this; + } + + BindGroupLayoutBuilder& storage_texture(uint32_t binding, WGPUShaderStageFlags vis, + WGPUTextureFormat format) { + WGPUBindGroupLayoutEntry e{}; + e.binding = binding; + e.visibility = vis; + e.storageTexture.access = WGPUStorageTextureAccess_WriteOnly; + e.storageTexture.format = format; + e.storageTexture.viewDimension = WGPUTextureViewDimension_2D; + entries_.push_back(e); + return *this; + } + BindGroupLayoutBuilder& sampler(uint32_t binding, WGPUShaderStageFlags vis) { WGPUBindGroupLayoutEntry e{}; e.binding = binding; -- cgit v1.2.3