From 1c9bc4abd5ab90a61e3485fe30ff3c6f9b4b319c Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 16 Feb 2026 15:20:39 +0100 Subject: refactor(headless): convert nullptr checks to strippable macros Added HEADLESS_RETURN_IF_NULL/HEADLESS_RETURN_VAL_IF_NULL macros that compile to no-ops in STRIP_ALL/FINAL_STRIP modes. Files updated: - fatal_error.h: New headless check macros - sequence.cc: NodeRegistry::create_texture - post_process_helper.cc: Pipeline creation functions - sampler_cache.h: SamplerCache::get_or_create - bind_group_builder.h: Layout/group builders - pipeline_builder.h: Shader and pipeline builders - All effect constructors (7 files) Headless tests passing. STRIP_ALL builds will have zero overhead. Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/pipeline_builder.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/gpu/pipeline_builder.h') diff --git a/src/gpu/pipeline_builder.h b/src/gpu/pipeline_builder.h index a258b49..937c55f 100644 --- a/src/gpu/pipeline_builder.h +++ b/src/gpu/pipeline_builder.h @@ -15,6 +15,7 @@ typedef struct WGPUShaderModuleImpl* WGPUShaderModule; #include "gpu/shader_composer.h" #include "platform/platform.h" +#include "util/fatal_error.h" class RenderPipelineBuilder { WGPUDevice device_; @@ -38,17 +39,18 @@ class RenderPipelineBuilder { RenderPipelineBuilder& shader(const char* wgsl, bool compose = true) { shader_text_ = compose ? ShaderComposer::Get().Compose({}, wgsl) : wgsl; - // Headless mode: skip shader module creation - if (device_ != nullptr) { - WGPUShaderSourceWGSL wgsl_src{}; - wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL; - wgsl_src.code = str_view(shader_text_.c_str()); - WGPUShaderModuleDescriptor shader_desc{}; - shader_desc.nextInChain = &wgsl_src.chain; - shader_module_ = wgpuDeviceCreateShaderModule(device_, &shader_desc); - desc_.vertex.module = shader_module_; - desc_.vertex.entryPoint = str_view("vs_main"); + // Headless mode: skip shader module creation (compiled out in STRIP_ALL) + if (device_ == nullptr) { + return *this; } + WGPUShaderSourceWGSL wgsl_src{}; + wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL; + wgsl_src.code = str_view(shader_text_.c_str()); + WGPUShaderModuleDescriptor shader_desc{}; + shader_desc.nextInChain = &wgsl_src.chain; + shader_module_ = wgpuDeviceCreateShaderModule(device_, &shader_desc); + desc_.vertex.module = shader_module_; + desc_.vertex.entryPoint = str_view("vs_main"); return *this; } @@ -88,10 +90,8 @@ class RenderPipelineBuilder { } WGPURenderPipeline build() { - // Headless mode: skip pipeline creation - if (device_ == nullptr) { - return nullptr; - } + // Headless mode: skip pipeline creation (compiled out in STRIP_ALL) + HEADLESS_RETURN_VAL_IF_NULL(device_, nullptr); color_.writeMask = WGPUColorWriteMask_All; if (has_blend_) -- cgit v1.2.3