You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow render pipelines to have color targets not written to by fragment outputs #1900
For each colorState layout descriptor in the list descriptor.targets:
descriptor.module must contain an output variable that:
is statically used by descriptor.entryPoint, and
has a type that is compatible with colorState.format.
This is overly restrictive because it means that the fragment shader must write to every color attachment.
It makes the following example use case difficult:
Begin a render pass with two color attachments
Bind a pipeline that writes to the first color attachment and draw, without modifying the second attachment
Bind a pipeline that writes to the second color attachment and draw, without modifying the first attachment
End the render pass
Another use case is a render pipeline that does not write to any attachments (may write to storage or to the depth attachment).
Technically, this can be worked around by setting the GPUColorTargetState.writeMask to 0 for all attachments the developer does not want to modify. However, it will also require them to modify their shaders to include these additional masked-out fragment outputs.
It would be good if we could avoid requiring the developer to disable writes and add dummy outputs to the shader. Experimentally, all of the target APIs Metal/D3D12/Vulkan allow you to have a fragment shader that does not write to all (or any) of the color attachments.
For Vulkan, the pipeline may write something undefined to the attachment [1], but this can be mitigated by the implementation by disabling blending for that color target and setting the write mask to 0. I didn't find documentation for Metal / D3D12, but disabling writes seems to work there as well. No shader modification is required.
Thank you for filing this! This is related to #1250
First of all, what we have today is sufficient for users to get this behavior. They can set 0 to the write masks, while their shaders would need to take into account that these outputs exist. I don't think it's a big issue, since the shaders need to know the output locations anyway, so if a shader outputs location 0 and 2, it's not like omitting 1 makes it significantly more generic.
Secondly, we can achieve the desired effect without changing the API. We can just say something along the lines of:
fragment shader outputs are only required to written if the color mask is not 0
fragment shader outputs are only required to written if the color mask is not 0
sounds good to me! main concern here is that not having this would impact shader reusability where authors may just need to needlessly add unused output locations in order to be used in the same render pass as at other shaders that write to those locations.
It might be worth noticing that WebGL2 (and WebGL 1 via WEBGL_draw_buffers extensions) requires all attached color attachments to be written to. That would mean for people coming from WebGL the current WebGPU behaviour is not new.
If any draw buffer with an attachment does not have a defined fragment shader output, draws generate INVALID_OPERATION, unless all 4 channels of colorMask are set to false.
Activity
kvark commentedon Jul 6, 2021
Thank you for filing this! This is related to #1250
First of all, what we have today is sufficient for users to get this behavior. They can set 0 to the write masks, while their shaders would need to take into account that these outputs exist. I don't think it's a big issue, since the shaders need to know the output locations anyway, so if a shader outputs location 0 and 2, it's not like omitting 1 makes it significantly more generic.
Secondly, we can achieve the desired effect without changing the API. We can just say something along the lines of:
austinEng commentedon Jul 7, 2021
sounds good to me! main concern here is that not having this would impact shader reusability where authors may just need to needlessly add unused output locations in order to be used in the same render pass as at other shaders that write to those locations.
vorg commentedon Jul 17, 2021
It might be worth noticing that WebGL2 (and WebGL 1 via WEBGL_draw_buffers extensions) requires all attached color attachments to be written to. That would mean for people coming from WebGL the current WebGPU behaviour is not new.
https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.4