Skip to content

Extension Request: texture-barrier. #439

Open

Description

@krogovin

This is an extension request for a feature that really only makes sense on non-tiled based renderer: texture barrier. The model for texture barrier is the old GL extension GL_ARB_texture_barrier (https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_barrier.txt) {whose base is GL_NV_texture_barrier that is over 10 years old}.

The basic gist is this:

  • One can source from a texture even if it is a render target BUT
  • To make sure the values in the target are correct, an application must issue a barrier call (which is essentially a message to a driver to flush the render and texture caches) whenever a fragment is written to that is sampled later.

One can argue that functionality like this is already available to an application via using image-load-store together with its memory barriers. However, from the point of view of a GPU implementation (and thus any driver too) there is a -big- difference very often in what happens underneath. Specifically: render targets are often much better cached and very often lossless compressed too with, more often than not, the lossless compression on a render target is understood by the sampler. In contrast, a number of desktop GPU's don't have any compression on image-load-store elements and the caching is not as efficient.

The use case, like #396, #395 and #391 is, for me, programmable blending.

Again, as an extension, as this makes less than zero sense on tiled-based renderers.

Activity

  1. added
    feature request
    on Sep 19, 2019
  2. kvark commented on Sep 19, 2019

    @kvark
    Contributor

    Thank you for writing down the extension request!
    I'm afraid this would be quite difficult to fit into our usage model: a resource can only be in a single writable usage at a time, or in a combination of read-only usages (just like D3D12). This means that it can't be bound in a bind group inside a render pass that has it as a target.

  3. krogovin commented on Sep 19, 2019

    @krogovin
    Author

    That usage model is analogous to GL's restriction of FBO feedback loops and that is the hidden meat of the extension request, allowing for a resource to be both a write and read.

    I have not checked what happen in the various APIs (D3D12, Metal and Vulkan) yet or if any of them have a barrier capability. What I'd like to do, or for someone to comment on, is which, if any, of these API's allow for this feature. If it turns out that none of them have, then this idea is dead. If only one, I don't know. If two or more, then I hope we can explore it some.

  4. litherum commented on Sep 20, 2019

    @litherum
    Contributor

    I don’t think you can do programmable blending in the general case with glTextureBarrier() because of overlapping geometry. Consider trying to render a hundred triangles on top of each other, and have the blending between the different triangles be some custom function. If the barrier is outside of the fragment shader, the intermediate results for each pixel of each overlapping triangle need to be stored somewhere so that the code after the barrier can read from those intermediate results. This means that the storage size requirements are proportional to the number of overlap in the scene, which is generally not achievable.

  5. krogovin commented on Sep 20, 2019

    @krogovin
    Author

    I don’t think you can do programmable blending in the general case with glTextureBarrier() because of overlapping geometry. Consider trying to render a hundred triangles on top of each other, and have the blending between the different triangles be some custom function.

    In my use cases, I can guarantee that a single draw call has zero overlapping triangles (taking into account the depth test) AND I can also pre-compute when texture barrier is needed. I can do this, in my use cases, because I am drawing UI's. It is that use case where I need the programmable blending.

    Without this, or other ways to do programmable blending, I will need to either do image-load-store (and issue memory barrier between each call) or do the horrible blit from current render target to texture instead of memory barrier.

  6. devshgraphicsprogramming commented on Oct 28, 2019

    @devshgraphicsprogramming

    I have not checked what happen in the various APIs (D3D12, Metal and Vulkan) yet or if any of them have a barrier capability. What I'd like to do, or for someone to comment on, is which, if any, of these API's allow for this feature.

    @krogovin its in the core Vulkan API, its called subpasses and subpass dependencies.

    I don’t think you can do programmable blending in the general case with glTextureBarrier() because of overlapping geometry.

    You'd usually use it for stuff like depth-based fog without needing to rebind to a different FBO / introduce serialization @litherum

    I did it in Build A World EDU for water without refraction, we raster the scene under water, issue a glTextureBarrier(), switch to a deferred fog shader that reads the depth buffer.

    On Vulkan we'd do it via subpass inputs, and subpass by region dependency (more fine grained barrier, only barriers the resources you want and only pixel to pixel).

    You could probably use this functionality for depth peeling or something similar without having to start new renderpasses (and serialize draw).

  7. added this to the post-V1 milestone on Sep 2, 2021
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