Cleanup d3d12::Device::ExecuteCommandLists

- All callers were passing either 0 or 1 commandlist to this
function. Removing the initializer list means we can save an
std::vector heap allocation.
- Checking the number of lists before calling ExecuteCommandLists
eliminates superfluous entries in PIX logs.

Bug:dawn:222
Change-Id: Ic50b9293c3f31bf8f52e7de10161fd284ef2e0f7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11060
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp
index e925a77..c4e5e96 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn_native/d3d12/DeviceD3D12.cpp
@@ -224,7 +224,7 @@
         mDescriptorHeapAllocator->Tick(mCompletedSerial);
         mMapRequestTracker->Tick(mCompletedSerial);
         mUsedComObjectRefs.ClearUpTo(mCompletedSerial);
-        ExecuteCommandLists({});
+        ExecuteCommandList(nullptr);
         NextSerial();
     }
 
@@ -245,21 +245,22 @@
         mUsedComObjectRefs.Enqueue(object, GetPendingCommandSerial());
     }
 
-    void Device::ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists) {
+    void Device::ExecuteCommandList(ID3D12CommandList* d3d12CommandList) {
+        UINT numLists = 0;
+        std::array<ID3D12CommandList*, 2> d3d12CommandLists;
+
         // If there are pending commands, prepend them to ExecuteCommandLists
         if (mPendingCommands.open) {
-            std::vector<ID3D12CommandList*> lists(commandLists.size() + 1);
             mPendingCommands.commandList->Close();
             mPendingCommands.open = false;
-            lists[0] = mPendingCommands.commandList.Get();
-            std::copy(commandLists.begin(), commandLists.end(), lists.begin() + 1);
-            mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size() + 1),
-                                               lists.data());
-            mPendingCommands.commandList = nullptr;
-        } else {
-            std::vector<ID3D12CommandList*> lists(commandLists);
-            mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size()),
-                                               lists.data());
+            d3d12CommandLists[numLists++] = mPendingCommands.commandList.Get();
+        }
+        if (d3d12CommandList != nullptr) {
+            d3d12CommandLists[numLists++] = d3d12CommandList;
+        }
+        if (numLists > 0) {
+            mCommandQueue->ExecuteCommandLists(numLists, d3d12CommandLists.data());
+            mPendingCommands.commandList.Reset();
         }
     }
 
diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h
index 237c8b4..e5a3734 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.h
+++ b/src/dawn_native/d3d12/DeviceD3D12.h
@@ -73,7 +73,7 @@
 
         void ReferenceUntilUnused(ComPtr<IUnknown> object);
 
-        void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
+        void ExecuteCommandList(ID3D12CommandList* d3d12CommandList);
 
         ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
         MaybeError CopyFromStagingToBuffer(StagingBufferBase* source,
diff --git a/src/dawn_native/d3d12/QueueD3D12.cpp b/src/dawn_native/d3d12/QueueD3D12.cpp
index 063942d..72c0acc 100644
--- a/src/dawn_native/d3d12/QueueD3D12.cpp
+++ b/src/dawn_native/d3d12/QueueD3D12.cpp
@@ -33,7 +33,7 @@
         }
         ASSERT_SUCCESS(mCommandList->Close());
 
-        device->ExecuteCommandLists({mCommandList.Get()});
+        device->ExecuteCommandList(mCommandList.Get());
 
         device->NextSerial();
     }
diff --git a/src/dawn_native/d3d12/SwapChainD3D12.cpp b/src/dawn_native/d3d12/SwapChainD3D12.cpp
index 0dffc29..8d67231 100644
--- a/src/dawn_native/d3d12/SwapChainD3D12.cpp
+++ b/src/dawn_native/d3d12/SwapChainD3D12.cpp
@@ -54,7 +54,7 @@
         // Perform the necessary transition for the texture to be presented.
         ToBackend(texture)->TransitionUsageNow(device->GetPendingCommandList(), mTextureUsage);
 
-        device->ExecuteCommandLists({});
+        device->ExecuteCommandList(nullptr);
     }
 
 }}  // namespace dawn_native::d3d12