Commit Graph

235 Commits

Author SHA1 Message Date
Nicolas Silva
e870c7e64f Bug 1777535 - Differentiate between destroying and dropping a buffer. r=jimb
The former frees resources but keeps the handle. It can be called multiple times. The latter destroys the handle. Any subsequent reference to the same buffer is a bug and will cause the GPU process to crash.

Depends on D152080

Differential Revision: https://phabricator.services.mozilla.com/D152081
2022-08-10 15:55:09 +00:00
Nicolas Silva
5fd15277ea Bug 1777535 - Don't crash when buffer_unmap returns an error. r=jimb
Depends on D151702

Differential Revision: https://phabricator.services.mozilla.com/D151703
2022-08-10 15:55:09 +00:00
Nicolas Silva
58ad96d358 Bug 1777535 - Validate mapAync mode on the parent side. r=jimb
Depends on D151632

Differential Revision: https://phabricator.services.mozilla.com/D151701
2022-08-10 15:55:08 +00:00
Nicolas Silva
dbd3c4297a Bug 1777535 - Track the buffer mapAsync promise. r=jimb
Per spec (and discussion with someone on the chromium side where spec is vague), the correct behavior should be:
 - MapAsync validation happens on the device timeline, so we should reject the promise in mapAsync on the content side if we run into an internal error not described by the spec.
 - Unmap immediately rejects all pending mapping promises on the content side (there can be multiple of them since we have to catch that error on the device timeline).

This patch tracks a single mapping promise at a time and immediately rejects on the content side any subseqent mapping
request made until unmap is called. This means our current implementation deviates slightly from the current state of
the spec in that:
 - The promise is rejected earlier on the content timeline,
 - If the first request fails, all subsequent requests will fail until either unmap or when the content side receives and processes the rejected
   promise, whereas Dawn's implementation would allow the first valid request to succed.

There was some confusion around the the use of uint64_t and size_t which probably originated at point where this code was working differently. This patch uses uint64_t (=BufferAddress) more consistently removing the need for some of the casting and overflow checks.
One notable change in the overall logic is that SetMapped is now called when the buffer is actually in the mapped state (before this patch it was called as soon as the buffer had a pending map request).

Depends on D151618

Differential Revision: https://phabricator.services.mozilla.com/D151619
2022-08-10 15:55:05 +00:00
Nicolas Silva
77fc0caeb0 Bug 1777535 - Map only the required buffer range on the Parent side. r=jimb
Depends on D151617

Differential Revision: https://phabricator.services.mozilla.com/D151618
2022-08-10 15:55:05 +00:00
Nicolas Silva
bd05b4c260 Bug 1777535 - Use unsafe shmems. r=jimb
This commit makes WebGPU buffers use unsafe shmems.
Instead of relying on moving the shmem back and forth between the two processes to ensure thread safety, we instead rely on the validation done on both sides. The upside is that it makes it much easier to implement said validation correctly.

In the interest of splitting the buffer mapping rework into small-ish commits, this one puts some structural pieces in place but doesn't necessarily do justice to the final implementation:
 - The validation itself is coming in subsequent patches in this series.
 - Mapping sub-ranges of the buffer was somewhat implemented in some parts of the parent code and not in others, and was fairly broken as a whole. This commit always maps the entire buffer and proper logic for sub-ranges is coming in another commit.

The main things this commit does put in place:
 - Each mappable buffer is associated with a Shmem that is accessible to both sides.
 - On the child side, if a buffer is not mappable, then Buffer::mShmem is in its default state (it doesn't point to any shared memory segment).
 - On the parent side, if a buffer is not mappable it does not have an entry in mSharedMemoryMap.
 - The shmem is always created by the child and destroyed by the parent.

Depends on D151615

Differential Revision: https://phabricator.services.mozilla.com/D151616
2022-08-10 15:55:03 +00:00
Nicolas Silva
251a5cb5dc Bug 1777535 - Return pointer and length in wgpu_server_buffer_get_mapped_range. r=jimb
Also return an empty slice instead of crashing in case of errors.
This is a small piece split off of the buffer mapping rework. Most of the call sites are completely rewritten in followup patches, and error reporting will also come in followups.

Depends on D151374

Differential Revision: https://phabricator.services.mozilla.com/D151615
2022-08-10 15:55:03 +00:00
Nicolas Silva
8ce85ad77d Bug 1778713 - Give the raw IDs in WebGPUParent useful names. r=jimb
Depends on D149892

Differential Revision: https://phabricator.services.mozilla.com/D151374
2022-08-10 15:55:02 +00:00
Nicolas Silva
a8274c6cc8 Bug 1771254 - Add MaybeShmem. r=jimb,aosmond
Most operations maniplating shmems in WebGPU are fallible, we'll have to handle passing them conditionally in most messages.

This commit starts with BufferMap, to avoid crashing when map is called on an invalid buffer.

Differential Revision: https://phabricator.services.mozilla.com/D149892
2022-08-10 15:55:02 +00:00
Marian-Vasile Laza
19a23c8a56 Backed out 22 changesets (bug 1780792, bug 1778713, bug 1771254, bug 1777535) for causing bustages on WebGPUParent.h. CLOSED TREE
Backed out changeset 84974dbb4d3f (bug 1780792)
Backed out changeset 5bef755ea09b (bug 1777535)
Backed out changeset 6de84921e7d0 (bug 1780792)
Backed out changeset 89450745f60b (bug 1777535)
Backed out changeset de8da0f89c50 (bug 1777535)
Backed out changeset 24707519fe7b (bug 1771254)
Backed out changeset fe75bdc54a31 (bug 1777535)
Backed out changeset aa8e1c7f727f (bug 1777535)
Backed out changeset f674057a477f (bug 1777535)
Backed out changeset b4210142bf82 (bug 1780792)
Backed out changeset 326511661875 (bug 1780792)
Backed out changeset 6178c6dd5c31 (bug 1780792)
Backed out changeset 219760e8c20e (bug 1777535)
Backed out changeset e312cdad1fee (bug 1777535)
Backed out changeset 446e62674d9d (bug 1777535)
Backed out changeset d2f4d878d51f (bug 1777535)
Backed out changeset 85ac57add037 (bug 1777535)
Backed out changeset 4c512a0c05a9 (bug 1780792)
Backed out changeset 6f732421a0b4 (bug 1777535)
Backed out changeset 0da5289fe5a9 (bug 1777535)
Backed out changeset c19a35a62ed4 (bug 1778713)
Backed out changeset 61e4e8e63a3e (bug 1771254)
2022-08-10 15:04:12 +03:00
Nicolas Silva
211bbe6f50 Bug 1780792 - Remove unnecessary MapRequest constructor. r=jimb
Differential Revision: https://phabricator.services.mozilla.com/D152521
2022-08-10 11:38:59 +00:00
Nicolas Silva
d722f84dff Bug 1777535 - Ensure WebGPUParent outlives the map callback. r=jimb
Depends on D152081

Differential Revision: https://phabricator.services.mozilla.com/D152082
2022-08-10 11:38:58 +00:00
Nicolas Silva
c2cb604e2d Bug 1777535 - Differentiate between destroying and dropping a buffer. r=jimb
The former frees resources but keeps the handle. It can be called multiple times. The latter destroys the handle. Any subsequent reference to the same buffer is a bug and will cause the GPU process to crash.

Depends on D152080

Differential Revision: https://phabricator.services.mozilla.com/D152081
2022-08-10 11:38:58 +00:00
Nicolas Silva
1e9f540889 Bug 1777535 - Don't crash when buffer_unmap returns an error. r=jimb
Depends on D151702

Differential Revision: https://phabricator.services.mozilla.com/D151703
2022-08-10 11:38:57 +00:00
Nicolas Silva
560ab8310f Bug 1777535 - Validate mapAync mode on the parent side. r=jimb
Depends on D151632

Differential Revision: https://phabricator.services.mozilla.com/D151701
2022-08-10 11:38:56 +00:00
Nicolas Silva
d7e723ea15 Bug 1777535 - Track the buffer mapAsync promise. r=jimb
Per spec (and discussion with someone on the chromium side where spec is vague), the correct behavior should be:
 - MapAsync validation happens on the device timeline, so we should reject the promise in mapAsync on the content side if we run into an internal error not described by the spec.
 - Unmap immediately rejects all pending mapping promises on the content side (there can be multiple of them since we have to catch that error on the device timeline).

This patch tracks a single mapping promise at a time and immediately rejects on the content side any subseqent mapping
request made until unmap is called. This means our current implementation deviates slightly from the current state of
the spec in that:
 - The promise is rejected earlier on the content timeline,
 - If the first request fails, all subsequent requests will fail until either unmap or when the content side receives and processes the rejected
   promise, whereas Dawn's implementation would allow the first valid request to succed.

There was some confusion around the the use of uint64_t and size_t which probably originated at point where this code was working differently. This patch uses uint64_t (=BufferAddress) more consistently removing the need for some of the casting and overflow checks.
One notable change in the overall logic is that SetMapped is now called when the buffer is actually in the mapped state (before this patch it was called as soon as the buffer had a pending map request).

Depends on D151618

Differential Revision: https://phabricator.services.mozilla.com/D151619
2022-08-10 11:38:54 +00:00
Nicolas Silva
c0b49c58a4 Bug 1777535 - Map only the required buffer range on the Parent side. r=jimb
Depends on D151617

Differential Revision: https://phabricator.services.mozilla.com/D151618
2022-08-10 11:38:53 +00:00
Nicolas Silva
52dc1bf73f Bug 1777535 - Use unsafe shmems. r=jimb
This commit makes WebGPU buffers use unsafe shmems.
Instead of relying on moving the shmem back and forth between the two processes to ensure thread safety, we instead rely on the validation done on both sides. The upside is that it makes it much easier to implement said validation correctly.

In the interest of splitting the buffer mapping rework into small-ish commits, this one puts some structural pieces in place but doesn't necessarily do justice to the final implementation:
 - The validation itself is coming in subsequent patches in this series.
 - Mapping sub-ranges of the buffer was somewhat implemented in some parts of the parent code and not in others, and was fairly broken as a whole. This commit always maps the entire buffer and proper logic for sub-ranges is coming in another commit.

The main things this commit does put in place:
 - Each mappable buffer is associated with a Shmem that is accessible to both sides.
 - On the child side, if a buffer is not mappable, then Buffer::mShmem is in its default state (it doesn't point to any shared memory segment).
 - On the parent side, if a buffer is not mappable it does not have an entry in mSharedMemoryMap.
 - The shmem is always created by the child and destroyed by the parent.

Depends on D151615

Differential Revision: https://phabricator.services.mozilla.com/D151616
2022-08-10 11:38:53 +00:00
Nicolas Silva
2264261a39 Bug 1777535 - Return pointer and length in wgpu_server_buffer_get_mapped_range. r=jimb
Also return an empty slice instead of crashing in case of errors.
This is a small piece split off of the buffer mapping rework. Most of the call sites are completely rewritten in followup patches, and error reporting will also come in followups.

Depends on D151374

Differential Revision: https://phabricator.services.mozilla.com/D151615
2022-08-10 11:38:52 +00:00
Nicolas Silva
828f4d2f14 Bug 1778713 - Give the raw IDs in WebGPUParent useful names. r=jimb
Depends on D149892

Differential Revision: https://phabricator.services.mozilla.com/D151374
2022-08-10 11:38:52 +00:00
Nicolas Silva
eb05e88aae Bug 1771254 - Add MaybeShmem. r=jimb,aosmond
Most operations maniplating shmems in WebGPU are fallible, we'll have to handle passing them conditionally in most messages.

This commit starts with BufferMap, to avoid crashing when map is called on an invalid buffer.

Differential Revision: https://phabricator.services.mozilla.com/D149892
2022-08-10 11:38:51 +00:00
Christian Holler
c84ce06471 Bug 1782703 - Add missing check to RecvSwapChainDestroy. r=nical
Differential Revision: https://phabricator.services.mozilla.com/D153459
2022-08-05 17:24:05 +00:00
Jim Blandy
751d9edd9b Bug 1780643: Fully initialize ffi::WGPUIdentityRecyclerFactory. r=nical
Differential Revision: https://phabricator.services.mozilla.com/D152450
2022-07-26 06:28:12 +00:00
Nicolas Silva
711966e43e Bug 1750576 - Avoid passing raw strings in a couple of wgpu bindings entry points. r=emilio
Inspired by emilio's suggestion in the shader module API patch. This tries to be the most straightforward way to go from the strings coming from IPC to the ones consumed by wgpu.

Differential Revision: https://phabricator.services.mozilla.com/D151024
2022-07-08 08:11:39 +00:00
Nicolas Silva
9b27095b07 Bug 1750576 - WebGPU shader module asynchronous CompilationInfo API. r=aosmond,emilio
This patch is a lot of plumbing for not that much functionality. The goal is to align CreateShaderModule's error reporting with the spec.
Creating a shader module is now a dedicated async IPDL message returning the compilation info so that it can be exposed as a promise by the WebGPU API.

Differential Revision: https://phabricator.services.mozilla.com/D146817
2022-07-08 08:11:39 +00:00
Cristian Tuns
86c321ca45 Backed out 2 changesets (bug 1750576) for causing lint failures and build bustages. CLOSED TREE
Backed out changeset 21ede22c4113 (bug 1750576)
Backed out changeset be7493c6f3cb (bug 1750576)
2022-07-07 10:51:38 -04:00
Nicolas Silva
8b6ccb9427 Bug 1750576 - Avoid passing raw strings in a couple of wgpu bindings entry points. r=emilio
Inspired by emilio's suggestion in the shader module API patch. This tries to be the most straightforward way to go from the strings coming from IPC to the ones consumed by wgpu.

Differential Revision: https://phabricator.services.mozilla.com/D151024
2022-07-07 14:35:29 +00:00
Nicolas Silva
e070f8027b Bug 1750576 - WebGPU shader module asynchronous CompilationInfo API. r=aosmond,emilio
This patch is a lot of plumbing for not that much functionality. The goal is to align CreateShaderModule's error reporting with the spec.
Creating a shader module is now a dedicated async IPDL message returning the compilation info so that it can be exposed as a promise by the WebGPU API.

Differential Revision: https://phabricator.services.mozilla.com/D146817
2022-07-07 14:35:28 +00:00
Narcis Beleuzu
4a6560373f Backed out changeset 0a2e3c4ca14f (bug 1750576) for bustages on RefPtr . CLOSED TREE 2022-07-06 19:18:20 +03:00
Nicolas Silva
8a69d97904 Bug 1750576 - WebGPU shader module asynchronous CompilationInfo API. r=aosmond,emilio
This patch is a lot of plumbing for not that much functionality. The goal is to align CreateShaderModule's error reporting with the spec.
Creating a shader module is now a dedicated async IPDL message returning the compilation info so that it can be exposed as a promise by the WebGPU API.

Differential Revision: https://phabricator.services.mozilla.com/D146817
2022-07-06 15:22:59 +00:00
Jim Blandy
769dc2dbf0 Bug 1777656: Delete mozilla::ipc::SharedMemory::SharedMemorytype. r=nika,media-playback-reviewers,padenot
Differential Revision: https://phabricator.services.mozilla.com/D150852
2022-07-05 20:08:31 +00:00
sotaro
bfa47ee3b1 Bug 1777657 - Remove SurfaceDescriptor from WebRenderTextureHost constructor r=gfx-reviewers,lsalzman
SurfaceDescriptor is not used anymore in WebRenderTextureHost constructor.

Differential Revision: https://phabricator.services.mozilla.com/D150853
2022-07-02 00:06:00 +00:00
Jim Blandy
da2b5a67de Bug 1752188: Move GPUBufferDescriptor validation to server. r=jgilbert
Depends on [`wgpu#2673`].

WebGPU requires `GPUBufferDescriptor` validation failure to:

1) generate an error on the Device timeline, and

2) mark the new buffer as invalid.

Satisfy 1) by moving most validation to the compositor process.

Requirement 2) is harder. `wgpu_core::Global::device_create_buffer`
already takes care of some validation for us, and marks the provided
buffer id invalid when there's a problem. However, there are certain
errors the spec requires us to detect which `device_create_buffer`
cannot even see, because they are caught by standard Rust validation
steps in the process of creating the `wgpu_types::BufferDescriptor`
that one would *pass to* that function. For example, if there are
bogus bits set in the `usage` property, we can't even construct a Rust
`BufferUsages` value from that to include in the `BufferDescriptor`
that we must pass to `device_create_buffer`.

This means that we need to do some validation ourselves, in the
process of constructing that `BufferDescriptor`, and use the
`Global::create_buffer_error` method added in [`wgpu#2673`] to mark
the new buffer as invalid.

[`wgpu#2673`]: https://github.com/gfx-rs/wgpu/pull/2673

Differential Revision: https://phabricator.services.mozilla.com/D146768
2022-06-06 06:33:13 +00:00
Jim Blandy
972d7da440 Bug 1752188: Error-handling cleanups. r=jgilbert
Document various things. Spell out that the error messages are UTF-8.

Let `server.rs`'s `ErrorBuffer` take a `&str` instead of a `String`.

Differential Revision: https://phabricator.services.mozilla.com/D146767
2022-06-06 06:33:13 +00:00
Jim Blandy
5ab0c2c610 Bug 1772004: Update wgpu to 32af4f56 (2022-5-31) r=jgilbert
Minor changes are needed to the `mapAsync` implementation due to:
https://github.com/gfx-rs/wgpu/pull/2698

Differential Revision: https://phabricator.services.mozilla.com/D147805
2022-06-05 20:30:13 +00:00
Andrew Osmond
cbf65c724f Bug 1768337. r=gfx-reviewers,lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D146222
2022-05-17 14:01:34 +00:00
Jim Blandy
a0e23ca8ad Bug 1752538: Properly report GPURenderPassDescriptors with too many color attachments. r=jgilbert
The WebGPU spec says that `beginRenderPass` should generate a
validation error if the valid usage rules for
`GPURenderPassDescriptor` are not satisfied. In particular, a
`GPURenderPassDescriptor` may not contain more than eight color
attachments.

The `wgpu-core` crate will panic if a
`wgpu_core::command::RenderPassDescriptor` contains too many color
attachments.  This is safe, but panics are not acceptable in Firefox,
so it falls to our WebGPU implementation to perform the error checks
described by the spec.

Since WebGPU error handling records the first error to occur within
each error scope, the API is sensitive to the order in which errors
are generated. To ensure that the error is properly ordered with
respect to other messages sent to the device, we must send the error
to compositor process. The WebGPUParent will then handle it
interleaved appropriately with other Device timeline activity.

Differential Revision: https://phabricator.services.mozilla.com/D146391
2022-05-17 00:25:35 +00:00
Kagami Sascha Rosylight
50f0e30a17 Bug 1768189 - Part 42: Apply modernize-concat-nested-namespaces to dom/webgpu/RenderBundle.h ... r=andi
Depends on D145777

Differential Revision: https://phabricator.services.mozilla.com/D145778
2022-05-09 20:41:19 +00:00
Jim Blandy
1bbc260372 Bug 1766754: Document WebGPU FFI ErrorBuffer types. r=jgilbert DONTBUILD
Differential Revision: https://phabricator.services.mozilla.com/D144904
2022-04-28 05:27:25 +00:00
Andrew Osmond
8133fa2390 Bug 1755704 - Part 1. Add support for reading back the front buffer for WebGPU. r=gfx-reviewers,lsalzman
This reworks the CanvasManagerChild::GetSnapshot method to work with
WebGPU. This will allow it to be called for a WebGPU context from any
thread, which is useful for screenshots.

Differential Revision: https://phabricator.services.mozilla.com/D144308
2022-04-27 16:05:28 +00:00
Csoregi Natalia
1b27ab5da8 Backed out 3 changesets (bug 1755704, bug 1765816) for causing reftest failures on webgl-color-test.html
Backed out changeset 2f074e2385d4 (bug 1765816)
Backed out changeset cd0b9e084bcd (bug 1755704)
Backed out changeset 39a846e43162 (bug 1755704)
2022-04-24 02:33:33 +03:00
Andrew Osmond
b30ba92d0a Bug 1755704 - Part 1. Add support for reading back the front buffer for WebGPU. r=gfx-reviewers,lsalzman
This reworks the CanvasManagerChild::GetSnapshot method to work with
WebGPU. This will allow it to be called for a WebGPU context from any
thread, which is useful for screenshots.

Differential Revision: https://phabricator.services.mozilla.com/D144308
2022-04-23 16:45:10 +00:00
Molnar Sandor
447e9dd8f4 Backed out 3 changesets (bug 1765816, bug 1755704) for causing bp hybrid bustages. CLOSED TREE
Backed out changeset 505897037daf (bug 1765816)
Backed out changeset bc4e2999a2a7 (bug 1755704)
Backed out changeset 26b11a2833b0 (bug 1755704)
2022-04-22 18:03:57 +03:00
Andrew Osmond
573c0aad92 Bug 1755704 - Part 1. Add support for reading back the front buffer for WebGPU. r=gfx-reviewers,lsalzman
This reworks the CanvasManagerChild::GetSnapshot method to work with
WebGPU. This will allow it to be called for a WebGPU context from any
thread, which is useful for screenshots.

Differential Revision: https://phabricator.services.mozilla.com/D144308
2022-04-22 15:05:42 +00:00
Randell Jesup
855202c183 Bug 1207753 - Add MOZ_UNANNOTATED to all Mutexes/Monitors r=nika,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D140849
2022-03-16 18:47:08 +00:00
Noemi Erli
16f5f5f2b9 Backed out changeset 12a59e5a50bf (bug 1207753) for causing build bustage CLOSED TREE 2022-03-16 18:32:51 +02:00
Randell Jesup
a98b1f8218 Bug 1207753 - Add MOZ_UNANNOTATED to all Mutexes/Monitors r=nika,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D140849
2022-03-16 16:16:14 +00:00
Butkovits Atila
01197944a0 Backed out changeset a68ee4b09f92 (bug 1207753) for causing Hazard bustages. CLOSED TREE 2022-03-16 14:38:14 +02:00
Randell Jesup
fe15f2115d Bug 1207753 - Add MOZ_UNANNOTATED to all Mutexes/Monitors r=nika,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D140849
2022-03-16 12:01:14 +00:00
Emilio Cobos Álvarez
50bd6bfae4 Bug 1758169 - Clean up WebGPU lifetime handling a bit. r=nical
No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D140384
2022-03-08 15:00:39 +00:00