From 6cb055b6aa0d9de5a1352a9542b653e0995d1613 Mon Sep 17 00:00:00 2001
From: Brandon Jones <bajones@chromium.org>
Date: Thu, 20 Apr 2023 23:35:14 +0000
Subject: [PATCH] Retain descriptor labels for error objects

Since these objects are more likely to be included in error messages
it's important that we keep the labels that the developer has given
them.

Bug: dawn:1771
Change-Id: I78f4ccc23ce40d8eeceed8ca7dd563dff949b4fb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128420
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Brandon Jones <bajones@chromium.org>
---
 src/dawn/native/BindGroup.cpp           |  8 ++++----
 src/dawn/native/BindGroup.h             |  4 ++--
 src/dawn/native/BindGroupLayout.cpp     | 10 ++++++----
 src/dawn/native/BindGroupLayout.h       |  4 ++--
 src/dawn/native/Buffer.cpp              |  2 +-
 src/dawn/native/CommandBuffer.cpp       | 10 ++++++----
 src/dawn/native/CommandBuffer.h         |  4 ++--
 src/dawn/native/CommandEncoder.cpp      | 19 +++++++++++--------
 src/dawn/native/CommandEncoder.h        |  4 ++--
 src/dawn/native/ComputePassEncoder.cpp  | 11 +++++++----
 src/dawn/native/ComputePassEncoder.h    |  6 ++++--
 src/dawn/native/ComputePipeline.cpp     | 14 ++++++++------
 src/dawn/native/ComputePipeline.h       |  4 ++--
 src/dawn/native/Device.cpp              | 18 +++++++++---------
 src/dawn/native/ExternalTexture.cpp     | 10 ++++++----
 src/dawn/native/ExternalTexture.h       |  4 ++--
 src/dawn/native/ObjectBase.cpp          |  7 ++++++-
 src/dawn/native/ObjectBase.h            |  2 +-
 src/dawn/native/Pipeline.cpp            |  4 ++--
 src/dawn/native/Pipeline.h              |  2 +-
 src/dawn/native/PipelineLayout.cpp      | 10 ++++++----
 src/dawn/native/PipelineLayout.h        |  4 ++--
 src/dawn/native/ProgrammableEncoder.cpp |  5 +++--
 src/dawn/native/ProgrammableEncoder.h   |  5 ++++-
 src/dawn/native/QuerySet.cpp            |  4 +++-
 src/dawn/native/Queue.cpp               | 10 ++++++----
 src/dawn/native/Queue.h                 |  4 ++--
 src/dawn/native/RenderBundle.cpp        |  8 ++++----
 src/dawn/native/RenderBundle.h          |  4 ++--
 src/dawn/native/RenderBundleEncoder.cpp | 10 +++++-----
 src/dawn/native/RenderBundleEncoder.h   |  4 ++--
 src/dawn/native/RenderEncoderBase.cpp   |  5 +++--
 src/dawn/native/RenderEncoderBase.h     |  5 ++++-
 src/dawn/native/RenderPassEncoder.cpp   | 11 +++++++----
 src/dawn/native/RenderPassEncoder.h     |  6 ++++--
 src/dawn/native/RenderPipeline.cpp      | 14 ++++++++------
 src/dawn/native/RenderPipeline.h        |  4 ++--
 src/dawn/native/Sampler.cpp             |  8 ++++----
 src/dawn/native/Sampler.h               |  4 ++--
 src/dawn/native/ShaderModule.cpp        |  8 ++++----
 src/dawn/native/ShaderModule.h          |  4 ++--
 src/dawn/native/Texture.cpp             | 12 ++++++------
 src/dawn/native/Texture.h               |  4 ++--
 43 files changed, 171 insertions(+), 129 deletions(-)

diff --git a/src/dawn/native/BindGroup.cpp b/src/dawn/native/BindGroup.cpp
index 5a2e3a44fc..c1345ca21c 100644
--- a/src/dawn/native/BindGroup.cpp
+++ b/src/dawn/native/BindGroup.cpp
@@ -475,12 +475,12 @@ void BindGroupBase::DeleteThis() {
     ApiObjectBase::DeleteThis();
 }
 
-BindGroupBase::BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag), mBindingData() {}
+BindGroupBase::BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
+    : ApiObjectBase(device, tag, label), mBindingData() {}
 
 // static
-BindGroupBase* BindGroupBase::MakeError(DeviceBase* device) {
-    return new BindGroupBase(device, ObjectBase::kError);
+BindGroupBase* BindGroupBase::MakeError(DeviceBase* device, const char* label) {
+    return new BindGroupBase(device, ObjectBase::kError, label);
 }
 
 ObjectType BindGroupBase::GetType() const {
diff --git a/src/dawn/native/BindGroup.h b/src/dawn/native/BindGroup.h
index 01df670bc9..c8a2c4f40f 100644
--- a/src/dawn/native/BindGroup.h
+++ b/src/dawn/native/BindGroup.h
@@ -44,7 +44,7 @@ struct BufferBinding {
 
 class BindGroupBase : public ApiObjectBase {
   public:
-    static BindGroupBase* MakeError(DeviceBase* device);
+    static BindGroupBase* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -81,7 +81,7 @@ class BindGroupBase : public ApiObjectBase {
     ~BindGroupBase() override;
 
   private:
-    BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
     void DeleteThis() override;
 
     Ref<BindGroupLayoutBase> mLayout;
diff --git a/src/dawn/native/BindGroupLayout.cpp b/src/dawn/native/BindGroupLayout.cpp
index 0f9f868234..fcedc2c583 100644
--- a/src/dawn/native/BindGroupLayout.cpp
+++ b/src/dawn/native/BindGroupLayout.cpp
@@ -491,8 +491,10 @@ BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device,
     GetObjectTrackingList()->Track(this);
 }
 
-BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag) {}
+BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device,
+                                         ObjectBase::ErrorTag tag,
+                                         const char* label)
+    : ApiObjectBase(device, tag, label) {}
 
 BindGroupLayoutBase::~BindGroupLayoutBase() = default;
 
@@ -504,8 +506,8 @@ void BindGroupLayoutBase::DestroyImpl() {
 }
 
 // static
-BindGroupLayoutBase* BindGroupLayoutBase::MakeError(DeviceBase* device) {
-    return new BindGroupLayoutBase(device, ObjectBase::kError);
+BindGroupLayoutBase* BindGroupLayoutBase::MakeError(DeviceBase* device, const char* label) {
+    return new BindGroupLayoutBase(device, ObjectBase::kError, label);
 }
 
 ObjectType BindGroupLayoutBase::GetType() const {
diff --git a/src/dawn/native/BindGroupLayout.h b/src/dawn/native/BindGroupLayout.h
index 3b435cd423..cfcbf433e5 100644
--- a/src/dawn/native/BindGroupLayout.h
+++ b/src/dawn/native/BindGroupLayout.h
@@ -61,7 +61,7 @@ class BindGroupLayoutBase : public ApiObjectBase, public CachedObject {
                         PipelineCompatibilityToken pipelineCompatibilityToken);
     ~BindGroupLayoutBase() override;
 
-    static BindGroupLayoutBase* MakeError(DeviceBase* device);
+    static BindGroupLayoutBase* MakeError(DeviceBase* device, const char* label = nullptr);
 
     ObjectType GetType() const override;
 
@@ -147,7 +147,7 @@ class BindGroupLayoutBase : public ApiObjectBase, public CachedObject {
     }
 
   private:
-    BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     BindingCounts mBindingCounts = {};
     ityp::vector<BindingIndex, BindingInfo> mBindingInfo;
diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp
index 1a72c90de0..83f56e7845 100644
--- a/src/dawn/native/Buffer.cpp
+++ b/src/dawn/native/Buffer.cpp
@@ -177,7 +177,7 @@ BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor)
 BufferBase::BufferBase(DeviceBase* device,
                        const BufferDescriptor* descriptor,
                        ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag),
+    : ApiObjectBase(device, tag, descriptor->label),
       mSize(descriptor->size),
       mUsage(descriptor->usage),
       mState(BufferState::Unmapped) {
diff --git a/src/dawn/native/CommandBuffer.cpp b/src/dawn/native/CommandBuffer.cpp
index 061d1c1af6..fbeb9f216a 100644
--- a/src/dawn/native/CommandBuffer.cpp
+++ b/src/dawn/native/CommandBuffer.cpp
@@ -33,12 +33,14 @@ CommandBufferBase::CommandBufferBase(CommandEncoder* encoder,
     GetObjectTrackingList()->Track(this);
 }
 
-CommandBufferBase::CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag) {}
+CommandBufferBase::CommandBufferBase(DeviceBase* device,
+                                     ObjectBase::ErrorTag tag,
+                                     const char* label)
+    : ApiObjectBase(device, tag, label) {}
 
 // static
-CommandBufferBase* CommandBufferBase::MakeError(DeviceBase* device) {
-    return new CommandBufferBase(device, ObjectBase::kError);
+CommandBufferBase* CommandBufferBase::MakeError(DeviceBase* device, const char* label) {
+    return new CommandBufferBase(device, ObjectBase::kError, label);
 }
 
 ObjectType CommandBufferBase::GetType() const {
diff --git a/src/dawn/native/CommandBuffer.h b/src/dawn/native/CommandBuffer.h
index 62b7c8bffc..2ffde90bc8 100644
--- a/src/dawn/native/CommandBuffer.h
+++ b/src/dawn/native/CommandBuffer.h
@@ -34,7 +34,7 @@ class CommandBufferBase : public ApiObjectBase {
   public:
     CommandBufferBase(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor);
 
-    static CommandBufferBase* MakeError(DeviceBase* device);
+    static CommandBufferBase* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -50,7 +50,7 @@ class CommandBufferBase : public ApiObjectBase {
     CommandIterator mCommands;
 
   private:
-    CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     CommandBufferResourceUsage mResourceUsages;
 };
diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp
index f74e0b3959..31e9290673 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -710,8 +710,8 @@ Ref<CommandEncoder> CommandEncoder::Create(DeviceBase* device,
 }
 
 // static
-CommandEncoder* CommandEncoder::MakeError(DeviceBase* device) {
-    return new CommandEncoder(device, ObjectBase::kError);
+CommandEncoder* CommandEncoder::MakeError(DeviceBase* device, const char* label) {
+    return new CommandEncoder(device, ObjectBase::kError, label);
 }
 
 CommandEncoder::CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor* descriptor)
@@ -728,8 +728,8 @@ CommandEncoder::CommandEncoder(DeviceBase* device, const CommandEncoderDescripto
     }
 }
 
-CommandEncoder::CommandEncoder(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag),
+CommandEncoder::CommandEncoder(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
+    : ApiObjectBase(device, tag, label),
       mEncodingContext(device, this),
       mUsageValidationMode(UsageValidationMode::Default) {
     mEncodingContext.HandleError(DAWN_VALIDATION_ERROR("%s is invalid.", this));
@@ -830,7 +830,8 @@ Ref<ComputePassEncoder> CommandEncoder::BeginComputePass(const ComputePassDescri
         return passEncoder;
     }
 
-    return ComputePassEncoder::MakeError(device, this, &mEncodingContext);
+    return ComputePassEncoder::MakeError(device, this, &mEncodingContext,
+                                         descriptor ? descriptor->label : nullptr);
 }
 
 RenderPassEncoder* CommandEncoder::APIBeginRenderPass(const RenderPassDescriptor* descriptor) {
@@ -1011,14 +1012,16 @@ Ref<RenderPassEncoder> CommandEncoder::BeginRenderPass(const RenderPassDescripto
             MaybeError error =
                 ApplyClearBigIntegerColorValueWithDraw(passEncoder.Get(), descriptor);
             if (error.IsError()) {
-                return RenderPassEncoder::MakeError(device, this, &mEncodingContext);
+                return RenderPassEncoder::MakeError(device, this, &mEncodingContext,
+                                                    descriptor ? descriptor->label : nullptr);
             }
         }
 
         return passEncoder;
     }
 
-    return RenderPassEncoder::MakeError(device, this, &mEncodingContext);
+    return RenderPassEncoder::MakeError(device, this, &mEncodingContext,
+                                        descriptor ? descriptor->label : nullptr);
 }
 
 // This function handles render pass workarounds. Because some cases may require
@@ -1627,7 +1630,7 @@ CommandBufferBase* CommandEncoder::APIFinish(const CommandBufferDescriptor* desc
 
     Ref<CommandBufferBase> commandBuffer;
     if (GetDevice()->ConsumedError(Finish(descriptor), &commandBuffer)) {
-        return CommandBufferBase::MakeError(GetDevice());
+        return CommandBufferBase::MakeError(GetDevice(), descriptor ? descriptor->label : nullptr);
     }
     ASSERT(!IsError());
     return commandBuffer.Detach();
diff --git a/src/dawn/native/CommandEncoder.h b/src/dawn/native/CommandEncoder.h
index 3b8f5fd52e..6b9d4a5404 100644
--- a/src/dawn/native/CommandEncoder.h
+++ b/src/dawn/native/CommandEncoder.h
@@ -40,7 +40,7 @@ class CommandEncoder final : public ApiObjectBase {
   public:
     static Ref<CommandEncoder> Create(DeviceBase* device,
                                       const CommandEncoderDescriptor* descriptor);
-    static CommandEncoder* MakeError(DeviceBase* device);
+    static CommandEncoder* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -119,7 +119,7 @@ class CommandEncoder final : public ApiObjectBase {
 
   private:
     CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor* descriptor);
-    CommandEncoder(DeviceBase* device, ObjectBase::ErrorTag tag);
+    CommandEncoder(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     void DestroyImpl() override;
 
diff --git a/src/dawn/native/ComputePassEncoder.cpp b/src/dawn/native/ComputePassEncoder.cpp
index 7fbf82b1c3..11254b6b55 100644
--- a/src/dawn/native/ComputePassEncoder.cpp
+++ b/src/dawn/native/ComputePassEncoder.cpp
@@ -128,15 +128,18 @@ Ref<ComputePassEncoder> ComputePassEncoder::Create(DeviceBase* device,
 ComputePassEncoder::ComputePassEncoder(DeviceBase* device,
                                        CommandEncoder* commandEncoder,
                                        EncodingContext* encodingContext,
-                                       ErrorTag errorTag)
-    : ProgrammableEncoder(device, encodingContext, errorTag), mCommandEncoder(commandEncoder) {}
+                                       ErrorTag errorTag,
+                                       const char* label)
+    : ProgrammableEncoder(device, encodingContext, errorTag, label),
+      mCommandEncoder(commandEncoder) {}
 
 // static
 Ref<ComputePassEncoder> ComputePassEncoder::MakeError(DeviceBase* device,
                                                       CommandEncoder* commandEncoder,
-                                                      EncodingContext* encodingContext) {
+                                                      EncodingContext* encodingContext,
+                                                      const char* label) {
     return AcquireRef(
-        new ComputePassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError));
+        new ComputePassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError, label));
 }
 
 void ComputePassEncoder::DestroyImpl() {
diff --git a/src/dawn/native/ComputePassEncoder.h b/src/dawn/native/ComputePassEncoder.h
index f48ef94cb7..ae5de357b0 100644
--- a/src/dawn/native/ComputePassEncoder.h
+++ b/src/dawn/native/ComputePassEncoder.h
@@ -36,7 +36,8 @@ class ComputePassEncoder final : public ProgrammableEncoder {
                                           EncodingContext* encodingContext);
     static Ref<ComputePassEncoder> MakeError(DeviceBase* device,
                                              CommandEncoder* commandEncoder,
-                                             EncodingContext* encodingContext);
+                                             EncodingContext* encodingContext,
+                                             const char* label);
 
     ObjectType GetType() const override;
 
@@ -75,7 +76,8 @@ class ComputePassEncoder final : public ProgrammableEncoder {
     ComputePassEncoder(DeviceBase* device,
                        CommandEncoder* commandEncoder,
                        EncodingContext* encodingContext,
-                       ErrorTag errorTag);
+                       ErrorTag errorTag,
+                       const char* label);
 
   private:
     void DestroyImpl() override;
diff --git a/src/dawn/native/ComputePipeline.cpp b/src/dawn/native/ComputePipeline.cpp
index 93d28040b5..99364e740b 100644
--- a/src/dawn/native/ComputePipeline.cpp
+++ b/src/dawn/native/ComputePipeline.cpp
@@ -56,8 +56,10 @@ ComputePipelineBase::ComputePipelineBase(DeviceBase* device,
     StreamIn(&mCacheKey, CacheKey::Type::ComputePipeline, device->GetCacheKey());
 }
 
-ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : PipelineBase(device, tag) {}
+ComputePipelineBase::ComputePipelineBase(DeviceBase* device,
+                                         ObjectBase::ErrorTag tag,
+                                         const char* label)
+    : PipelineBase(device, tag, label) {}
 
 ComputePipelineBase::~ComputePipelineBase() = default;
 
@@ -69,11 +71,11 @@ void ComputePipelineBase::DestroyImpl() {
 }
 
 // static
-ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) {
+ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device, const char* label) {
     class ErrorComputePipeline final : public ComputePipelineBase {
       public:
-        explicit ErrorComputePipeline(DeviceBase* device)
-            : ComputePipelineBase(device, ObjectBase::kError) {}
+        explicit ErrorComputePipeline(DeviceBase* device, const char* label)
+            : ComputePipelineBase(device, ObjectBase::kError, label) {}
 
         MaybeError Initialize() override {
             UNREACHABLE();
@@ -81,7 +83,7 @@ ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) {
         }
     };
 
-    return new ErrorComputePipeline(device);
+    return new ErrorComputePipeline(device, label);
 }
 
 ObjectType ComputePipelineBase::GetType() const {
diff --git a/src/dawn/native/ComputePipeline.h b/src/dawn/native/ComputePipeline.h
index f1345798c3..85794ecd86 100644
--- a/src/dawn/native/ComputePipeline.h
+++ b/src/dawn/native/ComputePipeline.h
@@ -32,7 +32,7 @@ class ComputePipelineBase : public PipelineBase {
     ComputePipelineBase(DeviceBase* device, const ComputePipelineDescriptor* descriptor);
     ~ComputePipelineBase() override;
 
-    static ComputePipelineBase* MakeError(DeviceBase* device);
+    static ComputePipelineBase* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -45,7 +45,7 @@ class ComputePipelineBase : public PipelineBase {
     void DestroyImpl() override;
 
   private:
-    ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 };
 
 }  // namespace dawn::native
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index dbd306c5b7..0cc3c4b56e 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -1107,7 +1107,7 @@ BindGroupBase* DeviceBase::APICreateBindGroup(const BindGroupDescriptor* descrip
     Ref<BindGroupBase> result;
     if (ConsumedError(CreateBindGroup(descriptor), &result, "calling %s.CreateBindGroup(%s).", this,
                       descriptor)) {
-        return BindGroupBase::MakeError(this);
+        return BindGroupBase::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1116,7 +1116,7 @@ BindGroupLayoutBase* DeviceBase::APICreateBindGroupLayout(
     Ref<BindGroupLayoutBase> result;
     if (ConsumedError(CreateBindGroupLayout(descriptor), &result,
                       "calling %s.CreateBindGroupLayout(%s).", this, descriptor)) {
-        return BindGroupLayoutBase::MakeError(this);
+        return BindGroupLayoutBase::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1133,7 +1133,7 @@ CommandEncoder* DeviceBase::APICreateCommandEncoder(const CommandEncoderDescript
     Ref<CommandEncoder> result;
     if (ConsumedError(CreateCommandEncoder(descriptor), &result,
                       "calling %s.CreateCommandEncoder(%s).", this, descriptor)) {
-        return CommandEncoder::MakeError(this);
+        return CommandEncoder::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1145,7 +1145,7 @@ ComputePipelineBase* DeviceBase::APICreateComputePipeline(
     Ref<ComputePipelineBase> result;
     if (ConsumedError(CreateComputePipeline(descriptor), &result,
                       "calling %s.CreateComputePipeline(%s).", this, descriptor)) {
-        return ComputePipelineBase::MakeError(this);
+        return ComputePipelineBase::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1176,7 +1176,7 @@ PipelineLayoutBase* DeviceBase::APICreatePipelineLayout(
     Ref<PipelineLayoutBase> result;
     if (ConsumedError(CreatePipelineLayout(descriptor), &result,
                       "calling %s.CreatePipelineLayout(%s).", this, descriptor)) {
-        return PipelineLayoutBase::MakeError(this);
+        return PipelineLayoutBase::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1192,7 +1192,7 @@ SamplerBase* DeviceBase::APICreateSampler(const SamplerDescriptor* descriptor) {
     Ref<SamplerBase> result;
     if (ConsumedError(CreateSampler(descriptor), &result, "calling %s.CreateSampler(%s).", this,
                       descriptor)) {
-        return SamplerBase::MakeError(this);
+        return SamplerBase::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1223,7 +1223,7 @@ RenderBundleEncoder* DeviceBase::APICreateRenderBundleEncoder(
     Ref<RenderBundleEncoder> result;
     if (ConsumedError(CreateRenderBundleEncoder(descriptor), &result,
                       "calling %s.CreateRenderBundleEncoder(%s).", this, descriptor)) {
-        return RenderBundleEncoder::MakeError(this);
+        return RenderBundleEncoder::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1235,7 +1235,7 @@ RenderPipelineBase* DeviceBase::APICreateRenderPipeline(
     Ref<RenderPipelineBase> result;
     if (ConsumedError(CreateRenderPipeline(descriptor), &result,
                       "calling %s.CreateRenderPipeline(%s).", this, descriptor)) {
-        return RenderPipelineBase::MakeError(this);
+        return RenderPipelineBase::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -1249,7 +1249,7 @@ ShaderModuleBase* DeviceBase::APICreateShaderModule(const ShaderModuleDescriptor
     if (ConsumedError(CreateShaderModule(descriptor, compilationMessages.get()), &result,
                       "calling %s.CreateShaderModule(%s).", this, descriptor)) {
         DAWN_ASSERT(result == nullptr);
-        result = ShaderModuleBase::MakeError(this);
+        result = ShaderModuleBase::MakeError(this, descriptor ? descriptor->label : nullptr);
     }
     // Move compilation messages into ShaderModuleBase and emit tint errors and warnings
     // after all other operations are finished, even if any of them is failed and result
diff --git a/src/dawn/native/ExternalTexture.cpp b/src/dawn/native/ExternalTexture.cpp
index 118b25c944..8b082fcb52 100644
--- a/src/dawn/native/ExternalTexture.cpp
+++ b/src/dawn/native/ExternalTexture.cpp
@@ -138,8 +138,10 @@ ExternalTextureBase::ExternalTextureBase(DeviceBase* device,
 }
 
 // Error external texture cannot be used in bind group.
-ExternalTextureBase::ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag), mState(ExternalTextureState::Destroyed) {}
+ExternalTextureBase::ExternalTextureBase(DeviceBase* device,
+                                         ObjectBase::ErrorTag tag,
+                                         const char* label)
+    : ApiObjectBase(device, tag, label), mState(ExternalTextureState::Destroyed) {}
 
 ExternalTextureBase::~ExternalTextureBase() = default;
 
@@ -371,8 +373,8 @@ void ExternalTextureBase::DestroyImpl() {
 }
 
 // static
-ExternalTextureBase* ExternalTextureBase::MakeError(DeviceBase* device) {
-    return new ExternalTextureBase(device, ObjectBase::kError);
+ExternalTextureBase* ExternalTextureBase::MakeError(DeviceBase* device, const char* label) {
+    return new ExternalTextureBase(device, ObjectBase::kError, label);
 }
 
 BufferBase* ExternalTextureBase::GetParamsBuffer() const {
diff --git a/src/dawn/native/ExternalTexture.h b/src/dawn/native/ExternalTexture.h
index b804bf725a..36a4579fe8 100644
--- a/src/dawn/native/ExternalTexture.h
+++ b/src/dawn/native/ExternalTexture.h
@@ -55,7 +55,7 @@ class ExternalTextureBase : public ApiObjectBase {
     const Origin2D& GetVisibleOrigin() const;
 
     MaybeError ValidateCanUseInSubmitNow() const;
-    static ExternalTextureBase* MakeError(DeviceBase* device);
+    static ExternalTextureBase* MakeError(DeviceBase* device, const char* label = nullptr);
 
     void APIExpire();
     void APIDestroy();
@@ -71,7 +71,7 @@ class ExternalTextureBase : public ApiObjectBase {
 
   private:
     enum class ExternalTextureState { Active, Expired, Destroyed };
-    ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     MaybeError ValidateRefresh();
     MaybeError ValidateExpire();
diff --git a/src/dawn/native/ObjectBase.cpp b/src/dawn/native/ObjectBase.cpp
index be9331c97a..859ebc0c3e 100644
--- a/src/dawn/native/ObjectBase.cpp
+++ b/src/dawn/native/ObjectBase.cpp
@@ -68,7 +68,12 @@ ApiObjectBase::ApiObjectBase(DeviceBase* device, const char* label) : ObjectBase
     }
 }
 
-ApiObjectBase::ApiObjectBase(DeviceBase* device, ErrorTag tag) : ObjectBase(device, tag) {}
+ApiObjectBase::ApiObjectBase(DeviceBase* device, ErrorTag tag, const char* label)
+    : ObjectBase(device, tag) {
+    if (label) {
+        mLabel = label;
+    }
+}
 
 ApiObjectBase::ApiObjectBase(DeviceBase* device, LabelNotImplementedTag tag) : ObjectBase(device) {}
 
diff --git a/src/dawn/native/ObjectBase.h b/src/dawn/native/ObjectBase.h
index 3bb77d20ee..daf5cc88c5 100644
--- a/src/dawn/native/ObjectBase.h
+++ b/src/dawn/native/ObjectBase.h
@@ -79,7 +79,7 @@ class ApiObjectBase : public ObjectBase, public LinkNode<ApiObjectBase> {
 
     ApiObjectBase(DeviceBase* device, LabelNotImplementedTag tag);
     ApiObjectBase(DeviceBase* device, const char* label);
-    ApiObjectBase(DeviceBase* device, ErrorTag tag);
+    ApiObjectBase(DeviceBase* device, ErrorTag tag, const char* label = nullptr);
     ~ApiObjectBase() override;
 
     virtual ObjectType GetType() const = 0;
diff --git a/src/dawn/native/Pipeline.cpp b/src/dawn/native/Pipeline.cpp
index cffeaa300f..3e2dada7dd 100644
--- a/src/dawn/native/Pipeline.cpp
+++ b/src/dawn/native/Pipeline.cpp
@@ -213,8 +213,8 @@ PipelineBase::PipelineBase(DeviceBase* device,
     }
 }
 
-PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag) {}
+PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
+    : ApiObjectBase(device, tag, label) {}
 
 PipelineBase::~PipelineBase() = default;
 
diff --git a/src/dawn/native/Pipeline.h b/src/dawn/native/Pipeline.h
index ac879e4d3e..aaee3f2194 100644
--- a/src/dawn/native/Pipeline.h
+++ b/src/dawn/native/Pipeline.h
@@ -81,7 +81,7 @@ class PipelineBase : public ApiObjectBase, public CachedObject {
                  PipelineLayoutBase* layout,
                  const char* label,
                  std::vector<StageAndDescriptor> stages);
-    PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
   private:
     MaybeError ValidateGetBindGroupLayout(BindGroupIndex group);
diff --git a/src/dawn/native/PipelineLayout.cpp b/src/dawn/native/PipelineLayout.cpp
index 93e915f308..82f40ce59f 100644
--- a/src/dawn/native/PipelineLayout.cpp
+++ b/src/dawn/native/PipelineLayout.cpp
@@ -74,8 +74,10 @@ PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device,
     GetObjectTrackingList()->Track(this);
 }
 
-PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag) {}
+PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device,
+                                       ObjectBase::ErrorTag tag,
+                                       const char* label)
+    : ApiObjectBase(device, tag, label) {}
 
 PipelineLayoutBase::~PipelineLayoutBase() = default;
 
@@ -87,8 +89,8 @@ void PipelineLayoutBase::DestroyImpl() {
 }
 
 // static
-PipelineLayoutBase* PipelineLayoutBase::MakeError(DeviceBase* device) {
-    return new PipelineLayoutBase(device, ObjectBase::kError);
+PipelineLayoutBase* PipelineLayoutBase::MakeError(DeviceBase* device, const char* label) {
+    return new PipelineLayoutBase(device, ObjectBase::kError, label);
 }
 
 // static
diff --git a/src/dawn/native/PipelineLayout.h b/src/dawn/native/PipelineLayout.h
index 11e998226c..f1b4358534 100644
--- a/src/dawn/native/PipelineLayout.h
+++ b/src/dawn/native/PipelineLayout.h
@@ -57,7 +57,7 @@ class PipelineLayoutBase : public ApiObjectBase, public CachedObject {
     PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor);
     ~PipelineLayoutBase() override;
 
-    static PipelineLayoutBase* MakeError(DeviceBase* device);
+    static PipelineLayoutBase* MakeError(DeviceBase* device, const char* label);
     static ResultOrError<Ref<PipelineLayoutBase>> CreateDefault(
         DeviceBase* device,
         std::vector<StageAndDescriptor> stages);
@@ -84,7 +84,7 @@ class PipelineLayoutBase : public ApiObjectBase, public CachedObject {
     };
 
   protected:
-    PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
     void DestroyImpl() override;
 
     BindGroupLayoutArray mBindGroupLayouts;
diff --git a/src/dawn/native/ProgrammableEncoder.cpp b/src/dawn/native/ProgrammableEncoder.cpp
index ce3140b289..07b44e7357 100644
--- a/src/dawn/native/ProgrammableEncoder.cpp
+++ b/src/dawn/native/ProgrammableEncoder.cpp
@@ -37,8 +37,9 @@ ProgrammableEncoder::ProgrammableEncoder(DeviceBase* device,
 
 ProgrammableEncoder::ProgrammableEncoder(DeviceBase* device,
                                          EncodingContext* encodingContext,
-                                         ErrorTag errorTag)
-    : ApiObjectBase(device, errorTag),
+                                         ErrorTag errorTag,
+                                         const char* label)
+    : ApiObjectBase(device, errorTag, label),
       mEncodingContext(encodingContext),
       mValidationEnabled(device->IsValidationEnabled()) {}
 
diff --git a/src/dawn/native/ProgrammableEncoder.h b/src/dawn/native/ProgrammableEncoder.h
index 25b730f3a8..cbbeeedb51 100644
--- a/src/dawn/native/ProgrammableEncoder.h
+++ b/src/dawn/native/ProgrammableEncoder.h
@@ -53,7 +53,10 @@ class ProgrammableEncoder : public ApiObjectBase {
                             const uint32_t* dynamicOffsets) const;
 
     // Construct an "error" programmable pass encoder.
-    ProgrammableEncoder(DeviceBase* device, EncodingContext* encodingContext, ErrorTag errorTag);
+    ProgrammableEncoder(DeviceBase* device,
+                        EncodingContext* encodingContext,
+                        ErrorTag errorTag,
+                        const char* label);
 
     EncodingContext* mEncodingContext = nullptr;
 
diff --git a/src/dawn/native/QuerySet.cpp b/src/dawn/native/QuerySet.cpp
index 327f304775..8f4047583f 100644
--- a/src/dawn/native/QuerySet.cpp
+++ b/src/dawn/native/QuerySet.cpp
@@ -114,7 +114,9 @@ QuerySetBase::QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descrip
 QuerySetBase::QuerySetBase(DeviceBase* device,
                            const QuerySetDescriptor* descriptor,
                            ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag), mQueryType(descriptor->type), mQueryCount(descriptor->count) {}
+    : ApiObjectBase(device, tag, descriptor->label),
+      mQueryType(descriptor->type),
+      mQueryCount(descriptor->count) {}
 
 QuerySetBase::~QuerySetBase() {
     // Uninitialized or already destroyed
diff --git a/src/dawn/native/Queue.cpp b/src/dawn/native/Queue.cpp
index 4fee1c0917..18039d05fc 100644
--- a/src/dawn/native/Queue.cpp
+++ b/src/dawn/native/Queue.cpp
@@ -159,7 +159,8 @@ struct SubmittedWorkDone : TrackTaskCallback {
 
 class ErrorQueue : public QueueBase {
   public:
-    explicit ErrorQueue(DeviceBase* device) : QueueBase(device, ObjectBase::kError) {}
+    explicit ErrorQueue(DeviceBase* device, const char* label)
+        : QueueBase(device, ObjectBase::kError, label) {}
 
   private:
     MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override {
@@ -177,7 +178,8 @@ void TrackTaskCallback::SetFinishedSerial(ExecutionSerial serial) {
 QueueBase::QueueBase(DeviceBase* device, const QueueDescriptor* descriptor)
     : ApiObjectBase(device, descriptor->label) {}
 
-QueueBase::QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag) : ApiObjectBase(device, tag) {}
+QueueBase::QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
+    : ApiObjectBase(device, tag, label) {}
 
 QueueBase::~QueueBase() {
     ASSERT(mTasksInFlight.Empty());
@@ -186,8 +188,8 @@ QueueBase::~QueueBase() {
 void QueueBase::DestroyImpl() {}
 
 // static
-QueueBase* QueueBase::MakeError(DeviceBase* device) {
-    return new ErrorQueue(device);
+QueueBase* QueueBase::MakeError(DeviceBase* device, const char* label) {
+    return new ErrorQueue(device, label);
 }
 
 ObjectType QueueBase::GetType() const {
diff --git a/src/dawn/native/Queue.h b/src/dawn/native/Queue.h
index 61227a6a34..b95e5084f0 100644
--- a/src/dawn/native/Queue.h
+++ b/src/dawn/native/Queue.h
@@ -49,7 +49,7 @@ class QueueBase : public ApiObjectBase {
   public:
     ~QueueBase() override;
 
-    static QueueBase* MakeError(DeviceBase* device);
+    static QueueBase* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -84,7 +84,7 @@ class QueueBase : public ApiObjectBase {
 
   protected:
     QueueBase(DeviceBase* device, const QueueDescriptor* descriptor);
-    QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
     void DestroyImpl() override;
 
   private:
diff --git a/src/dawn/native/RenderBundle.cpp b/src/dawn/native/RenderBundle.cpp
index c200cbe9da..0dd96baa10 100644
--- a/src/dawn/native/RenderBundle.cpp
+++ b/src/dawn/native/RenderBundle.cpp
@@ -51,12 +51,12 @@ void RenderBundleBase::DestroyImpl() {
 }
 
 // static
-RenderBundleBase* RenderBundleBase::MakeError(DeviceBase* device) {
-    return new RenderBundleBase(device, ObjectBase::kError);
+RenderBundleBase* RenderBundleBase::MakeError(DeviceBase* device, const char* label) {
+    return new RenderBundleBase(device, ObjectBase::kError, label);
 }
 
-RenderBundleBase::RenderBundleBase(DeviceBase* device, ErrorTag errorTag)
-    : ApiObjectBase(device, errorTag), mIndirectDrawMetadata(device->GetLimits()) {}
+RenderBundleBase::RenderBundleBase(DeviceBase* device, ErrorTag errorTag, const char* label)
+    : ApiObjectBase(device, errorTag, label), mIndirectDrawMetadata(device->GetLimits()) {}
 
 ObjectType RenderBundleBase::GetType() const {
     return ObjectType::RenderBundle;
diff --git a/src/dawn/native/RenderBundle.h b/src/dawn/native/RenderBundle.h
index f86eb5fbf1..6bae2b6769 100644
--- a/src/dawn/native/RenderBundle.h
+++ b/src/dawn/native/RenderBundle.h
@@ -43,7 +43,7 @@ class RenderBundleBase final : public ApiObjectBase {
                      RenderPassResourceUsage resourceUsage,
                      IndirectDrawMetadata indirectDrawMetadata);
 
-    static RenderBundleBase* MakeError(DeviceBase* device);
+    static RenderBundleBase* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -57,7 +57,7 @@ class RenderBundleBase final : public ApiObjectBase {
     const IndirectDrawMetadata& GetIndirectDrawMetadata();
 
   private:
-    RenderBundleBase(DeviceBase* device, ErrorTag errorTag);
+    RenderBundleBase(DeviceBase* device, ErrorTag errorTag, const char* label);
 
     void DestroyImpl() override;
 
diff --git a/src/dawn/native/RenderBundleEncoder.cpp b/src/dawn/native/RenderBundleEncoder.cpp
index 7649a3b09f..ce1c4ae511 100644
--- a/src/dawn/native/RenderBundleEncoder.cpp
+++ b/src/dawn/native/RenderBundleEncoder.cpp
@@ -108,8 +108,8 @@ RenderBundleEncoder::RenderBundleEncoder(DeviceBase* device,
     GetObjectTrackingList()->Track(this);
 }
 
-RenderBundleEncoder::RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag)
-    : RenderEncoderBase(device, &mBundleEncodingContext, errorTag),
+RenderBundleEncoder::RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag, const char* label)
+    : RenderEncoderBase(device, &mBundleEncodingContext, errorTag, label),
       mBundleEncodingContext(device, this) {}
 
 void RenderBundleEncoder::DestroyImpl() {
@@ -125,8 +125,8 @@ Ref<RenderBundleEncoder> RenderBundleEncoder::Create(
 }
 
 // static
-RenderBundleEncoder* RenderBundleEncoder::MakeError(DeviceBase* device) {
-    return new RenderBundleEncoder(device, ObjectBase::kError);
+RenderBundleEncoder* RenderBundleEncoder::MakeError(DeviceBase* device, const char* label) {
+    return new RenderBundleEncoder(device, ObjectBase::kError, label);
 }
 
 ObjectType RenderBundleEncoder::GetType() const {
@@ -142,7 +142,7 @@ RenderBundleBase* RenderBundleEncoder::APIFinish(const RenderBundleDescriptor* d
 
     if (GetDevice()->ConsumedError(FinishImpl(descriptor), &result, "calling %s.Finish(%s).", this,
                                    descriptor)) {
-        return RenderBundleBase::MakeError(GetDevice());
+        return RenderBundleBase::MakeError(GetDevice(), descriptor ? descriptor->label : nullptr);
     }
 
     return result;
diff --git a/src/dawn/native/RenderBundleEncoder.h b/src/dawn/native/RenderBundleEncoder.h
index b8a9d61502..c1daa07ecb 100644
--- a/src/dawn/native/RenderBundleEncoder.h
+++ b/src/dawn/native/RenderBundleEncoder.h
@@ -30,7 +30,7 @@ class RenderBundleEncoder final : public RenderEncoderBase {
   public:
     static Ref<RenderBundleEncoder> Create(DeviceBase* device,
                                            const RenderBundleEncoderDescriptor* descriptor);
-    static RenderBundleEncoder* MakeError(DeviceBase* device);
+    static RenderBundleEncoder* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -40,7 +40,7 @@ class RenderBundleEncoder final : public RenderEncoderBase {
 
   private:
     RenderBundleEncoder(DeviceBase* device, const RenderBundleEncoderDescriptor* descriptor);
-    RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag);
+    RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag, const char* label);
 
     void DestroyImpl() override;
 
diff --git a/src/dawn/native/RenderEncoderBase.cpp b/src/dawn/native/RenderEncoderBase.cpp
index 36aa9e12b7..6a989c780c 100644
--- a/src/dawn/native/RenderEncoderBase.cpp
+++ b/src/dawn/native/RenderEncoderBase.cpp
@@ -47,8 +47,9 @@ RenderEncoderBase::RenderEncoderBase(DeviceBase* device,
 
 RenderEncoderBase::RenderEncoderBase(DeviceBase* device,
                                      EncodingContext* encodingContext,
-                                     ErrorTag errorTag)
-    : ProgrammableEncoder(device, encodingContext, errorTag),
+                                     ErrorTag errorTag,
+                                     const char* label)
+    : ProgrammableEncoder(device, encodingContext, errorTag, label),
       mIndirectDrawMetadata(device->GetLimits()),
       mDisableBaseVertex(device->IsToggleEnabled(Toggle::DisableBaseVertex)),
       mDisableBaseInstance(device->IsToggleEnabled(Toggle::DisableBaseInstance)) {}
diff --git a/src/dawn/native/RenderEncoderBase.h b/src/dawn/native/RenderEncoderBase.h
index 0cb675a719..1407f44bc9 100644
--- a/src/dawn/native/RenderEncoderBase.h
+++ b/src/dawn/native/RenderEncoderBase.h
@@ -67,7 +67,10 @@ class RenderEncoderBase : public ProgrammableEncoder {
 
   protected:
     // Construct an "error" render encoder base.
-    RenderEncoderBase(DeviceBase* device, EncodingContext* encodingContext, ErrorTag errorTag);
+    RenderEncoderBase(DeviceBase* device,
+                      EncodingContext* encodingContext,
+                      ErrorTag errorTag,
+                      const char* label);
 
     void DestroyImpl() override;
 
diff --git a/src/dawn/native/RenderPassEncoder.cpp b/src/dawn/native/RenderPassEncoder.cpp
index aaba03f3a1..5b0b318a09 100644
--- a/src/dawn/native/RenderPassEncoder.cpp
+++ b/src/dawn/native/RenderPassEncoder.cpp
@@ -102,15 +102,18 @@ Ref<RenderPassEncoder> RenderPassEncoder::Create(DeviceBase* device,
 RenderPassEncoder::RenderPassEncoder(DeviceBase* device,
                                      CommandEncoder* commandEncoder,
                                      EncodingContext* encodingContext,
-                                     ErrorTag errorTag)
-    : RenderEncoderBase(device, encodingContext, errorTag), mCommandEncoder(commandEncoder) {}
+                                     ErrorTag errorTag,
+                                     const char* label)
+    : RenderEncoderBase(device, encodingContext, errorTag, label),
+      mCommandEncoder(commandEncoder) {}
 
 // static
 Ref<RenderPassEncoder> RenderPassEncoder::MakeError(DeviceBase* device,
                                                     CommandEncoder* commandEncoder,
-                                                    EncodingContext* encodingContext) {
+                                                    EncodingContext* encodingContext,
+                                                    const char* label) {
     return AcquireRef(
-        new RenderPassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError));
+        new RenderPassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError, label));
 }
 
 void RenderPassEncoder::DestroyImpl() {
diff --git a/src/dawn/native/RenderPassEncoder.h b/src/dawn/native/RenderPassEncoder.h
index 592869dc37..c0f596f4d9 100644
--- a/src/dawn/native/RenderPassEncoder.h
+++ b/src/dawn/native/RenderPassEncoder.h
@@ -40,7 +40,8 @@ class RenderPassEncoder final : public RenderEncoderBase {
                                          std::function<void()> endCallback = nullptr);
     static Ref<RenderPassEncoder> MakeError(DeviceBase* device,
                                             CommandEncoder* commandEncoder,
-                                            EncodingContext* encodingContext);
+                                            EncodingContext* encodingContext,
+                                            const char* label);
 
     ObjectType GetType() const override;
 
@@ -84,7 +85,8 @@ class RenderPassEncoder final : public RenderEncoderBase {
     RenderPassEncoder(DeviceBase* device,
                       CommandEncoder* commandEncoder,
                       EncodingContext* encodingContext,
-                      ErrorTag errorTag);
+                      ErrorTag errorTag,
+                      const char* label);
 
   private:
     void DestroyImpl() override;
diff --git a/src/dawn/native/RenderPipeline.cpp b/src/dawn/native/RenderPipeline.cpp
index f3d26be1c5..48f96fb16b 100644
--- a/src/dawn/native/RenderPipeline.cpp
+++ b/src/dawn/native/RenderPipeline.cpp
@@ -730,8 +730,10 @@ RenderPipelineBase::RenderPipelineBase(DeviceBase* device,
     StreamIn(&mCacheKey, CacheKey::Type::RenderPipeline, device->GetCacheKey());
 }
 
-RenderPipelineBase::RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : PipelineBase(device, tag) {}
+RenderPipelineBase::RenderPipelineBase(DeviceBase* device,
+                                       ObjectBase::ErrorTag tag,
+                                       const char* label)
+    : PipelineBase(device, tag, label) {}
 
 RenderPipelineBase::~RenderPipelineBase() = default;
 
@@ -747,11 +749,11 @@ void RenderPipelineBase::DestroyImpl() {
 }
 
 // static
-RenderPipelineBase* RenderPipelineBase::MakeError(DeviceBase* device) {
+RenderPipelineBase* RenderPipelineBase::MakeError(DeviceBase* device, const char* label) {
     class ErrorRenderPipeline final : public RenderPipelineBase {
       public:
-        explicit ErrorRenderPipeline(DeviceBase* device)
-            : RenderPipelineBase(device, ObjectBase::kError) {}
+        explicit ErrorRenderPipeline(DeviceBase* device, const char* label)
+            : RenderPipelineBase(device, ObjectBase::kError, label) {}
 
         MaybeError Initialize() override {
             UNREACHABLE();
@@ -759,7 +761,7 @@ RenderPipelineBase* RenderPipelineBase::MakeError(DeviceBase* device) {
         }
     };
 
-    return new ErrorRenderPipeline(device);
+    return new ErrorRenderPipeline(device, label);
 }
 
 ObjectType RenderPipelineBase::GetType() const {
diff --git a/src/dawn/native/RenderPipeline.h b/src/dawn/native/RenderPipeline.h
index 2f374733a7..ad5593a0c2 100644
--- a/src/dawn/native/RenderPipeline.h
+++ b/src/dawn/native/RenderPipeline.h
@@ -65,7 +65,7 @@ class RenderPipelineBase : public PipelineBase {
     RenderPipelineBase(DeviceBase* device, const RenderPipelineDescriptor* descriptor);
     ~RenderPipelineBase() override;
 
-    static RenderPipelineBase* MakeError(DeviceBase* device);
+    static RenderPipelineBase* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -116,7 +116,7 @@ class RenderPipelineBase : public PipelineBase {
     void DestroyImpl() override;
 
   private:
-    RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     // Vertex state
     uint32_t mVertexBufferCount;
diff --git a/src/dawn/native/Sampler.cpp b/src/dawn/native/Sampler.cpp
index 8f1b7b92ef..8b35dc8c48 100644
--- a/src/dawn/native/Sampler.cpp
+++ b/src/dawn/native/Sampler.cpp
@@ -89,8 +89,8 @@ SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor
     GetObjectTrackingList()->Track(this);
 }
 
-SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag) {}
+SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
+    : ApiObjectBase(device, tag, label) {}
 
 SamplerBase::~SamplerBase() = default;
 
@@ -102,8 +102,8 @@ void SamplerBase::DestroyImpl() {
 }
 
 // static
-SamplerBase* SamplerBase::MakeError(DeviceBase* device) {
-    return new SamplerBase(device, ObjectBase::kError);
+SamplerBase* SamplerBase::MakeError(DeviceBase* device, const char* label) {
+    return new SamplerBase(device, ObjectBase::kError, label);
 }
 
 ObjectType SamplerBase::GetType() const {
diff --git a/src/dawn/native/Sampler.h b/src/dawn/native/Sampler.h
index 1384327e72..181a1a471d 100644
--- a/src/dawn/native/Sampler.h
+++ b/src/dawn/native/Sampler.h
@@ -36,7 +36,7 @@ class SamplerBase : public ApiObjectBase, public CachedObject {
     SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor);
     ~SamplerBase() override;
 
-    static SamplerBase* MakeError(DeviceBase* device);
+    static SamplerBase* MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -56,7 +56,7 @@ class SamplerBase : public ApiObjectBase, public CachedObject {
     void DestroyImpl() override;
 
   private:
-    SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     // TODO(cwallez@chromium.org): Store a crypto hash of the items instead?
     wgpu::AddressMode mAddressModeU;
diff --git a/src/dawn/native/ShaderModule.cpp b/src/dawn/native/ShaderModule.cpp
index ae45a32d08..262bce18bc 100644
--- a/src/dawn/native/ShaderModule.cpp
+++ b/src/dawn/native/ShaderModule.cpp
@@ -1110,8 +1110,8 @@ ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescrip
     GetObjectTrackingList()->Track(this);
 }
 
-ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag), mType(Type::Undefined) {}
+ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
+    : ApiObjectBase(device, tag, label), mType(Type::Undefined) {}
 
 ShaderModuleBase::~ShaderModuleBase() = default;
 
@@ -1123,8 +1123,8 @@ void ShaderModuleBase::DestroyImpl() {
 }
 
 // static
-Ref<ShaderModuleBase> ShaderModuleBase::MakeError(DeviceBase* device) {
-    return AcquireRef(new ShaderModuleBase(device, ObjectBase::kError));
+Ref<ShaderModuleBase> ShaderModuleBase::MakeError(DeviceBase* device, const char* label) {
+    return AcquireRef(new ShaderModuleBase(device, ObjectBase::kError, label));
 }
 
 ObjectType ShaderModuleBase::GetType() const {
diff --git a/src/dawn/native/ShaderModule.h b/src/dawn/native/ShaderModule.h
index 5d33cd22ce..bd3d2562f9 100644
--- a/src/dawn/native/ShaderModule.h
+++ b/src/dawn/native/ShaderModule.h
@@ -258,7 +258,7 @@ class ShaderModuleBase : public ApiObjectBase, public CachedObject {
     ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor);
     ~ShaderModuleBase() override;
 
-    static Ref<ShaderModuleBase> MakeError(DeviceBase* device);
+    static Ref<ShaderModuleBase> MakeError(DeviceBase* device, const char* label);
 
     ObjectType GetType() const override;
 
@@ -292,7 +292,7 @@ class ShaderModuleBase : public ApiObjectBase, public CachedObject {
                               OwnedCompilationMessages* compilationMessages);
 
   private:
-    ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     // The original data in the descriptor for caching.
     enum class Type { Undefined, Spirv, Wgsl };
diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp
index 5c13abf28b..b188b766a1 100644
--- a/src/dawn/native/Texture.cpp
+++ b/src/dawn/native/Texture.cpp
@@ -584,7 +584,7 @@ static constexpr Format kUnusedFormat;
 TextureBase::TextureBase(DeviceBase* device,
                          const TextureDescriptor* descriptor,
                          ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag),
+    : ApiObjectBase(device, tag, descriptor->label),
       mDimension(descriptor->dimension),
       mFormat(kUnusedFormat),
       mSize(descriptor->size),
@@ -796,7 +796,7 @@ TextureViewBase* TextureBase::APICreateView(const TextureViewDescriptor* descrip
     Ref<TextureViewBase> result;
     if (device->ConsumedError(CreateView(descriptor), &result, "calling %s.CreateView(%s).", this,
                               descriptor)) {
-        return TextureViewBase::MakeError(device);
+        return TextureViewBase::MakeError(device, descriptor ? descriptor->label : nullptr);
     }
     return result.Detach();
 }
@@ -849,16 +849,16 @@ TextureViewBase::TextureViewBase(TextureBase* texture, const TextureViewDescript
     GetObjectTrackingList()->Track(this);
 }
 
-TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag)
-    : ApiObjectBase(device, tag), mFormat(kUnusedFormat) {}
+TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
+    : ApiObjectBase(device, tag, label), mFormat(kUnusedFormat) {}
 
 TextureViewBase::~TextureViewBase() = default;
 
 void TextureViewBase::DestroyImpl() {}
 
 // static
-TextureViewBase* TextureViewBase::MakeError(DeviceBase* device) {
-    return new TextureViewBase(device, ObjectBase::kError);
+TextureViewBase* TextureViewBase::MakeError(DeviceBase* device, const char* label) {
+    return new TextureViewBase(device, ObjectBase::kError, label);
 }
 
 ObjectType TextureViewBase::GetType() const {
diff --git a/src/dawn/native/Texture.h b/src/dawn/native/Texture.h
index b6c2143d0b..54676d0540 100644
--- a/src/dawn/native/Texture.h
+++ b/src/dawn/native/Texture.h
@@ -140,7 +140,7 @@ class TextureViewBase : public ApiObjectBase {
     TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor);
     ~TextureViewBase() override;
 
-    static TextureViewBase* MakeError(DeviceBase* device);
+    static TextureViewBase* MakeError(DeviceBase* device, const char* label = nullptr);
 
     ObjectType GetType() const override;
 
@@ -160,7 +160,7 @@ class TextureViewBase : public ApiObjectBase {
     void DestroyImpl() override;
 
   private:
-    TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag);
+    TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label);
 
     ApiObjectList* GetObjectTrackingList() override;