Skip to content

Dual source blending #391

Closed
Closed

Description

@krogovin

Add the blend modes: "src1-color", "one-minus-src1-color", "src1-alpha", "one-minus-src1-alpha", "src1-alpha-saturated". Each of these has a direct analogue in Vulkan, Metal and Direct3D12.

Dual source blending provides for applications that blend in multiple ways (for example to support the Porter-Duff blend modes) can significantly reduce pipeline state object changes and open the door to applications for more flexible blending.

I am advocating for this feature as part 1.0 release and not as an extension.

Activity

  1. added
    feature request
    on Aug 8, 2019
  2. kainino0x commented on Aug 8, 2019

    @kainino0x
    Contributor

    This feature is optional in Vulkan, and not available on some ARM/Qualcomm/Imagination GPUs:

    http://vulkan.gpuinfo.org/listreports.php?feature=dualSrcBlend&option=not

    It's not clear to me exactly why some of these do not support it; I can find an Adreno 530 which supports it and an Adreno 540 which does not. Probably driver version related?

  3. kainino0x commented on Aug 8, 2019

    @kainino0x
    Contributor

    Also, there seem to be NO ARM and Imagination GPUs that support it.

  4. magcius commented on Aug 8, 2019

    @magcius

    DSB usage is quite rare, and I remember having enough problems with driver support and bugs back when that when I was trying to implement subpixel text rendering, I just chose to make the text a single color and use blend-color instead.

    I would prefer if it was an extension. And as we've seen, some hardware doesn't have support for it.

  5. krogovin commented on Aug 8, 2019

    @krogovin
    Author

    Let's mark the support as optional then. From what I know of Imaginations Technology GPU's I am pretty sure it could be implemented, but they would need to have a business case to do so. Another chicken-egg fiasco.

    Lets make it optional but I would prefer at 1.0 instead of an extension as a way to prod ISV's to support it and to support it well.

  6. litherum commented on Sep 15, 2019

    @litherum
    Contributor

    What’s the motivation for this feature? What use-cases does it make possible?

    It strikes me that WebGPU app developers could implement this themselves if they could do programmable blending.

  7. krogovin commented on Sep 16, 2019

    @krogovin
    Author

    It strikes me that WebGPU app developers could implement this themselves if they could do programmable blending.

    If programmable blending, i.e. framebuffer fetch is available, then yes, a WebGPU app can do dual source blending itself.

    However, if framebuffer fetch is not available (or another means of doing programmable blending), then dual source blending not only opens up additional blending possibilities but also gives applications a possibility to cut down on the number of blend states needed. Indeed, to implement all 12 PorterDuff modes requires only three distinct blend modes. Direct3D has had dual source blending for a long time as has desktop OpenGL.

    But to reiterate, for me, the preference order is:

    1. Framebuffer fetch (best)
    2. Interlock (can do icky blend modes)
    3. Dual Source blending
  8. kvark commented on Sep 16, 2019

    @kvark
    Contributor

    @litherum WebRender relies on DSB for rendering subpixel AA text without doing multiple passes.
    I think, exposing dual-source blending is attractive, as an extension, because it's clearly defined and it requires only a tiny API to be added (a few blend factor variants).

  9. magcius commented on Sep 16, 2019

    @magcius

    Even Metal doesn't have programmable blending on desktop platforms. It's something that's much trickier to do on non-tilers.

  10. krogovin commented on Sep 17, 2019

    @krogovin
    Author

    Even Metal doesn't have programmable blending on desktop platforms. It's something that's much trickier to do on non-tilers.

    This is why I advocate framebuffer fetch and interlock to be available as extensions.

  11. krogovin commented on May 20, 2020

    @krogovin
    Author

    Something that I should have mentioned quite some time ago, but I did not. Without dual-source blending, it is nearly impossible to directly support all of the Porter-Duff blend modes with a shader computing a partial coverage value.

    Indeed, for Skia, without dual source blending, for a number of blend modes, it issues a glCopyTexImage2D for some of the blend modes. Ironically, this is needed for kSrc (but not kSrcOver).

    So please, do not let this be forgotten.

    Now to beg/ask in the correct place for GL_EXT_blend_func_extended in WebGL/WebGL2

  12. added this to the post-V1 milestone on Sep 2, 2021
  13. added a commit that references this issue on Sep 6, 2022
    5f1926b
  14. teoxoy commented on Aug 11, 2023

    @teoxoy
    Member

    Some additional info on this:

    When dual-source blending, you can't write to multiple render targets (only the one at index 0). References:

    You have to at least declare the 2nd blend src in the shader due to at least Vulkan.

    If the second color input to the blender is not written in the shader, or if no output is bound to the second input of a blender, the result of the blending operation is not defined.

    from https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap30.html#framebuffer-dsb

    You shouldn't declare/write to any other locations due to at least DX12.

    Writing to other pixel shader outputs (o2, o3 etc.) is undefined; you may not write to a render target if it is not bound to slot 0.

    from https://learn.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-output-merger-stage#dual-source-color-blending

  15. bjjones commented on Sep 7, 2023

    @bjjones
    Contributor

    I just opened a formal investigation and proposal for this feature at #4283. This comes after recently completing a prototype implementation of the feature in Chromium/Dawn.

    Additionally, @teoxoy, I appreciate you documenting many of the specific native API restrictions, which I've used in my proposal.

  16. Kangz commented on Sep 26, 2023

    @Kangz
    Contributor

    Closing in favor of #4283 that links to this issue and has a proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions