Bug 226422 - [WebXR] invalidateFramebuffer is not the same as clearing contents
Summary: [WebXR] invalidateFramebuffer is not the same as clearing contents
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Dean Jackson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-29 12:38 PDT by Dean Jackson
Modified: 2021-06-01 14:12 PDT (History)
4 users (show)

See Also:


Attachments
Patch (2.86 KB, patch)
2021-05-29 12:46 PDT, Dean Jackson
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dean Jackson 2021-05-29 12:38:34 PDT
[WebXR] invalidateFramebuffer is not the same as clearing contents
Comment 1 Dean Jackson 2021-05-29 12:40:06 PDT
The WebXR specification says that buffer contents must be cleared before each frame. The code currently does glInvalidateFramebuffer to wipe the attachments, which isn't the same thing (and produces an error since it tries to invalidate attachments that don't exist).
Comment 2 Radar WebKit Bug Importer 2021-05-29 12:42:44 PDT
<rdar://problem/78652351>
Comment 3 Dean Jackson 2021-05-29 12:46:48 PDT
Created attachment 430104 [details]
Patch
Comment 4 Sam Weinig 2021-05-29 13:41:36 PDT
Comment on attachment 430104 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=430104&action=review

> Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp:112
> -    gl.bindFramebuffer(GL::FRAMEBUFFER, m_framebuffer->object());
> +    gl.bindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_framebuffer->object());
>      // https://immersive-web.github.io/webxr/#opaque-framebuffer
> -    // The buffers attached to an opaque framebuffer MUST be cleared to the values in the table below when first created,
> +    // The buffers attached to an opaque framebuffer MUST be cleared to the values in the provided table when first created,
>      // or prior to the processing of each XR animation frame.
> -    std::array<const GCGLenum, 3> attachments = { GL::COLOR_ATTACHMENT0, GL::STENCIL_ATTACHMENT, GL::DEPTH_ATTACHMENT };
> -    gl.invalidateFramebuffer(GL::FRAMEBUFFER, makeGCGLSpan(attachments.data(), attachments.size()));
> +    // FIXME: Actually do the clearing (not using invalidateFramebuffer). This will have to be done after we've attached
> +    // the textures/renderbuffers.

We should also probably abstract this away from specific GL at some point so it can support WebGPU framebuffers as well.
Comment 5 Dean Jackson 2021-05-30 12:43:48 PDT
Comment on attachment 430104 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=430104&action=review

>> Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp:112
>> +    // the textures/renderbuffers.
> 
> We should also probably abstract this away from specific GL at some point so it can support WebGPU framebuffers as well.

Agreed.
Comment 6 Dean Jackson 2021-05-30 12:45:29 PDT
Committed r278256 (238293@main): <https://commits.webkit.org/238293@main>
Comment 7 Imanol Fernandez 2021-05-31 02:32:18 PDT
>
> We should also probably abstract this away from specific GL at some point so
> it can support WebGPU framebuffers as well.

In theory the Opaque Framebuffer approach is kind of deprecated and the path forward is the WebXR Layers API, specifically the XRProjectionLayer for this use case. The UAs will provide "Opaque Textures" and the framebuffer creation complexity will me moved to JS and WebGL/WebGPU side.

So it's probably better to focus on that path since I dont expect that a WebGPU Opaque Framebuffer will be added to the spec
Comment 8 Sam Weinig 2021-06-01 09:43:09 PDT
(In reply to Imanol Fernandez from comment #7)
> >
> > We should also probably abstract this away from specific GL at some point so
> > it can support WebGPU framebuffers as well.
> 
> In theory the Opaque Framebuffer approach is kind of deprecated and the path
> forward is the WebXR Layers API, specifically the XRProjectionLayer for this
> use case. The UAs will provide "Opaque Textures" and the framebuffer
> creation complexity will me moved to JS and WebGL/WebGPU side.
> 
> So it's probably better to focus on that path since I dont expect that a
> WebGPU Opaque Framebuffer will be added to the spec

Gotcha. Can you point me wo where XRProjectionLayer is being spec'd? I couldn't find it in https://immersive-web.github.io/webxr/.
Comment 9 Imanol Fernandez 2021-06-01 14:12:26 PDT
> 
> Gotcha. Can you point me wo where XRProjectionLayer is being spec'd? I
> couldn't find it in https://immersive-web.github.io/webxr/.

It's spec'd here https://immersive-web.github.io/layers/#xrprojectionlayertype