Add support for tracking resources on d3d command list.
Change-Id: I9f1db0d099d2071af0028a3c1e563671b4b2b18c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/278860 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
8b932b157b
commit
4105e45752
@ -11,25 +11,55 @@
|
||||
|
||||
GrD3DCommandList::GrD3DCommandList(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList)
|
||||
: fAllocator(std::move(allocator))
|
||||
, fCommandList(std::move(commandList)) {
|
||||
: fCommandList(std::move(commandList))
|
||||
, fAllocator(std::move(allocator)) {
|
||||
}
|
||||
|
||||
void GrD3DCommandList::close() {
|
||||
SkASSERT(fIsActive);
|
||||
SkDEBUGCODE(HRESULT hr = ) fCommandList->Close();
|
||||
SkASSERT(SUCCEEDED(hr));
|
||||
SkDEBUGCODE(fIsActive = false;)
|
||||
}
|
||||
|
||||
void GrD3DCommandList::submit(ID3D12CommandQueue* queue) {
|
||||
SkASSERT(!fIsActive);
|
||||
ID3D12CommandList* ppCommandLists[] = { fCommandList.Get() };
|
||||
queue->ExecuteCommandLists(1, ppCommandLists);
|
||||
SkDEBUGCODE(HRESULT hr = ) fCommandList->Reset(fAllocator.Get(), nullptr);
|
||||
SkASSERT(SUCCEEDED(hr));
|
||||
}
|
||||
|
||||
void GrD3DCommandList::reset() {
|
||||
SkASSERT(!fIsActive);
|
||||
SkDEBUGCODE(HRESULT hr = ) fAllocator->Reset();
|
||||
SkASSERT(SUCCEEDED(hr));
|
||||
SkDEBUGCODE(hr = ) fCommandList->Reset(fAllocator.Get(), nullptr);
|
||||
SkASSERT(SUCCEEDED(hr));
|
||||
|
||||
SkDEBUGCODE(fIsActive = true;)
|
||||
}
|
||||
|
||||
void GrD3DCommandList::releaseResources() {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
SkASSERT(!fIsActive);
|
||||
for (int i = 0; i < fTrackedResources.count(); ++i) {
|
||||
fTrackedResources[i]->notifyFinishedWithWorkOnGpu();
|
||||
fTrackedResources[i]->unref();
|
||||
}
|
||||
for (int i = 0; i < fTrackedRecycledResources.count(); ++i) {
|
||||
fTrackedRecycledResources[i]->notifyFinishedWithWorkOnGpu();
|
||||
fTrackedRecycledResources[i]->recycle();
|
||||
}
|
||||
|
||||
if (++fNumResets > kNumRewindResetsBeforeFullReset) {
|
||||
fTrackedResources.reset();
|
||||
fTrackedRecycledResources.reset();
|
||||
fTrackedResources.setReserve(kInitialTrackedResourcesCount);
|
||||
fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount);
|
||||
fNumResets = 0;
|
||||
} else {
|
||||
fTrackedResources.rewind();
|
||||
fTrackedRecycledResources.rewind();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define GrD3DCommandList_DEFINED
|
||||
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "src/gpu/GrManagedResource.h"
|
||||
#include "src/gpu/d3d/GrD3D12.h"
|
||||
|
||||
#include <memory>
|
||||
@ -23,13 +24,47 @@ public:
|
||||
|
||||
void reset();
|
||||
|
||||
// Add ref-counted resource that will be tracked and released when this command buffer finishes
|
||||
// execution
|
||||
void addResource(const GrManagedResource* resource) {
|
||||
SkASSERT(resource);
|
||||
resource->ref();
|
||||
resource->notifyQueuedForWorkOnGpu();
|
||||
fTrackedResources.append(1, &resource);
|
||||
}
|
||||
|
||||
// Add ref-counted resource that will be tracked and released when this command buffer finishes
|
||||
// execution. When it is released, it will signal that the resource can be recycled for reuse.
|
||||
void addRecycledResource(const GrRecycledResource* resource) {
|
||||
resource->ref();
|
||||
resource->notifyQueuedForWorkOnGpu();
|
||||
fTrackedRecycledResources.append(1, &resource);
|
||||
}
|
||||
|
||||
void releaseResources();
|
||||
|
||||
protected:
|
||||
GrD3DCommandList(gr_cp<ID3D12CommandAllocator> allocator,
|
||||
gr_cp<ID3D12GraphicsCommandList> commandList);
|
||||
|
||||
gr_cp<ID3D12GraphicsCommandList> fCommandList;
|
||||
|
||||
SkTDArray<const GrManagedResource*> fTrackedResources;
|
||||
SkTDArray<const GrRecycledResource*> fTrackedRecycledResources;
|
||||
|
||||
// When we create a command list it starts in an active recording state
|
||||
SkDEBUGCODE(bool fIsActive = true;)
|
||||
|
||||
private:
|
||||
gr_cp<ID3D12CommandAllocator> fAllocator;
|
||||
gr_cp<ID3D12GraphicsCommandList> fCommandList;
|
||||
|
||||
static const int kInitialTrackedResourcesCount = 32;
|
||||
// When resetting the command buffer, we remove the tracked resources from their arrays, and
|
||||
// we prefer to not free all the memory every time so usually we just rewind. However, to avoid
|
||||
// all arrays growing to the max size, after so many resets we'll do a full reset of the tracked
|
||||
// resource arrays.
|
||||
static const int kNumRewindResetsBeforeFullReset = 8;
|
||||
int fNumResets = 0;
|
||||
};
|
||||
|
||||
class GrD3DDirectCommandList : public GrD3DCommandList {
|
||||
|
@ -56,7 +56,6 @@ void GrVkCommandBuffer::freeGPUData(const GrGpu* gpu, VkCommandPool cmdPool) con
|
||||
|
||||
void GrVkCommandBuffer::releaseResources() {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
SkDEBUGCODE(fResourcesReleased = true;)
|
||||
SkASSERT(!fIsActive);
|
||||
for (int i = 0; i < fTrackedResources.count(); ++i) {
|
||||
fTrackedResources[i]->notifyFinishedWithWorkOnGpu();
|
||||
|
@ -170,9 +170,6 @@ private:
|
||||
VkRect2D fCachedScissor;
|
||||
float fCachedBlendConstant[4];
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
mutable bool fResourcesReleased = false;
|
||||
#endif
|
||||
// Tracking of memory barriers so that we can submit them all in a batch together.
|
||||
SkSTArray<4, VkBufferMemoryBarrier> fBufferBarriers;
|
||||
SkSTArray<1, VkImageMemoryBarrier> fImageBarriers;
|
||||
|
Loading…
Reference in New Issue
Block a user