summaryrefslogtreecommitdiff
path: root/src/gpu/gpu.h
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-14 12:38:59 +0100
committerskal <pascal.massimino@gmail.com>2026-02-14 12:38:59 +0100
commitc4cfc8459dbc6fde74d5553519dc3fcb1afccad0 (patch)
treea6869d1f3c14778345ab45b9c69763d07adcca45 /src/gpu/gpu.h
parent0f53ed1ed8ed7c07cd7ea8e88e21b5be5d5494e5 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'src/gpu/gpu.h')
-rw-r--r--src/gpu/gpu.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h
index c7ee89f..b52d6ab 100644
--- a/src/gpu/gpu.h
+++ b/src/gpu/gpu.h
@@ -82,8 +82,23 @@ inline void gpu_init_color_attachment(WGPURenderPassColorAttachment& attachment,
#endif
}
+// Texture creation helper
+struct TextureWithView {
+ WGPUTexture texture;
+ WGPUTextureView view;
+};
+
GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage,
const void* data = nullptr);
+TextureWithView gpu_create_texture_2d(WGPUDevice device, uint32_t width,
+ uint32_t height, WGPUTextureFormat format,
+ WGPUTextureUsage usage,
+ uint32_t mip_levels = 1);
+TextureWithView gpu_create_storage_texture_2d(WGPUDevice device, uint32_t width,
+ uint32_t height,
+ WGPUTextureFormat format);
+WGPUTextureView gpu_create_mip_view(WGPUTexture texture,
+ WGPUTextureFormat format, uint32_t mip_level);
ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code,
ResourceBinding* bindings,
int num_bindings);