Skip to content

Fragment shader framebuffer fetch #396

Open

Description

@krogovin

This is a feature request for an extension to allow for a fragment shader to read the current value of the framebuffer when it is running as outlined in the current GL/GLES extension. GL_EXT_shader_framebuffer_fetch

This can be achieved functionality can be achieved with fragment shader interlock (#395), but for hardware that has direct support for this (for example Intel Gen9 or higher GPU's) framebuffer fetch is better because a GPU can more easily use its render cache which in turn means it can more easily maintain lossless color compression. Naturally tiled based renderers can then read directly from the tile which is always better than a read/write to an image.

Activity

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

    @Degerz

    I don't think either AMD or Nvidia hardware supports this feature so I'd prefer not to expose it. This feature is also not present in D3D12 or Vulkan as well.

  3. krogovin commented on Aug 9, 2019

    @krogovin
    Author

    Lets make this an extension quickly after 1.0 release. It is a game changer for some situations.

  4. Degerz commented on Aug 9, 2019

    @Degerz

    Bad idea since WebGPU was intended to be 'portable' as well. Missing support from two notable hardware vendors and no equivalent functionality currently in D3D12 and Vulkan makes this counterproductive.

    WebGPU is supposed to be a wrapper for D3D12/Vulkan as well!

  5. krogovin commented on Aug 9, 2019

    @krogovin
    Author

    That is why I suggest it as an extension just as done in OpenGL. An extension, to me, embodies the idea that "only some devices have it and that is why it is optional".

    If all devices had it and the API's exposed it, then it would be core in the spec.

  6. Degerz commented on Aug 9, 2019

    @Degerz

    I'd prefer it if every extension exposed were in ALL of the supported APIs and had wide ranging hardware support as well. Exposing shader framebuffer fetch just after the public release of WebGPU wouldn't serve much purpose since it's currently only supported officially on iOS GPUs in Metal and that's a problem among the other previously mentioned issues ...

  7. krogovin commented on Aug 9, 2019

    @krogovin
    Author

    I admit what I am so say is pedantic: if it is in ALL of the supported API's and in the hardware, then it should be in core because all have it.

  8. Degerz commented on Aug 9, 2019

    @Degerz

    Having the feature alone supported in all of the APIs isn't good enough. Need to be considerate about the hardware support and hardware vendors as well. If we're going to expose new functionality then I also want all hardware vendors to have supported it as well in their hardware for at least 5+ years just to be on the conservative side ...

  9. krogovin commented on Aug 9, 2019

    @krogovin
    Author

    If the feature is a requirement for each of the 3 API's then it should be safe to make it a requirement in WebGPU.

    If the feature is an extension in some of the API's, then it is a strong candidate for being an extension. If it is an extension in all 3, then it should be an extension in WebGPU. Direct3D12 is very conservative already anyways. The 3 API's being targeted are only for newish hardware anyways (plenty of Direct3D11 class cards will never have Direct3D 12 drivers).

    Mandating that an optional or required feature needs to be around for 5+ years before being an optional (respectively required) feature in WebGPU means that at best WebGPU is 5+ years old which makes it a terrible candidate for first-tier support among developers. The only exception to this is when a feature is known to perform horribly on mobile which is, for now, geometry and tessellation shading.

    If WebGPU is to target only 5+ year old features, then most developers will strongly prefer to make a native app instead of a web-app.

  10. krogovin commented on Aug 9, 2019

    @krogovin
    Author

    At any rate, the discussion has gotten a touch off the rails from Framebuffer fetch.

    The core observations:

    1. of the 3 API's, only one has this feature and as an extension
    2. not all hardware on desktop can support this (only 1 of the 3 support it directly)
    3. most, but not all, mobile hardware can support this and often do in an older API, GLES3.x

    Number 1. and 2. are very strong points. However, I advocate to make it an extension and a browser can decide to advertise if the underlying API has based off their own opinions.

    Again, by making noise, software drivers and then hardware will make it happen as having that feature will improve the user's experience. Lets break the chicken-egg dead lock.

  11. Degerz commented on Aug 9, 2019

    @Degerz

    Direct3D12 is very conservative already anyways. The 3 API's being targeted are only for newish hardware anyways (plenty of Direct3D11 class cards will never have Direct3D 12 drivers).

    The first statement is hardly true since much of the mobile hardware out there wouldn't even serve as role models for advanced modern GPU functionality. Your second statement is absolutely not true since D3D12/Vulkan are targeting hardware as old as 7+ years old. Even Nvidia's Fermi GPUs are D3D12 compatible which are over 9+ years old!

    Mandating that an optional or required feature needs to be around for 5+ years before being an optional (respectively required) feature in WebGPU means that at best WebGPU is 5+ years old which makes it a terrible candidate for first-tier support among developers.

    If WebGPU is to target only 5+ year old features, then most developers will strongly prefer to make a native app instead of a web-app.

    Then those people should use native APIs instead since WebGPU is obviously not suited for those expecting the most bleeding edge hardware features such as ray tracing or mesh shaders for an example since they'll be disappointed ...

    Again, by making noise, software drivers and then hardware will make it happen as having that feature will improve the user's experience. Lets break the chicken-egg dead lock.

    That's not a model of how the industry operates in the real world. IHVs take a lot of time to converge support for a newly standardized functionality because of the tons of backroom politics happening behind us in the background ...

  12. krogovin commented on Aug 9, 2019

    @krogovin
    Author

    Your second statement is absolutely not true since D3D12/Vulkan are targeting hardware as old >as 7+ years old. Even Nvidia's Fermi GPUs are D3D12 compatible which are over 9+ years old!

    This link, https://www.youtube.com/watch?v=nGkpPp2tGSs&feature=youtu.be&t=46m25s, from a Vulkan Webinar with NVIDIA personal answering that Fermi series GPU's were not getting Vulkan support. Those GPU's where NVIDIA's first Direct3D 11 class parts. The hardware could support it base level Vulkan though, but their driver does not. If there is more recent info contradicting that, I would love to know it. Indeed, on Intel, their first Direct3D 11 part can also do Vulkan, but that support is not present in MS-Windows (and its support on Linux is tenuous). The simple answer was that the hardware was old and newer games/software would use the newer API's, so there was a cutoff and there it was.

    That's not a model of how the industry operates in the real world. IHVs take a lot of time to >converge support for a newly standardized functionality because of the tons of backroom >politics happening behind us in the background ...

    I worked for one of these in the past. The issue is about return on investment and market forces. Intel added framebuffer fetch (my guess) is because it was an easy way to do blend-equations-advanced that was wanted a bunch by a massively large software firm with heck-a-big influence. It was added that way because it was possible to add to its architecture in non-overly-invasive way AND it gave a performance benefit over doing via interlock with image-load-store because of the render-cache architecture (biggest one being lossless framebuffer compression).

    Let's get the discussion back on track.

    Your point, with which I can emphasize, is that WebGPU apps should just "work always on any browser with reasonable older hardware". My point of view is that if a large family of GPU's have that feature (framebuffer fetch originated as a GLES3 extension from Apple on quite old hardware), then it should be exposed as an extensions so that web-developers can get the most out of the device if they seek the extension out. The entire point of an extension is that it declares "this feature is not always present, so have a backup plan even if the performance or visual quality suffer". By having extensions on WebGPU, it will help bring the market together since there is market pressure to do so.

  13. Degerz commented on Aug 9, 2019

    @Degerz

    I didn't say Fermi was getting Vulkan drivers but it does have D3D12 drivers so it would absolutely be useful if WebGPU can target Fermi even if only for Windows 10 which is still a rather noticeable chunk of users.

    Having more extensions than necessary in WebGPU is more likely to cause fragmentation issues with supported hardware/driver configurations depending on the applications themselves.

  14. kvark commented on Aug 12, 2019

    @kvark
    Contributor

    I think it's fine to have framebuffer fetch as an extension if and only if we can prove the behavior to be portable across the platforms that will expose the extension. Given that framebuffer writes are ordered, it seems to me that the behavior will be portable, but a more detailed investigation would need to be done at some point.

  15. krogovin commented on Aug 12, 2019

    @krogovin
    Author

    Aces!

    Let's place the results of that investigation into this issue.

  16. litherum commented on Sep 6, 2019

    @litherum
    Contributor

    I'd like to hear more about the motivation and use-cases before we agree to add it to the API. I'm also particular interested in how it interacts with a few of the other proposals we've heard, like advanced blend equations and raster order groups. Rather than implementing extensions arbitrarily as they come up, we should understand the entire problem space and come up with a design which solves the important problems well on all platforms.

  17. krogovin commented on Sep 6, 2019

    @krogovin
    Author

    I did not find in the Issues a proposal related to Raster Order Groups, except for the Interlock proposal that I had made.

    The main use case (for me) is programmable blending. For tiled based renderers (that support framebuffer fetch which is the super-majority of them), framebuffer fetch is MUCH better than interlock because the FB fetch will come from tile memory on the GPU, thus avoiding any memory fetch. Related to performance, a number of tiled based GPU's do not even have a fixed function blending unit and they add epilogue code to a shader to do the blending.

    Interactions:

    1. Essentially, FB Fetch is orthogonal to blending (be it fixed function blending or advanced blend equations). Specifically, the value fetched is from the framebuffer after it was blended when it was renderer. The value written by the frag shader is to be what is inputted to the blender.

    2. MSAA interaction. This part is awful. The value fetched is different at each sample. The upshot of this is that FB-Fetch with MSAA will force a shader to be SSAA, or atleast the part that comes after the FB-fetch. For what it it worth, I HATE this part with respect to performance.

    3. Interlock. Again, FB Fetch is essentially orthogonal. Interlock only requires a guarantee that a portion of the fragment shader is a "critical section" where that code will make the fragments at the fragment from the shader be in API order. In contrast, FB Fetch essentially means that the fragment value is known at the start of the fragment shader (though a good implementation will delay fetching the value until the last possible moment).

    I am also perfectly happy for FB-Fetch to have limitations, such as: if a shader has FB-Fetch, then the pipelinestate object must have blending disabled. In addition, I am also ok with if a shader has FB-fetch, then MSAA is also not allowed

  18. devshgraphicsprogramming commented on Oct 28, 2019

    @devshgraphicsprogramming

    I think on Vulkan @krogovin you could use subpass input + EXT_fragment_shader_interlock to achieve a gl_FramebufferFetch

    Normally you can only use a subpass input in the same way as on OpenGL you'd use an input texture that is also bound to the current FBO + glTextureBarrier

    Since WebGPU is unlikely to run on desktop OpenGL (AFAIK its rather low priority) and desktop will be mostly serviced by Vulkan instead, adding support for an extension that ONLY works on OPENGL & INTEL & Desktop does not make much sense.

  19. krogovin commented on Oct 28, 2019

    @krogovin
    Author

    I think the Vulkan way you are suggesting won't really work because of the nature of a sub-pass input. However, using an image read/write with interlock would work.

    However, there is a potentially significant difference between framebuffer fetch and using interlock on hardware implementations. When using interlock, the reads and writes are to an image rather than the currently bound framebuffer. For immediate mode renderers, the impact is mostly related to render-cache vs image-cache (and potentially lossless render buffer compression). Tiled based renderers, it is a really big deal because the read will be from the tile-memory which is best possible almost. Moreover, some of the tiled-based renderers do the fixed function blending by essentially adding epilogue code to the fragment shader to do the blending by framebuffer fetch.

    On mobile, GL_EXT_shader_framebuffer_fetch is on many of the GPU's (Imaginations Technology SGX, ARM Mali and QCOM Adreno all have it for quite some time). It is also on mobile where WebGPU is mostly likely to shine the strongest (in my humble opinion).

  20. devshgraphicsprogramming commented on Oct 28, 2019

    @devshgraphicsprogramming

    I think the Vulkan way you are suggesting won't really work because of the nature of a sub-pass input. However, using an image read/write with interlock would work.

    not really, try this

    INTERLOCK_ORDERED_START(); // put before first subpass read
    vec3 notgl_LastFragData[i] = subpassLoad(input[i]);
    output[i] = someFunction(notgl_LastFragData[0],...);
    INTERLOCK_ORDERED_END(); // put after last color output
    

    AFAIK on Vulkan subpass works exactly like reading a texture after a glTextureBarrier, i.e. the value is ok until the first time it gets written in the subpass, then its undefined garbage.

    On mobile, GL_EXT_shader_framebuffer_fetch is on many of the GPU's (Imaginations Technology SGX, ARM Mali and QCOM Adreno all have it for quite some time). It is also on mobile where WebGPU is mostly likely to shine the strongest (in my humble opinion).

    I think an OpenGL ES 3.1 WebGPU backend is even less likely than a desktop OpenGL backend.

  21. added this to the post-V1 milestone on Sep 2, 2021
  22. tklajnscek commented on Sep 27, 2021

    @tklajnscek

    +1 for this from our side too. We use this heavily to do programmable blending which is feels like the most common cross platform use case out there, with OIT and other advanced techniques being more of a desktop thing.

    And I also wanted to emphasize what @krogovin said - this is essential for performance on mobile/tile-based hardware as hitting memory is simply not an option.

    On mobile, it's supported properly on Metal iOS and on GLES 3 via the mentioned extension. I realize GLES is not a WebGPU backend target on mobile so it "only" leaves iOS devices. Which IMO is still a very significant chunk of mobile devices that will be able to run WebGPU at all. There's still hope Vulkan gets something decent here.

    On desktop there's krogovin's #395.

    With these 2 we can get optimal performance across the board and that's the whole point of extensions. We check if it's supported and we use it. Simple. I don't care whether it's some API doesn't support it or some hardware doesn't support it as long as I can just do if(hasThisExt) useIt() else slowFallback()

  23. devshgraphicsprogramming commented on Sep 27, 2021

    @devshgraphicsprogramming

    I think the Vulkan way you are suggesting won't really work because of the nature of a sub-pass input. However, using an image read/write with interlock would work.

    not really, try this

    INTERLOCK_ORDERED_START(); // put before first subpass read
    vec3 notgl_LastFragData[i] = subpassLoad(input[i]);
    output[i] = someFunction(notgl_LastFragData[0],...);
    INTERLOCK_ORDERED_END(); // put after last color output
    

    AFAIK on Vulkan subpass works exactly like reading a texture after a glTextureBarrier, i.e. the value is ok until the first time it gets written in the subpass, then its undefined garbage.

    On mobile, GL_EXT_shader_framebuffer_fetch is on many of the GPU's (Imaginations Technology SGX, ARM Mali and QCOM Adreno all have it for quite some time). It is also on mobile where WebGPU is mostly likely to shine the strongest (in my humble opinion).

    I think an OpenGL ES 3.1 WebGPU backend is even less likely than a desktop OpenGL backend.

    I retract my statements, you were 100% correct @krogovin about the nature of subpass inputs.

    We're about to add a MLAB/HT/AT OIT sample to our engine, there will be two paths:

    • Desktop = Fragment Shader Interlock and Storage Images (all desktop GPUs have stuff for implementing ROVs nowadays)
    • Mobile = Same Images Same formats but attached with framebuffer fetch

    INTEL kinda classifies as Mobile because its the only "Desktop" GPU to support the framebuffer fetch extension.
    Will let you know the performance difference in MLAB4 (224 bits HDR) on Intel between the two approaches.

    I think WebGPU needs support for both layout(location=N) inout [coherent] and fragment shader interlock, its impossible to implement Programmable Blending (RGB9E5 rendering) or some of the newer OIT techniques across all platforms without having access to both extensions via the API.

  24. devshgraphicsprogramming commented on Sep 28, 2021

    @devshgraphicsprogramming

    I've actually ran into this issue with Vulkan
    KhronosGroup/Vulkan-Docs#1649

    Seems like its the only case when OpenGL + GLES can result in more features & performance than Vulkan.

  25. krogovin commented on Sep 28, 2021

    @krogovin
    Author

    The more depressing thing is to take an Android phone and look at the GLES vs Vulkan extensions. For example, on my cheap Nokia with a Qualcomm SoC, the feature set from GLES with extensions is more than the feature set of Vulkan with extensions. The main point of Vulkan, in my opinion, was to make the drivers more reliable by making the interface easier for driver development. This might change soon-ish, but not yet.

  26. Kangz commented on Sep 29, 2021

    @Kangz
    Contributor

    To be clear framebuffer fetch / interlock / framebuffer fetch emulated on interlock / other seem pretty high on the list of things after V1, however since it is an optional extension the group isn't really taking a look yet because we need to get something out first so that optional features are useful.

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

    apifeature request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions