-
Notifications
You must be signed in to change notification settings - Fork 345
Description
Currently, validating GPUFragmentState(descriptor) says:
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.
[1] Vulkan spec 14.3 Fragment Output Interface
The input values to blending or color attachment writes are undefined for components which do not correspond to a fragment shader output.