Add "putBack" analogs to the DrawIndirect buffer pool

Bug: skia:10419
Change-Id: Id5f4fe79c661c3d402411dcb830ffd144d21254a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338008
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2020-11-24 09:30:51 -07:00 committed by Skia Commit-Bot
parent a6e0d83899
commit 7512507050
4 changed files with 22 additions and 6 deletions

View File

@ -324,12 +324,20 @@ public:
(size_t)drawCount * sizeof(GrDrawIndirectCommand), 4, buffer, offset));
}
void putBack(int drawCount) {
this->GrBufferAllocPool::putBack((size_t)drawCount * sizeof(GrDrawIndirectCommand));
}
GrDrawIndexedIndirectCommand* makeIndexedSpace(int drawCount, sk_sp<const GrBuffer>* buffer,
size_t* offset) {
return static_cast<GrDrawIndexedIndirectCommand*>(this->GrBufferAllocPool::makeSpace(
(size_t)drawCount * sizeof(GrDrawIndexedIndirectCommand), 4, buffer, offset));
}
void putBackIndexed(int drawCount) {
this->GrBufferAllocPool::putBack((size_t)drawCount * sizeof(GrDrawIndexedIndirectCommand));
}
using GrBufferAllocPool::unmap;
using GrBufferAllocPool::reset;
};

View File

@ -144,6 +144,10 @@ public:
}
void putBackIndices(int indexCount) final;
void putBackVertices(int vertices, size_t vertexStride) final;
void putBackIndirectDraws(int drawCount) final { fDrawIndirectPool.putBack(drawCount); }
void putBackIndexedIndirectDraws(int drawCount) final {
fDrawIndirectPool.putBackIndexed(drawCount);
}
const GrSurfaceProxyView& writeView() const final { return this->drawOpArgs().writeView(); }
GrRenderTargetProxy* rtProxy() const final { return this->drawOpArgs().rtProxy(); }
const GrAppliedClip* appliedClip() const final { return this->drawOpArgs().appliedClip(); }

View File

@ -35,29 +35,27 @@ public:
GrLoadOp colorLoadOp() const override { return GrLoadOp::kLoad; }
void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
int* startVertex) override {
int* /*startVertex*/) override {
if (vertexSize * vertexCount > sizeof(fStaticVertexData)) {
SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
vertexSize * vertexCount, sizeof(fStaticVertexData));
}
*startVertex = 0;
return fStaticVertexData;
}
void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount,
sk_sp<const GrBuffer>*, int* startVertex,
sk_sp<const GrBuffer>*, int* /*startVertex*/,
int* actualVertexCount) override {
if (vertexSize * minVertexCount > sizeof(fStaticVertexData)) {
SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
vertexSize * minVertexCount, sizeof(fStaticVertexData));
}
*startVertex = 0;
*actualVertexCount = sizeof(fStaticVertexData) / vertexSize;
return fStaticVertexData;
}
GrDrawIndirectCommand* makeDrawIndirectSpace(int drawCount, sk_sp<const GrBuffer>* buffer,
size_t* offsetInBytes) override {
size_t* /*offsetInBytes*/) override {
int staticBufferCount = (int)SK_ARRAY_COUNT(fStaticDrawIndirectData);
if (drawCount > staticBufferCount) {
SK_ABORT("FATAL: wanted %i static drawIndirect elements; only have %i.\n",
@ -66,8 +64,10 @@ public:
return fStaticDrawIndirectData;
}
void putBackIndirectDraws(int count) override { /* no-op */ }
GrDrawIndexedIndirectCommand* makeDrawIndexedIndirectSpace(
int drawCount, sk_sp<const GrBuffer>* buffer, size_t* offsetInBytes) override {
int drawCount, sk_sp<const GrBuffer>* buffer, size_t* /*offsetInBytes*/) override {
int staticBufferCount = (int)SK_ARRAY_COUNT(fStaticDrawIndexedIndirectData);
if (drawCount > staticBufferCount) {
SK_ABORT("FATAL: wanted %i static drawIndexedIndirect elements; only have %i.\n",
@ -76,6 +76,8 @@ public:
return fStaticDrawIndexedIndirectData;
}
void putBackIndexedIndirectDraws(int count) override { /* no-op */ }
#define UNIMPL(...) __VA_ARGS__ override { SK_ABORT("unimplemented."); }
UNIMPL(void recordDraw(const GrGeometryProcessor*, const GrSimpleMesh[], int,
const GrSurfaceProxy* const[], GrPrimitiveType))

View File

@ -213,6 +213,8 @@ public:
/** Helpers for ops which over-allocate and then return excess data to the pool. */
virtual void putBackIndices(int indices) = 0;
virtual void putBackVertices(int vertices, size_t vertexStride) = 0;
virtual void putBackIndirectDraws(int count) = 0;
virtual void putBackIndexedIndirectDraws(int count) = 0;
GrSimpleMesh* allocMesh() { return this->allocator()->make<GrSimpleMesh>(); }
GrSimpleMesh* allocMeshes(int n) { return this->allocator()->makeArray<GrSimpleMesh>(n); }