Skip Unneccessary GetPendingCommandContext() Call To Save An Extra Fence

GetPendingCommandContext() call might create a new commandList. Dawn handles
it in Tick() by executing this commandList and signal a fence even it is empty.
Skip the unnecessary GetPendingCommandContext() call saves an extra fence and might
resolve the callback for MapAsync earlier.

Bug: dawn:1335
Change-Id: I07f82388edb6978473eeaa2ed0834edbb5e1f497
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86621
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
diff --git a/src/dawn/native/d3d12/BufferD3D12.cpp b/src/dawn/native/d3d12/BufferD3D12.cpp
index 27d9991..84fbbb6 100644
--- a/src/dawn/native/d3d12/BufferD3D12.cpp
+++ b/src/dawn/native/d3d12/BufferD3D12.cpp
@@ -354,9 +354,14 @@
     }
 
     MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) {
-        CommandRecordingContext* commandContext;
-        DAWN_TRY_ASSIGN(commandContext, ToBackend(GetDevice())->GetPendingCommandContext());
-        DAWN_TRY(EnsureDataInitialized(commandContext));
+        // GetPendingCommandContext() call might create a new commandList. Dawn will handle
+        // it in Tick() by execute the commandList and signal a fence for it even it is empty.
+        // Skip the unnecessary GetPendingCommandContext() call saves an extra fence.
+        if (NeedsInitialization()) {
+            CommandRecordingContext* commandContext;
+            DAWN_TRY_ASSIGN(commandContext, ToBackend(GetDevice())->GetPendingCommandContext());
+            DAWN_TRY(EnsureDataInitialized(commandContext));
+        }
 
         return MapInternal(mode & wgpu::MapMode::Write, offset, size, "D3D12 map async");
     }