From 0362b835efa8c89794c60b3d8c6eea1ca7de4558 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 17 Feb 2026 11:05:17 +0100 Subject: docs(style): Add rule for WGPU object initialization --- doc/CODING_STYLE.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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, rd: vec3, result: ptr` 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. -- cgit v1.2.3