Bug 223734

Summary: Depth test affects WebGL rendering when context has depth == false, stencil == true
Product: WebKit Reporter: Kimmo Kinnunen <kkinnunen>
Component: WebGLAssignee: Kimmo Kinnunen <kkinnunen>
Status: RESOLVED CONFIGURATION CHANGED    
Severity: Normal CC: cdumez, changseok, dino, esprehn+autocc, ews-watchlist, gyuyoung.kim, jdarpinian, kbr, kkinnunen, kondapallykalyan, kpiddington, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 223735, 242657    
Bug Blocks: 222812    
Attachments:
Description Flags
Patch
none
Patch for landing none

Description Kimmo Kinnunen 2021-03-25 01:19:32 PDT
Depth test affects WebGL rendering when context has depth == false, stencil == true

Happens when stencil is enabled and stencil is stencil+depth.
Comment 1 Kimmo Kinnunen 2021-03-25 03:45:46 PDT
Created attachment 424231 [details]
Patch
Comment 2 Kyle Piddington 2021-03-25 10:59:57 PDT
Comment on attachment 424231 [details]
Patch

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

Overall, this should certainly work to keep depth and stencil correctly set.

> Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:7694
> +    enableOrDisable(GraphicsContextGL::DEPTH_TEST, enable);

The logic here is sound. I also believe that you could get a similar result in Metal_Angle by attaching a d24s8 attachment to just STENCIL_ATTACHMENT instead of always DEPTH_STENCIL_ATTACHMENT when available. See void GraphicsContextGLOpenGL::attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height) in GraphicsContextANGLE
Comment 3 Kenneth Russell 2021-03-29 15:43:58 PDT
Great work on this Kimmo - would be great if you could propose the conformance test changes as a pull request against https://github.com/KhronosGroup/WebGL .
Comment 4 Kimmo Kinnunen 2021-03-30 03:45:17 PDT
(In reply to Kyle Piddington from comment #2)
> The logic here is sound. I also believe that you could get a similar result
> in Metal_Angle by attaching a d24s8 attachment to just STENCIL_ATTACHMENT
> instead of always DEPTH_STENCIL_ATTACHMENT when available. See void
> GraphicsContextGLOpenGL::attachDepthAndStencilBufferIfNeeded(GLuint
> internalDepthStencilFormat, int width, int height) in GraphicsContextANGLE

Kyle, thanks for the review.
I'm hesitant to do that cleanup yet since there's this comment
        // WebGL 1.0's rules state that combined depth/stencil renderbuffers
        // have to be attached to the synthetic DEPTH_STENCIL_ATTACHMENT point.

I don't know enough of the spec / implementation to say if storing the stencil depth buffer in stencil for the case stencil=true, depth=false would satisfy the getter behavior we currently have or should have.
Comment 5 Kenneth Russell 2021-03-30 10:58:04 PDT
(In reply to Kimmo Kinnunen from comment #4)
> (In reply to Kyle Piddington from comment #2)
> > The logic here is sound. I also believe that you could get a similar result
> > in Metal_Angle by attaching a d24s8 attachment to just STENCIL_ATTACHMENT
> > instead of always DEPTH_STENCIL_ATTACHMENT when available. See void
> > GraphicsContextGLOpenGL::attachDepthAndStencilBufferIfNeeded(GLuint
> > internalDepthStencilFormat, int width, int height) in GraphicsContextANGLE
> 
> Kyle, thanks for the review.
> I'm hesitant to do that cleanup yet since there's this comment
>         // WebGL 1.0's rules state that combined depth/stencil renderbuffers
>         // have to be attached to the synthetic DEPTH_STENCIL_ATTACHMENT
> point.
> 
> I don't know enough of the spec / implementation to say if storing the
> stencil depth buffer in stencil for the case stencil=true, depth=false would
> satisfy the getter behavior we currently have or should have.

Hopefully the WebGL 1.0 and 2.0 conformance tests should cover this behavior well.

The bookkeeping for WebGL 1.0's synthetic DEPTH_STENCIL_ATTACHMENT can / should be managed entirely at the WebGLRenderingContextBase / WebGL2RenderingContext level, so maybe GraphicsContextANGLE can offer the semantic that Kyle suggests (depth/stencil are combined, and the same object is attached separately to the DEPTH and STENCIL attachment points). See the associated code in Chromium:

https://source.chromium.org/search?q=DEPTH_STENCIL_ATTACHMENT%20f:third_party%2Fblink%2Frenderer%2Fmodules%2Fwebgl
Comment 6 Radar WebKit Bug Importer 2021-04-01 01:20:14 PDT
<rdar://problem/76093639>
Comment 7 Kimmo Kinnunen 2021-08-23 04:14:03 PDT
Created attachment 436182 [details]
Patch for landing
Comment 8 Kimmo Kinnunen 2021-08-23 11:01:12 PDT
https://github.com/KhronosGroup/WebGL/issues/3277
Comment 9 Kimmo Kinnunen 2022-08-11 02:40:08 PDT
This is fixed in bug 242657 and the patch is not needed.