Add device lock around depth blit workarounds

The device lock needs to be acquired before calling
these workarounds which allocate new objects.

Fixes failures seen in:
https://ci.chromium.org/ui/p/chromium/builders/ci/Dawn%20Win10%20x64%20Release%20%28Intel%29/4702/overview

Bug: dawn:1782, dawn:1618
Change-Id: Iaab42e3244ecf127d217548a72f28e7b3e9237bb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/136185
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Shrek Shao <shrekshao@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp
index 7e251b4..371e1b4 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -1359,6 +1359,11 @@
                     (format.format == wgpu::TextureFormat::Depth32Float &&
                      GetDevice()->IsToggleEnabled(
                          Toggle::UseBlitForDepth32FloatTextureToBufferCopy))) {
+                    // This function might create new resources. Need to lock the Device.
+                    // TODO(crbug.com/dawn/1618): In future, all temp resources should be created at
+                    // Command Submit time, so the locking would be removed from here at that point.
+                    auto deviceLock(GetDevice()->GetScopedLock());
+
                     TextureCopy src;
                     src.texture = source->texture;
                     src.origin = source->origin;
@@ -1378,6 +1383,11 @@
                 }
             } else if (aspect == Aspect::Stencil) {
                 if (GetDevice()->IsToggleEnabled(Toggle::UseBlitForStencilTextureToBufferCopy)) {
+                    // This function might create new resources. Need to lock the Device.
+                    // TODO(crbug.com/dawn/1618): In future, all temp resources should be created at
+                    // Command Submit time, so the locking would be removed from here at that point.
+                    auto deviceLock(GetDevice()->GetScopedLock());
+
                     TextureCopy src;
                     src.texture = source->texture;
                     src.origin = source->origin;