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>
This commit is contained in:
parent
04b9443274
commit
b8ae7fa12a
@ -9,6 +9,9 @@ Milestone 87
|
||||
|
||||
* <insert new release notes here>
|
||||
|
||||
* 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
|
||||
|
||||
|
@ -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<IDXGIAdapter1> fAdapter;
|
||||
gr_cp<ID3D12Device> fDevice;
|
||||
gr_cp<ID3D12CommandQueue> fQueue;
|
||||
ComPtr<IDXGIAdapter1> fAdapter;
|
||||
ComPtr<ID3D12Device> fDevice;
|
||||
ComPtr<ID3D12CommandQueue> fQueue;
|
||||
GrProtected fProtectedContext = GrProtected::kNo;
|
||||
};
|
||||
|
||||
|
@ -24,138 +24,15 @@
|
||||
#include "include/gpu/d3d/GrD3DTypesMinimal.h"
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_4.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
/** 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();
|
||||
}
|
||||
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<ID3D12Resource> fResource;
|
||||
ComPtr<ID3D12Resource> 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<ID3D12Resource>& resource,
|
||||
D3D12_RESOURCE_STATES resourceState,
|
||||
DXGI_FORMAT format,
|
||||
uint32_t levelCount,
|
||||
@ -207,8 +84,8 @@ struct GrD3DFenceInfo {
|
||||
, fValue(0) {
|
||||
}
|
||||
|
||||
gr_cp<ID3D12Fence> fFence;
|
||||
uint64_t fValue; // signal value for the fence
|
||||
ComPtr<ID3D12Fence> fFence;
|
||||
uint64_t fValue; // signal value for the fence
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define VALIDATE() do {} while(false)
|
||||
#endif
|
||||
|
||||
static gr_cp<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
|
||||
static ComPtr<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
|
||||
size_t size,
|
||||
GrGpuBufferType intendedType,
|
||||
GrAccessPattern accessPattern,
|
||||
@ -61,7 +61,7 @@ static gr_cp<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
|
||||
bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
||||
bufferDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
||||
|
||||
ID3D12Resource* resource;
|
||||
ComPtr<ID3D12Resource> resource;
|
||||
HRESULT hr = gpu->device()->CreateCommittedResource(
|
||||
&heapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
@ -73,7 +73,7 @@ static gr_cp<ID3D12Resource> make_d3d_buffer(GrD3DGpu* gpu,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return gr_cp<ID3D12Resource>(resource);
|
||||
return 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;
|
||||
|
||||
|
||||
gr_cp<ID3D12Resource> resource = make_d3d_buffer(gpu, size, intendedType, accessPattern,
|
||||
&resourceState);
|
||||
ComPtr<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, gr_cp<ID3D12Resource> bufferResource,
|
||||
GrAccessPattern accessPattern, ComPtr<ID3D12Resource> bufferResource,
|
||||
D3D12_RESOURCE_STATES resourceState)
|
||||
: INHERITED(gpu, size, intendedType, accessPattern)
|
||||
, fResourceState(resourceState)
|
||||
|
@ -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<ID3D12Resource>,
|
||||
GrD3DBuffer(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern, ComPtr<ID3D12Resource>,
|
||||
D3D12_RESOURCE_STATES);
|
||||
|
||||
void onAbandon() override;
|
||||
@ -52,7 +52,7 @@ private:
|
||||
return reinterpret_cast<GrD3DGpu*>(this->getGpu());
|
||||
}
|
||||
|
||||
gr_cp<ID3D12Resource> fD3DResource;
|
||||
ComPtr<ID3D12Resource> fD3DResource;
|
||||
ID3D12Resource* fStagingBuffer = nullptr;
|
||||
size_t fStagingOffset = 0;
|
||||
|
||||
|
@ -18,8 +18,8 @@
|
||||
#include "src/gpu/d3d/GrD3DTextureResource.h"
|
||||
#include "src/gpu/d3d/GrD3DUtil.h"
|
||||
|
||||
GrD3DCommandList::GrD3DCommandList(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList)
|
||||
GrD3DCommandList::GrD3DCommandList(ComPtr<ID3D12CommandAllocator> allocator,
|
||||
ComPtr<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) {
|
||||
gr_cp<ID3D12CommandAllocator> allocator;
|
||||
ComPtr<ID3D12CommandAllocator> allocator;
|
||||
GR_D3D_CALL_ERRCHECK(device->CreateCommandAllocator(
|
||||
D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator)));
|
||||
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList;
|
||||
ComPtr<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(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList)
|
||||
GrD3DDirectCommandList::GrD3DDirectCommandList(ComPtr<ID3D12CommandAllocator> allocator,
|
||||
ComPtr<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) {
|
||||
gr_cp<ID3D12GraphicsCommandList1> commandList1;
|
||||
ComPtr<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) {
|
||||
gr_cp<ID3D12GraphicsCommandList1> commandList1;
|
||||
ComPtr<ID3D12GraphicsCommandList1> 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<ID3D12GraphicsCommandList1> commandList1;
|
||||
ComPtr<ID3D12GraphicsCommandList1> 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> GrD3DCopyCommandList::Make(ID3D12Device* device) {
|
||||
gr_cp<ID3D12CommandAllocator> allocator;
|
||||
ComPtr<ID3D12CommandAllocator> allocator;
|
||||
GR_D3D_CALL_ERRCHECK(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
IID_PPV_ARGS(&allocator)));
|
||||
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList;
|
||||
GR_D3D_CALL_ERRCHECK(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, allocator.get(),
|
||||
ComPtr<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(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList)
|
||||
GrD3DCopyCommandList::GrD3DCopyCommandList(ComPtr<ID3D12CommandAllocator> allocator,
|
||||
ComPtr<ID3D12GraphicsCommandList> commandList)
|
||||
: GrD3DCommandList(std::move(allocator), std::move(commandList)) {
|
||||
}
|
||||
|
@ -100,8 +100,8 @@ private:
|
||||
static const int kInitialTrackedResourcesCount = 32;
|
||||
|
||||
protected:
|
||||
GrD3DCommandList(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList);
|
||||
GrD3DCommandList(ComPtr<ID3D12CommandAllocator> allocator,
|
||||
ComPtr<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();
|
||||
|
||||
gr_cp<ID3D12GraphicsCommandList> fCommandList;
|
||||
ComPtr<ID3D12GraphicsCommandList> fCommandList;
|
||||
|
||||
SkSTArray<kInitialTrackedResourcesCount, sk_sp<GrManagedResource>> fTrackedResources;
|
||||
SkSTArray<kInitialTrackedResourcesCount, sk_sp<GrRecycledResource>> fTrackedRecycledResources;
|
||||
@ -137,7 +137,7 @@ protected:
|
||||
private:
|
||||
void callFinishedCallbacks() { fFinishedCallbacks.reset(); }
|
||||
|
||||
gr_cp<ID3D12CommandAllocator> fAllocator;
|
||||
ComPtr<ID3D12CommandAllocator> fAllocator;
|
||||
|
||||
SkSTArray<4, D3D12_RESOURCE_BARRIER> fResourceBarriers;
|
||||
|
||||
@ -194,8 +194,8 @@ public:
|
||||
void addSampledTextureRef(GrD3DTexture*);
|
||||
|
||||
private:
|
||||
GrD3DDirectCommandList(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList);
|
||||
GrD3DDirectCommandList(ComPtr<ID3D12CommandAllocator> allocator,
|
||||
ComPtr<ID3D12GraphicsCommandList> commandList);
|
||||
|
||||
void onReset() override;
|
||||
|
||||
@ -219,7 +219,7 @@ public:
|
||||
static std::unique_ptr<GrD3DCopyCommandList> Make(ID3D12Device* device);
|
||||
|
||||
private:
|
||||
GrD3DCopyCommandList(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList);
|
||||
GrD3DCopyCommandList(ComPtr<ID3D12CommandAllocator> allocator,
|
||||
ComPtr<ID3D12GraphicsCommandList> commandList);
|
||||
};
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@ sk_sp<GrD3DCommandSignature> GrD3DCommandSignature::Make(GrD3DGpu* gpu, ForIndex
|
||||
commandSigDesc.pArgumentDescs = &argumentDesc;
|
||||
commandSigDesc.NodeMask = 0;
|
||||
|
||||
gr_cp<ID3D12CommandSignature> commandSig;
|
||||
ComPtr<ID3D12CommandSignature> commandSig;
|
||||
HRESULT hr = gpu->device()->CreateCommandSignature(&commandSigDesc, nullptr,
|
||||
IID_PPV_ARGS(&commandSig));
|
||||
if (!SUCCEEDED(hr)) {
|
||||
|
@ -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<ID3D12CommandSignature> commandSignature, ForIndexed indexed,
|
||||
GrD3DCommandSignature(ComPtr<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 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<ID3D12CommandSignature> fCommandSignature;
|
||||
ComPtr<ID3D12CommandSignature> fCommandSignature;
|
||||
ForIndexed fIndexed;
|
||||
unsigned int fSlot;
|
||||
};
|
||||
|
@ -17,15 +17,15 @@ std::unique_ptr<GrD3DDescriptorHeap> GrD3DDescriptorHeap::Make(GrD3DGpu* gpu,
|
||||
heapDesc.NumDescriptors = numDescriptors;
|
||||
heapDesc.Flags = flags;
|
||||
|
||||
ID3D12DescriptorHeap* heap;
|
||||
ComPtr<ID3D12DescriptorHeap> heap;
|
||||
gpu->device()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&heap));
|
||||
|
||||
return std::unique_ptr<GrD3DDescriptorHeap>(
|
||||
new GrD3DDescriptorHeap(std::move(gr_cp<ID3D12DescriptorHeap>(heap)),
|
||||
new GrD3DDescriptorHeap(std::move(heap),
|
||||
gpu->device()->GetDescriptorHandleIncrementSize(type)));
|
||||
}
|
||||
|
||||
GrD3DDescriptorHeap::GrD3DDescriptorHeap(const gr_cp<ID3D12DescriptorHeap>& heap,
|
||||
GrD3DDescriptorHeap::GrD3DDescriptorHeap(const ComPtr<ID3D12DescriptorHeap>& heap,
|
||||
unsigned int handleIncrementSize)
|
||||
: fHeap(heap)
|
||||
, fHandleIncrementSize(handleIncrementSize)
|
||||
|
@ -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<ID3D12DescriptorHeap>&, unsigned int handleIncrementSize);
|
||||
GrD3DDescriptorHeap(const ComPtr<ID3D12DescriptorHeap>&, unsigned int handleIncrementSize);
|
||||
|
||||
static uint32_t GenID() {
|
||||
static std::atomic<uint32_t> nextID{1};
|
||||
@ -67,7 +67,7 @@ protected:
|
||||
return id;
|
||||
}
|
||||
|
||||
gr_cp<ID3D12DescriptorHeap> fHeap;
|
||||
ComPtr<ID3D12DescriptorHeap> fHeap;
|
||||
size_t fHandleIncrementSize;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE fCPUHeapStart;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE fGPUHeapStart;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<ID3D12Device> fDevice;
|
||||
gr_cp<ID3D12CommandQueue> fQueue;
|
||||
ComPtr<ID3D12Device> fDevice;
|
||||
ComPtr<ID3D12CommandQueue> fQueue;
|
||||
|
||||
GrD3DResourceProvider fResourceProvider;
|
||||
GrStagingBufferManager fStagingBufferManager;
|
||||
GrRingBuffer fConstantsRingBuffer;
|
||||
|
||||
gr_cp<ID3D12Fence> fFence;
|
||||
ComPtr<ID3D12Fence> fFence;
|
||||
uint64_t fCurrentFenceValue = 0;
|
||||
|
||||
std::unique_ptr<GrD3DDirectCommandList> fCurrentDirectCommandList;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "src/gpu/glsl/GrGLSLXferProcessor.h"
|
||||
|
||||
GrD3DPipelineState::GrD3DPipelineState(
|
||||
gr_cp<ID3D12PipelineState> pipelineState,
|
||||
ComPtr<ID3D12PipelineState> pipelineState,
|
||||
sk_sp<GrD3DRootSignature> rootSignature,
|
||||
const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
|
||||
const UniformInfoArray& uniforms, uint32_t uniformSize,
|
||||
|
@ -24,7 +24,7 @@ class GrD3DPipelineState : public GrManagedResource {
|
||||
public:
|
||||
using UniformInfoArray = GrD3DPipelineStateDataManager::UniformInfoArray;
|
||||
|
||||
GrD3DPipelineState(gr_cp<ID3D12PipelineState> pipelineState,
|
||||
GrD3DPipelineState(ComPtr<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 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<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);
|
||||
|
||||
gr_cp<ID3D12PipelineState> fPipelineState;
|
||||
ComPtr<ID3D12PipelineState> fPipelineState;
|
||||
sk_sp<GrD3DRootSignature> fRootSignature;
|
||||
|
||||
// Tracks the current render target uniforms stored in the vertex buffer.
|
||||
|
@ -66,7 +66,7 @@ void GrD3DPipelineStateBuilder::finalizeFragmentSecondaryColor(GrShaderVar& outp
|
||||
outputColor.addLayoutQualifier("location = 0, index = 1");
|
||||
}
|
||||
|
||||
static gr_cp<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
|
||||
static ComPtr<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
|
||||
const SkSL::String& hlsl,
|
||||
SkSL::Program::Kind kind) {
|
||||
const char* compileTarget = nullptr;
|
||||
@ -92,8 +92,8 @@ static gr_cp<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
|
||||
// SPRIV-cross does matrix multiplication expecting row major matrices
|
||||
compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
|
||||
|
||||
gr_cp<ID3DBlob> shader;
|
||||
gr_cp<ID3DBlob> errors;
|
||||
ComPtr<ID3DBlob> shader;
|
||||
ComPtr<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 gr_cp<ID3DBlob> GrCompileHLSLShader(GrD3DGpu* gpu,
|
||||
return shader;
|
||||
}
|
||||
|
||||
bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, gr_cp<ID3DBlob> shaders[]) {
|
||||
bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, ComPtr<ID3DBlob> shaders[]) {
|
||||
|
||||
SkSL::String hlsl[kGrShaderTypeCount];
|
||||
SkSL::Program::Inputs inputs[kGrShaderTypeCount];
|
||||
@ -117,7 +117,7 @@ bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, gr_cp<ID
|
||||
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, gr_cp<ID
|
||||
compile(SkSL::Program::kGeometry_Kind, kGeometry_GrShaderType));
|
||||
}
|
||||
|
||||
gr_cp<ID3DBlob> GrD3DPipelineStateBuilder::compileD3DProgram(
|
||||
ComPtr<ID3DBlob> GrD3DPipelineStateBuilder::compileD3DProgram(
|
||||
SkSL::Program::Kind kind,
|
||||
const SkSL::String& sksl,
|
||||
const SkSL::Program::Settings& settings,
|
||||
@ -138,13 +138,13 @@ gr_cp<ID3DBlob> GrD3DPipelineStateBuilder::compileD3DProgram(
|
||||
if (!program) {
|
||||
errorHandler->compileError(sksl.c_str(),
|
||||
fGpu->shaderCompiler()->errorText().c_str());
|
||||
return gr_cp<ID3DBlob>();
|
||||
return ComPtr<ID3DBlob>();
|
||||
}
|
||||
*outInputs = program->fInputs;
|
||||
if (!fGpu->shaderCompiler()->toHLSL(*program, outHLSL)) {
|
||||
errorHandler->compileError(sksl.c_str(),
|
||||
fGpu->shaderCompiler()->errorText().c_str());
|
||||
return gr_cp<ID3DBlob>();
|
||||
return ComPtr<ID3DBlob>();
|
||||
}
|
||||
|
||||
if (program->fInputs.fRTHeight) {
|
||||
@ -472,11 +472,11 @@ static D3D12_PRIMITIVE_TOPOLOGY_TYPE gr_primitive_type_to_d3d(GrPrimitiveType pr
|
||||
}
|
||||
}
|
||||
|
||||
gr_cp<ID3D12PipelineState> create_pipeline_state(
|
||||
ComPtr<ID3D12PipelineState> create_pipeline_state(
|
||||
GrD3DGpu* gpu, const GrProgramInfo& programInfo, const sk_sp<GrD3DRootSignature>& rootSig,
|
||||
gr_cp<ID3DBlob> vertexShader, gr_cp<ID3DBlob> geometryShader, gr_cp<ID3DBlob> pixelShader,
|
||||
DXGI_FORMAT renderTargetFormat, DXGI_FORMAT depthStencilFormat,
|
||||
unsigned int sampleQualityPattern) {
|
||||
ComPtr<ID3DBlob> vertexShader, ComPtr<ID3DBlob> geometryShader,
|
||||
ComPtr<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 @@ gr_cp<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 @@ gr_cp<ID3D12PipelineState> create_pipeline_state(
|
||||
psoDesc.CachedPSO = { nullptr, 0 };
|
||||
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
|
||||
|
||||
gr_cp<ID3D12PipelineState> pipelineState;
|
||||
ComPtr<ID3D12PipelineState> pipelineState;
|
||||
GR_D3D_CALL_ERRCHECK(gpu->device()->CreateGraphicsPipelineState(
|
||||
&psoDesc, IID_PPV_ARGS(&pipelineState)));
|
||||
|
||||
@ -576,7 +576,7 @@ sk_sp<GrD3DPipelineState> GrD3DPipelineStateBuilder::finalize() {
|
||||
}
|
||||
|
||||
const GrPrimitiveProcessor& primProc = this->primitiveProcessor();
|
||||
gr_cp<ID3DBlob> shaders[kGrShaderTypeCount];
|
||||
ComPtr<ID3DBlob> shaders[kGrShaderTypeCount];
|
||||
|
||||
if (kHLSL_Tag == shaderType && this->loadHLSLFromCache(&reader, shaders)) {
|
||||
// We successfully loaded and compiled HLSL
|
||||
@ -602,7 +602,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) ||
|
||||
@ -641,7 +641,7 @@ sk_sp<GrD3DPipelineState> GrD3DPipelineStateBuilder::finalize() {
|
||||
}
|
||||
|
||||
const GrD3DRenderTarget* rt = static_cast<const GrD3DRenderTarget*>(fRenderTarget);
|
||||
gr_cp<ID3D12PipelineState> pipelineState = create_pipeline_state(
|
||||
ComPtr<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());
|
||||
|
@ -45,9 +45,9 @@ private:
|
||||
|
||||
sk_sp<GrD3DPipelineState> finalize();
|
||||
|
||||
bool loadHLSLFromCache(SkReadBuffer* reader, gr_cp<ID3DBlob> shaders[]);
|
||||
bool loadHLSLFromCache(SkReadBuffer* reader, ComPtr<ID3DBlob> shaders[]);
|
||||
|
||||
gr_cp<ID3DBlob> compileD3DProgram(SkSL::Program::Kind kind,
|
||||
ComPtr<ID3DBlob> compileD3DProgram(SkSL::Program::Kind kind,
|
||||
const SkSL::String& sksl,
|
||||
const SkSL::Program::Settings& settings,
|
||||
SkSL::Program::Inputs* outInputs,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
gr_cp<ID3DBlob> rootSigBinary;
|
||||
gr_cp<ID3DBlob> error;
|
||||
ComPtr<ID3DBlob> rootSigBinary;
|
||||
ComPtr<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;
|
||||
}
|
||||
|
||||
gr_cp<ID3D12RootSignature> rootSig;
|
||||
ComPtr<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(gr_cp<ID3D12RootSignature> rootSig, int numTextureSamplers)
|
||||
GrD3DRootSignature::GrD3DRootSignature(ComPtr<ID3D12RootSignature> rootSig, int numTextureSamplers)
|
||||
: fRootSignature(std::move(rootSig))
|
||||
, fNumTextureSamplers(numTextureSamplers) {
|
||||
}
|
||||
|
@ -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<ID3D12RootSignature> rootSig, int numTextureSamplers);
|
||||
GrD3DRootSignature(ComPtr<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 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<ID3D12RootSignature> fRootSignature;
|
||||
ComPtr<ID3D12RootSignature> fRootSignature;
|
||||
int fNumTextureSamplers;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<GrD3DResourceState> state(new GrD3DResourceState(info.fResourceState));
|
||||
GrD3DStencilAttachment* stencil = new GrD3DStencilAttachment(gpu, format, resourceDesc,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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<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
|
||||
}
|
||||
|
@ -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<ID3D12Resource>& textureResource)
|
||||
Resource(const ComPtr<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 gr_cp<ID3D12Resource> fResource;
|
||||
mutable ComPtr<ID3D12Resource> fResource;
|
||||
|
||||
using INHERITED = GrTextureResource;
|
||||
};
|
||||
|
@ -39,7 +39,7 @@ bool CreateD3DBackendContext(GrD3DBackendContext* ctx,
|
||||
#if defined(SK_ENABLE_D3D_DEBUG_LAYER)
|
||||
// Enable the D3D12 debug layer.
|
||||
{
|
||||
gr_cp<ID3D12Debug> debugController;
|
||||
ComPtr<ID3D12Debug> debugController;
|
||||
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
|
||||
{
|
||||
debugController->EnableDebugLayer();
|
||||
@ -47,23 +47,23 @@ bool CreateD3DBackendContext(GrD3DBackendContext* ctx,
|
||||
}
|
||||
#endif
|
||||
// Create the device
|
||||
gr_cp<IDXGIFactory4> factory;
|
||||
ComPtr<IDXGIFactory4> factory;
|
||||
if (!SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gr_cp<IDXGIAdapter1> hardwareAdapter;
|
||||
get_hardware_adapter(factory.get(), &hardwareAdapter);
|
||||
ComPtr<IDXGIAdapter1> hardwareAdapter;
|
||||
get_hardware_adapter(factory.Get(), &hardwareAdapter);
|
||||
|
||||
gr_cp<ID3D12Device> device;
|
||||
if (!SUCCEEDED(D3D12CreateDevice(hardwareAdapter.get(),
|
||||
ComPtr<ID3D12Device> device;
|
||||
if (!SUCCEEDED(D3D12CreateDevice(hardwareAdapter.Get(),
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
IID_PPV_ARGS(&device)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the command queue
|
||||
gr_cp<ID3D12CommandQueue> queue;
|
||||
ComPtr<ID3D12CommandQueue> queue;
|
||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
|
@ -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;
|
||||
gr_cp<ID3D12Device> fDevice;
|
||||
gr_cp<ID3D12CommandQueue> fQueue;
|
||||
gr_cp<IDXGISwapChain3> fSwapChain;
|
||||
gr_cp<ID3D12Resource> fBuffers[kNumFrames];
|
||||
ComPtr<ID3D12Device> fDevice;
|
||||
ComPtr<ID3D12CommandQueue> fQueue;
|
||||
ComPtr<IDXGISwapChain3> fSwapChain;
|
||||
ComPtr<ID3D12Resource> fBuffers[kNumFrames];
|
||||
sk_sp<SkSurface> fSurfaces[kNumFrames];
|
||||
|
||||
// Synchronization objects.
|
||||
unsigned int fBufferIndex;
|
||||
HANDLE fFenceEvent;
|
||||
gr_cp<ID3D12Fence> fFence;
|
||||
ComPtr<ID3D12Fence> fFence;
|
||||
uint64_t fFenceValues[kNumFrames];
|
||||
};
|
||||
|
||||
@ -94,7 +94,7 @@ void D3D12WindowContext::initializeContext() {
|
||||
UINT dxgiFactoryFlags = 0;
|
||||
SkDEBUGCODE(dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;)
|
||||
|
||||
gr_cp<IDXGIFactory4> factory;
|
||||
ComPtr<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;
|
||||
|
||||
gr_cp<IDXGISwapChain1> swapChain;
|
||||
ComPtr<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(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<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(nullptr);
|
||||
fBuffers[i].reset(nullptr);
|
||||
fSurfaces[i].reset();
|
||||
fBuffers[i].Reset();
|
||||
}
|
||||
|
||||
GR_D3D_CALL_ERRCHECK(fSwapChain->ResizeBuffers(0, width, height,
|
||||
|
Loading…
Reference in New Issue
Block a user