Commit eded4d51 authored by Jim Blandy's avatar Jim Blandy
Browse files

Bug 1824265: Clarify WebGPU mapAsync error messages. r=webgpu-reviewers,teoxoy

Calling `GPUBuffer.mapAsync` returns a `Promise` that is rejected if something goes wrong mapping the buffer, but Firefox's error message doesn't really say anything to indicate that mapping was involved: "Invalid buffer" is a bit mysterious.

Ideally we would attach call stacks to these promises - and I think there is a way to do that - but for now this patch just changes the error messages to mention mapping.

While we're in the neighborhood, improve some `NS_WARNING` messages.

Differential Revision: https://phabricator.services.mozilla.com/D173493
parent 7bdb6fe4
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -377,28 +377,28 @@ struct MapRequest {
  WebGPUParent::BufferMapResolver mResolver;
};

nsCString MapStatusString(ffi::WGPUBufferMapAsyncStatus status) {
static const char* MapStatusString(ffi::WGPUBufferMapAsyncStatus status) {
  switch (status) {
    case ffi::WGPUBufferMapAsyncStatus_Success:
      return nsCString("Success");
      return "Success";
    case ffi::WGPUBufferMapAsyncStatus_AlreadyMapped:
      return nsCString("Already mapped");
      return "Already mapped";
    case ffi::WGPUBufferMapAsyncStatus_MapAlreadyPending:
      return nsCString("Map is already pending");
      return "Map is already pending";
    case ffi::WGPUBufferMapAsyncStatus_Aborted:
      return nsCString("Map aborted");
      return "Map aborted";
    case ffi::WGPUBufferMapAsyncStatus_ContextLost:
      return nsCString("Context lost");
      return "Context lost";
    case ffi::WGPUBufferMapAsyncStatus_Invalid:
      return nsCString("Invalid buffer");
      return "Invalid buffer";
    case ffi::WGPUBufferMapAsyncStatus_InvalidRange:
      return nsCString("Invalid range");
      return "Invalid range";
    case ffi::WGPUBufferMapAsyncStatus_InvalidAlignment:
      return nsCString("Invalid alignment");
      return "Invalid alignment";
    case ffi::WGPUBufferMapAsyncStatus_InvalidUsageFlags:
      return nsCString("Invalid usage flags");
      return "Invalid usage flags";
    case ffi::WGPUBufferMapAsyncStatus_Error:
      return nsCString("Map failed");
      return "Map failed";
    case ffi::WGPUBufferMapAsyncStatus_Sentinel:  // For -Wswitch
      break;
  }
@@ -422,7 +422,8 @@ static void MapCallback(ffi::WGPUBufferMapAsyncStatus status,
  MOZ_RELEASE_ASSERT(mapData);

  if (status != ffi::WGPUBufferMapAsyncStatus_Success) {
    result = BufferMapError(MapStatusString(status));
    result = BufferMapError(nsPrintfCString("Mapping WebGPU buffer failed: %s",
                                            MapStatusString(status)));
  } else {
    auto size = req->mSize;
    auto offset = req->mOffset;
@@ -1081,7 +1082,7 @@ ipc::IPCResult WebGPUParent::RecvBumpImplicitBindGroupLayout(RawId aPipelineId,
ipc::IPCResult WebGPUParent::RecvDevicePushErrorScope(RawId aDeviceId) {
  const auto& lookup = mErrorScopeMap.find(aDeviceId);
  if (lookup == mErrorScopeMap.end()) {
    NS_WARNING("WebGPU error scopes on a destroyed device!");
    NS_WARNING("WebGPU: attempt to push an error scope on a destroyed device!");
    return IPC_OK();
  }

@@ -1093,7 +1094,7 @@ ipc::IPCResult WebGPUParent::RecvDevicePopErrorScope(
    RawId aDeviceId, DevicePopErrorScopeResolver&& aResolver) {
  const auto& lookup = mErrorScopeMap.find(aDeviceId);
  if (lookup == mErrorScopeMap.end()) {
    NS_WARNING("WebGPU error scopes on a destroyed device!");
    NS_WARNING("WebGPU: attempt to pop an error scope on a destroyed device!");
    ScopedError error = {true};
    aResolver(Some(error));
    return IPC_OK();