这是indexloc提供的服务,不要输入任何密码
Skip to content

Allow render pipelines to have color targets not written to by fragment outputs #1900

@austinEng

Description

@austinEng

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:

  1. Begin a render pass with two color attachments
  2. Bind a pipeline that writes to the first color attachment and draw, without modifying the second attachment
  3. Bind a pipeline that writes to the second color attachment and draw, without modifying the first attachment
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions