From 1aaf41b7a784436b049f4540b013db84c32ee304 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Wed, 29 Jul 2020 09:24:29 -0400 Subject: [PATCH] Change GrRingBuffer::finishSubmit to be a finishedProc Change-Id: I307669ee928152ea3616f3814716da7476a03c46 Bug: skia:10530 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305716 Reviewed-by: Brian Osman Commit-Queue: Jim Van Verth --- src/gpu/GrGpu.h | 7 +++---- src/gpu/GrRingBuffer.cpp | 24 +++++++++++++++++------- src/gpu/GrRingBuffer.h | 21 ++++++++------------- src/gpu/GrStagingBufferManager.cpp | 2 +- src/gpu/GrStagingBufferManager.h | 4 ++-- src/gpu/d3d/GrD3DCommandList.cpp | 17 ----------------- src/gpu/d3d/GrD3DCommandList.h | 5 ----- src/gpu/d3d/GrD3DGpu.cpp | 4 ++-- src/gpu/d3d/GrD3DGpu.h | 2 +- src/gpu/dawn/GrDawnGpu.cpp | 2 +- src/gpu/dawn/GrDawnGpu.h | 2 +- src/gpu/vk/GrVkGpu.cpp | 2 +- src/gpu/vk/GrVkGpu.h | 2 +- 13 files changed, 38 insertions(+), 56 deletions(-) diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 23704aa464..6883d736a0 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -382,9 +382,11 @@ public: virtual void insertSemaphore(GrSemaphore* semaphore) = 0; virtual void waitSemaphore(GrSemaphore* semaphore) = 0; + virtual void addFinishedProc(GrGpuFinishedProc finishedProc, + GrGpuFinishedContext finishedContext) = 0; virtual void checkFinishProcs() = 0; - virtual void takeOwnershipOfStagingBuffer(sk_sp) {} + virtual void takeOwnershipOfBuffer(sk_sp) {} /** * Checks if we detected an OOM from the underlying 3D API and if so returns true and resets @@ -820,9 +822,6 @@ private: virtual bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) = 0; - virtual void addFinishedProc(GrGpuFinishedProc finishedProc, - GrGpuFinishedContext finishedContext) = 0; - virtual void prepareSurfacesForBackendAccessAndStateUpdates( GrSurfaceProxy* proxies[], int numProxies, diff --git a/src/gpu/GrRingBuffer.cpp b/src/gpu/GrRingBuffer.cpp index a911c20100..86b7904c1a 100644 --- a/src/gpu/GrRingBuffer.cpp +++ b/src/gpu/GrRingBuffer.cpp @@ -79,17 +79,27 @@ GrRingBuffer::Slice GrRingBuffer::suballocate(size_t size) { } // used when current command buffer/command list is submitted -void GrRingBuffer::startSubmit(GrRingBuffer::SubmitData* submitData) { - submitData->fTrackedBuffers = std::move(fTrackedBuffers); - submitData->fLastHead = fHead; - submitData->fGenID = fGenID; +void GrRingBuffer::startSubmit(GrGpu* gpu) { + for (unsigned int i = 0; i < fTrackedBuffers.size(); ++i) { + gpu->takeOwnershipOfBuffer(std::move(fTrackedBuffers[i])); + } + fTrackedBuffers.clear(); // add current buffer to be tracked for next submit fTrackedBuffers.push_back(fCurrentBuffer); + + SubmitData* submitData = new SubmitData(); + submitData->fOwner = this; + submitData->fLastHead = fHead; + submitData->fGenID = fGenID; + gpu->addFinishedProc(FinishSubmit, submitData); } // used when current command buffer/command list is completed -void GrRingBuffer::finishSubmit(const GrRingBuffer::SubmitData& submitData) { - if (submitData.fGenID == fGenID) { - fTail = submitData.fLastHead; +void GrRingBuffer::FinishSubmit(void* finishedContext) { + GrRingBuffer::SubmitData* submitData = (GrRingBuffer::SubmitData*)finishedContext; + if (submitData && submitData->fOwner && submitData->fGenID == submitData->fOwner->fGenID) { + submitData->fOwner->fTail = submitData->fLastHead; + submitData->fOwner = nullptr; } + delete submitData; } diff --git a/src/gpu/GrRingBuffer.h b/src/gpu/GrRingBuffer.h index caa23116d8..5aeaad6d51 100644 --- a/src/gpu/GrRingBuffer.h +++ b/src/gpu/GrRingBuffer.h @@ -41,24 +41,19 @@ public: }; Slice suballocate(size_t size); - class SubmitData { - public: - const GrRingBuffer* fRingBuffer; - std::vector> fTrackedBuffers; - private: - friend class GrRingBuffer; - size_t fLastHead; - size_t fGenID; - }; - // Backends should call startSubmit() at submit time, and finishSubmit() when the - // command buffer/list finishes. - void startSubmit(SubmitData*); - void finishSubmit(const SubmitData&); + // Backends should call startSubmit() at submit time + void startSubmit(GrGpu*); size_t size() const { return fTotalSize; } private: size_t getAllocationOffset(size_t size); + struct SubmitData { + GrRingBuffer* fOwner; + size_t fLastHead; + size_t fGenID; + }; + static void FinishSubmit(void*); GrGpu* fGpu; sk_sp fCurrentBuffer; diff --git a/src/gpu/GrStagingBufferManager.cpp b/src/gpu/GrStagingBufferManager.cpp index e85f7045d1..8c2d6e1863 100644 --- a/src/gpu/GrStagingBufferManager.cpp +++ b/src/gpu/GrStagingBufferManager.cpp @@ -54,7 +54,7 @@ GrStagingBufferManager::Slice GrStagingBufferManager::allocateStagingBufferSlice void GrStagingBufferManager::detachBuffers() { for (size_t i = 0; i < fBuffers.size(); ++i) { fBuffers[i].fBuffer->unmap(); - fGpu->takeOwnershipOfStagingBuffer(std::move(fBuffers[i].fBuffer)); + fGpu->takeOwnershipOfBuffer(std::move(fBuffers[i].fBuffer)); } fBuffers.clear(); } diff --git a/src/gpu/GrStagingBufferManager.h b/src/gpu/GrStagingBufferManager.h index 514ec32c0d..d2d78ed594 100644 --- a/src/gpu/GrStagingBufferManager.h +++ b/src/gpu/GrStagingBufferManager.h @@ -30,9 +30,9 @@ public: Slice allocateStagingBufferSlice(size_t size, size_t requiredAlignment = 1); // This call is used to move all the buffers off of the manager and to backend gpu by calling - // the virtual GrGpu::takeOwnershipOfStagingBuffer on each buffer. This is called during + // the virtual GrGpu::takeOwnershipOfBuffer on each buffer. This is called during // submitToGpu. It is up to the backend to take refs to the buffers in their implemented - // takeOwnershipOfStagingBuffer implementation if they need to. After this call returns the + // takeOwnershipOfBuffer implementation if they need to. After this call returns the // manager will have released all refs to its buffers. void detachBuffers(); diff --git a/src/gpu/d3d/GrD3DCommandList.cpp b/src/gpu/d3d/GrD3DCommandList.cpp index 6a5de211d5..bc607b3629 100644 --- a/src/gpu/d3d/GrD3DCommandList.cpp +++ b/src/gpu/d3d/GrD3DCommandList.cpp @@ -223,7 +223,6 @@ GrD3DDirectCommandList::GrD3DDirectCommandList(gr_cp all , fCurrentInstanceBuffer(nullptr) , fCurrentInstanceStride(0) , fCurrentIndexBuffer(nullptr) - , fCurrentConstantRingBuffer(nullptr) , fCurrentConstantBufferAddress(0) , fCurrentSRVCRVDescriptorHeap(nullptr) , fCurrentSamplerDescriptorHeap(nullptr) { @@ -238,10 +237,6 @@ void GrD3DDirectCommandList::onReset() { fCurrentInstanceBuffer = nullptr; fCurrentInstanceStride = 0; fCurrentIndexBuffer = nullptr; - if (fCurrentConstantRingBuffer) { - fCurrentConstantRingBuffer->finishSubmit(fConstantRingBufferSubmitData); - fCurrentConstantRingBuffer = nullptr; - } fCurrentConstantBufferAddress = 0; sk_bzero(fCurrentRootDescriptorTable, sizeof(fCurrentRootDescriptorTable)); fCurrentSRVCRVDescriptorHeap = nullptr; @@ -257,18 +252,6 @@ void GrD3DDirectCommandList::setPipelineState(sk_sp pipeline } } -void GrD3DDirectCommandList::setCurrentConstantBuffer(GrRingBuffer* constantsRingBuffer) { - fCurrentConstantRingBuffer = constantsRingBuffer; - if (fCurrentConstantRingBuffer) { - constantsRingBuffer->startSubmit(&fConstantRingBufferSubmitData); - for (unsigned int i = 0; i < fConstantRingBufferSubmitData.fTrackedBuffers.size(); ++i) { - this->addGrBuffer(std::move(fConstantRingBufferSubmitData.fTrackedBuffers[i])); - } - // we don't need these any more so clear this copy out - fConstantRingBufferSubmitData.fTrackedBuffers.clear(); - } -} - void GrD3DDirectCommandList::setStencilRef(unsigned int stencilRef) { SkASSERT(fIsActive); fCommandList->OMSetStencilRef(stencilRef); diff --git a/src/gpu/d3d/GrD3DCommandList.h b/src/gpu/d3d/GrD3DCommandList.h index 41e4672f61..3293fb6027 100644 --- a/src/gpu/d3d/GrD3DCommandList.h +++ b/src/gpu/d3d/GrD3DCommandList.h @@ -152,8 +152,6 @@ public: void setPipelineState(sk_sp pipelineState); - void setCurrentConstantBuffer(GrRingBuffer* constantsRingBuffer); - void setStencilRef(unsigned int stencilRef); void setBlendFactor(const float blendFactor[4]); void setPrimitiveTopology(D3D12_PRIMITIVE_TOPOLOGY primitiveTopology); @@ -207,9 +205,6 @@ private: size_t fCurrentInstanceStride; const GrBuffer* fCurrentIndexBuffer; - GrRingBuffer* fCurrentConstantRingBuffer; - GrRingBuffer::SubmitData fConstantRingBufferSubmitData; - D3D12_GPU_VIRTUAL_ADDRESS fCurrentConstantBufferAddress; D3D12_GPU_DESCRIPTOR_HANDLE fCurrentRootDescriptorTable[GrD3DRootSignature::kParamIndexCount]; const ID3D12DescriptorHeap* fCurrentSRVCRVDescriptorHeap; diff --git a/src/gpu/d3d/GrD3DGpu.cpp b/src/gpu/d3d/GrD3DGpu.cpp index 13fd18ca34..07b8a08060 100644 --- a/src/gpu/d3d/GrD3DGpu.cpp +++ b/src/gpu/d3d/GrD3DGpu.cpp @@ -121,7 +121,7 @@ bool GrD3DGpu::submitDirectCommandList(SyncQueue sync) { SkASSERT(fCurrentDirectCommandList); // set up constant data - fCurrentDirectCommandList->setCurrentConstantBuffer(&fConstantsRingBuffer); + fConstantsRingBuffer.startSubmit(this); fResourceProvider.prepForSubmit(); @@ -1290,7 +1290,7 @@ void GrD3DGpu::prepareSurfacesForBackendAccessAndStateUpdates( } } -void GrD3DGpu::takeOwnershipOfStagingBuffer(sk_sp buffer) { +void GrD3DGpu::takeOwnershipOfBuffer(sk_sp buffer) { fCurrentDirectCommandList->addGrBuffer(std::move(buffer)); } diff --git a/src/gpu/d3d/GrD3DGpu.h b/src/gpu/d3d/GrD3DGpu.h index f790624e1f..2b93b80c4c 100644 --- a/src/gpu/d3d/GrD3DGpu.h +++ b/src/gpu/d3d/GrD3DGpu.h @@ -46,7 +46,7 @@ public: GrD3DDirectCommandList* currentCommandList() const { return fCurrentDirectCommandList.get(); } GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; } - void takeOwnershipOfStagingBuffer(sk_sp) override; + void takeOwnershipOfBuffer(sk_sp) override; // TODO: hoist up to GrGpu GrRingBuffer* constantsRingBuffer() { return &fConstantsRingBuffer; } diff --git a/src/gpu/dawn/GrDawnGpu.cpp b/src/gpu/dawn/GrDawnGpu.cpp index e368bd6ef5..dbbc25175c 100644 --- a/src/gpu/dawn/GrDawnGpu.cpp +++ b/src/gpu/dawn/GrDawnGpu.cpp @@ -497,7 +497,7 @@ void GrDawnGpu::waitOnAllBusyStagingBuffers() { } } -void GrDawnGpu::takeOwnershipOfStagingBuffer(sk_sp buffer) { +void GrDawnGpu::takeOwnershipOfBuffer(sk_sp buffer) { fSubmittedStagingBuffers.push_back(std::move(buffer)); } diff --git a/src/gpu/dawn/GrDawnGpu.h b/src/gpu/dawn/GrDawnGpu.h index 47a2b38a13..e1c4c6495a 100644 --- a/src/gpu/dawn/GrDawnGpu.h +++ b/src/gpu/dawn/GrDawnGpu.h @@ -38,7 +38,7 @@ public: void disconnect(DisconnectType) override; GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; } - void takeOwnershipOfStagingBuffer(sk_sp) override; + void takeOwnershipOfBuffer(sk_sp) override; const wgpu::Device& device() const { return fDevice; } const wgpu::Queue& queue() const { return fQueue; } diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 3b70ea1f2a..ba1fcca890 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -2042,7 +2042,7 @@ void GrVkGpu::addFinishedCallback(sk_sp finishedCallback) { fResourceProvider.addFinishedProcToActiveCommandBuffers(std::move(finishedCallback)); } -void GrVkGpu::takeOwnershipOfStagingBuffer(sk_sp buffer) { +void GrVkGpu::takeOwnershipOfBuffer(sk_sp buffer) { this->currentCommandBuffer()->addGrBuffer(std::move(buffer)); } diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index 2e71638ad7..eca9279c88 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -50,7 +50,7 @@ public: const GrVkCaps& vkCaps() const { return *fVkCaps; } GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; } - void takeOwnershipOfStagingBuffer(sk_sp) override; + void takeOwnershipOfBuffer(sk_sp) override; bool isDeviceLost() const override { return fDeviceIsLost; } void setDeviceLost() { fDeviceIsLost = true; }