diff options
Diffstat (limited to 'doc/CODING_STYLE.md')
| -rw-r--r-- | doc/CODING_STYLE.md | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/doc/CODING_STYLE.md b/doc/CODING_STYLE.md index 254a1c3..b688d6b 100644 --- a/doc/CODING_STYLE.md +++ b/doc/CODING_STYLE.md @@ -169,3 +169,34 @@ fn rayMarchWithID(ro: vec3<f32>, rd: vec3<f32>, result: ptr<function, RayMarchRe - Small structs (≤16 bytes) are efficiently handled by GPU return value optimization - Functional style is clearer and less error-prone - `ptr<function, T>` adds complexity with no performance gain for small types + +--- + +## WGPU Object Initialization + +**Rule:** Initialization of `WGPU...` objects should leverage `gpu.h` function helpers as much as possible. + +### Correct +```cpp +// In an effect file +WGPURenderPassColorAttachment color_attachment = {}; +gpu_init_color_attachment(color_attachment, output_view); +``` + +### Wrong +```cpp +// In an effect file +WGPURenderPassColorAttachment color_attachment = {}; +color_attachment.view = output_view; +color_attachment.loadOp = WGPULoadOp_Clear; +color_attachment.storeOp = WGPUStoreOp_Store; +color_attachment.clearValue = {0.0f, 0.0f, 0.0f, 1.0f}; +#if !defined(DEMO_CROSS_COMPILE_WIN32) +color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; +#endif +``` + +**Rationale:** +- Centralizes platform-specific initialization logic (e.g., `depthSlice`). +- Reduces boilerplate code in effects and other rendering code. +- Ensures consistent and correct initialization across the codebase. |
