D3D12: Remove ComPtr from d3d12::Buffer::GetD3D12Resource

Creating lots of SRVs needlessly refcounts and floods PIX traces.

BUG=dawn:155

Change-Id: I26fd1019c8c1326f0e6db3e94240a29e4d466be1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24002
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/d3d12/BindGroupD3D12.cpp b/src/dawn_native/d3d12/BindGroupD3D12.cpp
index 76fb028..21d2743 100644
--- a/src/dawn_native/d3d12/BindGroupD3D12.cpp
+++ b/src/dawn_native/d3d12/BindGroupD3D12.cpp
@@ -88,7 +88,7 @@
                     desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
 
                     d3d12Device->CreateUnorderedAccessView(
-                        ToBackend(binding.buffer)->GetD3D12Resource().Get(), nullptr, &desc,
+                        ToBackend(binding.buffer)->GetD3D12Resource(), nullptr, &desc,
                         viewAllocation.OffsetFrom(viewSizeIncrement, bindingOffsets[bindingIndex]));
                     break;
                 }
@@ -108,7 +108,7 @@
                     desc.Buffer.StructureByteStride = 0;
                     desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
                     d3d12Device->CreateShaderResourceView(
-                        ToBackend(binding.buffer)->GetD3D12Resource().Get(), &desc,
+                        ToBackend(binding.buffer)->GetD3D12Resource(), &desc,
                         viewAllocation.OffsetFrom(viewSizeIncrement, bindingOffsets[bindingIndex]));
                     break;
                 }
diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp
index 879709f..8e7e479 100644
--- a/src/dawn_native/d3d12/BufferD3D12.cpp
+++ b/src/dawn_native/d3d12/BufferD3D12.cpp
@@ -133,7 +133,7 @@
         DestroyInternal();
     }
 
-    ComPtr<ID3D12Resource> Buffer::GetD3D12Resource() const {
+    ID3D12Resource* Buffer::GetD3D12Resource() const {
         return mResourceAllocation.GetD3D12Resource();
     }
 
@@ -183,7 +183,7 @@
         if (needsUAVBarrier) {
             barrier->Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
             barrier->Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
-            barrier->UAV.pResource = GetD3D12Resource().Get();
+            barrier->UAV.pResource = GetD3D12Resource();
 
             mLastUsage = newUsage;
             return true;
@@ -227,7 +227,7 @@
 
         barrier->Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
         barrier->Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
-        barrier->Transition.pResource = GetD3D12Resource().Get();
+        barrier->Transition.pResource = GetD3D12Resource();
         barrier->Transition.StateBefore = lastState;
         barrier->Transition.StateAfter = newState;
         barrier->Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
diff --git a/src/dawn_native/d3d12/BufferD3D12.h b/src/dawn_native/d3d12/BufferD3D12.h
index 3c51b74..5bc8107 100644
--- a/src/dawn_native/d3d12/BufferD3D12.h
+++ b/src/dawn_native/d3d12/BufferD3D12.h
@@ -32,7 +32,7 @@
 
         MaybeError Initialize();
 
-        ComPtr<ID3D12Resource> GetD3D12Resource() const;
+        ID3D12Resource* GetD3D12Resource() const;
         D3D12_GPU_VIRTUAL_ADDRESS GetVA() const;
 
         bool TrackUsageAndGetResourceBarrier(CommandRecordingContext* commandContext,
diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
index 2867ffe..1b4f8cc 100644
--- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
@@ -566,8 +566,8 @@
                                                           wgpu::BufferUsage::CopyDst);
 
                     commandList->CopyBufferRegion(
-                        dstBuffer->GetD3D12Resource().Get(), copy->destinationOffset,
-                        srcBuffer->GetD3D12Resource().Get(), copy->sourceOffset, copy->size);
+                        dstBuffer->GetD3D12Resource(), copy->destinationOffset,
+                        srcBuffer->GetD3D12Resource(), copy->sourceOffset, copy->size);
                     break;
                 }
 
@@ -618,7 +618,7 @@
 
                             D3D12_TEXTURE_COPY_LOCATION bufferLocation =
                                 ComputeBufferLocationForCopyTextureRegion(
-                                    texture, buffer->GetD3D12Resource().Get(), info.bufferSize,
+                                    texture, buffer->GetD3D12Resource(), info.bufferSize,
                                     copySplit.offset, copy->source.bytesPerRow);
                             D3D12_BOX sourceRegion =
                                 ComputeD3D12BoxFromOffsetAndSize(info.bufferOffset, info.copySize);
@@ -673,7 +673,7 @@
 
                             D3D12_TEXTURE_COPY_LOCATION bufferLocation =
                                 ComputeBufferLocationForCopyTextureRegion(
-                                    texture, buffer->GetD3D12Resource().Get(), info.bufferSize,
+                                    texture, buffer->GetD3D12Resource(), info.bufferSize,
                                     copySplit.offset, copy->destination.bytesPerRow);
 
                             D3D12_BOX sourceRegion =
@@ -787,8 +787,7 @@
                     Buffer* buffer = ToBackend(dispatch->indirectBuffer.Get());
                     ComPtr<ID3D12CommandSignature> signature =
                         ToBackend(GetDevice())->GetDispatchIndirectSignature();
-                    commandList->ExecuteIndirect(signature.Get(), 1,
-                                                 buffer->GetD3D12Resource().Get(),
+                    commandList->ExecuteIndirect(signature.Get(), 1, buffer->GetD3D12Resource(),
                                                  dispatch->indirectOffset, nullptr, 0);
                     break;
                 }
@@ -1103,8 +1102,7 @@
                     Buffer* buffer = ToBackend(draw->indirectBuffer.Get());
                     ComPtr<ID3D12CommandSignature> signature =
                         ToBackend(GetDevice())->GetDrawIndirectSignature();
-                    commandList->ExecuteIndirect(signature.Get(), 1,
-                                                 buffer->GetD3D12Resource().Get(),
+                    commandList->ExecuteIndirect(signature.Get(), 1, buffer->GetD3D12Resource(),
                                                  draw->indirectOffset, nullptr, 0);
                     break;
                 }
@@ -1118,8 +1116,7 @@
                     Buffer* buffer = ToBackend(draw->indirectBuffer.Get());
                     ComPtr<ID3D12CommandSignature> signature =
                         ToBackend(GetDevice())->GetDrawIndexedIndirectSignature();
-                    commandList->ExecuteIndirect(signature.Get(), 1,
-                                                 buffer->GetD3D12Resource().Get(),
+                    commandList->ExecuteIndirect(signature.Get(), 1, buffer->GetD3D12Resource(),
                                                  draw->indirectOffset, nullptr, 0);
                     break;
                 }
diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp
index 9f18045..d4b9b51 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn_native/d3d12/DeviceD3D12.cpp
@@ -340,7 +340,7 @@
         dstBuffer->TrackUsageAndTransitionNow(commandRecordingContext, wgpu::BufferUsage::CopyDst);
 
         commandRecordingContext->GetCommandList()->CopyBufferRegion(
-            dstBuffer->GetD3D12Resource().Get(), destinationOffset, srcBuffer->GetResource(),
+            dstBuffer->GetD3D12Resource(), destinationOffset, srcBuffer->GetResource(),
             sourceOffset, size);
 
         return {};
diff --git a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp
index 4e48f2e..14be08f 100644
--- a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp
+++ b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp
@@ -221,7 +221,7 @@
         // calls DeallocateMemory again using the same allocation.
         allocation.Invalidate();
 
-        ASSERT(allocation.GetD3D12Resource().Get() == nullptr);
+        ASSERT(allocation.GetD3D12Resource() == nullptr);
     }
 
     void ResourceAllocatorManager::FreeMemory(ResourceHeapAllocation& allocation) {
diff --git a/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp
index c3a89f0..edf21c1 100644
--- a/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp
+++ b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.cpp
@@ -32,8 +32,8 @@
         mResource.Reset();
     }
 
-    ComPtr<ID3D12Resource> ResourceHeapAllocation::GetD3D12Resource() const {
-        return mResource;
+    ID3D12Resource* ResourceHeapAllocation::GetD3D12Resource() const {
+        return mResource.Get();
     }
 
     D3D12_GPU_VIRTUAL_ADDRESS ResourceHeapAllocation::GetGPUPointer() const {
diff --git a/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h
index 71b00fd..ace1a7e 100644
--- a/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h
+++ b/src/dawn_native/d3d12/ResourceHeapAllocationD3D12.h
@@ -33,7 +33,7 @@
 
         void Invalidate() override;
 
-        ComPtr<ID3D12Resource> GetD3D12Resource() const;
+        ID3D12Resource* GetD3D12Resource() const;
         D3D12_GPU_VIRTUAL_ADDRESS GetGPUPointer() const;
 
       private:
diff --git a/src/dawn_native/d3d12/StagingBufferD3D12.cpp b/src/dawn_native/d3d12/StagingBufferD3D12.cpp
index b3aec3f..11c612b 100644
--- a/src/dawn_native/d3d12/StagingBufferD3D12.cpp
+++ b/src/dawn_native/d3d12/StagingBufferD3D12.cpp
@@ -69,6 +69,6 @@
     }
 
     ID3D12Resource* StagingBuffer::GetResource() const {
-        return mUploadHeap.GetD3D12Resource().Get();
+        return mUploadHeap.GetD3D12Resource();
     }
 }}  // namespace dawn_native::d3d12
diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp
index 7b86367..49b71c7 100644
--- a/src/dawn_native/d3d12/TextureD3D12.cpp
+++ b/src/dawn_native/d3d12/TextureD3D12.cpp
@@ -527,7 +527,7 @@
         if (mSwapChainTexture) {
             ID3D12SharingContract* d3dSharingContract = device->GetSharingContract();
             if (d3dSharingContract != nullptr) {
-                d3dSharingContract->Present(mResourceAllocation.GetD3D12Resource().Get(), 0, 0);
+                d3dSharingContract->Present(mResourceAllocation.GetD3D12Resource(), 0, 0);
             }
         }
 
@@ -544,7 +544,7 @@
     }
 
     ID3D12Resource* Texture::GetD3D12Resource() const {
-        return mResourceAllocation.GetD3D12Resource().Get();
+        return mResourceAllocation.GetD3D12Resource();
     }
 
     void Texture::TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,