diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index ccb5bcf00e..edf7e7c9cc 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -9,6 +9,9 @@ Milestone 87 * + * Switch to using Microsoft::WRL::ComPtr for wrapping D3D12 objects. + https://review.skia.org/314957 + * GPU backends now properly honor the SkFilterQuality when calling drawAtlas. https://review.skia.org/313081 diff --git a/include/gpu/d3d/GrD3DBackendContext.h b/include/gpu/d3d/GrD3DBackendContext.h index 73933f37f8..d04ebd4f4a 100644 --- a/include/gpu/d3d/GrD3DBackendContext.h +++ b/include/gpu/d3d/GrD3DBackendContext.h @@ -25,9 +25,9 @@ // The BackendContext contains all of the base D3D objects needed by the GrD3DGpu. The assumption // is that the client will set these up and pass them to the GrD3DGpu constructor. struct SK_API GrD3DBackendContext { - gr_cp fAdapter; - gr_cp fDevice; - gr_cp fQueue; + ComPtr fAdapter; + ComPtr fDevice; + ComPtr fQueue; GrProtected fProtectedContext = GrProtected::kNo; }; diff --git a/include/gpu/d3d/GrD3DTypes.h b/include/gpu/d3d/GrD3DTypes.h index f9565d3d7b..02459590b9 100644 --- a/include/gpu/d3d/GrD3DTypes.h +++ b/include/gpu/d3d/GrD3DTypes.h @@ -24,138 +24,15 @@ #include "include/gpu/d3d/GrD3DTypesMinimal.h" #include #include +#include - /** Check if the argument is non-null, and if so, call obj->AddRef() and return obj. - */ -template static inline T* GrSafeComAddRef(T* obj) { - if (obj) { - obj->AddRef(); - } - return obj; -} - -/** Check if the argument is non-null, and if so, call obj->Release() - */ -template static inline void GrSafeComRelease(T* obj) { - if (obj) { - obj->Release(); - } -} - -template class gr_cp { -public: - using element_type = T; - - constexpr gr_cp() : fObject(nullptr) {} - constexpr gr_cp(std::nullptr_t) : fObject(nullptr) {} - - /** - * Shares the underlying object by calling AddRef(), so that both the argument and the newly - * created gr_cp both have a reference to it. - */ - gr_cp(const gr_cp& that) : fObject(GrSafeComAddRef(that.get())) {} - - /** - * Move the underlying object from the argument to the newly created gr_cp. Afterwards only - * the new gr_cp will have a reference to the object, and the argument will point to null. - * No call to AddRef() or Release() will be made. - */ - gr_cp(gr_cp&& that) : fObject(that.release()) {} - - /** - * Adopt the bare object into the newly created gr_cp. - * No call to AddRef() or Release() will be made. - */ - explicit gr_cp(T* obj) { - fObject = obj; - } - - /** - * Calls Release() on the underlying object pointer. - */ - ~gr_cp() { - GrSafeComRelease(fObject); - SkDEBUGCODE(fObject = nullptr); - } - - /** - * Shares the underlying object referenced by the argument by calling AddRef() on it. If this - * gr_cp previously had a reference to an object (i.e. not null) it will call Release() - * on that object. - */ - gr_cp& operator=(const gr_cp& that) { - if (this != &that) { - this->reset(GrSafeComAddRef(that.get())); - } - return *this; - } - - /** - * Move the underlying object from the argument to the gr_cp. If the gr_cp - * previously held a reference to another object, Release() will be called on that object. - * No call to AddRef() will be made. - */ - gr_cp& operator=(gr_cp&& that) { - this->reset(that.release()); - return *this; - } - - explicit operator bool() const { return this->get() != nullptr; } - - T* get() const { return fObject; } - T* operator->() const { return fObject; } - T** operator&() { return &fObject; } - - /** - * Adopt the new object, and call Release() on any previously held object (if not null). - * No call to AddRef() will be made. - */ - void reset(T* object = nullptr) { - T* oldObject = fObject; - fObject = object; - GrSafeComRelease(oldObject); - } - - /** - * Shares the new object by calling AddRef() on it. If this gr_cp previously had a - * reference to an object (i.e. not null) it will call Release() on that object. - */ - void retain(T* object) { - if (this->fObject != object) { - this->reset(GrSafeComAddRef(object)); - } - } - - /** - * Return the original object, and set the internal object to nullptr. - * The caller must assume ownership of the object, and manage its reference count directly. - * No call to Release() will be made. - */ - T* SK_WARN_UNUSED_RESULT release() { - T* obj = fObject; - fObject = nullptr; - return obj; - } - -private: - T* fObject; -}; - -template inline bool operator==(const gr_cp& a, - const gr_cp& b) { - return a.get() == b.get(); -} - -template inline bool operator!=(const gr_cp& a, - const gr_cp& b) { - return a.get() != b.get(); -} +using Microsoft::WRL::ComPtr; // Note: there is no notion of Borrowed or Adopted resources in the D3D backend, // so Ganesh will ref fResource once it's asked to wrap it. // Clients are responsible for releasing their own ref to avoid memory leaks. struct GrD3DTextureResourceInfo { - gr_cp fResource; + ComPtr fResource; D3D12_RESOURCE_STATES fResourceState; DXGI_FORMAT fFormat; uint32_t fLevelCount; @@ -170,7 +47,7 @@ struct GrD3DTextureResourceInfo { , fSampleQualityPattern(DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN) , fProtected(GrProtected::kNo) {} - GrD3DTextureResourceInfo(ID3D12Resource* resource, + GrD3DTextureResourceInfo(const ComPtr& resource, D3D12_RESOURCE_STATES resourceState, DXGI_FORMAT format, uint32_t levelCount, @@ -207,8 +84,8 @@ struct GrD3DFenceInfo { , fValue(0) { } - gr_cp fFence; - uint64_t fValue; // signal value for the fence + ComPtr fFence; + uint64_t fValue; // signal value for the fence }; #endif diff --git a/src/gpu/d3d/GrD3DBuffer.cpp b/src/gpu/d3d/GrD3DBuffer.cpp index bc06c85d74..a7b10f6965 100644 --- a/src/gpu/d3d/GrD3DBuffer.cpp +++ b/src/gpu/d3d/GrD3DBuffer.cpp @@ -16,7 +16,7 @@ #define VALIDATE() do {} while(false) #endif -static gr_cp make_d3d_buffer(GrD3DGpu* gpu, +static ComPtr make_d3d_buffer(GrD3DGpu* gpu, size_t size, GrGpuBufferType intendedType, GrAccessPattern accessPattern, @@ -61,7 +61,7 @@ static gr_cp make_d3d_buffer(GrD3DGpu* gpu, bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; bufferDesc.Flags = D3D12_RESOURCE_FLAG_NONE; - ID3D12Resource* resource; + ComPtr resource; HRESULT hr = gpu->device()->CreateCommittedResource( &heapProperties, D3D12_HEAP_FLAG_NONE, @@ -73,7 +73,7 @@ static gr_cp make_d3d_buffer(GrD3DGpu* gpu, return nullptr; } - return gr_cp(resource); + return resource; } sk_sp GrD3DBuffer::Make(GrD3DGpu* gpu, size_t size, GrGpuBufferType intendedType, @@ -82,8 +82,8 @@ sk_sp GrD3DBuffer::Make(GrD3DGpu* gpu, size_t size, GrGpuBufferType D3D12_RESOURCE_STATES resourceState; - gr_cp resource = make_d3d_buffer(gpu, size, intendedType, accessPattern, - &resourceState); + ComPtr resource = make_d3d_buffer(gpu, size, intendedType, accessPattern, + &resourceState); if (!resource) { return nullptr; } @@ -93,7 +93,7 @@ sk_sp GrD3DBuffer::Make(GrD3DGpu* gpu, size_t size, GrGpuBufferType } GrD3DBuffer::GrD3DBuffer(GrD3DGpu* gpu, size_t size, GrGpuBufferType intendedType, - GrAccessPattern accessPattern, gr_cp bufferResource, + GrAccessPattern accessPattern, ComPtr bufferResource, D3D12_RESOURCE_STATES resourceState) : INHERITED(gpu, size, intendedType, accessPattern) , fResourceState(resourceState) diff --git a/src/gpu/d3d/GrD3DBuffer.h b/src/gpu/d3d/GrD3DBuffer.h index d74b29ac80..eb37f9d990 100644 --- a/src/gpu/d3d/GrD3DBuffer.h +++ b/src/gpu/d3d/GrD3DBuffer.h @@ -23,13 +23,13 @@ public: ID3D12Resource* d3dResource() const { SkASSERT(fD3DResource); - return fD3DResource.get(); + return fD3DResource.Get(); } void setResourceState(const GrD3DGpu* gpu, D3D12_RESOURCE_STATES newResourceState); protected: - GrD3DBuffer(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern, gr_cp, + GrD3DBuffer(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern, ComPtr, D3D12_RESOURCE_STATES); void onAbandon() override; @@ -52,7 +52,7 @@ private: return reinterpret_cast(this->getGpu()); } - gr_cp fD3DResource; + ComPtr fD3DResource; ID3D12Resource* fStagingBuffer = nullptr; size_t fStagingOffset = 0; diff --git a/src/gpu/d3d/GrD3DCommandList.cpp b/src/gpu/d3d/GrD3DCommandList.cpp index 22b13251c4..5164061bb7 100644 --- a/src/gpu/d3d/GrD3DCommandList.cpp +++ b/src/gpu/d3d/GrD3DCommandList.cpp @@ -18,8 +18,8 @@ #include "src/gpu/d3d/GrD3DTextureResource.h" #include "src/gpu/d3d/GrD3DUtil.h" -GrD3DCommandList::GrD3DCommandList(gr_cp allocator, - gr_cp commandList) +GrD3DCommandList::GrD3DCommandList(ComPtr allocator, + ComPtr commandList) : fCommandList(std::move(commandList)) , fAllocator(std::move(allocator)) { } @@ -43,7 +43,7 @@ GrD3DCommandList::SubmitResult GrD3DCommandList::submit(ID3D12CommandQueue* queu return SubmitResult::kFailure; } SkASSERT(!fIsActive); - ID3D12CommandList* ppCommandLists[] = { fCommandList.get() }; + ID3D12CommandList* ppCommandLists[] = { fCommandList.Get() }; queue->ExecuteCommandLists(1, ppCommandLists); return SubmitResult::kSuccess; @@ -52,7 +52,7 @@ GrD3DCommandList::SubmitResult GrD3DCommandList::submit(ID3D12CommandQueue* queu void GrD3DCommandList::reset() { SkASSERT(!fIsActive); GR_D3D_CALL_ERRCHECK(fAllocator->Reset()); - GR_D3D_CALL_ERRCHECK(fCommandList->Reset(fAllocator.get(), nullptr)); + GR_D3D_CALL_ERRCHECK(fCommandList->Reset(fAllocator.Get(), nullptr)); this->onReset(); this->releaseResources(); @@ -200,21 +200,21 @@ void GrD3DCommandList::addingWork() { //////////////////////////////////////////////////////////////////////////////////////////////////// std::unique_ptr GrD3DDirectCommandList::Make(ID3D12Device* device) { - gr_cp allocator; + ComPtr allocator; GR_D3D_CALL_ERRCHECK(device->CreateCommandAllocator( D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator))); - gr_cp commandList; + ComPtr commandList; GR_D3D_CALL_ERRCHECK(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, - allocator.get(), nullptr, + allocator.Get(), nullptr, IID_PPV_ARGS(&commandList))); auto grCL = new GrD3DDirectCommandList(std::move(allocator), std::move(commandList)); return std::unique_ptr(grCL); } -GrD3DDirectCommandList::GrD3DDirectCommandList(gr_cp allocator, - gr_cp commandList) +GrD3DDirectCommandList::GrD3DDirectCommandList(ComPtr allocator, + ComPtr commandList) : GrD3DCommandList(std::move(allocator), std::move(commandList)) , fCurrentPipelineState(nullptr) , fCurrentRootSignature(nullptr) @@ -281,7 +281,7 @@ void GrD3DDirectCommandList::setViewports(unsigned int numViewports, void GrD3DDirectCommandList::setCenteredSamplePositions(unsigned int numSamples) { if (!fUsingCenteredSamples && numSamples > 1) { - gr_cp commandList1; + ComPtr commandList1; GR_D3D_CALL_ERRCHECK(fCommandList->QueryInterface(IID_PPV_ARGS(&commandList1))); static D3D12_SAMPLE_POSITION kCenteredSampleLocations[16] = {}; commandList1->SetSamplePositions(numSamples, 1, kCenteredSampleLocations); @@ -291,7 +291,7 @@ void GrD3DDirectCommandList::setCenteredSamplePositions(unsigned int numSamples) void GrD3DDirectCommandList::setDefaultSamplePositions() { if (fUsingCenteredSamples) { - gr_cp commandList1; + ComPtr commandList1; GR_D3D_CALL_ERRCHECK(fCommandList->QueryInterface(IID_PPV_ARGS(&commandList1))); commandList1->SetSamplePositions(0, 0, nullptr); fUsingCenteredSamples = false; @@ -442,7 +442,7 @@ void GrD3DDirectCommandList::resolveSubresourceRegion(const GrD3DTextureResource this->addResource(dstTexture->resource()); this->addResource(srcTexture->resource()); - gr_cp commandList1; + ComPtr commandList1; HRESULT result = fCommandList->QueryInterface(IID_PPV_ARGS(&commandList1)); if (SUCCEEDED(result)) { commandList1->ResolveSubresourceRegion(dstTexture->d3dResource(), 0, dstX, dstY, @@ -503,18 +503,18 @@ void GrD3DDirectCommandList::addSampledTextureRef(GrD3DTexture* texture) { //////////////////////////////////////////////////////////////////////////////////////////////////// std::unique_ptr GrD3DCopyCommandList::Make(ID3D12Device* device) { - gr_cp allocator; + ComPtr allocator; GR_D3D_CALL_ERRCHECK(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator))); - gr_cp commandList; - GR_D3D_CALL_ERRCHECK(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, allocator.get(), + ComPtr commandList; + GR_D3D_CALL_ERRCHECK(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, allocator.Get(), nullptr, IID_PPV_ARGS(&commandList))); auto grCL = new GrD3DCopyCommandList(std::move(allocator), std::move(commandList)); return std::unique_ptr(grCL); } -GrD3DCopyCommandList::GrD3DCopyCommandList(gr_cp allocator, - gr_cp commandList) +GrD3DCopyCommandList::GrD3DCopyCommandList(ComPtr allocator, + ComPtr commandList) : GrD3DCommandList(std::move(allocator), std::move(commandList)) { } diff --git a/src/gpu/d3d/GrD3DCommandList.h b/src/gpu/d3d/GrD3DCommandList.h index 58d0a527f7..5ace2a8af0 100644 --- a/src/gpu/d3d/GrD3DCommandList.h +++ b/src/gpu/d3d/GrD3DCommandList.h @@ -100,8 +100,8 @@ private: static const int kInitialTrackedResourcesCount = 32; protected: - GrD3DCommandList(gr_cp allocator, - gr_cp commandList); + GrD3DCommandList(ComPtr allocator, + ComPtr commandList); // Add ref-counted resource that will be tracked and released when this command buffer finishes // execution @@ -123,7 +123,7 @@ protected: void submitResourceBarriers(); - gr_cp fCommandList; + ComPtr fCommandList; SkSTArray> fTrackedResources; SkSTArray> fTrackedRecycledResources; @@ -137,7 +137,7 @@ protected: private: void callFinishedCallbacks() { fFinishedCallbacks.reset(); } - gr_cp fAllocator; + ComPtr fAllocator; SkSTArray<4, D3D12_RESOURCE_BARRIER> fResourceBarriers; @@ -194,8 +194,8 @@ public: void addSampledTextureRef(GrD3DTexture*); private: - GrD3DDirectCommandList(gr_cp allocator, - gr_cp commandList); + GrD3DDirectCommandList(ComPtr allocator, + ComPtr commandList); void onReset() override; @@ -219,7 +219,7 @@ public: static std::unique_ptr Make(ID3D12Device* device); private: - GrD3DCopyCommandList(gr_cp allocator, - gr_cp commandList); + GrD3DCopyCommandList(ComPtr allocator, + ComPtr commandList); }; #endif diff --git a/src/gpu/d3d/GrD3DCommandSignature.cpp b/src/gpu/d3d/GrD3DCommandSignature.cpp index e874a49bf8..1b656bcd32 100644 --- a/src/gpu/d3d/GrD3DCommandSignature.cpp +++ b/src/gpu/d3d/GrD3DCommandSignature.cpp @@ -24,7 +24,7 @@ sk_sp GrD3DCommandSignature::Make(GrD3DGpu* gpu, ForIndex commandSigDesc.pArgumentDescs = &argumentDesc; commandSigDesc.NodeMask = 0; - gr_cp commandSig; + ComPtr commandSig; HRESULT hr = gpu->device()->CreateCommandSignature(&commandSigDesc, nullptr, IID_PPV_ARGS(&commandSig)); if (!SUCCEEDED(hr)) { diff --git a/src/gpu/d3d/GrD3DCommandSignature.h b/src/gpu/d3d/GrD3DCommandSignature.h index adb4954bd7..a47d01b0ca 100644 --- a/src/gpu/d3d/GrD3DCommandSignature.h +++ b/src/gpu/d3d/GrD3DCommandSignature.h @@ -25,29 +25,29 @@ public: return (fIndexed == indexed && fSlot == slot); } - ID3D12CommandSignature* commandSignature() const { return fCommandSignature.get(); } + ID3D12CommandSignature* commandSignature() const { return fCommandSignature.Get(); } #ifdef SK_TRACE_MANAGED_RESOURCES /** Output a human-readable dump of this resource's information */ void dumpInfo() const override { SkDebugf("GrD3DCommandSignature: %p, (%d refs)\n", - fCommandSignature.get(), this->getRefCnt()); + fCommandSignature.Get(), this->getRefCnt()); } #endif private: - GrD3DCommandSignature(gr_cp commandSignature, ForIndexed indexed, + GrD3DCommandSignature(ComPtr commandSignature, ForIndexed indexed, unsigned int slot) : fCommandSignature(commandSignature) , fIndexed(indexed) , fSlot(slot) {} // This will be called right before this class is destroyed and there is no reason to explicitly - // release the fCommandSignature cause the gr_cp will handle that in the dtor. + // release the fCommandSignature cause the ComPtr will handle that in the dtor. void freeGPUData() const override {} - gr_cp fCommandSignature; + ComPtr fCommandSignature; ForIndexed fIndexed; unsigned int fSlot; }; diff --git a/src/gpu/d3d/GrD3DDescriptorHeap.cpp b/src/gpu/d3d/GrD3DDescriptorHeap.cpp index 8d2569783b..4da29044fc 100644 --- a/src/gpu/d3d/GrD3DDescriptorHeap.cpp +++ b/src/gpu/d3d/GrD3DDescriptorHeap.cpp @@ -17,15 +17,15 @@ std::unique_ptr GrD3DDescriptorHeap::Make(GrD3DGpu* gpu, heapDesc.NumDescriptors = numDescriptors; heapDesc.Flags = flags; - ID3D12DescriptorHeap* heap; + ComPtr heap; gpu->device()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&heap)); return std::unique_ptr( - new GrD3DDescriptorHeap(std::move(gr_cp(heap)), + new GrD3DDescriptorHeap(std::move(heap), gpu->device()->GetDescriptorHandleIncrementSize(type))); } -GrD3DDescriptorHeap::GrD3DDescriptorHeap(const gr_cp& heap, +GrD3DDescriptorHeap::GrD3DDescriptorHeap(const ComPtr& heap, unsigned int handleIncrementSize) : fHeap(heap) , fHandleIncrementSize(handleIncrementSize) diff --git a/src/gpu/d3d/GrD3DDescriptorHeap.h b/src/gpu/d3d/GrD3DDescriptorHeap.h index 30fdc1358e..9c8a1764c0 100644 --- a/src/gpu/d3d/GrD3DDescriptorHeap.h +++ b/src/gpu/d3d/GrD3DDescriptorHeap.h @@ -36,7 +36,7 @@ public: CPUHandle getCPUHandle(unsigned int index); // write-only if shader-visible GPUHandle getGPUHandle(unsigned int index); - ID3D12DescriptorHeap* descriptorHeap() const { return fHeap.get(); } + ID3D12DescriptorHeap* descriptorHeap() const { return fHeap.Get(); } size_t handleIncrementSize() { return fHandleIncrementSize; } size_t getIndex(const CPUHandle& handle) { @@ -56,7 +56,7 @@ public: } protected: - GrD3DDescriptorHeap(const gr_cp&, unsigned int handleIncrementSize); + GrD3DDescriptorHeap(const ComPtr&, unsigned int handleIncrementSize); static uint32_t GenID() { static std::atomic nextID{1}; @@ -67,7 +67,7 @@ protected: return id; } - gr_cp fHeap; + ComPtr fHeap; size_t fHandleIncrementSize; D3D12_CPU_DESCRIPTOR_HANDLE fCPUHeapStart; D3D12_GPU_DESCRIPTOR_HANDLE fGPUHeapStart; diff --git a/src/gpu/d3d/GrD3DGpu.cpp b/src/gpu/d3d/GrD3DGpu.cpp index 9c4e7ca5c9..e075dc3a5b 100644 --- a/src/gpu/d3d/GrD3DGpu.cpp +++ b/src/gpu/d3d/GrD3DGpu.cpp @@ -53,8 +53,8 @@ GrD3DGpu::GrD3DGpu(GrDirectContext* direct, const GrContextOptions& contextOptio , fOutstandingCommandLists(sizeof(OutstandingCommandList), kDefaultOutstandingAllocCnt) , fCompiler(new SkSL::Compiler()) { fCaps.reset(new GrD3DCaps(contextOptions, - backendContext.fAdapter.get(), - backendContext.fDevice.get())); + backendContext.fAdapter.Get(), + backendContext.fDevice.Get())); fCurrentDirectCommandList = fResourceProvider.findOrCreateDirectCommandList(); SkASSERT(fCurrentDirectCommandList); @@ -123,7 +123,7 @@ bool GrD3DGpu::submitDirectCommandList(SyncQueue sync) { fResourceProvider.prepForSubmit(); - GrD3DDirectCommandList::SubmitResult result = fCurrentDirectCommandList->submit(fQueue.get()); + GrD3DDirectCommandList::SubmitResult result = fCurrentDirectCommandList->submit(fQueue.Get()); if (result == GrD3DDirectCommandList::SubmitResult::kFailure) { return false; } else if (result == GrD3DDirectCommandList::SubmitResult::kNoWork) { @@ -775,7 +775,7 @@ bool GrD3DGpu::uploadToTexture(GrD3DTexture* tex, int left, int top, int width, } static bool check_resource_info(const GrD3DTextureResourceInfo& info) { - if (!info.fResource.get()) { + if (!info.fResource.Get()) { return false; } return true; @@ -1235,7 +1235,7 @@ bool GrD3DGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { if (!tex.getD3DTextureResourceInfo(&info)) { return false; } - ID3D12Resource* textureResource = info.fResource.get(); + ID3D12Resource* textureResource = info.fResource.Get(); if (!textureResource) { return false; } @@ -1379,7 +1379,7 @@ void GrD3DGpu::waitSemaphore(GrSemaphore* semaphore) { } GrFence SK_WARN_UNUSED_RESULT GrD3DGpu::insertFence() { - GR_D3D_CALL_ERRCHECK(fQueue->Signal(fFence.get(), ++fCurrentFenceValue)); + GR_D3D_CALL_ERRCHECK(fQueue->Signal(fFence.Get(), ++fCurrentFenceValue)); return fCurrentFenceValue; } diff --git a/src/gpu/d3d/GrD3DGpu.h b/src/gpu/d3d/GrD3DGpu.h index 4d8c2fdc3c..f14af2e0c4 100644 --- a/src/gpu/d3d/GrD3DGpu.h +++ b/src/gpu/d3d/GrD3DGpu.h @@ -40,8 +40,8 @@ public: GrD3DResourceProvider& resourceProvider() { return fResourceProvider; } - ID3D12Device* device() const { return fDevice.get(); } - ID3D12CommandQueue* queue() const { return fQueue.get(); } + ID3D12Device* device() const { return fDevice.Get(); } + ID3D12CommandQueue* queue() const { return fQueue.Get(); } GrD3DDirectCommandList* currentCommandList() const { return fCurrentDirectCommandList.get(); } @@ -258,14 +258,14 @@ private: GrD3DTextureResourceInfo* info, GrProtected isProtected); - gr_cp fDevice; - gr_cp fQueue; + ComPtr fDevice; + ComPtr fQueue; GrD3DResourceProvider fResourceProvider; GrStagingBufferManager fStagingBufferManager; GrRingBuffer fConstantsRingBuffer; - gr_cp fFence; + ComPtr fFence; uint64_t fCurrentFenceValue = 0; std::unique_ptr fCurrentDirectCommandList; diff --git a/src/gpu/d3d/GrD3DPipelineState.cpp b/src/gpu/d3d/GrD3DPipelineState.cpp index 1515671f24..17219beb32 100644 --- a/src/gpu/d3d/GrD3DPipelineState.cpp +++ b/src/gpu/d3d/GrD3DPipelineState.cpp @@ -19,7 +19,7 @@ #include "src/gpu/glsl/GrGLSLXferProcessor.h" GrD3DPipelineState::GrD3DPipelineState( - gr_cp pipelineState, + ComPtr pipelineState, sk_sp rootSignature, const GrGLSLBuiltinUniformHandles& builtinUniformHandles, const UniformInfoArray& uniforms, uint32_t uniformSize, diff --git a/src/gpu/d3d/GrD3DPipelineState.h b/src/gpu/d3d/GrD3DPipelineState.h index 1d1795fb8b..b5e52d3824 100644 --- a/src/gpu/d3d/GrD3DPipelineState.h +++ b/src/gpu/d3d/GrD3DPipelineState.h @@ -24,7 +24,7 @@ class GrD3DPipelineState : public GrManagedResource { public: using UniformInfoArray = GrD3DPipelineStateDataManager::UniformInfoArray; - GrD3DPipelineState(gr_cp pipelineState, + GrD3DPipelineState(ComPtr pipelineState, sk_sp rootSignature, const GrGLSLBuiltinUniformHandles& builtinUniformHandles, const UniformInfoArray& uniforms, @@ -40,15 +40,15 @@ public: /** Output a human-readable dump of this resource's information */ void dumpInfo() const override { - SkDebugf("GrD3DPipelineState: %p (%d refs)\n", fPipelineState.get(), this->getRefCnt()); + SkDebugf("GrD3DPipelineState: %p (%d refs)\n", fPipelineState.Get(), this->getRefCnt()); } #endif // This will be called right before this class is destroyed and there is no reason to explicitly - // release the fPipelineState cause the gr_cp will handle that in the dtor. + // release the fPipelineState cause the ComPtr will handle that in the dtor. void freeGPUData() const override {} - ID3D12PipelineState* pipelineState() const { return fPipelineState.get(); } + ID3D12PipelineState* pipelineState() const { return fPipelineState.Get(); } const sk_sp& rootSignature() const { return fRootSignature; } void setAndBindConstants(GrD3DGpu*, const GrRenderTarget*, const GrProgramInfo&); @@ -107,7 +107,7 @@ private: // Helper for setData() that sets the view matrix and loads the render target height uniform void setRenderTargetState(const GrRenderTarget*, GrSurfaceOrigin); - gr_cp fPipelineState; + ComPtr fPipelineState; sk_sp fRootSignature; // Tracks the current render target uniforms stored in the vertex buffer. diff --git a/src/gpu/d3d/GrD3DPipelineStateBuilder.cpp b/src/gpu/d3d/GrD3DPipelineStateBuilder.cpp index a653ce1f3d..a425d62ef0 100644 --- a/src/gpu/d3d/GrD3DPipelineStateBuilder.cpp +++ b/src/gpu/d3d/GrD3DPipelineStateBuilder.cpp @@ -66,7 +66,7 @@ void GrD3DPipelineStateBuilder::finalizeFragmentSecondaryColor(GrShaderVar& outp outputColor.addLayoutQualifier("location = 0, index = 1"); } -static gr_cp GrCompileHLSLShader(GrD3DGpu* gpu, +static ComPtr GrCompileHLSLShader(GrD3DGpu* gpu, const SkSL::String& hlsl, SkSL::Program::Kind kind) { const char* compileTarget = nullptr; @@ -92,8 +92,8 @@ static gr_cp GrCompileHLSLShader(GrD3DGpu* gpu, // SPRIV-cross does matrix multiplication expecting row major matrices compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR; - gr_cp shader; - gr_cp errors; + ComPtr shader; + ComPtr errors; HRESULT hr = D3DCompile(hlsl.c_str(), hlsl.length(), nullptr, nullptr, nullptr, "main", compileTarget, compileFlags, 0, &shader, &errors); if (!SUCCEEDED(hr)) { @@ -103,7 +103,7 @@ static gr_cp GrCompileHLSLShader(GrD3DGpu* gpu, return shader; } -bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, gr_cp shaders[]) { +bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, ComPtr shaders[]) { SkSL::String hlsl[kGrShaderTypeCount]; SkSL::Program::Inputs inputs[kGrShaderTypeCount]; @@ -117,7 +117,7 @@ bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, gr_cpaddRTHeightUniform(SKSL_RTHEIGHT_NAME); } shaders[shaderType] = GrCompileHLSLShader(fGpu, hlsl[shaderType], kind); - return shaders[shaderType].get(); + return shaders[shaderType].Get(); }; return compile(SkSL::Program::kVertex_Kind, kVertex_GrShaderType) && @@ -126,7 +126,7 @@ bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, gr_cp GrD3DPipelineStateBuilder::compileD3DProgram( +ComPtr GrD3DPipelineStateBuilder::compileD3DProgram( SkSL::Program::Kind kind, const SkSL::String& sksl, const SkSL::Program::Settings& settings, @@ -138,13 +138,13 @@ gr_cp GrD3DPipelineStateBuilder::compileD3DProgram( if (!program) { errorHandler->compileError(sksl.c_str(), fGpu->shaderCompiler()->errorText().c_str()); - return gr_cp(); + return ComPtr(); } *outInputs = program->fInputs; if (!fGpu->shaderCompiler()->toHLSL(*program, outHLSL)) { errorHandler->compileError(sksl.c_str(), fGpu->shaderCompiler()->errorText().c_str()); - return gr_cp(); + return ComPtr(); } if (program->fInputs.fRTHeight) { @@ -472,11 +472,11 @@ static D3D12_PRIMITIVE_TOPOLOGY_TYPE gr_primitive_type_to_d3d(GrPrimitiveType pr } } -gr_cp create_pipeline_state( +ComPtr create_pipeline_state( GrD3DGpu* gpu, const GrProgramInfo& programInfo, const sk_sp& rootSig, - gr_cp vertexShader, gr_cp geometryShader, gr_cp pixelShader, - DXGI_FORMAT renderTargetFormat, DXGI_FORMAT depthStencilFormat, - unsigned int sampleQualityPattern) { + ComPtr vertexShader, ComPtr geometryShader, + ComPtr pixelShader, DXGI_FORMAT renderTargetFormat, + DXGI_FORMAT depthStencilFormat, unsigned int sampleQualityPattern) { D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.pRootSignature = rootSig->rootSignature(); @@ -486,7 +486,7 @@ gr_cp create_pipeline_state( psoDesc.PS = { reinterpret_cast(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; - if (geometryShader.get()) { + if (geometryShader.Get()) { psoDesc.GS = { reinterpret_cast(geometryShader->GetBufferPointer()), geometryShader->GetBufferSize() }; } @@ -527,7 +527,7 @@ gr_cp create_pipeline_state( psoDesc.CachedPSO = { nullptr, 0 }; psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE; - gr_cp pipelineState; + ComPtr pipelineState; GR_D3D_CALL_ERRCHECK(gpu->device()->CreateGraphicsPipelineState( &psoDesc, IID_PPV_ARGS(&pipelineState))); @@ -576,7 +576,7 @@ sk_sp GrD3DPipelineStateBuilder::finalize() { } const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); - gr_cp shaders[kGrShaderTypeCount]; + ComPtr shaders[kGrShaderTypeCount]; if (kHLSL_Tag == shaderType && this->loadHLSLFromCache(&reader, shaders)) { // We successfully loaded and compiled HLSL @@ -602,7 +602,7 @@ sk_sp GrD3DPipelineStateBuilder::finalize() { auto compile = [&](SkSL::Program::Kind kind, GrShaderType shaderType) { shaders[shaderType] = this->compileD3DProgram(kind, *sksl[shaderType], settings, &inputs[shaderType], &hlsl[shaderType]); - return shaders[shaderType].get(); + return shaders[shaderType].Get(); }; if (!compile(SkSL::Program::kVertex_Kind, kVertex_GrShaderType) || @@ -641,7 +641,7 @@ sk_sp GrD3DPipelineStateBuilder::finalize() { } const GrD3DRenderTarget* rt = static_cast(fRenderTarget); - gr_cp pipelineState = create_pipeline_state( + ComPtr pipelineState = create_pipeline_state( fGpu, fProgramInfo, rootSig, std::move(shaders[kVertex_GrShaderType]), std::move(shaders[kGeometry_GrShaderType]), std::move(shaders[kFragment_GrShaderType]), rt->dxgiFormat(), rt->stencilDxgiFormat(), rt->sampleQualityPattern()); diff --git a/src/gpu/d3d/GrD3DPipelineStateBuilder.h b/src/gpu/d3d/GrD3DPipelineStateBuilder.h index 5cbd017a95..08e922ec3f 100644 --- a/src/gpu/d3d/GrD3DPipelineStateBuilder.h +++ b/src/gpu/d3d/GrD3DPipelineStateBuilder.h @@ -45,9 +45,9 @@ private: sk_sp finalize(); - bool loadHLSLFromCache(SkReadBuffer* reader, gr_cp shaders[]); + bool loadHLSLFromCache(SkReadBuffer* reader, ComPtr shaders[]); - gr_cp compileD3DProgram(SkSL::Program::Kind kind, + ComPtr compileD3DProgram(SkSL::Program::Kind kind, const SkSL::String& sksl, const SkSL::Program::Settings& settings, SkSL::Program::Inputs* outInputs, diff --git a/src/gpu/d3d/GrD3DRenderTarget.cpp b/src/gpu/d3d/GrD3DRenderTarget.cpp index c6d14e61f9..3ba80be741 100644 --- a/src/gpu/d3d/GrD3DRenderTarget.cpp +++ b/src/gpu/d3d/GrD3DRenderTarget.cpp @@ -93,12 +93,12 @@ GrD3DRenderTarget::GrD3DRenderTarget(GrD3DGpu* gpu, sk_sp GrD3DRenderTarget::MakeWrappedRenderTarget( GrD3DGpu* gpu, SkISize dimensions, int sampleCnt, const GrD3DTextureResourceInfo& info, sk_sp state) { - SkASSERT(info.fResource.get()); + SkASSERT(info.fResource.Get()); SkASSERT(1 == info.fLevelCount); GrD3DDescriptorHeap::CPUHandle renderTargetView = - gpu->resourceProvider().createRenderTargetView(info.fResource.get()); + gpu->resourceProvider().createRenderTargetView(info.fResource.Get()); // create msaa surface if necessary GrD3DRenderTarget* d3dRT; @@ -111,7 +111,7 @@ sk_sp GrD3DRenderTarget::MakeWrappedRenderTarget( GrD3DTextureResource::CreateMSAA(gpu, dimensions, sampleCnt, info, clearColor); GrD3DDescriptorHeap::CPUHandle msaaRenderTargetView = - gpu->resourceProvider().createRenderTargetView(msInfo.fResource.get()); + gpu->resourceProvider().createRenderTargetView(msInfo.fResource.Get()); d3dRT = new GrD3DRenderTarget(gpu, dimensions, sampleCnt, info, std::move(state), msInfo, std::move(msState), msaaRenderTargetView, diff --git a/src/gpu/d3d/GrD3DRootSignature.cpp b/src/gpu/d3d/GrD3DRootSignature.cpp index e64faa2ba0..8ecb798d45 100644 --- a/src/gpu/d3d/GrD3DRootSignature.cpp +++ b/src/gpu/d3d/GrD3DRootSignature.cpp @@ -69,8 +69,8 @@ sk_sp GrD3DRootSignature::Make(GrD3DGpu* gpu, int numTexture rootDesc.pStaticSamplers = nullptr; rootDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; - gr_cp rootSigBinary; - gr_cp error; + ComPtr rootSigBinary; + ComPtr error; // TODO: D3D Static Function HRESULT hr = D3D12SerializeRootSignature(&rootDesc, D3D_ROOT_SIGNATURE_VERSION_1_0, &rootSigBinary, &error); @@ -81,7 +81,7 @@ sk_sp GrD3DRootSignature::Make(GrD3DGpu* gpu, int numTexture return nullptr; } - gr_cp rootSig; + ComPtr rootSig; hr = gpu->device()->CreateRootSignature(0, rootSigBinary->GetBufferPointer(), rootSigBinary->GetBufferSize(), IID_PPV_ARGS(&rootSig)); @@ -94,7 +94,7 @@ sk_sp GrD3DRootSignature::Make(GrD3DGpu* gpu, int numTexture numTextureSamplers)); } -GrD3DRootSignature::GrD3DRootSignature(gr_cp rootSig, int numTextureSamplers) +GrD3DRootSignature::GrD3DRootSignature(ComPtr rootSig, int numTextureSamplers) : fRootSignature(std::move(rootSig)) , fNumTextureSamplers(numTextureSamplers) { } diff --git a/src/gpu/d3d/GrD3DRootSignature.h b/src/gpu/d3d/GrD3DRootSignature.h index 9ce311076b..68e9859a37 100644 --- a/src/gpu/d3d/GrD3DRootSignature.h +++ b/src/gpu/d3d/GrD3DRootSignature.h @@ -28,25 +28,25 @@ public: bool isCompatible(int numTextureSamplers) const; - ID3D12RootSignature* rootSignature() const { return fRootSignature.get(); } + ID3D12RootSignature* rootSignature() const { return fRootSignature.Get(); } #ifdef SK_TRACE_MANAGED_RESOURCES /** Output a human-readable dump of this resource's information */ void dumpInfo() const override { SkDebugf("GrD3DRootSignature: %p, numTextures: %d (%d refs)\n", - fRootSignature.get(), fNumTextureSamplers, this->getRefCnt()); + fRootSignature.Get(), fNumTextureSamplers, this->getRefCnt()); } #endif private: - GrD3DRootSignature(gr_cp rootSig, int numTextureSamplers); + GrD3DRootSignature(ComPtr rootSig, int numTextureSamplers); // This will be called right before this class is destroyed and there is no reason to explicitly - // release the fRootSignature cause the gr_cp will handle that in the dtor. + // release the fRootSignature cause the ComPtr will handle that in the dtor. void freeGPUData() const override {} - gr_cp fRootSignature; + ComPtr fRootSignature; int fNumTextureSamplers; }; diff --git a/src/gpu/d3d/GrD3DSemaphore.h b/src/gpu/d3d/GrD3DSemaphore.h index da1afdcf7b..5c1a494a32 100644 --- a/src/gpu/d3d/GrD3DSemaphore.h +++ b/src/gpu/d3d/GrD3DSemaphore.h @@ -23,7 +23,7 @@ public: ~GrD3DSemaphore() override {} - ID3D12Fence* fence() const { return fFenceInfo.fFence.get(); } + ID3D12Fence* fence() const { return fFenceInfo.fFence.Get(); } uint64_t value() const { return fFenceInfo.fValue; } GrBackendSemaphore backendSemaphore() const override; diff --git a/src/gpu/d3d/GrD3DStencilAttachment.cpp b/src/gpu/d3d/GrD3DStencilAttachment.cpp index 7874876322..9b9cecc916 100644 --- a/src/gpu/d3d/GrD3DStencilAttachment.cpp +++ b/src/gpu/d3d/GrD3DStencilAttachment.cpp @@ -53,7 +53,7 @@ GrD3DStencilAttachment* GrD3DStencilAttachment::Make(GrD3DGpu* gpu, } GrD3DDescriptorHeap::CPUHandle view = - gpu->resourceProvider().createDepthStencilView(info.fResource.get()); + gpu->resourceProvider().createDepthStencilView(info.fResource.Get()); sk_sp state(new GrD3DResourceState(info.fResourceState)); GrD3DStencilAttachment* stencil = new GrD3DStencilAttachment(gpu, format, resourceDesc, diff --git a/src/gpu/d3d/GrD3DTexture.cpp b/src/gpu/d3d/GrD3DTexture.cpp index b7603652d0..427f23e57f 100644 --- a/src/gpu/d3d/GrD3DTexture.cpp +++ b/src/gpu/d3d/GrD3DTexture.cpp @@ -78,7 +78,7 @@ sk_sp GrD3DTexture::MakeNewTexture(GrD3DGpu* gpu, SkBudgeted budge new GrD3DResourceState(static_cast(info.fResourceState))); GrD3DDescriptorHeap::CPUHandle shaderResourceView = - gpu->resourceProvider().createShaderResourceView(info.fResource.get()); + gpu->resourceProvider().createShaderResourceView(info.fResource.Get()); GrD3DTexture* tex = new GrD3DTexture(gpu, budgeted, dimensions, info, std::move(state), shaderResourceView, mipmapStatus); @@ -101,7 +101,7 @@ sk_sp GrD3DTexture::MakeWrappedTexture(GrD3DGpu* gpu, : GrMipmapStatus::kNotAllocated; GrD3DDescriptorHeap::CPUHandle shaderResourceView = - gpu->resourceProvider().createShaderResourceView(info.fResource.get()); + gpu->resourceProvider().createShaderResourceView(info.fResource.Get()); return sk_sp(new GrD3DTexture(gpu, dimensions, info, std::move(state), shaderResourceView, mipmapStatus, cacheable, diff --git a/src/gpu/d3d/GrD3DTextureRenderTarget.cpp b/src/gpu/d3d/GrD3DTextureRenderTarget.cpp index 682c32e8cd..95ed78a3a1 100644 --- a/src/gpu/d3d/GrD3DTextureRenderTarget.cpp +++ b/src/gpu/d3d/GrD3DTextureRenderTarget.cpp @@ -100,10 +100,10 @@ sk_sp GrD3DTextureRenderTarget::MakeNewTextureRenderTa static_cast(info.fResourceState))); const GrD3DDescriptorHeap::CPUHandle shaderResourceView = - gpu->resourceProvider().createShaderResourceView(info.fResource.get()); + gpu->resourceProvider().createShaderResourceView(info.fResource.Get()); const GrD3DDescriptorHeap::CPUHandle renderTargetView = - gpu->resourceProvider().createRenderTargetView(info.fResource.get()); + gpu->resourceProvider().createRenderTargetView(info.fResource.Get()); if (sampleCnt > 1) { GrD3DTextureResourceInfo msInfo; @@ -114,7 +114,7 @@ sk_sp GrD3DTextureRenderTarget::MakeNewTextureRenderTa GrD3DTextureResource::CreateMSAA(gpu, dimensions, sampleCnt, info, clearColor); const GrD3DDescriptorHeap::CPUHandle msaaRenderTargetView = - gpu->resourceProvider().createRenderTargetView(msInfo.fResource.get()); + gpu->resourceProvider().createRenderTargetView(msInfo.fResource.Get()); GrD3DTextureRenderTarget* trt = new GrD3DTextureRenderTarget( gpu, budgeted, dimensions, sampleCnt, info, std::move(state), shaderResourceView, @@ -144,10 +144,10 @@ sk_sp GrD3DTextureRenderTarget::MakeWrappedTextureRend : GrMipmapStatus::kNotAllocated; const GrD3DDescriptorHeap::CPUHandle shaderResourceView = - gpu->resourceProvider().createShaderResourceView(info.fResource.get()); + gpu->resourceProvider().createShaderResourceView(info.fResource.Get()); const GrD3DDescriptorHeap::CPUHandle renderTargetView = - gpu->resourceProvider().createRenderTargetView(info.fResource.get()); + gpu->resourceProvider().createRenderTargetView(info.fResource.Get()); if (sampleCnt > 1) { GrD3DTextureResourceInfo msInfo; @@ -158,7 +158,7 @@ sk_sp GrD3DTextureRenderTarget::MakeWrappedTextureRend GrD3DTextureResource::CreateMSAA(gpu, dimensions, sampleCnt, info, clearColor); const GrD3DDescriptorHeap::CPUHandle msaaRenderTargetView = - gpu->resourceProvider().createRenderTargetView(msInfo.fResource.get()); + gpu->resourceProvider().createRenderTargetView(msInfo.fResource.Get()); GrD3DTextureRenderTarget* trt = new GrD3DTextureRenderTarget( gpu, dimensions, sampleCnt, info, std::move(state), shaderResourceView, diff --git a/src/gpu/d3d/GrD3DTextureResource.cpp b/src/gpu/d3d/GrD3DTextureResource.cpp index 1fa7005c5b..883d734157 100644 --- a/src/gpu/d3d/GrD3DTextureResource.cpp +++ b/src/gpu/d3d/GrD3DTextureResource.cpp @@ -61,7 +61,7 @@ bool GrD3DTextureResource::InitTextureResourceInfo(GrD3DGpu* gpu, const D3D12_RE return false; } - info->fResource.reset(resource); + info->fResource.Attach(resource); info->fResourceState = initialState; info->fFormat = desc.Format; info->fLevelCount = desc.MipLevels; @@ -134,5 +134,5 @@ void GrD3DTextureResource::setResourceRelease(sk_sp releaseH void GrD3DTextureResource::Resource::freeGPUData() const { this->invokeReleaseProc(); - fResource.reset(); // Release our ref to the resource + fResource.Reset(); // Release our ref to the resource } diff --git a/src/gpu/d3d/GrD3DTextureResource.h b/src/gpu/d3d/GrD3DTextureResource.h index 37802d80a7..329f97314f 100644 --- a/src/gpu/d3d/GrD3DTextureResource.h +++ b/src/gpu/d3d/GrD3DTextureResource.h @@ -26,14 +26,14 @@ public: : fInfo(info) , fState(std::move(state)) , fResource(new Resource(fInfo.fResource)) { - // gr_cp will implicitly ref the ID3D12Resource for us, so we don't need to worry about + // ComPtr will implicitly ref the ID3D12Resource for us, so we don't need to worry about // whether it's borrowed or not } virtual ~GrD3DTextureResource(); ID3D12Resource* d3dResource() const { SkASSERT(fResource); - return fInfo.fResource.get(); + return fInfo.fResource.Get(); } DXGI_FORMAT dxgiFormat() const { return fInfo.fFormat; } GrBackendFormat getBackendFormat() const { @@ -109,7 +109,7 @@ private: : fResource(nullptr) { } - Resource(const gr_cp& textureResource) + Resource(const ComPtr& textureResource) : fResource(textureResource) { } @@ -117,14 +117,14 @@ private: #ifdef SK_TRACE_MANAGED_RESOURCES void dumpInfo() const override { - SkDebugf("GrD3DTextureResource: %d (%d refs)\n", fResource.get(), this->getRefCnt()); + SkDebugf("GrD3DTextureResource: %d (%d refs)\n", fResource.Get(), this->getRefCnt()); } #endif private: void freeGPUData() const override; - mutable gr_cp fResource; + mutable ComPtr fResource; using INHERITED = GrTextureResource; }; diff --git a/tools/gpu/d3d/D3DTestUtils.cpp b/tools/gpu/d3d/D3DTestUtils.cpp index 574c7fd36e..e104e627de 100644 --- a/tools/gpu/d3d/D3DTestUtils.cpp +++ b/tools/gpu/d3d/D3DTestUtils.cpp @@ -39,7 +39,7 @@ bool CreateD3DBackendContext(GrD3DBackendContext* ctx, #if defined(SK_ENABLE_D3D_DEBUG_LAYER) // Enable the D3D12 debug layer. { - gr_cp debugController; + ComPtr debugController; if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { debugController->EnableDebugLayer(); @@ -47,23 +47,23 @@ bool CreateD3DBackendContext(GrD3DBackendContext* ctx, } #endif // Create the device - gr_cp factory; + ComPtr factory; if (!SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) { return false; } - gr_cp hardwareAdapter; - get_hardware_adapter(factory.get(), &hardwareAdapter); + ComPtr hardwareAdapter; + get_hardware_adapter(factory.Get(), &hardwareAdapter); - gr_cp device; - if (!SUCCEEDED(D3D12CreateDevice(hardwareAdapter.get(), + ComPtr device; + if (!SUCCEEDED(D3D12CreateDevice(hardwareAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)))) { return false; } // Create the command queue - gr_cp queue; + ComPtr queue; D3D12_COMMAND_QUEUE_DESC queueDesc = {}; queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; diff --git a/tools/sk_app/win/D3D12WindowContext_win.cpp b/tools/sk_app/win/D3D12WindowContext_win.cpp index 14dbc5f654..6ce1c2700c 100644 --- a/tools/sk_app/win/D3D12WindowContext_win.cpp +++ b/tools/sk_app/win/D3D12WindowContext_win.cpp @@ -40,7 +40,7 @@ public: void setupSurfaces(int width, int height); bool isValid() override { - return fDevice.get() != nullptr; + return fDevice.Get() != nullptr; } sk_sp getBackbufferSurface() override; @@ -52,16 +52,16 @@ private: static constexpr int kNumFrames = 2; HWND fWindow; - gr_cp fDevice; - gr_cp fQueue; - gr_cp fSwapChain; - gr_cp fBuffers[kNumFrames]; + ComPtr fDevice; + ComPtr fQueue; + ComPtr fSwapChain; + ComPtr fBuffers[kNumFrames]; sk_sp fSurfaces[kNumFrames]; // Synchronization objects. unsigned int fBufferIndex; HANDLE fFenceEvent; - gr_cp fFence; + ComPtr fFence; uint64_t fFenceValues[kNumFrames]; }; @@ -94,7 +94,7 @@ void D3D12WindowContext::initializeContext() { UINT dxgiFactoryFlags = 0; SkDEBUGCODE(dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;) - gr_cp factory; + ComPtr factory; GR_D3D_CALL_ERRCHECK(CreateDXGIFactory2(dxgiFactoryFlags, IID_PPV_ARGS(&factory))); DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {}; @@ -106,9 +106,9 @@ void D3D12WindowContext::initializeContext() { swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.SampleDesc.Count = 1; - gr_cp swapChain; + ComPtr swapChain; GR_D3D_CALL_ERRCHECK(factory->CreateSwapChainForHwnd( - fQueue.get(), fWindow, &swapChainDesc, nullptr, nullptr, &swapChain)); + fQueue.Get(), fWindow, &swapChainDesc, nullptr, nullptr, &swapChain)); // We don't support fullscreen transitions. GR_D3D_CALL_ERRCHECK(factory->MakeWindowAssociation(fWindow, DXGI_MWA_NO_ALT_ENTER)); @@ -164,16 +164,16 @@ void D3D12WindowContext::setupSurfaces(int width, int height) { void D3D12WindowContext::destroyContext() { CloseHandle(fFenceEvent); - fFence.reset(nullptr); + fFence.Reset(); for (int i = 0; i < kNumFrames; ++i) { - fSurfaces[i].reset(nullptr); - fBuffers[i].reset(nullptr); + fSurfaces[i].reset(); + fBuffers[i].Reset(); } - fSwapChain.reset(nullptr); - fQueue.reset(nullptr); - fDevice.reset(nullptr); + fSwapChain.Reset(); + fQueue.Reset(); + fDevice.Reset(); } sk_sp D3D12WindowContext::getBackbufferSurface() { @@ -203,7 +203,7 @@ void D3D12WindowContext::swapBuffers() { GR_D3D_CALL_ERRCHECK(fSwapChain->Present(1, 0)); // Schedule a Signal command in the queue. - GR_D3D_CALL_ERRCHECK(fQueue->Signal(fFence.get(), fFenceValues[fBufferIndex])); + GR_D3D_CALL_ERRCHECK(fQueue->Signal(fFence.Get(), fFenceValues[fBufferIndex])); } void D3D12WindowContext::resize(int width, int height) { @@ -218,8 +218,8 @@ void D3D12WindowContext::resize(int width, int height) { GR_D3D_CALL_ERRCHECK(fFence->SetEventOnCompletion(fFenceValues[i], fFenceEvent)); WaitForSingleObjectEx(fFenceEvent, INFINITE, FALSE); } - fSurfaces[i].reset(nullptr); - fBuffers[i].reset(nullptr); + fSurfaces[i].reset(); + fBuffers[i].Reset(); } GR_D3D_CALL_ERRCHECK(fSwapChain->ResizeBuffers(0, width, height,