From 12f83d4615a38cb0b1ed8a3eb436c4acca170479 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 14 Feb 2026 14:15:07 +0100 Subject: Refactor: add gpu_create_post_process_texture helper Adds new helper for common post-process texture pattern (RenderAttachment | TextureBinding | CopySrc usage). Refactors test_post_process_helper.cc to use gpu_create_buffer() and gpu_create_post_process_texture(), eliminating 91 lines of boilerplate. - New: gpu_create_post_process_texture() in gpu.{h,cc} - Refactor: test_post_process_helper.cc uses helpers instead of raw WGPU - Doc: Updated WGPU_HELPERS.md with usage examples - Verified: All tests passing (test_post_process_helper, test_demo_effects) Co-Authored-By: Claude Sonnet 4.5 --- doc/WGPU_HELPERS.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'doc/WGPU_HELPERS.md') diff --git a/doc/WGPU_HELPERS.md b/doc/WGPU_HELPERS.md index 5642eef..f1d83d5 100644 --- a/doc/WGPU_HELPERS.md +++ b/doc/WGPU_HELPERS.md @@ -133,6 +133,45 @@ TextureWithView output = gpu_create_storage_texture_2d( --- +#### `gpu_create_post_process_texture` +```cpp +TextureWithView gpu_create_post_process_texture( + WGPUDevice device, uint32_t width, uint32_t height, + WGPUTextureFormat format); +``` + +**Purpose:** Create texture for post-processing effects (render target + input + readback). + +**Parameters:** +- `device` - WGPU device handle +- `width`, `height` - Texture dimensions +- `format` - Pixel format (typically `WGPUTextureFormat_RGBA8Unorm`) + +**Returns:** `TextureWithView` with usage flags: +- `WGPUTextureUsage_RenderAttachment` - Can render to it +- `WGPUTextureUsage_TextureBinding` - Can sample from it +- `WGPUTextureUsage_CopySrc` - Can read back pixels + +**Example:** +```cpp +// Create ping-pong buffers for multi-pass post-processing +TextureWithView buffer_a = gpu_create_post_process_texture( + device, 1920, 1080, WGPUTextureFormat_RGBA8Unorm); +TextureWithView buffer_b = gpu_create_post_process_texture( + device, 1920, 1080, WGPUTextureFormat_RGBA8Unorm); + +// Pass 1: Render to buffer_a +// Pass 2: Sample buffer_a, render to buffer_b +// Pass 3: Copy buffer_b to screen +``` + +**Common Use Cases:** +- Post-process ping-pong buffers +- Off-screen render targets that need sampling +- Test fixtures requiring texture readback + +--- + #### `gpu_create_mip_view` ```cpp WGPUTextureView gpu_create_mip_view(WGPUTexture texture, -- cgit v1.2.3