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 <bryan.bernhart@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Bryan Bernhart 2020-05-11 16:47:21 +00:00 committed by Commit Bot service account
parent 4084c94c43
commit 19b21c5b85
11 changed files with 26 additions and 26 deletions

View File

@ -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);

View File

@ -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<ID3D12PipelineState> ComputePipeline::GetPipelineState() {
return mPipelineState;
ID3D12PipelineState* ComputePipeline::GetPipelineState() const {
return mPipelineState.Get();
}
}} // namespace dawn_native::d3d12

View File

@ -29,7 +29,7 @@ namespace dawn_native { namespace d3d12 {
const ComputePipelineDescriptor* descriptor);
ComputePipeline() = delete;
ComPtr<ID3D12PipelineState> GetPipelineState();
ID3D12PipelineState* GetPipelineState() const;
private:
~ComputePipeline() override;

View File

@ -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<ID3D12Heap> Heap::GetD3D12Heap() const {
ID3D12Heap* Heap::GetD3D12Heap() const {
ComPtr<ID3D12Heap> heap;
HRESULT result = mD3d12Pageable.As(&heap);
ASSERT(SUCCEEDED(result));
return heap;
return heap.Get();
}
ComPtr<ID3D12Pageable> Heap::GetD3D12Pageable() const {
return mD3d12Pageable;
ID3D12Pageable* Heap::GetD3D12Pageable() const {
return mD3d12Pageable.Get();
}
MemorySegment Heap::GetMemorySegment() const {

View File

@ -35,8 +35,8 @@ namespace dawn_native { namespace d3d12 {
Heap(ComPtr<ID3D12Pageable> d3d12Pageable, MemorySegment memorySegment, uint64_t size);
~Heap();
ComPtr<ID3D12Heap> GetD3D12Heap() const;
ComPtr<ID3D12Pageable> 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.

View File

@ -186,8 +186,8 @@ namespace dawn_native { namespace d3d12 {
return mSamplerRootParameterInfo[group];
}
ComPtr<ID3D12RootSignature> PipelineLayout::GetRootSignature() const {
return mRootSignature;
ID3D12RootSignature* PipelineLayout::GetRootSignature() const {
return mRootSignature.Get();
}
uint32_t PipelineLayout::GetDynamicRootParameterIndex(uint32_t group,

View File

@ -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<ID3D12RootSignature> GetRootSignature() const;
ID3D12RootSignature* GetRootSignature() const;
private:
~PipelineLayout() override = default;

View File

@ -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<D3D12_INPUT_ELEMENT_DESC, kMaxVertexAttributes> inputElementDescriptors;
@ -420,8 +420,8 @@ namespace dawn_native { namespace d3d12 {
return mD3d12PrimitiveTopology;
}
ComPtr<ID3D12PipelineState> RenderPipeline::GetPipelineState() {
return mPipelineState;
ID3D12PipelineState* RenderPipeline::GetPipelineState() const {
return mPipelineState.Get();
}
D3D12_INPUT_LAYOUT_DESC RenderPipeline::ComputeInputLayout(

View File

@ -30,7 +30,7 @@ namespace dawn_native { namespace d3d12 {
RenderPipeline() = delete;
D3D12_PRIMITIVE_TOPOLOGY GetD3D12PrimitiveTopology() const;
ComPtr<ID3D12PipelineState> GetPipelineState();
ID3D12PipelineState* GetPipelineState() const;
private:
~RenderPipeline() override;

View File

@ -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 {

View File

@ -294,8 +294,8 @@ namespace dawn_native { namespace d3d12 {
ComPtr<ID3D12Resource> 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