Repository navigation
Return SubmissionIndex only if submissions succeed - #10218
Conversation
90c7b65 to
2342e4e
Compare
| self.inner.submit(&array); | ||
|
|
||
| 0 | ||
| Some(0) |
There was a problem hiding this comment.
| Some(0) | |
| // This is a (rather poor) sentinel that means "submission result unknown". | |
| // On the WebGPU backend, status is only available via validation errors. | |
| Some(0) |
There was a problem hiding this comment.
Maybe we should change this to None since it's a submission with an unknown index so it can't really be waited on via a poll?
There was a problem hiding this comment.
I was thinking that it's more important to distinguish success from failure than "have wait cursor" from "don't have wait cursor". Or I also considered defining a 3-way enum, or trying to offer an API where the app can opt in to "I want this to work on the WebGPU backend" validation, which would cause operations that won't work on the WebGPU backend to fail even when running against core.
There was a problem hiding this comment.
I started thinking of SubmissionIndex as a "wait cursor" because that's how it's used in the wgpu API; it's opaque and only poll with PollType::Wait can receive it. I'm also thinking to avoid saying the submission was successful since it might be confused with "submit didn't error" but it can due to the inner call to maintain.
poll seems useless on the WebGPU backend since there is no way to synchronously wait on a submission in WASM (when specifying PollType::Wait) and PollType::Poll is a no-op since the browser is already making progress via its event loop.
To normalize behavior across backends I think we need a new poll error variant (PollError::CantWait) that's always returned on WebGPU if PollType::Wait is supplied and have submit always return None.
There was a problem hiding this comment.
The design of poll and the submission ID was trying to be clever to make portable code easier - its contract that calling poll will wait until the callbacks associated with that submission with eventually resolve. Which means a no-op on wasm is a valid implementation.
Now if that was the correct solution or too clever? I'm not sure. I could see the utility of switching SubmissionIndex from being opaque to being transparent and then using an enum to determine what happened inside a poll.
There was a problem hiding this comment.
its contract that calling poll will wait until the callbacks associated with that submission with eventually resolve. Which means a no-op on wasm is a valid implementation.
That seems to be its contract if its argument is PollType::Poll which I think is fine but if it's PollType::Wait then it must wait either on one specific submission or the last active submission which doesn't happen on WASM. I think this is a portability issue since it's observable: you can race poll(PollType::Wait) with on_submitted_work_done or map_async; timing the operations would also reveal that poll(PollType::Wait) completes immediately.
There was a problem hiding this comment.
I'm inclined to have the WebGPU backend return None to make this portable. Can I do it in this PR so I can also update the docs above? @cwfitzgerald @andyleiserson
The PR should be good to land otherwise.
There was a problem hiding this comment.
I'm not sure I follow the proposal. Some(SubmissionIndex) vs. None, where the former means waitable, the latter means "not waitable"? WebGPU always returns "not waitable" (even if the submission was successful), but that's okay, because the place we want to consume this is Firefox, which doesn't use the WebGPU backend, and can assume waitable == success?
I guess that is okay. I would probably belabor the point a bit more in the docs:
Returns
Someif the submission started and can be waited on via apoll, orNoneotherwise. On the WebGPU backend, always returnsNone(even for successful submissions), because the WebGPU backend does not support waiting for a particular submission.
"Until the callbacks associated with that submission with eventually resolve" seems too clever to me. Is it documented somewhere? The docs on Device::maintain say "The poll_type argument tells if this function should wait for a particular submission index to complete, or if it should just poll the current status.", which doesn't seem right to me for the "eventually resolve" contract, but I guess this is wgpu-core and it's not wrong as long as the scope is understood correctly (very easy to misunderstand IMO). In the "eventually resolve" regime, poll/maintain doesn't really do anything (from the application's perspective), right? You just have to call it or else your callbacks are not guaranteed to fire. Maybe PollType::Wait should return an unsupported error on the WebGPU backend? (Unfortunately that seems likely to turn up a lot of false positives in apps in addition to real problems.)
But in any case None seems like a better return than Some(0) for the non-waitable case. Portable code can still just ignore the result from submit and only use PollType::Poll (which is the only one that works portably, anyways). It doesn't seem useful to maintain the usage sequence "Return a fake SubmissionIndex of zero which the app can then pass to PollType::Wait, which will ignore it (on WebGPU)."
There was a problem hiding this comment.
I made the changes in this PR. 668b12f
The commits will get squashed anyway.
| - Remove the never-constructed `CreateBlasError::InvalidAabbStride` variant. `create_blas` takes no stride, so it could never be produced; AABB stride is validated at build time as `BuildAccelerationStructureError::InvalidAabbStride`. By @mstampfli in [#9935](https://github.com/gfx-rs/wgpu/pull/9935). | ||
|
|
||
| - Added `DownlevelFlags::LINEAR_INTERPOLATION`, indicating that the adapter supports `@interpolate(linear)`. It is absent on GLES/WebGL2, since GLSL ES has no `noperspective` qualifier. By @emilk in [#9972](https://github.com/gfx-rs/wgpu/pull/9972). | ||
| - `Queue::submit` now returns `Option<SubmissionIndex>`, and returns `None` if the submission failed. A `None` result means the submission never reached the driver, so fences/events/semaphores attached to HAL queues will never be signalled. By @teoxoy in [#10218](https://github.com/gfx-rs/wgpu/pull/10218). |
There was a problem hiding this comment.
Maybe worth adding the "on wgpu-core-based backends" caveat here as well.
|
Not directly related to this change, but related more generally to the question of handling submit errors, Vulkan says:
I think this means we can't drop resources immediately after a submit that fails with |
HACK: push additional error scope then pop it, do whatever FF is doing with error then return it back into the error sink using |
|
That's a good suggestion - I ended up doing that to unblock the wgpu update. It's nice that the maintain call will also not interfere since it doesn't generate validation errors - it can only lose the device. |
|
Made Firefox bug 2084148 to track this. |
This comment was marked as resolved.
This comment was marked as resolved.
…pu::Queue::submit` r=#webgpu-reviewers This is only intended as a temporary location for a larger migration that will need to be done for wgpu after consuming [`wgpu`#10218](gfx-rs/wgpu#10218). This patch definitely preserves existing semantics, but isn't the code we'll ultimately want. Differential Revision: https://phabricator.services.mozilla.com/D335125
2342e4e to
88ac8c0
Compare
668b12f to
5897cbc
Compare
If submissions were not successful, a subsequent call to `poll` with the returned `SubmissionIndex` would have raised a validation error anyway. Making the result type `Option<SubmissionIndex>` hints to users that the submission has not reached the driver so fences/events/semaphores that were attached to HAL queues will never be signalled.
5897cbc to
70951c1
Compare
|
@Mergifyio queue |
…pu::Queue::submit` r=#webgpu-reviewers This is only intended as a temporary location for a larger migration that will need to be done for wgpu after consuming [`wgpu`#10218](gfx-rs/wgpu#10218). This patch definitely preserves existing semantics, but isn't the code we'll ultimately want. Differential Revision: https://phabricator.services.mozilla.com/D335125
Connections
Firefox's wgpu update (Bug 2066780) needs this since
queue_submitonly returns the submission index now and we have no way to tell if the submission succeeded (we can't use an error scope since validation errors should still be surfaced to users).Firefox was also incorrectly using the presence of
Result::Errto mean the submission failed but that's not correct since the inner call tomaintain(below the call to HALsubmit) could error. The error would be propagated but the submission did reach the driver and our lifetime tracking. This PR also enables us to fix this issue.Description
If submissions were not successful, a subsequent call to
pollwith the returnedSubmissionIndexwould have raised a validation error anyway.Making the result type
Option<SubmissionIndex>hints to users that the submission has not reached the driver so fences/events/semaphores that were attached to HAL queues will never be signalled.Testing
Existing tests.
Squash or Rebase?
Squash
Checklist
CHANGELOG.mdentries for the user-facing effects of this change are present.wgpumay be affected behaviorally.