-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should XRWebGLLayers clear/invalidate their framebuffers prior to each frame #775
Comments
Oh, and to be clear: I don't see this as a backwards compatibility-breaking change. If we decided that yes, everything should be cleared then the worst that we do in introduce some unnecessary overhead for early apps that assumed a clear was necessary, but no content will break. |
Somewhat related, if the spec adds new optional features that supply color or depth buffers to the app, i.e. pose-aligned AR camera frames or occlusion data, would this potentially use prepopulated attachments to the webxr framebuffer? That's a separate decision, but I think that requiring UA-provided ready-to-use framebuffers and discouraging apps from calling For background (no pun intended), the experimental |
For the Servo implementation of WebXR, it doesn't make a huge amount of difference whether user code calls |
I think we'd want to specify it as transparent or opaque black, depending on whether or not the framebuffer has an alpha channel. |
That would certainly be the easiest to implement. |
I am supportive of the proposal: |
But let separate clear from invalidation. What I think we should do is to INVALIDATE both color and depth buffers at the end of the frame, and this must be mandatory. Clear is another story and it could be a waste of GPU if I still need to re-clear it to something different from (0,0,0,0). |
As per my comments in the last call, I would suggest that if we do define the buffers being cleared, we should also define what happens with the depth and stencil buffers. For the depth in particular, there is no single value that will be ideal for all rendering engines, but the value that it is cleared to can be expected to be the same for all frames. Many render engines will prefer an inverted depth buffer in order to reduce depth sorting artifacts, by interpreting "1" as the near plane and "0" as the far plane. Simpler WebGL samples are likely to use "0" as the near plane and "1" as the far plane, as this is the traditional OpenGL format. For background on this particular optimization: https://developer.nvidia.com/content/depth-precision-visualized |
IMHO, it would be okay to let the depth and stencil be cleared by the platform; however, the value that it is cleared to should be configurable (at least allow it to be set once at XRSession initialization). Please note that clearing the depth buffer redundantly has implications other than consuming fill rate. On tile-based-deferred rendering GPU's (most modern mobile GPU's), this operation also resets acceleration structures used to perform early culling operations. If done incorrectly or at the incorrect time during a frame, early culling can be effectively disabled, resulting in greater fragment shading costs and increased fill in subsequent render passes. |
I agree with @Artyom17 that the browser should avoid needless clears by only clearing buffers when the developer chooses not to clear it themselves. The only buffers the WebXR API should lazy clear are ones it specifically hands out to web developers. In the future, the plan is to have XR WebGL layers supply just a texture array to the web developer that they can use in any framebuffer of their choosing. So unless the depth buffer is supplied by the XR API for enhanced LSR purposes, I do not think we should get in the business of lazy clearing random buffers behind the developer's back. We should use the clear values WebGL already defines as initial values. For depth, the lazy clear value is 1.0. |
I have not heard about such a proposal. Is this for a new WebXR spec? |
@cabanier , the issue I was referring to was the Use Texture Arrays with WebGL 2 one. It will be part of the layers module. |
I'm going to back away from what I said earlier about it not making a difference for Servo... We're thinking of moving from an implementation that uses one texture which is locked during compositing, to an implementation that uses double-buffering (or triple-buffering, details still under construction). This is fine if the layer is cleared on each rAF loop, not so fine if it's required to keep state. |
Put up a pull request to fix this at #866. Don't think it'll be controversial, but please take a look! |
I'm relatively certain that we've had this conversation before and that the consensus was "yes, they should" but I can't find any record of it (which is a fail on my part) so let's get this done properly!
We should explicitly state whether or not framebuffers provided by
XRWebGLLayer
(and in the future similar layer sources) should be invalidated or cleared by the WebXR implementation prior to each frame. My recollection is that on some platforms the target buffers provided by the native API will be invalidated by default, and as such forcing web apps to do an explicit clear each frame "just in case" is a waste of fillrate in a situation where we have very little to spare. As such the spec should probably just specify that framebuffers are "ready to go" at the start of each frame so that developers can skip the clear step with confidence.Any objections?
(I definitely recall that we made the explicit decision to leave the
preserveDrawingBuffer
option off of theXRWebGLLayer
for similar reasons, so we don't ever need to worry about needing to preserve the content of the buffer for more than a frame.)The text was updated successfully, but these errors were encountered: