Make GrRingBuffer more generic so it can be used over all backends
* Removes the spinlock (should no longer be necessary)
* Uses GrGpuBuffer and creation through GrResourceProvider
instead of internal native creation
* Changes the SubmitData to pass up all buffers used over a given submit
so the backend can track that better
Bug: skia:10530
Change-Id: I0d3a686b950dd5cb5f720f827b573238386b9524
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305567
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/GrRingBuffer.cpp b/src/gpu/GrRingBuffer.cpp
index 145c88a..a911c20 100644
--- a/src/gpu/GrRingBuffer.cpp
+++ b/src/gpu/GrRingBuffer.cpp
@@ -7,12 +7,15 @@
#include "src/gpu/GrRingBuffer.h"
+#include "src/gpu/GrContextPriv.h"
+#include "src/gpu/GrGpu.h"
+#include "src/gpu/GrResourceProvider.h"
+
// Get offset into buffer that has enough space for size
// Returns fTotalSize if no space
size_t GrRingBuffer::getAllocationOffset(size_t size) {
// capture current state locally (because fTail could be overwritten by the completion handler)
size_t head, tail;
- SkAutoSpinlock lock(fMutex);
head = fHead;
tail = fTail;
@@ -52,39 +55,40 @@
}
GrRingBuffer::Slice GrRingBuffer::suballocate(size_t size) {
- size_t offset = this->getAllocationOffset(size);
- if (offset < fTotalSize) {
- return { fBuffer, offset };
+ if (fCurrentBuffer) {
+ size_t offset = this->getAllocationOffset(size);
+ if (offset < fTotalSize) {
+ return { fCurrentBuffer.get(), offset };
+ }
+
+ // Try to grow allocation (old allocation will age out).
+ fTotalSize *= 2;
}
- // Try to grow allocation (old allocation will age out).
- fTotalSize *= 2;
- fBuffer = this->createBuffer(fTotalSize);
- SkASSERT(fBuffer);
- {
- SkAutoSpinlock lock(fMutex);
- fHead = 0;
- fTail = 0;
- fGenID++;
- }
- offset = this->getAllocationOffset(size);
+ GrResourceProvider* resourceProvider = fGpu->getContext()->priv().resourceProvider();
+ fCurrentBuffer = resourceProvider->createBuffer(fTotalSize, fType, kDynamic_GrAccessPattern);
+
+ SkASSERT(fCurrentBuffer);
+ fTrackedBuffers.push_back(fCurrentBuffer);
+ fHead = 0;
+ fTail = 0;
+ fGenID++;
+ size_t offset = this->getAllocationOffset(size);
SkASSERT(offset < fTotalSize);
- return { fBuffer, offset };
+ return { fCurrentBuffer.get(), offset };
}
// used when current command buffer/command list is submitted
-GrRingBuffer::SubmitData GrRingBuffer::startSubmit() {
- SubmitData submitData;
- SkAutoSpinlock lock(fMutex);
- submitData.fBuffer = fBuffer;
- submitData.fLastHead = fHead;
- submitData.fGenID = fGenID;
- return submitData;
+void GrRingBuffer::startSubmit(GrRingBuffer::SubmitData* submitData) {
+ submitData->fTrackedBuffers = std::move(fTrackedBuffers);
+ submitData->fLastHead = fHead;
+ submitData->fGenID = fGenID;
+ // add current buffer to be tracked for next submit
+ fTrackedBuffers.push_back(fCurrentBuffer);
}
// used when current command buffer/command list is completed
void GrRingBuffer::finishSubmit(const GrRingBuffer::SubmitData& submitData) {
- SkAutoSpinlock lock(fMutex);
if (submitData.fGenID == fGenID) {
fTail = submitData.fLastHead;
}