juj / wasm_webgpu

System headers for interfacing WebGPU from C programs compiled via Emscripten to WebAssembly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

create_render_pipeline needs target blend to be optional

brendan-duncan opened this issue · comments

An arguably poor WebGPU API design, a RenderPipelineDescriptor color target determines if blending is enabled or disabled by the existence of the BlendState member in the ColorTargetState dictionary. If 'blend' is defined, then blending is enabled even if set to ONE,ZERO. If 'blend' is not included, blending is disabled.

Currently wgpuReadRenderPipelineDescriptor always sets the BlendState, so blending is always enabled. Some color target formats don't allow blending, so these color targets don't work with the way wgpuReadRenderPipelineDescriptor constructs the RenderPipelineDescriptor.

For now, I locally changed wgpuReadRenderPipelineDescriptor so that if the blend.color.operator is set to WGPU_BLEND_OPERATION_INVALID, it skips adding the BlendState to the descriptor, disabling blending.

commented

Thanks, should be fixed in above commit. First opted to add an explicit blendEnabled field to enable alpha blending, because there's both color and alpha blend ops, but on further thought, it reads simpler to C/C++ code to set blend.color.operation = WGPU_BLEND_OPERATION_DISABLED or blend.color.operation = WGPU_BLEND_OPERATION_ADD to control alpha blending, rather than to manage two different fields to control alpha blending. (even though that will read a bit like enabling the color operation will also control the enabling of alpha operation, but that should be ok since those two can never be independently enabled/disabled anyways).