Revert "Reland "Use Microsoft's ComPtr to wrap D3D12 objects.""

This reverts commit b8ae7fa12a.

Reason for revert: Introduced a memory leak

Original change's description:
> Reland "Use Microsoft's ComPtr to wrap D3D12 objects."
> 
> This is a reland of 0ef049177f
> 
> Original change's description:
> > Use Microsoft's ComPtr to wrap D3D12 objects.
> > 
> > Change-Id: I4bd173428a2b65f0bc1994fb794ef9d4d68d5ba0
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314957
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > Commit-Queue: Jim Van Verth <jvanverth@google.com>
> 
> Change-Id: Id0199db4061c67ed53da35e74dc31a004744be95
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315655
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Jim Van Verth <jvanverth@google.com>

TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I3f8744668558f6b8f4f367eeeeff2f6aa2c36992
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318209
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2020-09-21 17:18:04 -04:00 committed by Skia Commit-Bot
parent 2b788b11e0
commit 5fba9ae0cb
28 changed files with 268 additions and 148 deletions

View File

@ -15,9 +15,6 @@ Milestone 87
the deprecated, expanding clip ops.
https://review.skia.org/317209
* 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

View File

@ -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 {
ComPtr<IDXGIAdapter1> fAdapter;
ComPtr<ID3D12Device> fDevice;
ComPtr<ID3D12CommandQueue> fQueue;
gr_cp<IDXGIAdapter1> fAdapter;
gr_cp<ID3D12Device> fDevice;
gr_cp<ID3D12CommandQueue> fQueue;
GrProtected fProtectedContext = GrProtected::kNo;
};

View File

@ -24,15 +24,138 @@
#include "include/gpu/d3d/GrD3DTypesMinimal.h"
#include <d3d12.h>
#include <dxgi1_4.h>
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;
/** Check if the argument is non-null, and if so, call obj->AddRef() and return obj.
*/
template <typename T> 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 <typename T> static inline void GrSafeComRelease(T* obj) {
if (obj) {
obj->Release();
}
}
template <typename T> 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<T>& 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<T>&& 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<T>& operator=(const gr_cp<T>& 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<T>& operator=(gr_cp<T>&& 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 <typename T> inline bool operator==(const gr_cp<T>& a,
const gr_cp<T>& b) {
return a.get() == b.get();
}
template <typename T> inline bool operator!=(const gr_cp<T>& a,
const gr_cp<T>& b) {
return a.get() != b.get();
}
// 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 {
ComPtr<ID3D12Resource> fResource;
gr_cp<ID3D12Resource> fResource;
D3D12_RESOURCE_STATES fResourceState;
DXGI_FORMAT fFormat;
uint32_t fLevelCount;
@ -47,7 +170,7 @@ struct GrD3DTextureResourceInfo {
, fSampleQualityPattern(DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN)
, fProtected(GrProtected::kNo) {}
GrD3DTextureResourceInfo(const ComPtr<ID3D12Resource>& resource,
GrD3DTextureResourceInfo(ID3D12Resource* resource,
D3D12_RESOURCE_STATES resourceState,
DXGI_FORMAT format,
uint32_t levelCount,
@ -84,8 +207,8 @@ struct GrD3DFenceInfo {
, fValue(0) {
}
ComPtr<ID3D12Fence> fFence;
uint64_t fValue; // signal value for the fence
gr_cp<ID3D12Fence> fFence;
uint64_t fValue; // signal value for the fence
};
#endif

View File

@ -16,7 +16,7 @@
#define VALIDATE() do {} while(false)
#endif
static ComPtr<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
static gr_cp<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern,
@ -61,7 +61,7 @@ static ComPtr<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
bufferDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
ComPtr<ID3D12Resource> resource;
ID3D12Resource* resource;
HRESULT hr = gpu->device()->CreateCommittedResource(
&heapProperties,
D3D12_HEAP_FLAG_NONE,
@ -73,7 +73,7 @@ static ComPtr<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
return nullptr;
}
return resource;
return gr_cp<ID3D12Resource>(resource);
}
sk_sp<GrD3DBuffer> GrD3DBuffer::Make(GrD3DGpu* gpu, size_t size, GrGpuBufferType intendedType,
@ -82,8 +82,8 @@ sk_sp<GrD3DBuffer> GrD3DBuffer::Make(GrD3DGpu* gpu, size_t size, GrGpuBufferType
D3D12_RESOURCE_STATES resourceState;
ComPtr<ID3D12Resource> resource = make_d3d_buffer(gpu, size, intendedType, accessPattern,
&resourceState);
gr_cp<ID3D12Resource> resource = make_d3d_buffer(gpu, size, intendedType, accessPattern,
&resourceState);
if (!resource) {
return nullptr;
}
@ -93,7 +93,7 @@ sk_sp<GrD3DBuffer> GrD3DBuffer::Make(GrD3DGpu* gpu, size_t size, GrGpuBufferType
}
GrD3DBuffer::GrD3DBuffer(GrD3DGpu* gpu, size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, ComPtr<ID3D12Resource> bufferResource,
GrAccessPattern accessPattern, gr_cp<ID3D12Resource> bufferResource,
D3D12_RESOURCE_STATES resourceState)
: INHERITED(gpu, size, intendedType, accessPattern)
, fResourceState(resourceState)

View File

@ -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, ComPtr<ID3D12Resource>,
GrD3DBuffer(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern, gr_cp<ID3D12Resource>,
D3D12_RESOURCE_STATES);
void onAbandon() override;
@ -52,7 +52,7 @@ private:
return reinterpret_cast<GrD3DGpu*>(this->getGpu());
}
ComPtr<ID3D12Resource> fD3DResource;
gr_cp<ID3D12Resource> fD3DResource;
ID3D12Resource* fStagingBuffer = nullptr;
size_t fStagingOffset = 0;

View File

@ -18,8 +18,8 @@
#include "src/gpu/d3d/GrD3DTextureResource.h"
#include "src/gpu/d3d/GrD3DUtil.h"
GrD3DCommandList::GrD3DCommandList(ComPtr<ID3D12CommandAllocator> allocator,
ComPtr<ID3D12GraphicsCommandList> commandList)
GrD3DCommandList::GrD3DCommandList(gr_cp<ID3D12CommandAllocator> allocator,
gr_cp<ID3D12GraphicsCommandList> 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> GrD3DDirectCommandList::Make(ID3D12Device* device) {
ComPtr<ID3D12CommandAllocator> allocator;
gr_cp<ID3D12CommandAllocator> allocator;
GR_D3D_CALL_ERRCHECK(device->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator)));
ComPtr<ID3D12GraphicsCommandList> commandList;
gr_cp<ID3D12GraphicsCommandList> 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<GrD3DDirectCommandList>(grCL);
}
GrD3DDirectCommandList::GrD3DDirectCommandList(ComPtr<ID3D12CommandAllocator> allocator,
ComPtr<ID3D12GraphicsCommandList> commandList)
GrD3DDirectCommandList::GrD3DDirectCommandList(gr_cp<ID3D12CommandAllocator> allocator,
gr_cp<ID3D12GraphicsCommandList> 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) {
ComPtr<ID3D12GraphicsCommandList1> commandList1;
gr_cp<ID3D12GraphicsCommandList1> 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) {
ComPtr<ID3D12GraphicsCommandList1> commandList1;
gr_cp<ID3D12GraphicsCommandList1> commandList1;
GR_D3D_CALL_ERRCHECK(fCommandList->QueryInterface(IID_PPV_ARGS(&commandList1)));
commandList1->SetSamplePositions(0, 0, nullptr);
fUsingCenteredSamples = false;
@ -444,7 +444,7 @@ void GrD3DDirectCommandList::resolveSubresourceRegion(const GrD3DTextureResource
this->addResource(dstTexture->resource());
this->addResource(srcTexture->resource());
ComPtr<ID3D12GraphicsCommandList1> commandList1;
gr_cp<ID3D12GraphicsCommandList1> commandList1;
HRESULT result = fCommandList->QueryInterface(IID_PPV_ARGS(&commandList1));
if (SUCCEEDED(result)) {
commandList1->ResolveSubresourceRegion(dstTexture->d3dResource(), 0, dstX, dstY,
@ -505,18 +505,18 @@ void GrD3DDirectCommandList::addSampledTextureRef(GrD3DTexture* texture) {
////////////////////////////////////////////////////////////////////////////////////////////////////
std::unique_ptr<GrD3DCopyCommandList> GrD3DCopyCommandList::Make(ID3D12Device* device) {
ComPtr<ID3D12CommandAllocator> allocator;
gr_cp<ID3D12CommandAllocator> allocator;
GR_D3D_CALL_ERRCHECK(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&allocator)));
ComPtr<ID3D12GraphicsCommandList> commandList;
GR_D3D_CALL_ERRCHECK(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, allocator.Get(),
gr_cp<ID3D12GraphicsCommandList> 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<GrD3DCopyCommandList>(grCL);
}
GrD3DCopyCommandList::GrD3DCopyCommandList(ComPtr<ID3D12CommandAllocator> allocator,
ComPtr<ID3D12GraphicsCommandList> commandList)
GrD3DCopyCommandList::GrD3DCopyCommandList(gr_cp<ID3D12CommandAllocator> allocator,
gr_cp<ID3D12GraphicsCommandList> commandList)
: GrD3DCommandList(std::move(allocator), std::move(commandList)) {
}

View File

@ -100,8 +100,8 @@ private:
static const int kInitialTrackedResourcesCount = 32;
protected:
GrD3DCommandList(ComPtr<ID3D12CommandAllocator> allocator,
ComPtr<ID3D12GraphicsCommandList> commandList);
GrD3DCommandList(gr_cp<ID3D12CommandAllocator> allocator,
gr_cp<ID3D12GraphicsCommandList> commandList);
// Add ref-counted resource that will be tracked and released when this command buffer finishes
// execution
@ -123,7 +123,7 @@ protected:
void submitResourceBarriers();
ComPtr<ID3D12GraphicsCommandList> fCommandList;
gr_cp<ID3D12GraphicsCommandList> fCommandList;
SkSTArray<kInitialTrackedResourcesCount, sk_sp<GrManagedResource>> fTrackedResources;
SkSTArray<kInitialTrackedResourcesCount, sk_sp<GrRecycledResource>> fTrackedRecycledResources;
@ -137,7 +137,7 @@ protected:
private:
void callFinishedCallbacks() { fFinishedCallbacks.reset(); }
ComPtr<ID3D12CommandAllocator> fAllocator;
gr_cp<ID3D12CommandAllocator> fAllocator;
SkSTArray<4, D3D12_RESOURCE_BARRIER> fResourceBarriers;
@ -194,8 +194,8 @@ public:
void addSampledTextureRef(GrD3DTexture*);
private:
GrD3DDirectCommandList(ComPtr<ID3D12CommandAllocator> allocator,
ComPtr<ID3D12GraphicsCommandList> commandList);
GrD3DDirectCommandList(gr_cp<ID3D12CommandAllocator> allocator,
gr_cp<ID3D12GraphicsCommandList> commandList);
void onReset() override;
@ -219,7 +219,7 @@ public:
static std::unique_ptr<GrD3DCopyCommandList> Make(ID3D12Device* device);
private:
GrD3DCopyCommandList(ComPtr<ID3D12CommandAllocator> allocator,
ComPtr<ID3D12GraphicsCommandList> commandList);
GrD3DCopyCommandList(gr_cp<ID3D12CommandAllocator> allocator,
gr_cp<ID3D12GraphicsCommandList> commandList);
};
#endif

View File

@ -24,7 +24,7 @@ sk_sp<GrD3DCommandSignature> GrD3DCommandSignature::Make(GrD3DGpu* gpu, ForIndex
commandSigDesc.pArgumentDescs = &argumentDesc;
commandSigDesc.NodeMask = 0;
ComPtr<ID3D12CommandSignature> commandSig;
gr_cp<ID3D12CommandSignature> commandSig;
HRESULT hr = gpu->device()->CreateCommandSignature(&commandSigDesc, nullptr,
IID_PPV_ARGS(&commandSig));
if (!SUCCEEDED(hr)) {

View File

@ -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(ComPtr<ID3D12CommandSignature> commandSignature, ForIndexed indexed,
GrD3DCommandSignature(gr_cp<ID3D12CommandSignature> 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 ComPtr will handle that in the dtor.
// release the fCommandSignature cause the gr_cp will handle that in the dtor.
void freeGPUData() const override {}
ComPtr<ID3D12CommandSignature> fCommandSignature;
gr_cp<ID3D12CommandSignature> fCommandSignature;
ForIndexed fIndexed;
unsigned int fSlot;
};

View File

@ -17,15 +17,15 @@ std::unique_ptr<GrD3DDescriptorHeap> GrD3DDescriptorHeap::Make(GrD3DGpu* gpu,
heapDesc.NumDescriptors = numDescriptors;
heapDesc.Flags = flags;
ComPtr<ID3D12DescriptorHeap> heap;
ID3D12DescriptorHeap* heap;
gpu->device()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&heap));
return std::unique_ptr<GrD3DDescriptorHeap>(
new GrD3DDescriptorHeap(std::move(heap),
new GrD3DDescriptorHeap(std::move(gr_cp<ID3D12DescriptorHeap>(heap)),
gpu->device()->GetDescriptorHandleIncrementSize(type)));
}
GrD3DDescriptorHeap::GrD3DDescriptorHeap(const ComPtr<ID3D12DescriptorHeap>& heap,
GrD3DDescriptorHeap::GrD3DDescriptorHeap(const gr_cp<ID3D12DescriptorHeap>& heap,
unsigned int handleIncrementSize)
: fHeap(heap)
, fHandleIncrementSize(handleIncrementSize)

View File

@ -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 ComPtr<ID3D12DescriptorHeap>&, unsigned int handleIncrementSize);
GrD3DDescriptorHeap(const gr_cp<ID3D12DescriptorHeap>&, unsigned int handleIncrementSize);
static uint32_t GenID() {
static std::atomic<uint32_t> nextID{1};
@ -67,7 +67,7 @@ protected:
return id;
}
ComPtr<ID3D12DescriptorHeap> fHeap;
gr_cp<ID3D12DescriptorHeap> fHeap;
size_t fHandleIncrementSize;
D3D12_CPU_DESCRIPTOR_HANDLE fCPUHeapStart;
D3D12_GPU_DESCRIPTOR_HANDLE fGPUHeapStart;

View File

@ -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;
@ -1234,7 +1234,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;
}
@ -1378,7 +1378,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;
}

View File

@ -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);
ComPtr<ID3D12Device> fDevice;
ComPtr<ID3D12CommandQueue> fQueue;
gr_cp<ID3D12Device> fDevice;
gr_cp<ID3D12CommandQueue> fQueue;
GrD3DResourceProvider fResourceProvider;
GrStagingBufferManager fStagingBufferManager;
GrRingBuffer fConstantsRingBuffer;
ComPtr<ID3D12Fence> fFence;
gr_cp<ID3D12Fence> fFence;
uint64_t fCurrentFenceValue = 0;
std::unique_ptr<GrD3DDirectCommandList> fCurrentDirectCommandList;

View File

@ -19,7 +19,7 @@
#include "src/gpu/glsl/GrGLSLXferProcessor.h"
GrD3DPipelineState::GrD3DPipelineState(
ComPtr<ID3D12PipelineState> pipelineState,
gr_cp<ID3D12PipelineState> pipelineState,
sk_sp<GrD3DRootSignature> rootSignature,
const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
const UniformInfoArray& uniforms, uint32_t uniformSize,

View File

@ -24,7 +24,7 @@ class GrD3DPipelineState : public GrManagedResource {
public:
using UniformInfoArray = GrD3DPipelineStateDataManager::UniformInfoArray;
GrD3DPipelineState(ComPtr<ID3D12PipelineState> pipelineState,
GrD3DPipelineState(gr_cp<ID3D12PipelineState> pipelineState,
sk_sp<GrD3DRootSignature> 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 ComPtr will handle that in the dtor.
// release the fPipelineState cause the gr_cp 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<GrD3DRootSignature>& 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);
ComPtr<ID3D12PipelineState> fPipelineState;
gr_cp<ID3D12PipelineState> fPipelineState;
sk_sp<GrD3DRootSignature> fRootSignature;
// Tracks the current render target uniforms stored in the vertex buffer.

View File

@ -66,7 +66,7 @@ void GrD3DPipelineStateBuilder::finalizeFragmentSecondaryColor(GrShaderVar& outp
outputColor.addLayoutQualifier("location = 0, index = 1");
}
static ComPtr<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
static gr_cp<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
const SkSL::String& hlsl,
SkSL::Program::Kind kind) {
const char* compileTarget = nullptr;
@ -92,8 +92,8 @@ static ComPtr<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
// SPRIV-cross does matrix multiplication expecting row major matrices
compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
ComPtr<ID3DBlob> shader;
ComPtr<ID3DBlob> errors;
gr_cp<ID3DBlob> shader;
gr_cp<ID3DBlob> 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 ComPtr<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
return shader;
}
bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, ComPtr<ID3DBlob> shaders[]) {
bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, gr_cp<ID3DBlob> shaders[]) {
SkSL::String hlsl[kGrShaderTypeCount];
SkSL::Program::Inputs inputs[kGrShaderTypeCount];
@ -117,7 +117,7 @@ bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, ComPtr<I
this->addRTHeightUniform(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, ComPtr<I
compile(SkSL::Program::kGeometry_Kind, kGeometry_GrShaderType));
}
ComPtr<ID3DBlob> GrD3DPipelineStateBuilder::compileD3DProgram(
gr_cp<ID3DBlob> GrD3DPipelineStateBuilder::compileD3DProgram(
SkSL::Program::Kind kind,
const SkSL::String& sksl,
const SkSL::Program::Settings& settings,
@ -138,13 +138,13 @@ ComPtr<ID3DBlob> GrD3DPipelineStateBuilder::compileD3DProgram(
if (!program) {
errorHandler->compileError(sksl.c_str(),
fGpu->shaderCompiler()->errorText().c_str());
return ComPtr<ID3DBlob>();
return gr_cp<ID3DBlob>();
}
*outInputs = program->fInputs;
if (!fGpu->shaderCompiler()->toHLSL(*program, outHLSL)) {
errorHandler->compileError(sksl.c_str(),
fGpu->shaderCompiler()->errorText().c_str());
return ComPtr<ID3DBlob>();
return gr_cp<ID3DBlob>();
}
if (program->fInputs.fRTHeight) {
@ -472,11 +472,11 @@ static D3D12_PRIMITIVE_TOPOLOGY_TYPE gr_primitive_type_to_d3d(GrPrimitiveType pr
}
}
ComPtr<ID3D12PipelineState> create_pipeline_state(
gr_cp<ID3D12PipelineState> create_pipeline_state(
GrD3DGpu* gpu, const GrProgramInfo& programInfo, const sk_sp<GrD3DRootSignature>& rootSig,
ComPtr<ID3DBlob> vertexShader, ComPtr<ID3DBlob> geometryShader,
ComPtr<ID3DBlob> pixelShader, DXGI_FORMAT renderTargetFormat,
DXGI_FORMAT depthStencilFormat, unsigned int sampleQualityPattern) {
gr_cp<ID3DBlob> vertexShader, gr_cp<ID3DBlob> geometryShader, gr_cp<ID3DBlob> pixelShader,
DXGI_FORMAT renderTargetFormat, DXGI_FORMAT depthStencilFormat,
unsigned int sampleQualityPattern) {
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
psoDesc.pRootSignature = rootSig->rootSignature();
@ -486,7 +486,7 @@ ComPtr<ID3D12PipelineState> create_pipeline_state(
psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()),
pixelShader->GetBufferSize() };
if (geometryShader.Get()) {
if (geometryShader.get()) {
psoDesc.GS = { reinterpret_cast<UINT8*>(geometryShader->GetBufferPointer()),
geometryShader->GetBufferSize() };
}
@ -527,7 +527,7 @@ ComPtr<ID3D12PipelineState> create_pipeline_state(
psoDesc.CachedPSO = { nullptr, 0 };
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
ComPtr<ID3D12PipelineState> pipelineState;
gr_cp<ID3D12PipelineState> pipelineState;
GR_D3D_CALL_ERRCHECK(gpu->device()->CreateGraphicsPipelineState(
&psoDesc, IID_PPV_ARGS(&pipelineState)));
@ -575,7 +575,7 @@ sk_sp<GrD3DPipelineState> GrD3DPipelineStateBuilder::finalize() {
}
const GrPrimitiveProcessor& primProc = this->primitiveProcessor();
ComPtr<ID3DBlob> shaders[kGrShaderTypeCount];
gr_cp<ID3DBlob> shaders[kGrShaderTypeCount];
if (kHLSL_Tag == shaderType && this->loadHLSLFromCache(&reader, shaders)) {
// We successfully loaded and compiled HLSL
@ -601,7 +601,7 @@ sk_sp<GrD3DPipelineState> 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) ||
@ -640,7 +640,7 @@ sk_sp<GrD3DPipelineState> GrD3DPipelineStateBuilder::finalize() {
}
const GrD3DRenderTarget* rt = static_cast<const GrD3DRenderTarget*>(fRenderTarget);
ComPtr<ID3D12PipelineState> pipelineState = create_pipeline_state(
gr_cp<ID3D12PipelineState> 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());

View File

@ -45,9 +45,9 @@ private:
sk_sp<GrD3DPipelineState> finalize();
bool loadHLSLFromCache(SkReadBuffer* reader, ComPtr<ID3DBlob> shaders[]);
bool loadHLSLFromCache(SkReadBuffer* reader, gr_cp<ID3DBlob> shaders[]);
ComPtr<ID3DBlob> compileD3DProgram(SkSL::Program::Kind kind,
gr_cp<ID3DBlob> compileD3DProgram(SkSL::Program::Kind kind,
const SkSL::String& sksl,
const SkSL::Program::Settings& settings,
SkSL::Program::Inputs* outInputs,

View File

@ -93,12 +93,12 @@ GrD3DRenderTarget::GrD3DRenderTarget(GrD3DGpu* gpu,
sk_sp<GrD3DRenderTarget> GrD3DRenderTarget::MakeWrappedRenderTarget(
GrD3DGpu* gpu, SkISize dimensions, int sampleCnt, const GrD3DTextureResourceInfo& info,
sk_sp<GrD3DResourceState> 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> 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,

View File

@ -69,8 +69,8 @@ sk_sp<GrD3DRootSignature> GrD3DRootSignature::Make(GrD3DGpu* gpu, int numTexture
rootDesc.pStaticSamplers = nullptr;
rootDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
ComPtr<ID3DBlob> rootSigBinary;
ComPtr<ID3DBlob> error;
gr_cp<ID3DBlob> rootSigBinary;
gr_cp<ID3DBlob> error;
// TODO: D3D Static Function
HRESULT hr = D3D12SerializeRootSignature(&rootDesc, D3D_ROOT_SIGNATURE_VERSION_1_0,
&rootSigBinary, &error);
@ -81,7 +81,7 @@ sk_sp<GrD3DRootSignature> GrD3DRootSignature::Make(GrD3DGpu* gpu, int numTexture
return nullptr;
}
ComPtr<ID3D12RootSignature> rootSig;
gr_cp<ID3D12RootSignature> rootSig;
hr = gpu->device()->CreateRootSignature(0, rootSigBinary->GetBufferPointer(),
rootSigBinary->GetBufferSize(), IID_PPV_ARGS(&rootSig));
@ -94,7 +94,7 @@ sk_sp<GrD3DRootSignature> GrD3DRootSignature::Make(GrD3DGpu* gpu, int numTexture
numTextureSamplers));
}
GrD3DRootSignature::GrD3DRootSignature(ComPtr<ID3D12RootSignature> rootSig, int numTextureSamplers)
GrD3DRootSignature::GrD3DRootSignature(gr_cp<ID3D12RootSignature> rootSig, int numTextureSamplers)
: fRootSignature(std::move(rootSig))
, fNumTextureSamplers(numTextureSamplers) {
}

View File

@ -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(ComPtr<ID3D12RootSignature> rootSig, int numTextureSamplers);
GrD3DRootSignature(gr_cp<ID3D12RootSignature> 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 ComPtr will handle that in the dtor.
// release the fRootSignature cause the gr_cp will handle that in the dtor.
void freeGPUData() const override {}
ComPtr<ID3D12RootSignature> fRootSignature;
gr_cp<ID3D12RootSignature> fRootSignature;
int fNumTextureSamplers;
};

View File

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

View File

@ -54,7 +54,7 @@ GrD3DStencilAttachment* GrD3DStencilAttachment::Make(GrD3DGpu* gpu,
}
GrD3DDescriptorHeap::CPUHandle view =
gpu->resourceProvider().createDepthStencilView(info.fResource.Get());
gpu->resourceProvider().createDepthStencilView(info.fResource.get());
sk_sp<GrD3DResourceState> state(new GrD3DResourceState(info.fResourceState));
GrD3DStencilAttachment* stencil = new GrD3DStencilAttachment(gpu, dimensions, format,

View File

@ -78,7 +78,7 @@ sk_sp<GrD3DTexture> GrD3DTexture::MakeNewTexture(GrD3DGpu* gpu, SkBudgeted budge
new GrD3DResourceState(static_cast<D3D12_RESOURCE_STATES>(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> GrD3DTexture::MakeWrappedTexture(GrD3DGpu* gpu,
: GrMipmapStatus::kNotAllocated;
GrD3DDescriptorHeap::CPUHandle shaderResourceView =
gpu->resourceProvider().createShaderResourceView(info.fResource.Get());
gpu->resourceProvider().createShaderResourceView(info.fResource.get());
return sk_sp<GrD3DTexture>(new GrD3DTexture(gpu, dimensions, info, std::move(state),
shaderResourceView, mipmapStatus, cacheable,

View File

@ -100,10 +100,10 @@ sk_sp<GrD3DTextureRenderTarget> GrD3DTextureRenderTarget::MakeNewTextureRenderTa
static_cast<D3D12_RESOURCE_STATES>(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> 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> 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> 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,

View File

@ -61,7 +61,7 @@ bool GrD3DTextureResource::InitTextureResourceInfo(GrD3DGpu* gpu, const D3D12_RE
return false;
}
info->fResource.Attach(resource);
info->fResource.reset(resource);
info->fResourceState = initialState;
info->fFormat = desc.Format;
info->fLevelCount = desc.MipLevels;
@ -134,5 +134,5 @@ void GrD3DTextureResource::setResourceRelease(sk_sp<GrRefCntedCallback> releaseH
void GrD3DTextureResource::Resource::freeGPUData() const {
this->invokeReleaseProc();
fResource.Reset(); // Release our ref to the resource
fResource.reset(); // Release our ref to the resource
}

View File

@ -26,14 +26,14 @@ public:
: fInfo(info)
, fState(std::move(state))
, fResource(new Resource(fInfo.fResource)) {
// ComPtr will implicitly ref the ID3D12Resource for us, so we don't need to worry about
// gr_cp 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 ComPtr<ID3D12Resource>& textureResource)
Resource(const gr_cp<ID3D12Resource>& 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 ComPtr<ID3D12Resource> fResource;
mutable gr_cp<ID3D12Resource> fResource;
using INHERITED = GrTextureResource;
};

View File

@ -39,7 +39,7 @@ bool CreateD3DBackendContext(GrD3DBackendContext* ctx,
#if defined(SK_ENABLE_D3D_DEBUG_LAYER)
// Enable the D3D12 debug layer.
{
ComPtr<ID3D12Debug> debugController;
gr_cp<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
{
debugController->EnableDebugLayer();
@ -47,23 +47,23 @@ bool CreateD3DBackendContext(GrD3DBackendContext* ctx,
}
#endif
// Create the device
ComPtr<IDXGIFactory4> factory;
gr_cp<IDXGIFactory4> factory;
if (!SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) {
return false;
}
ComPtr<IDXGIAdapter1> hardwareAdapter;
get_hardware_adapter(factory.Get(), &hardwareAdapter);
gr_cp<IDXGIAdapter1> hardwareAdapter;
get_hardware_adapter(factory.get(), &hardwareAdapter);
ComPtr<ID3D12Device> device;
if (!SUCCEEDED(D3D12CreateDevice(hardwareAdapter.Get(),
gr_cp<ID3D12Device> device;
if (!SUCCEEDED(D3D12CreateDevice(hardwareAdapter.get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&device)))) {
return false;
}
// Create the command queue
ComPtr<ID3D12CommandQueue> queue;
gr_cp<ID3D12CommandQueue> queue;
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;

View File

@ -40,7 +40,7 @@ public:
void setupSurfaces(int width, int height);
bool isValid() override {
return fDevice.Get() != nullptr;
return fDevice.get() != nullptr;
}
sk_sp<SkSurface> getBackbufferSurface() override;
@ -52,16 +52,16 @@ private:
static constexpr int kNumFrames = 2;
HWND fWindow;
ComPtr<ID3D12Device> fDevice;
ComPtr<ID3D12CommandQueue> fQueue;
ComPtr<IDXGISwapChain3> fSwapChain;
ComPtr<ID3D12Resource> fBuffers[kNumFrames];
gr_cp<ID3D12Device> fDevice;
gr_cp<ID3D12CommandQueue> fQueue;
gr_cp<IDXGISwapChain3> fSwapChain;
gr_cp<ID3D12Resource> fBuffers[kNumFrames];
sk_sp<SkSurface> fSurfaces[kNumFrames];
// Synchronization objects.
unsigned int fBufferIndex;
HANDLE fFenceEvent;
ComPtr<ID3D12Fence> fFence;
gr_cp<ID3D12Fence> fFence;
uint64_t fFenceValues[kNumFrames];
};
@ -94,7 +94,7 @@ void D3D12WindowContext::initializeContext() {
UINT dxgiFactoryFlags = 0;
SkDEBUGCODE(dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;)
ComPtr<IDXGIFactory4> factory;
gr_cp<IDXGIFactory4> 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;
ComPtr<IDXGISwapChain1> swapChain;
gr_cp<IDXGISwapChain1> 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();
fFence.reset(nullptr);
for (int i = 0; i < kNumFrames; ++i) {
fSurfaces[i].reset();
fBuffers[i].Reset();
fSurfaces[i].reset(nullptr);
fBuffers[i].reset(nullptr);
}
fSwapChain.Reset();
fQueue.Reset();
fDevice.Reset();
fSwapChain.reset(nullptr);
fQueue.reset(nullptr);
fDevice.reset(nullptr);
}
sk_sp<SkSurface> 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();
fBuffers[i].Reset();
fSurfaces[i].reset(nullptr);
fBuffers[i].reset(nullptr);
}
GR_D3D_CALL_ERRCHECK(fSwapChain->ResizeBuffers(0, width, height,