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] popErrorScope causes an IPC assertion #9584

Conversation

mwyrzykowski
Copy link
Contributor

@mwyrzykowski mwyrzykowski commented Feb 3, 2023

d5a1264

[WebGPU] popErrorScope causes an IPC assertion
https://bugs.webkit.org/show_bug.cgi?id=251666
<radar://104993240>

Reviewed by Myles C. Maxfield.

GPUDevice.popErrorScope is supposed to be asynchronous, so use sendWithAsyncReply
instead of sendSync.

* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteDevice.messages.in:
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteDeviceProxy.cpp:
(WebKit::WebGPU::RemoteDeviceProxy::popErrorScope):
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteDeviceProxy.h:

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

8802095

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ›  gtk
βœ… πŸ§ͺ 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 Feb 3, 2023
@mwyrzykowski mwyrzykowski added the WebGPU For bugs in WebGPU label Feb 3, 2023
@@ -287,20 +287,16 @@ static void captureFrame(id<MTLDevice> captureObject)
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-poperrorscope

if (!validatePopErrorScope()) {
instance().scheduleWork([callback = WTFMove(callback)]() mutable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto for the other patch. This function philosophically should be async; we should be making it properly async rather than temporarily making it sync.

OK for temporary code, but I think we can do better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why should it be async and doesn't scheduleWork() run on the same dispatch queue which the containing function runs? If so, what is the benefit to making it async?

Copy link
Contributor

@litherum litherum Feb 4, 2023

Choose a reason for hiding this comment

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

Because that's the API contract of promises, you are guaranteed your promise's .then callback won't run in the middle of your popErrorScope() call. I'm trying to match the API behavior of the WebGPU IDL as much as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct but we shouldn't impact the web api for due to how the native API is structured. Instead I think we should ensure the contract on the native API in a way that does not impact the web API.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. An app that wants to use WebGPU.framework is going to expect that it behaves the same way as the web API does, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so however native WebGPU still seems under development.

My point is that making the callback asynchronous here negatively impacts users of the web api as now they incur additional latency for the task to return, when it was already asynchronous from the website’s perspective.

If we want the native API to appear the same, we should implement that in a way that doesn’t add latency to the web api. This patch doesn’t address that as the web api is priority.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the difference measurable?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the answer is "yes", I propose we add a boolean to WGPUInstanceCocoaDescriptor that represents whether violating the asynchronicity guarantees of the spec is more desirable than upholding them, and set the value of the boolean to true in WebKit and false everywhere else, and then implement both codepaths, and use the boolean to select between them.

If the answer is "no" then we should just use the async codepath everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not measurable especially given the discussion is about popErrorScope

I will try the new IPC sendToStreamWithAsyncReply to see if we can resolve this issue that way. I'm kind of opposed to using NotStreamEncodableReply as that is a workaround

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@litherum PR updated with sendWithAsyncReply, I reverted the changes to Device.mm

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Feb 3, 2023
@mwyrzykowski mwyrzykowski removed the merging-blocked Applied to prevent a change from being merged label Feb 4, 2023
@mwyrzykowski mwyrzykowski force-pushed the eng/WebGPU-popErrorScope-causes-an-IPC-assertion branch from a2fc827 to d32cbd7 Compare February 4, 2023 00:17
@mwyrzykowski mwyrzykowski force-pushed the eng/WebGPU-popErrorScope-causes-an-IPC-assertion branch from d32cbd7 to 2b62217 Compare February 4, 2023 00:23
@mwyrzykowski mwyrzykowski added the merge-queue Applied to send a pull request to merge-queue label Feb 17, 2023
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/WebGPU-popErrorScope-causes-an-IPC-assertion branch from 8802095 to a60f8cc Compare February 17, 2023 02:38
https://bugs.webkit.org/show_bug.cgi?id=251666
<radar://104993240>

Reviewed by Myles C. Maxfield.

GPUDevice.popErrorScope is supposed to be asynchronous, so use sendWithAsyncReply
instead of sendSync.

* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteDevice.messages.in:
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteDeviceProxy.cpp:
(WebKit::WebGPU::RemoteDeviceProxy::popErrorScope):
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteDeviceProxy.h:

Canonical link: https://commits.webkit.org/260413@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/WebGPU-popErrorScope-causes-an-IPC-assertion branch from a60f8cc to d5a1264 Compare February 17, 2023 02:41
@webkit-commit-queue
Copy link
Collaborator

Committed 260413@main (d5a1264): https://commits.webkit.org/260413@main

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

@webkit-early-warning-system webkit-early-warning-system merged commit d5a1264 into WebKit:main Feb 17, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Feb 17, 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