summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/ipc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /dom/webgpu/ipc
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webgpu/ipc')
-rw-r--r--dom/webgpu/ipc/PWebGPU.ipdl2
-rw-r--r--dom/webgpu/ipc/WebGPUChild.cpp4
-rw-r--r--dom/webgpu/ipc/WebGPUParent.cpp82
-rw-r--r--dom/webgpu/ipc/WebGPUParent.h6
-rw-r--r--dom/webgpu/ipc/WebGPUSerialize.h5
5 files changed, 67 insertions, 32 deletions
diff --git a/dom/webgpu/ipc/PWebGPU.ipdl b/dom/webgpu/ipc/PWebGPU.ipdl
index 5146dd6826..451480a1c3 100644
--- a/dom/webgpu/ipc/PWebGPU.ipdl
+++ b/dom/webgpu/ipc/PWebGPU.ipdl
@@ -44,6 +44,8 @@ parent:
async DeviceActionWithAck(RawId selfId, ByteBuf buf) returns (bool dummy);
async TextureAction(RawId selfId, RawId aDeviceId, ByteBuf buf);
async CommandEncoderAction(RawId selfId, RawId aDeviceId, ByteBuf buf);
+ async RenderPass(RawId selfId, RawId aDeviceId, ByteBuf buf);
+ async ComputePass(RawId selfId, RawId aDeviceId, ByteBuf buf);
async BumpImplicitBindGroupLayout(RawId pipelineId, bool isCompute, uint32_t index, RawId assignId);
async DeviceCreateBuffer(RawId deviceId, RawId bufferId, GPUBufferDescriptor desc, UnsafeSharedMemoryHandle shm);
diff --git a/dom/webgpu/ipc/WebGPUChild.cpp b/dom/webgpu/ipc/WebGPUChild.cpp
index 663dd5cb89..ab1a100736 100644
--- a/dom/webgpu/ipc/WebGPUChild.cpp
+++ b/dom/webgpu/ipc/WebGPUChild.cpp
@@ -40,10 +40,10 @@ void WebGPUChild::JsWarning(nsIGlobalObject* aGlobal,
if (aGlobal) {
dom::AutoJSAPI api;
if (api.Init(aGlobal)) {
- JS::WarnUTF8(api.cx(), "%s", flatString.get());
+ JS::WarnUTF8(api.cx(), "Uncaptured WebGPU error: %s", flatString.get());
}
} else {
- printf_stderr("Validation error without device target: %s\n",
+ printf_stderr("Uncaptured WebGPU error without device target: %s\n",
flatString.get());
}
}
diff --git a/dom/webgpu/ipc/WebGPUParent.cpp b/dom/webgpu/ipc/WebGPUParent.cpp
index 9b79988245..1c0560d31e 100644
--- a/dom/webgpu/ipc/WebGPUParent.cpp
+++ b/dom/webgpu/ipc/WebGPUParent.cpp
@@ -154,6 +154,12 @@ class ErrorBuffer {
}
return Some(Error{*filterType, false, nsCString{mMessageUtf8}});
}
+
+ void CoerceValidationToInternal() {
+ if (mType == ffi::WGPUErrorBufferType_Validation) {
+ mType = ffi::WGPUErrorBufferType_Internal;
+ }
+ }
};
struct PendingSwapChainDrop {
@@ -180,10 +186,9 @@ class PresentationData {
Maybe<PendingSwapChainDrop> mPendingSwapChainDrop;
const uint32_t mSourcePitch;
- std::vector<RawId> mUnassignedBufferIds MOZ_GUARDED_BY(mBuffersLock);
- std::vector<RawId> mAvailableBufferIds MOZ_GUARDED_BY(mBuffersLock);
- std::vector<RawId> mQueuedBufferIds MOZ_GUARDED_BY(mBuffersLock);
- Mutex mBuffersLock;
+ std::vector<RawId> mUnassignedBufferIds;
+ std::vector<RawId> mAvailableBufferIds;
+ std::vector<RawId> mQueuedBufferIds;
PresentationData(WebGPUParent* aParent, bool aUseExternalTextureInSwapChain,
RawId aDeviceId, RawId aQueueId,
@@ -194,8 +199,7 @@ class PresentationData {
mDeviceId(aDeviceId),
mQueueId(aQueueId),
mDesc(aDesc),
- mSourcePitch(aSourcePitch),
- mBuffersLock("WebGPU presentation buffers") {
+ mSourcePitch(aSourcePitch) {
MOZ_COUNT_CTOR(PresentationData);
for (const RawId id : aBufferIds) {
@@ -354,6 +358,11 @@ ipc::IPCResult WebGPUParent::RecvInstanceRequestAdapter(
nsAutoCString message(aMessage);
req->mParent->LoseDevice(deviceId, reason, message);
+ auto it = req->mParent->mDeviceFenceHandles.find(deviceId);
+ if (it != req->mParent->mDeviceFenceHandles.end()) {
+ req->mParent->mDeviceFenceHandles.erase(it);
+ }
+
// We're no longer tracking the memory for this callback, so erase
// it to ensure we don't leak memory.
req->mParent->mDeviceLostRequests.erase(deviceId);
@@ -394,7 +403,9 @@ ipc::IPCResult WebGPUParent::RecvAdapterRequestDevice(
HANDLE handle =
wgpu_server_get_device_fence_handle(mContext.get(), aDeviceId);
if (handle) {
- mFenceHandle = new gfx::FileHandleWrapper(UniqueFileHandle(handle));
+ RefPtr<gfx::FileHandleWrapper> fenceHandle =
+ new gfx::FileHandleWrapper(UniqueFileHandle(handle));
+ mDeviceFenceHandles.emplace(aDeviceId, std::move(fenceHandle));
}
#endif
@@ -970,20 +981,16 @@ static void ReadbackPresentCallback(ffi::WGPUBufferMapAsyncStatus status,
return;
}
- PresentationData* data = req->mData.get();
+ RefPtr<PresentationData> data = req->mData;
// get the buffer ID
RawId bufferId;
{
- MutexAutoLock lock(data->mBuffersLock);
bufferId = data->mQueuedBufferIds.back();
data->mQueuedBufferIds.pop_back();
}
// Ensure we'll make the bufferId available for reuse
- auto releaseBuffer = MakeScopeExit([data = RefPtr{data}, bufferId] {
- MutexAutoLock lock(data->mBuffersLock);
- data->mAvailableBufferIds.push_back(bufferId);
- });
+ data->mAvailableBufferIds.push_back(bufferId);
MOZ_LOG(sLogger, LogLevel::Info,
("ReadbackPresentCallback for buffer %" PRIu64 " status=%d\n",
@@ -994,15 +1001,16 @@ static void ReadbackPresentCallback(ffi::WGPUBufferMapAsyncStatus status,
ErrorBuffer getRangeError;
const auto mapped = ffi::wgpu_server_buffer_get_mapped_range(
req->mContext, bufferId, 0, bufferSize, getRangeError.ToFFI());
+ getRangeError.CoerceValidationToInternal();
if (req->mData->mParent) {
req->mData->mParent->ForwardError(data->mDeviceId, getRangeError);
- } else if (auto innerError = getRangeError.GetError()) {
- // If an error occured in get_mapped_range, treat it as an internal error
- // and crash. The error handling story for something unexpected happening
- // during the present glue needs to befigured out in a more global way.
+ }
+ if (auto innerError = getRangeError.GetError()) {
MOZ_LOG(sLogger, LogLevel::Info,
- ("WebGPU present: buffer get_mapped_range failed: %s\n",
+ ("WebGPU present: buffer get_mapped_range for internal "
+ "presentation readback failed: %s\n",
innerError->message.get()));
+ return;
}
MOZ_RELEASE_ASSERT(mapped.length >= bufferSize);
@@ -1029,11 +1037,14 @@ static void ReadbackPresentCallback(ffi::WGPUBufferMapAsyncStatus status,
}
ErrorBuffer unmapError;
wgpu_server_buffer_unmap(req->mContext, bufferId, unmapError.ToFFI());
+ unmapError.CoerceValidationToInternal();
if (req->mData->mParent) {
req->mData->mParent->ForwardError(data->mDeviceId, unmapError);
- } else if (auto innerError = unmapError.GetError()) {
+ }
+ if (auto innerError = unmapError.GetError()) {
MOZ_LOG(sLogger, LogLevel::Info,
- ("WebGPU present: buffer unmap failed: %s\n",
+ ("WebGPU present: buffer unmap for internal presentation "
+ "readback failed: %s\n",
innerError->message.get()));
}
} else {
@@ -1083,9 +1094,12 @@ void WebGPUParent::PostExternalTexture(
const auto index = aExternalTexture->GetSubmissionIndex();
MOZ_ASSERT(index != 0);
+ RefPtr<PresentationData> data = lookup->second.get();
+
Maybe<gfx::FenceInfo> fenceInfo;
- if (mFenceHandle) {
- fenceInfo = Some(gfx::FenceInfo(mFenceHandle, index));
+ auto it = mDeviceFenceHandles.find(data->mDeviceId);
+ if (it != mDeviceFenceHandles.end()) {
+ fenceInfo = Some(gfx::FenceInfo(it->second, index));
}
Maybe<layers::SurfaceDescriptor> desc =
@@ -1098,8 +1112,6 @@ void WebGPUParent::PostExternalTexture(
mRemoteTextureOwner->PushTexture(aRemoteTextureId, aOwnerId, aExternalTexture,
size, surfaceFormat, *desc);
- RefPtr<PresentationData> data = lookup->second.get();
-
auto recycledTexture = mRemoteTextureOwner->GetRecycledExternalTexture(
size, surfaceFormat, desc->type(), aOwnerId);
if (recycledTexture) {
@@ -1140,7 +1152,6 @@ ipc::IPCResult WebGPUParent::RecvSwapChainPresent(
// step 1: find an available staging buffer, or create one
{
- MutexAutoLock lock(data->mBuffersLock);
if (!data->mAvailableBufferIds.empty()) {
bufferId = data->mAvailableBufferIds.back();
data->mAvailableBufferIds.pop_back();
@@ -1285,7 +1296,6 @@ ipc::IPCResult WebGPUParent::RecvSwapChainDrop(
mPresentationDataMap.erase(lookup);
- MutexAutoLock lock(data->mBuffersLock);
ipc::ByteBuf dropByteBuf;
for (const auto bid : data->mUnassignedBufferIds) {
wgpu_server_buffer_free(bid, ToFFI(&dropByteBuf));
@@ -1351,6 +1361,24 @@ ipc::IPCResult WebGPUParent::RecvCommandEncoderAction(
return IPC_OK();
}
+ipc::IPCResult WebGPUParent::RecvRenderPass(RawId aEncoderId, RawId aDeviceId,
+ const ipc::ByteBuf& aByteBuf) {
+ ErrorBuffer error;
+ ffi::wgpu_server_render_pass(mContext.get(), aEncoderId, ToFFI(&aByteBuf),
+ error.ToFFI());
+ ForwardError(aDeviceId, error);
+ return IPC_OK();
+}
+
+ipc::IPCResult WebGPUParent::RecvComputePass(RawId aEncoderId, RawId aDeviceId,
+ const ipc::ByteBuf& aByteBuf) {
+ ErrorBuffer error;
+ ffi::wgpu_server_compute_pass(mContext.get(), aEncoderId, ToFFI(&aByteBuf),
+ error.ToFFI());
+ ForwardError(aDeviceId, error);
+ return IPC_OK();
+}
+
ipc::IPCResult WebGPUParent::RecvBumpImplicitBindGroupLayout(RawId aPipelineId,
bool aIsCompute,
uint32_t aIndex,
@@ -1426,8 +1454,6 @@ ipc::IPCResult WebGPUParent::RecvDevicePopErrorScope(
case dom::GPUErrorFilter::Internal:
ret.resultType = PopErrorScopeResultType::InternalError;
break;
- case dom::GPUErrorFilter::EndGuard_:
- MOZ_CRASH("Bad GPUErrorFilter");
}
}
return ret;
diff --git a/dom/webgpu/ipc/WebGPUParent.h b/dom/webgpu/ipc/WebGPUParent.h
index 6ad539c21e..a1eb36d723 100644
--- a/dom/webgpu/ipc/WebGPUParent.h
+++ b/dom/webgpu/ipc/WebGPUParent.h
@@ -118,6 +118,10 @@ class WebGPUParent final : public PWebGPUParent, public SupportsWeakPtr {
const ipc::ByteBuf& aByteBuf);
ipc::IPCResult RecvCommandEncoderAction(RawId aEncoderId, RawId aDeviceId,
const ipc::ByteBuf& aByteBuf);
+ ipc::IPCResult RecvRenderPass(RawId aEncoderId, RawId aDeviceId,
+ const ipc::ByteBuf& aByteBuf);
+ ipc::IPCResult RecvComputePass(RawId aEncoderId, RawId aDeviceId,
+ const ipc::ByteBuf& aByteBuf);
ipc::IPCResult RecvBumpImplicitBindGroupLayout(RawId aPipelineId,
bool aIsCompute,
uint32_t aIndex,
@@ -219,7 +223,7 @@ class WebGPUParent final : public PWebGPUParent, public SupportsWeakPtr {
nsTHashSet<RawId> mLostDeviceIds;
// Shared handle of wgpu device's fence.
- RefPtr<gfx::FileHandleWrapper> mFenceHandle;
+ std::unordered_map<RawId, RefPtr<gfx::FileHandleWrapper>> mDeviceFenceHandles;
// Store DeviceLostRequest structs for each device as unique_ptrs mapped
// to their device ids. We keep these unique_ptrs alive as long as the
diff --git a/dom/webgpu/ipc/WebGPUSerialize.h b/dom/webgpu/ipc/WebGPUSerialize.h
index 8d78d784cb..03f9ee1676 100644
--- a/dom/webgpu/ipc/WebGPUSerialize.h
+++ b/dom/webgpu/ipc/WebGPUSerialize.h
@@ -9,6 +9,7 @@
#include "WebGPUTypes.h"
#include "ipc/EnumSerializer.h"
#include "ipc/IPCMessageUtils.h"
+#include "mozilla/dom/BindingIPCUtils.h"
#include "mozilla/dom/WebGPUBinding.h"
#include "mozilla/webgpu/ffi/wgpu.h"
@@ -20,7 +21,9 @@ namespace IPC {
: public ContiguousEnumSerializer<something, something(0), guard> {}
#define DEFINE_IPC_SERIALIZER_DOM_ENUM(something) \
- DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, something::EndGuard_)
+ template <> \
+ struct ParamTraits<something> \
+ : public mozilla::dom::WebIDLEnumSerializer<something> {}
#define DEFINE_IPC_SERIALIZER_FFI_ENUM(something) \
DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, something##_Sentinel)