From 19b21c5b85cfd79fb7f4bd62538edc22f83bf8f0 Mon Sep 17 00:00:00 2001 From: Bryan Bernhart Date: Mon, 11 May 2020 16:47:21 +0000 Subject: [PATCH] D3D12: Remove ComPtr from D3D12 objects when possible. Returning COM for getters needlessly refcounts which wastes CPU cycles in critial sections and floods PIX traces with [Add/Release]Ref. BUG=dawn:212 Change-Id: Ifa853f2d5f78a450fdb7ffb9492f0d08dfbcdd37 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21364 Commit-Queue: Bryan Bernhart Reviewed-by: Corentin Wallez --- src/dawn_native/d3d12/CommandBufferD3D12.cpp | 8 ++++---- src/dawn_native/d3d12/ComputePipelineD3D12.cpp | 6 +++--- src/dawn_native/d3d12/ComputePipelineD3D12.h | 2 +- src/dawn_native/d3d12/HeapD3D12.cpp | 8 ++++---- src/dawn_native/d3d12/HeapD3D12.h | 4 ++-- src/dawn_native/d3d12/PipelineLayoutD3D12.cpp | 4 ++-- src/dawn_native/d3d12/PipelineLayoutD3D12.h | 2 +- src/dawn_native/d3d12/RenderPipelineD3D12.cpp | 6 +++--- src/dawn_native/d3d12/RenderPipelineD3D12.h | 2 +- src/dawn_native/d3d12/ResidencyManagerD3D12.cpp | 6 +++--- src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp | 4 ++-- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index 72377f7326..0ec73aaa76 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -741,8 +741,8 @@ namespace dawn_native { namespace d3d12 { ComputePipeline* pipeline = ToBackend(cmd->pipeline).Get(); PipelineLayout* layout = ToBackend(pipeline->GetLayout()); - commandList->SetComputeRootSignature(layout->GetRootSignature().Get()); - commandList->SetPipelineState(pipeline->GetPipelineState().Get()); + commandList->SetComputeRootSignature(layout->GetRootSignature()); + commandList->SetPipelineState(pipeline->GetPipelineState()); bindingTracker->OnSetPipeline(pipeline); @@ -1105,8 +1105,8 @@ namespace dawn_native { namespace d3d12 { RenderPipeline* pipeline = ToBackend(cmd->pipeline).Get(); PipelineLayout* layout = ToBackend(pipeline->GetLayout()); - commandList->SetGraphicsRootSignature(layout->GetRootSignature().Get()); - commandList->SetPipelineState(pipeline->GetPipelineState().Get()); + commandList->SetGraphicsRootSignature(layout->GetRootSignature()); + commandList->SetPipelineState(pipeline->GetPipelineState()); commandList->IASetPrimitiveTopology(pipeline->GetD3D12PrimitiveTopology()); bindingTracker->OnSetPipeline(pipeline); diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp index fbade96fc2..940a3e9d3f 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp @@ -56,7 +56,7 @@ namespace dawn_native { namespace d3d12 { } D3D12_COMPUTE_PIPELINE_STATE_DESC d3dDesc = {}; - d3dDesc.pRootSignature = ToBackend(GetLayout())->GetRootSignature().Get(); + d3dDesc.pRootSignature = ToBackend(GetLayout())->GetRootSignature(); d3dDesc.CS.pShaderBytecode = compiledShader->GetBufferPointer(); d3dDesc.CS.BytecodeLength = compiledShader->GetBufferSize(); @@ -69,8 +69,8 @@ namespace dawn_native { namespace d3d12 { ToBackend(GetDevice())->ReferenceUntilUnused(mPipelineState); } - ComPtr ComputePipeline::GetPipelineState() { - return mPipelineState; + ID3D12PipelineState* ComputePipeline::GetPipelineState() const { + return mPipelineState.Get(); } }} // namespace dawn_native::d3d12 diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.h b/src/dawn_native/d3d12/ComputePipelineD3D12.h index 89b6752da5..7d05f0b3c1 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.h +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.h @@ -29,7 +29,7 @@ namespace dawn_native { namespace d3d12 { const ComputePipelineDescriptor* descriptor); ComputePipeline() = delete; - ComPtr GetPipelineState(); + ID3D12PipelineState* GetPipelineState() const; private: ~ComputePipeline() override; diff --git a/src/dawn_native/d3d12/HeapD3D12.cpp b/src/dawn_native/d3d12/HeapD3D12.cpp index 3d3f04f390..add21cfcce 100644 --- a/src/dawn_native/d3d12/HeapD3D12.cpp +++ b/src/dawn_native/d3d12/HeapD3D12.cpp @@ -32,15 +32,15 @@ namespace dawn_native { namespace d3d12 { // ID3D12Pageable that was initially created as an ID3D12Heap (i.e. SubAllocation). If the // ID3D12Pageable was initially created as an ID3D12Resource (i.e. DirectAllocation), then // use GetD3D12Pageable(). - ComPtr Heap::GetD3D12Heap() const { + ID3D12Heap* Heap::GetD3D12Heap() const { ComPtr heap; HRESULT result = mD3d12Pageable.As(&heap); ASSERT(SUCCEEDED(result)); - return heap; + return heap.Get(); } - ComPtr Heap::GetD3D12Pageable() const { - return mD3d12Pageable; + ID3D12Pageable* Heap::GetD3D12Pageable() const { + return mD3d12Pageable.Get(); } MemorySegment Heap::GetMemorySegment() const { diff --git a/src/dawn_native/d3d12/HeapD3D12.h b/src/dawn_native/d3d12/HeapD3D12.h index 1ce108dba1..71a4a0f204 100644 --- a/src/dawn_native/d3d12/HeapD3D12.h +++ b/src/dawn_native/d3d12/HeapD3D12.h @@ -35,8 +35,8 @@ namespace dawn_native { namespace d3d12 { Heap(ComPtr d3d12Pageable, MemorySegment memorySegment, uint64_t size); ~Heap(); - ComPtr GetD3D12Heap() const; - ComPtr GetD3D12Pageable() const; + ID3D12Heap* GetD3D12Heap() const; + ID3D12Pageable* GetD3D12Pageable() const; MemorySegment GetMemorySegment() const; // We set mLastRecordingSerial to denote the serial this heap was last recorded to be used. diff --git a/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp b/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp index 1f060a7344..3c8a7f7b89 100644 --- a/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp +++ b/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp @@ -186,8 +186,8 @@ namespace dawn_native { namespace d3d12 { return mSamplerRootParameterInfo[group]; } - ComPtr PipelineLayout::GetRootSignature() const { - return mRootSignature; + ID3D12RootSignature* PipelineLayout::GetRootSignature() const { + return mRootSignature.Get(); } uint32_t PipelineLayout::GetDynamicRootParameterIndex(uint32_t group, diff --git a/src/dawn_native/d3d12/PipelineLayoutD3D12.h b/src/dawn_native/d3d12/PipelineLayoutD3D12.h index 3123dc6afb..5bcc1addac 100644 --- a/src/dawn_native/d3d12/PipelineLayoutD3D12.h +++ b/src/dawn_native/d3d12/PipelineLayoutD3D12.h @@ -34,7 +34,7 @@ namespace dawn_native { namespace d3d12 { // Returns the index of the root parameter reserved for a dynamic buffer binding uint32_t GetDynamicRootParameterIndex(uint32_t group, BindingIndex bindingIndex) const; - ComPtr GetRootSignature() const; + ID3D12RootSignature* GetRootSignature() const; private: ~PipelineLayout() override = default; diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp index 85cd0b721c..82fdedfad9 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp @@ -359,7 +359,7 @@ namespace dawn_native { namespace d3d12 { PipelineLayout* layout = ToBackend(GetLayout()); - descriptorD3D12.pRootSignature = layout->GetRootSignature().Get(); + descriptorD3D12.pRootSignature = layout->GetRootSignature(); // D3D12 logs warnings if any empty input state is used std::array inputElementDescriptors; @@ -420,8 +420,8 @@ namespace dawn_native { namespace d3d12 { return mD3d12PrimitiveTopology; } - ComPtr RenderPipeline::GetPipelineState() { - return mPipelineState; + ID3D12PipelineState* RenderPipeline::GetPipelineState() const { + return mPipelineState.Get(); } D3D12_INPUT_LAYOUT_DESC RenderPipeline::ComputeInputLayout( diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.h b/src/dawn_native/d3d12/RenderPipelineD3D12.h index 1d8882de89..50f0decac7 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.h +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.h @@ -30,7 +30,7 @@ namespace dawn_native { namespace d3d12 { RenderPipeline() = delete; D3D12_PRIMITIVE_TOPOLOGY GetD3D12PrimitiveTopology() const; - ComPtr GetPipelineState(); + ID3D12PipelineState* GetPipelineState() const; private: ~RenderPipeline() override; diff --git a/src/dawn_native/d3d12/ResidencyManagerD3D12.cpp b/src/dawn_native/d3d12/ResidencyManagerD3D12.cpp index dd7002d480..c65d56a242 100644 --- a/src/dawn_native/d3d12/ResidencyManagerD3D12.cpp +++ b/src/dawn_native/d3d12/ResidencyManagerD3D12.cpp @@ -39,7 +39,7 @@ namespace dawn_native { namespace d3d12 { if (!heap->IsInResidencyLRUCache() && !heap->IsResidencyLocked()) { DAWN_TRY(EnsureCanMakeResident(heap->GetSize(), GetMemorySegmentInfo(heap->GetMemorySegment()))); - ID3D12Pageable* pageable = heap->GetD3D12Pageable().Get(); + ID3D12Pageable* pageable = heap->GetD3D12Pageable(); DAWN_TRY(CheckHRESULT(mDevice->GetD3D12Device()->MakeResident(1, &pageable), "Making a scheduled-to-be-used resource resident")); } @@ -206,7 +206,7 @@ namespace dawn_native { namespace d3d12 { } sizeEvicted += heap->GetSize(); - resourcesToEvict.push_back(heap->GetD3D12Pageable().Get()); + resourcesToEvict.push_back(heap->GetD3D12Pageable()); } if (resourcesToEvict.size() > 0) { @@ -244,7 +244,7 @@ namespace dawn_native { namespace d3d12 { // update its position in the LRU. heap->RemoveFromList(); } else { - heapsToMakeResident.push_back(heap->GetD3D12Pageable().Get()); + heapsToMakeResident.push_back(heap->GetD3D12Pageable()); if (heap->GetMemorySegment() == MemorySegment::Local) { localSizeToMakeResident += heap->GetSize(); } else { diff --git a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp index f52c598e4f..7f4738649e 100644 --- a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp +++ b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp @@ -294,8 +294,8 @@ namespace dawn_native { namespace d3d12 { ComPtr placedResource; DAWN_TRY(CheckOutOfMemoryHRESULT( mDevice->GetD3D12Device()->CreatePlacedResource( - heap->GetD3D12Heap().Get(), allocation.GetOffset(), &resourceDescriptor, - initialUsage, nullptr, IID_PPV_ARGS(&placedResource)), + heap->GetD3D12Heap(), allocation.GetOffset(), &resourceDescriptor, initialUsage, + nullptr, IID_PPV_ARGS(&placedResource)), "ID3D12Device::CreatePlacedResource")); // After CreatePlacedResource has finished, the heap can be unlocked from residency. This