Skip to content
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

[WebGPU] Extra deref of SwapChainImpl::m_backing #8941

Conversation

mwyrzykowski
Copy link
Contributor

@mwyrzykowski mwyrzykowski commented Jan 22, 2023

83826f3

[WebGPU] Extra deref of SwapChainImpl::m_backing
https://bugs.webkit.org/show_bug.cgi?id=250963
<rdar://104522929>

Reviewed by Myles C. Maxfield.

WebGPUSurfaceImpl and WebGPUSwapChainImpl called release in both
destroy and their destructor, resulting in a double release.

Fix this issue by setting the backing to null when the object is released.

* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSurfaceImpl.cpp:
(PAL::WebGPU::SurfaceImpl::destroy):
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSwapChainImpl.cpp:
(PAL::WebGPU::SwapChainImpl::~SwapChainImpl):
(PAL::WebGPU::SwapChainImpl::destroy):

Canonical link: https://commits.webkit.org/259318@main

c6f2805

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  πŸ§ͺ win
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ›  gtk βœ… πŸ›  wincairo
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch βœ… πŸ§ͺ mac-wk2-stress
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch-sim

@mwyrzykowski mwyrzykowski self-assigned this Jan 22, 2023
@mwyrzykowski mwyrzykowski added the WebGPU For bugs in WebGPU label Jan 22, 2023
Comment on lines 47 to 53
wgpuSwapChainRelease(m_backing);
destroy();
}

void SwapChainImpl::destroy()
{
wgpuSwapChainRelease(m_backing);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's wrong to delete all calls to wgpuSwapChainRelease(). I think the fact that there's only a single object under the hood shouldn't be visible from outside WebGPU.framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I'll increment the ref count instead on m_backing

Copy link
Contributor

@litherum litherum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requesting changes due to missing wgpuSwapChainRelease()

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 22, 2023
@mwyrzykowski mwyrzykowski removed the merging-blocked Applied to prevent a change from being merged label Jan 24, 2023
@mwyrzykowski mwyrzykowski force-pushed the eng/WebGPU-Extra-deref-of-SwapChainImplm_backing branch from 9236988 to de93d28 Compare January 24, 2023 01:53
Copy link
Contributor

@litherum litherum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this bumps the ref by 2 instead of by 1

@@ -36,6 +36,7 @@
Ref<PresentationContext> Device::createSwapChain(PresentationContext& presentationContext, const WGPUSwapChainDescriptor& descriptor)
{
presentationContext.configure(*this, descriptor);
presentationContext.ref();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? The input to this function is a PresentationContext& and the output is a Ref. So the next line return statement will invoke the constructor of Ref that will increment the ref count. So I think this change will actually bump the ref count by 2, not 1.

Also, suspicious that every ref needs to be matched with a deref but this one doesn't seem to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation, I will take a closer look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think I found the root cause now. The destructor and destroy were both calling release. wgpuSurfaceRelease doesn't actually release the backing, it just decrements the ref count. So after calling this I now set the backing to null so it can't be released again.

@mwyrzykowski mwyrzykowski force-pushed the eng/WebGPU-Extra-deref-of-SwapChainImplm_backing branch from de93d28 to c6f2805 Compare January 24, 2023 07:49
Copy link
Contributor

@litherum litherum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'm curious how this will end up, regarding #8856 and #8940

@mwyrzykowski mwyrzykowski added the merge-queue Applied to send a pull request to merge-queue label Jan 24, 2023
https://bugs.webkit.org/show_bug.cgi?id=250963
<rdar://104522929>

Reviewed by Myles C. Maxfield.

WebGPUSurfaceImpl and WebGPUSwapChainImpl called release in both
destroy and their destructor, resulting in a double release.

Fix this issue by setting the backing to null when the object is released.

* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSurfaceImpl.cpp:
(PAL::WebGPU::SurfaceImpl::destroy):
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSwapChainImpl.cpp:
(PAL::WebGPU::SwapChainImpl::~SwapChainImpl):
(PAL::WebGPU::SwapChainImpl::destroy):

Canonical link: https://commits.webkit.org/259318@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/WebGPU-Extra-deref-of-SwapChainImplm_backing branch from c6f2805 to 83826f3 Compare January 25, 2023 00:44
@webkit-early-warning-system webkit-early-warning-system merged commit 83826f3 into WebKit:main Jan 25, 2023
@webkit-commit-queue
Copy link
Collaborator

Committed 259318@main (83826f3): https://commits.webkit.org/259318@main

Reviewed commits have been landed. Closing PR #8941 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebGPU For bugs in WebGPU
Projects
None yet
5 participants