Add support for holding onto refs for input buffers from bindBuffer calls.
Mostly this is a lot of plumbing of sk_sp around instead of const*.
This does allow the d3d and vk backends to hold refs to the GrBuffers that
are bound on a command buffer. This means that our buffer alloc pools will
not try to reuse this buffers until the gpu is done with them. Previously
vk and d3d will sniff out if one of these buffers was being used again
while still active on the gpu and rip out the internal backend buffer and
allocate a new one which is not cheap. We see a lot of perf wins from
not doing this.
Change-Id: I9ffe649151ee43066dce620bd3e2763b029a9811
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303583
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/gm/clockwise.cpp b/gm/clockwise.cpp
index be15517..88613cf 100644
--- a/gm/clockwise.cpp
+++ b/gm/clockwise.cpp
@@ -216,7 +216,7 @@
}
flushState->bindPipeline(*fProgramInfo, SkRect::MakeXYWH(0, fY, 100, 100));
- flushState->bindBuffers(nullptr, nullptr, fVertexBuffer.get());
+ flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer));
flushState->draw(4, 0);
}
diff --git a/gm/fwidth_squircle.cpp b/gm/fwidth_squircle.cpp
index d95c495..c2fcc0e 100644
--- a/gm/fwidth_squircle.cpp
+++ b/gm/fwidth_squircle.cpp
@@ -226,7 +226,7 @@
}
flushState->bindPipeline(*fProgramInfo, SkRect::MakeIWH(kWidth, kHeight));
- flushState->bindBuffers(nullptr, nullptr, fVertexBuffer.get());
+ flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer));
flushState->draw(4, 0);
}
diff --git a/gm/tessellation.cpp b/gm/tessellation.cpp
index 2cfc62d..3e515c9 100644
--- a/gm/tessellation.cpp
+++ b/gm/tessellation.cpp
@@ -348,7 +348,7 @@
tessellationPatchVertexCount);
state->bindPipeline(programInfo, SkRect::MakeIWH(kWidth, kHeight));
- state->bindBuffers(nullptr, nullptr, fVertexBuffer.get());
+ state->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer));
state->draw(tessellationPatchVertexCount, fBaseVertex);
}
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index 0bd2c09..551cf92 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -371,7 +371,7 @@
GrGpuBufferType::kVertex, kDynamic_GrAccessPattern,
fView->fQuadPointInstances.begin()));
if (!fView->fQuadPointInstances.empty() && instBuff) {
- proc->bindBuffers(renderPass, instBuff.get());
+ proc->bindBuffers(renderPass, std::move(instBuff));
proc->drawInstances(renderPass, fView->fQuadPointInstances.count(), 0);
}
} else {
@@ -380,7 +380,7 @@
GrGpuBufferType::kVertex, kDynamic_GrAccessPattern,
fView->fTriPointInstances.begin()));
if (!fView->fTriPointInstances.empty() && instBuff) {
- proc->bindBuffers(renderPass, instBuff.get());
+ proc->bindBuffers(renderPass, std::move(instBuff));
proc->drawInstances(renderPass, fView->fTriPointInstances.count(), 0);
}
}
diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp
index 5e4a602..7f47488 100644
--- a/src/gpu/GrOpFlushState.cpp
+++ b/src/gpu/GrOpFlushState.cpp
@@ -209,11 +209,10 @@
void GrOpFlushState::drawMesh(const GrSimpleMesh& mesh) {
SkASSERT(mesh.fIsInitialized);
if (!mesh.fIndexBuffer) {
- this->bindBuffers(nullptr, nullptr, mesh.fVertexBuffer.get());
+ this->bindBuffers(nullptr, nullptr, mesh.fVertexBuffer);
this->draw(mesh.fVertexCount, mesh.fBaseVertex);
} else {
- this->bindBuffers(mesh.fIndexBuffer.get(), nullptr, mesh.fVertexBuffer.get(),
- mesh.fPrimitiveRestart);
+ this->bindBuffers(mesh.fIndexBuffer, nullptr, mesh.fVertexBuffer, mesh.fPrimitiveRestart);
if (0 == mesh.fPatternRepeatCount) {
this->drawIndexed(mesh.fIndexCount, mesh.fBaseIndex, mesh.fMinIndexValue,
mesh.fMaxIndexValue, mesh.fBaseVertex);
diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h
index 5b5907a..9e674a2 100644
--- a/src/gpu/GrOpFlushState.h
+++ b/src/gpu/GrOpFlushState.h
@@ -198,10 +198,11 @@
const GrSurfaceProxy* const primProcTextures[], const GrPipeline& pipeline) {
fOpsRenderPass->bindTextures(primProc, primProcTextures, pipeline);
}
- void bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer,
+ void bindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
GrPrimitiveRestart primitiveRestart = GrPrimitiveRestart::kNo) {
- fOpsRenderPass->bindBuffers(indexBuffer, instanceBuffer, vertexBuffer, primitiveRestart);
+ fOpsRenderPass->bindBuffers(std::move(indexBuffer), std::move(instanceBuffer),
+ std::move(vertexBuffer), primitiveRestart);
}
void draw(int vertexCount, int baseVertex) {
fOpsRenderPass->draw(vertexCount, baseVertex);
diff --git a/src/gpu/GrOpsRenderPass.cpp b/src/gpu/GrOpsRenderPass.cpp
index 3e6d478..b891d1b 100644
--- a/src/gpu/GrOpsRenderPass.cpp
+++ b/src/gpu/GrOpsRenderPass.cpp
@@ -184,8 +184,10 @@
SkDEBUGCODE(fTextureBindingStatus = DynamicStateStatus::kConfigured);
}
-void GrOpsRenderPass::bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart primRestart) {
+void GrOpsRenderPass::bindBuffers(sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
+ GrPrimitiveRestart primRestart) {
if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
return;
@@ -211,7 +213,8 @@
}
#endif
- this->onBindBuffers(indexBuffer, instanceBuffer, vertexBuffer, primRestart);
+ this->onBindBuffers(std::move(indexBuffer), std::move(instanceBuffer), std::move(vertexBuffer),
+ primRestart);
}
bool GrOpsRenderPass::prepareToDraw() {
diff --git a/src/gpu/GrOpsRenderPass.h b/src/gpu/GrOpsRenderPass.h
index ec7960f..8f478ad 100644
--- a/src/gpu/GrOpsRenderPass.h
+++ b/src/gpu/GrOpsRenderPass.h
@@ -71,8 +71,8 @@
void bindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
const GrPipeline&);
- void bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart = GrPrimitiveRestart::kNo);
+ void bindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart = GrPrimitiveRestart::kNo);
// The next several draw*() methods issue draws using the current pipeline state. Before
// drawing, the caller must configure the pipeline and dynamic state:
@@ -180,8 +180,8 @@
virtual bool onBindTextures(const GrPrimitiveProcessor&,
const GrSurfaceProxy* const primProcTextures[],
const GrPipeline&) = 0;
- virtual void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) = 0;
+ virtual void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) = 0;
virtual void onDraw(int vertexCount, int baseVertex) = 0;
virtual void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
uint16_t maxIndexValue, int baseVertex) = 0;
diff --git a/src/gpu/ccpr/GrAutoMapVertexBuffer.h b/src/gpu/ccpr/GrAutoMapVertexBuffer.h
index 5121e4d..ff2b831 100644
--- a/src/gpu/ccpr/GrAutoMapVertexBuffer.h
+++ b/src/gpu/ccpr/GrAutoMapVertexBuffer.h
@@ -22,7 +22,8 @@
}
}
- const GrGpuBuffer* gpuBuffer() const { return fGpuBuffer.get(); }
+ bool hasGpuBuffer() const { return SkToBool(fGpuBuffer.get()); }
+ sk_sp<const GrGpuBuffer> gpuBuffer() const { return fGpuBuffer; }
bool isMapped() const { return SkToBool(fData); }
void* data() const { SkASSERT(this->isMapped()); return fData; }
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor.h b/src/gpu/ccpr/GrCCCoverageProcessor.h
index fb195c7..36835f6 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor.h
+++ b/src/gpu/ccpr/GrCCCoverageProcessor.h
@@ -117,7 +117,7 @@
virtual int numSubpasses() const = 0;
virtual void reset(PrimitiveType, int subpassIdx, GrResourceProvider*) = 0;
void bindPipeline(GrOpFlushState*, const GrPipeline&, const SkRect& drawBounds) const;
- virtual void bindBuffers(GrOpsRenderPass*, const GrBuffer* instanceBuffer) const = 0;
+ virtual void bindBuffers(GrOpsRenderPass*, sk_sp<const GrBuffer> instanceBuffer) const = 0;
virtual void drawInstances(GrOpsRenderPass*, int instanceCount, int baseInstance) const = 0;
// The Shader provides code to calculate each pixel's coverage in a RenderPass. It also
diff --git a/src/gpu/ccpr/GrCCFiller.cpp b/src/gpu/ccpr/GrCCFiller.cpp
index 9b30a70..783be74 100644
--- a/src/gpu/ccpr/GrCCFiller.cpp
+++ b/src/gpu/ccpr/GrCCFiller.cpp
@@ -37,7 +37,7 @@
void GrCCFiller::parseDeviceSpaceFill(const SkPath& path, const SkPoint* deviceSpacePts,
GrScissorTest scissorTest, const SkIRect& clippedDevIBounds,
const SkIVector& devToAtlasOffset) {
- SkASSERT(!fInstanceBuffer.gpuBuffer()); // Can't call after prepareToDraw().
+ SkASSERT(!fInstanceBuffer.hasGpuBuffer()); // Can't call after prepareToDraw().
SkASSERT(!path.isEmpty());
int currPathPointsIdx = fGeometry.points().count();
@@ -206,7 +206,7 @@
}
GrCCFiller::BatchID GrCCFiller::closeCurrentBatch() {
- SkASSERT(!fInstanceBuffer.gpuBuffer());
+ SkASSERT(!fInstanceBuffer.hasGpuBuffer());
SkASSERT(!fBatches.empty());
const auto& lastBatch = fBatches.back();
@@ -295,7 +295,7 @@
bool GrCCFiller::prepareToDraw(GrOnFlushResourceProvider* onFlushRP) {
using Verb = GrCCFillGeometry::Verb;
- SkASSERT(!fInstanceBuffer.gpuBuffer());
+ SkASSERT(!fInstanceBuffer.hasGpuBuffer());
SkASSERT(fBatches.back().fEndNonScissorIndices == // Call closeCurrentBatch().
fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled]);
SkASSERT(fBatches.back().fEndScissorSubBatchIdx == fScissorSubBatches.count());
@@ -342,7 +342,7 @@
int quadEndIdx = fBaseInstances[1].fConics + fTotalPrimitiveCounts[1].fConics;
fInstanceBuffer.resetAndMapBuffer(onFlushRP, quadEndIdx * sizeof(QuadPointInstance));
- if (!fInstanceBuffer.gpuBuffer()) {
+ if (!fInstanceBuffer.hasGpuBuffer()) {
SkDebugf("WARNING: failed to allocate CCPR fill instance buffer.\n");
return false;
}
@@ -475,7 +475,7 @@
BatchID batchID, const SkIRect& drawBounds) const {
using PrimitiveType = GrCCCoverageProcessor::PrimitiveType;
- SkASSERT(fInstanceBuffer.gpuBuffer());
+ SkASSERT(fInstanceBuffer.hasGpuBuffer());
GrResourceProvider* rp = flushState->resourceProvider();
const PrimitiveTallies& batchTotalCounts = fBatches[batchID].fTotalPrimitiveCounts;
diff --git a/src/gpu/ccpr/GrCCPerFlushResources.cpp b/src/gpu/ccpr/GrCCPerFlushResources.cpp
index 004ea0d..a8803ca 100644
--- a/src/gpu/ccpr/GrCCPerFlushResources.cpp
+++ b/src/gpu/ccpr/GrCCPerFlushResources.cpp
@@ -207,7 +207,7 @@
}
fPathInstanceBuffer.resetAndMapBuffer(onFlushRP,
inst_buffer_count(specs) * sizeof(PathInstance));
- if (!fPathInstanceBuffer.gpuBuffer()) {
+ if (!fPathInstanceBuffer.hasGpuBuffer()) {
SkDebugf("WARNING: failed to allocate CCPR instance buffer. No paths will be drawn.\n");
return;
}
@@ -218,7 +218,7 @@
specs.fNumClipPaths;
fStencilResolveBuffer.resetAndMapBuffer(
onFlushRP, numRenderedPaths * sizeof(GrStencilAtlasOp::ResolveRectInstance));
- if (!fStencilResolveBuffer.gpuBuffer()) {
+ if (!fStencilResolveBuffer.hasGpuBuffer()) {
SkDebugf("WARNING: failed to allocate CCPR stencil resolve buffer. "
"No paths will be drawn.\n");
return;
@@ -504,7 +504,7 @@
fPathInstanceBuffer.unmapBuffer();
- if (fStencilResolveBuffer.gpuBuffer()) {
+ if (fStencilResolveBuffer.hasGpuBuffer()) {
fStencilResolveBuffer.unmapBuffer();
}
diff --git a/src/gpu/ccpr/GrCCPerFlushResources.h b/src/gpu/ccpr/GrCCPerFlushResources.h
index 770b59d..4ae04d7 100644
--- a/src/gpu/ccpr/GrCCPerFlushResources.h
+++ b/src/gpu/ccpr/GrCCPerFlushResources.h
@@ -113,19 +113,19 @@
// Accessors used by draw calls, once the resources have been finalized.
const GrCCFiller& filler() const { SkASSERT(!this->isMapped()); return fFiller; }
const GrCCStroker& stroker() const { SkASSERT(!this->isMapped()); return fStroker; }
- const GrGpuBuffer* indexBuffer() const {
+ sk_sp<const GrGpuBuffer> indexBuffer() const {
SkASSERT(!this->isMapped());
- return fIndexBuffer.get();
+ return fIndexBuffer;
}
- const GrGpuBuffer* instanceBuffer() const {
+ sk_sp<const GrGpuBuffer> instanceBuffer() const {
SkASSERT(!this->isMapped());
return fPathInstanceBuffer.gpuBuffer();
}
- const GrGpuBuffer* vertexBuffer() const {
+ sk_sp<const GrGpuBuffer> vertexBuffer() const {
SkASSERT(!this->isMapped());
- return fVertexBuffer.get();
+ return fVertexBuffer;
}
- const GrGpuBuffer* stencilResolveBuffer() const {
+ sk_sp<const GrGpuBuffer> stencilResolveBuffer() const {
SkASSERT(!this->isMapped());
return fStencilResolveBuffer.gpuBuffer();
}
diff --git a/src/gpu/ccpr/GrCCStroker.cpp b/src/gpu/ccpr/GrCCStroker.cpp
index a1805f8..a836b52 100644
--- a/src/gpu/ccpr/GrCCStroker.cpp
+++ b/src/gpu/ccpr/GrCCStroker.cpp
@@ -371,7 +371,7 @@
int endConicsIdx = stroker->fBaseInstances[1].fConics +
stroker->fInstanceCounts[1]->fConics;
fInstanceBuffer.resetAndMapBuffer(onFlushRP, endConicsIdx * sizeof(ConicInstance));
- if (!fInstanceBuffer.gpuBuffer()) {
+ if (!fInstanceBuffer.hasGpuBuffer()) {
SkDebugf("WARNING: failed to allocate CCPR stroke instance buffer.\n");
return;
}
@@ -504,12 +504,12 @@
}
}
- sk_sp<GrGpuBuffer> finish() {
+ sk_sp<const GrGpuBuffer> finish() {
SkASSERT(this->isMapped());
SkASSERT(!memcmp(fNextInstances, fEndInstances, sizeof(fNextInstances)));
fInstanceBuffer.unmapBuffer();
SkASSERT(!this->isMapped());
- return sk_ref_sp(fInstanceBuffer.gpuBuffer());
+ return fInstanceBuffer.gpuBuffer();
}
private:
@@ -733,7 +733,7 @@
GrPrimitiveType::kTriangleStrip);
flushState->bindPipeline(programInfo, SkRect::Make(drawBounds));
- flushState->bindBuffers(nullptr, fInstanceBuffer.get(), nullptr);
+ flushState->bindBuffers(nullptr, fInstanceBuffer, nullptr);
// Linear strokes draw a quad. Cubic strokes emit a strip with normals at "numSegments"
// evenly-spaced points along the curve, plus one more for the final endpoint, plus two more for
@@ -772,7 +772,7 @@
int startScissorSubBatch,
const SkIRect& drawBounds) const {
processor.bindPipeline(flushState, pipeline, SkRect::Make(drawBounds));
- processor.bindBuffers(flushState->opsRenderPass(), fInstanceBuffer.get());
+ processor.bindBuffers(flushState->opsRenderPass(), fInstanceBuffer);
// Append non-scissored meshes.
int baseInstance = fBaseInstances[(int)GrScissorTest::kDisabled].*InstanceType;
diff --git a/src/gpu/ccpr/GrCCStroker.h b/src/gpu/ccpr/GrCCStroker.h
index f830bf1..3fe5e87 100644
--- a/src/gpu/ccpr/GrCCStroker.h
+++ b/src/gpu/ccpr/GrCCStroker.h
@@ -117,7 +117,7 @@
InstanceTalliesAllocator fTalliesAllocator;
const InstanceTallies* fInstanceCounts[kNumScissorModes] = {&fZeroTallies, &fZeroTallies};
- sk_sp<GrGpuBuffer> fInstanceBuffer;
+ sk_sp<const GrGpuBuffer> fInstanceBuffer;
// The indices stored in batches are relative to these base instances.
InstanceTallies fBaseInstances[kNumScissorModes];
};
diff --git a/src/gpu/ccpr/GrGSCoverageProcessor.cpp b/src/gpu/ccpr/GrGSCoverageProcessor.cpp
index a627db5..49e2fce 100644
--- a/src/gpu/ccpr/GrGSCoverageProcessor.cpp
+++ b/src/gpu/ccpr/GrGSCoverageProcessor.cpp
@@ -431,8 +431,8 @@
}
void GrGSCoverageProcessor::bindBuffers(GrOpsRenderPass* renderPass,
- const GrBuffer* instanceBuffer) const {
- renderPass->bindBuffers(nullptr, nullptr, instanceBuffer);
+ sk_sp<const GrBuffer> instanceBuffer) const {
+ renderPass->bindBuffers(nullptr, nullptr, std::move(instanceBuffer));
}
void GrGSCoverageProcessor::drawInstances(GrOpsRenderPass* renderPass, int instanceCount,
diff --git a/src/gpu/ccpr/GrGSCoverageProcessor.h b/src/gpu/ccpr/GrGSCoverageProcessor.h
index dab28a7..dc0299b 100644
--- a/src/gpu/ccpr/GrGSCoverageProcessor.h
+++ b/src/gpu/ccpr/GrGSCoverageProcessor.h
@@ -28,7 +28,7 @@
GrPrimitiveType primType() const final { return GrPrimitiveType::kLines; }
int numSubpasses() const override { return 2; }
void reset(PrimitiveType, int subpassIdx, GrResourceProvider*) override;
- void bindBuffers(GrOpsRenderPass*, const GrBuffer* instanceBuffer) const override;
+ void bindBuffers(GrOpsRenderPass*, sk_sp<const GrBuffer> instanceBuffer) const override;
void drawInstances(GrOpsRenderPass*, int instanceCount, int baseInstance) const override;
GrGLSLPrimitiveProcessor* onCreateGLSLInstance(std::unique_ptr<Shader>) const override;
diff --git a/src/gpu/ccpr/GrSampleMaskProcessor.cpp b/src/gpu/ccpr/GrSampleMaskProcessor.cpp
index 87fe341..01613ae 100644
--- a/src/gpu/ccpr/GrSampleMaskProcessor.cpp
+++ b/src/gpu/ccpr/GrSampleMaskProcessor.cpp
@@ -108,19 +108,19 @@
}
void GrSampleMaskProcessor::bindBuffers(GrOpsRenderPass* renderPass,
- const GrBuffer* instanceBuffer) const {
+ sk_sp<const GrBuffer> instanceBuffer) const {
SkASSERT(PrimitiveType::kWeightedTriangles != fPrimitiveType);
switch (fPrimitiveType) {
case PrimitiveType::kTriangles:
case PrimitiveType::kWeightedTriangles: {
- renderPass->bindBuffers(nullptr, nullptr, instanceBuffer);
+ renderPass->bindBuffers(nullptr, nullptr, std::move(instanceBuffer));
break;
}
case PrimitiveType::kQuadratics:
case PrimitiveType::kCubics:
case PrimitiveType::kConics: {
- renderPass->bindBuffers(nullptr, instanceBuffer, nullptr);
+ renderPass->bindBuffers(nullptr, std::move(instanceBuffer), nullptr);
break;
}
}
diff --git a/src/gpu/ccpr/GrSampleMaskProcessor.h b/src/gpu/ccpr/GrSampleMaskProcessor.h
index 9811bd3..f3a6796 100644
--- a/src/gpu/ccpr/GrSampleMaskProcessor.h
+++ b/src/gpu/ccpr/GrSampleMaskProcessor.h
@@ -21,7 +21,7 @@
GrPrimitiveType primType() const final;
int numSubpasses() const override { return 1; }
void reset(PrimitiveType, int subpassIdx, GrResourceProvider*) override;
- void bindBuffers(GrOpsRenderPass*, const GrBuffer* instanceBuffer) const override;
+ void bindBuffers(GrOpsRenderPass*, sk_sp<const GrBuffer> instanceBuffer) const override;
void drawInstances(GrOpsRenderPass*, int instanceCount, int baseInstance) const override;
GrGLSLPrimitiveProcessor* onCreateGLSLInstance(std::unique_ptr<Shader>) const override;
diff --git a/src/gpu/ccpr/GrVSCoverageProcessor.cpp b/src/gpu/ccpr/GrVSCoverageProcessor.cpp
index 43aff62..cac3c2f 100644
--- a/src/gpu/ccpr/GrVSCoverageProcessor.cpp
+++ b/src/gpu/ccpr/GrVSCoverageProcessor.cpp
@@ -530,10 +530,10 @@
}
void GrVSCoverageProcessor::bindBuffers(GrOpsRenderPass* renderPass,
- const GrBuffer* instanceBuffer) const {
+ sk_sp<const GrBuffer> instanceBuffer) const {
SkASSERT(fTriangleType == GrPrimitiveType::kTriangles ||
fTriangleType == GrPrimitiveType::kTriangleStrip);
- renderPass->bindBuffers(fIndexBuffer.get(), instanceBuffer, fVertexBuffer.get(),
+ renderPass->bindBuffers(fIndexBuffer, std::move(instanceBuffer), fVertexBuffer,
GrPrimitiveRestart(GrPrimitiveType::kTriangleStrip == fTriangleType));
}
diff --git a/src/gpu/ccpr/GrVSCoverageProcessor.h b/src/gpu/ccpr/GrVSCoverageProcessor.h
index 258b2b0..88f0840 100644
--- a/src/gpu/ccpr/GrVSCoverageProcessor.h
+++ b/src/gpu/ccpr/GrVSCoverageProcessor.h
@@ -21,7 +21,7 @@
GrPrimitiveType primType() const final { return fTriangleType; }
int numSubpasses() const override { return 1; }
void reset(PrimitiveType, int subpassIdx, GrResourceProvider*) override;
- void bindBuffers(GrOpsRenderPass*, const GrBuffer* instanceBuffer) const override;
+ void bindBuffers(GrOpsRenderPass*, sk_sp<const GrBuffer> instanceBuffer) const override;
void drawInstances(GrOpsRenderPass*, int instanceCount, int baseInstance) const override;
GrGLSLPrimitiveProcessor* onCreateGLSLInstance(std::unique_ptr<Shader>) const override;
diff --git a/src/gpu/d3d/GrD3DCommandList.cpp b/src/gpu/d3d/GrD3DCommandList.cpp
index 1a4ef6d..10c5fba 100644
--- a/src/gpu/d3d/GrD3DCommandList.cpp
+++ b/src/gpu/d3d/GrD3DCommandList.cpp
@@ -282,44 +282,55 @@
}
void GrD3DDirectCommandList::setVertexBuffers(unsigned int startSlot,
- const GrD3DBuffer* vertexBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
size_t vertexStride,
- const GrD3DBuffer* instanceBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
size_t instanceStride) {
- if (fCurrentVertexBuffer != vertexBuffer || fCurrentVertexStride != vertexStride ||
- fCurrentInstanceBuffer != instanceBuffer || fCurrentInstanceStride != instanceStride) {
+ if (fCurrentVertexBuffer != vertexBuffer.get() ||
+ fCurrentVertexStride != vertexStride ||
+ fCurrentInstanceBuffer != instanceBuffer.get() ||
+ fCurrentInstanceStride != instanceStride) {
+
+ fCurrentVertexBuffer = vertexBuffer.get();
+ fCurrentVertexStride = vertexStride;
+ fCurrentInstanceBuffer = instanceBuffer.get();
+ fCurrentInstanceStride = instanceStride;
+
D3D12_VERTEX_BUFFER_VIEW views[2];
int numViews = 0;
if (vertexBuffer) {
- this->addResource(vertexBuffer->resource());
- views[numViews].BufferLocation = vertexBuffer->d3dResource()->GetGPUVirtualAddress();
+ auto* d3dBuffer = static_cast<const GrD3DBuffer*>(vertexBuffer.get());
+ this->addResource(d3dBuffer->resource());
+ views[numViews].BufferLocation = d3dBuffer->d3dResource()->GetGPUVirtualAddress();
views[numViews].SizeInBytes = vertexBuffer->size();
views[numViews++].StrideInBytes = vertexStride;
+ this->addGrBuffer(std::move(vertexBuffer));
}
if (instanceBuffer) {
- this->addResource(instanceBuffer->resource());
- views[numViews].BufferLocation = instanceBuffer->d3dResource()->GetGPUVirtualAddress();
+ auto* d3dBuffer = static_cast<const GrD3DBuffer*>(instanceBuffer.get());
+ this->addResource(d3dBuffer->resource());
+ views[numViews].BufferLocation = d3dBuffer->d3dResource()->GetGPUVirtualAddress();
views[numViews].SizeInBytes = instanceBuffer->size();
views[numViews++].StrideInBytes = instanceStride;
+ this->addGrBuffer(std::move(instanceBuffer));
}
fCommandList->IASetVertexBuffers(startSlot, numViews, views);
-
- fCurrentVertexBuffer = vertexBuffer;
- fCurrentVertexStride = vertexStride;
- fCurrentInstanceBuffer = instanceBuffer;
- fCurrentInstanceStride = instanceStride;
}
}
-void GrD3DDirectCommandList::setIndexBuffer(const GrD3DBuffer* indexBuffer) {
- if (fCurrentIndexBuffer != indexBuffer) {
- this->addResource(indexBuffer->resource());
+void GrD3DDirectCommandList::setIndexBuffer(sk_sp<const GrBuffer> indexBuffer) {
+ if (fCurrentIndexBuffer != indexBuffer.get()) {
+ auto* d3dBuffer = static_cast<const GrD3DBuffer*>(indexBuffer.get());
+ this->addResource(d3dBuffer->resource());
D3D12_INDEX_BUFFER_VIEW view = {};
- view.BufferLocation = indexBuffer->d3dResource()->GetGPUVirtualAddress();
+ view.BufferLocation = d3dBuffer->d3dResource()->GetGPUVirtualAddress();
view.SizeInBytes = indexBuffer->size();
view.Format = DXGI_FORMAT_R16_UINT;
fCommandList->IASetIndexBuffer(&view);
+
+ fCurrentIndexBuffer = indexBuffer.get();
+ this->addGrBuffer(std::move(indexBuffer));
}
}
diff --git a/src/gpu/d3d/GrD3DCommandList.h b/src/gpu/d3d/GrD3DCommandList.h
index 25c0115..c65ad82 100644
--- a/src/gpu/d3d/GrD3DCommandList.h
+++ b/src/gpu/d3d/GrD3DCommandList.h
@@ -73,7 +73,7 @@
ID3D12Resource* srcBuffer, uint64_t srcOffset,
uint64_t numBytes);
- void addGpuBuffer(sk_sp<GrGpuBuffer> buffer) {
+ void addGrBuffer(sk_sp<const GrBuffer> buffer) {
fTrackedGpuBuffers.push_back(std::move(buffer));
}
@@ -114,7 +114,7 @@
SkSTArray<kInitialTrackedResourcesCount, sk_sp<GrManagedResource>> fTrackedResources;
SkSTArray<kInitialTrackedResourcesCount, sk_sp<GrRecycledResource>> fTrackedRecycledResources;
- SkSTArray<kInitialTrackedResourcesCount, sk_sp<GrGpuBuffer>> fTrackedGpuBuffers;
+ SkSTArray<kInitialTrackedResourcesCount, sk_sp<const GrBuffer>> fTrackedGpuBuffers;
// When we create a command list it starts in an active recording state
@@ -148,9 +148,9 @@
void setViewports(unsigned int numViewports, const D3D12_VIEWPORT* viewports);
void setGraphicsRootSignature(const sk_sp<GrD3DRootSignature>& rootSignature);
void setVertexBuffers(unsigned int startSlot,
- const GrD3DBuffer* vertexBuffer, size_t vertexStride,
- const GrD3DBuffer* instanceBuffer, size_t instanceStride);
- void setIndexBuffer(const GrD3DBuffer* indexBuffer);
+ sk_sp<const GrBuffer> vertexBuffer, size_t vertexStride,
+ sk_sp<const GrBuffer> instanceBuffer, size_t instanceStride);
+ void setIndexBuffer(sk_sp<const GrBuffer> indexBuffer);
void drawInstanced(unsigned int vertexCount, unsigned int instanceCount,
unsigned int startVertex, unsigned int startInstance);
void drawIndexedInstanced(unsigned int indexCount, unsigned int instanceCount,
@@ -187,11 +187,11 @@
void onReset() override;
const GrD3DRootSignature* fCurrentRootSignature;
- const GrD3DBuffer* fCurrentVertexBuffer;
+ const GrBuffer* fCurrentVertexBuffer;
size_t fCurrentVertexStride;
- const GrD3DBuffer* fCurrentInstanceBuffer;
+ const GrBuffer* fCurrentInstanceBuffer;
size_t fCurrentInstanceStride;
- const GrD3DBuffer* fCurrentIndexBuffer;
+ const GrBuffer* fCurrentIndexBuffer;
GrD3DConstantRingBuffer* fCurrentConstantRingBuffer;
GrD3DConstantRingBuffer::SubmitData fConstantRingBufferSubmitData;
diff --git a/src/gpu/d3d/GrD3DGpu.cpp b/src/gpu/d3d/GrD3DGpu.cpp
index ac4a767..850e6a0 100644
--- a/src/gpu/d3d/GrD3DGpu.cpp
+++ b/src/gpu/d3d/GrD3DGpu.cpp
@@ -1273,7 +1273,7 @@
}
void GrD3DGpu::takeOwnershipOfStagingBuffer(sk_sp<GrGpuBuffer> buffer) {
- fCurrentDirectCommandList->addGpuBuffer(std::move(buffer));
+ fCurrentDirectCommandList->addGrBuffer(std::move(buffer));
}
bool GrD3DGpu::onSubmitToGpu(bool syncCpu) {
diff --git a/src/gpu/d3d/GrD3DOpsRenderPass.cpp b/src/gpu/d3d/GrD3DOpsRenderPass.cpp
index 4932cff..da676d8 100644
--- a/src/gpu/d3d/GrD3DOpsRenderPass.cpp
+++ b/src/gpu/d3d/GrD3DOpsRenderPass.cpp
@@ -237,8 +237,9 @@
return true;
}
-void GrD3DOpsRenderPass::onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer,
+void GrD3DOpsRenderPass::onBindBuffers(sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
GrPrimitiveRestart primRestart) {
SkASSERT(GrPrimitiveRestart::kNo == primRestart);
SkASSERT(fCurrentPipelineState);
@@ -247,10 +248,8 @@
GrD3DDirectCommandList* currCmdList = fGpu->currentCommandList();
SkASSERT(currCmdList);
- // TODO: do we need a memory barrier here?
-
- fCurrentPipelineState->bindBuffers(fGpu, indexBuffer, instanceBuffer, vertexBuffer,
- currCmdList);
+ fCurrentPipelineState->bindBuffers(fGpu, std::move(indexBuffer), std::move(instanceBuffer),
+ std::move(vertexBuffer), currCmdList);
}
void GrD3DOpsRenderPass::onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
diff --git a/src/gpu/d3d/GrD3DOpsRenderPass.h b/src/gpu/d3d/GrD3DOpsRenderPass.h
index c5bfde4..17116c0 100644
--- a/src/gpu/d3d/GrD3DOpsRenderPass.h
+++ b/src/gpu/d3d/GrD3DOpsRenderPass.h
@@ -40,8 +40,8 @@
void onSetScissorRect(const SkIRect&) override;
bool onBindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
const GrPipeline&) override;
- void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) override;
+ void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
void onDraw(int vertexCount, int baseVertex) override {
this->onDrawInstanced(1, 0, vertexCount, baseVertex);
}
diff --git a/src/gpu/d3d/GrD3DPipelineState.cpp b/src/gpu/d3d/GrD3DPipelineState.cpp
index d41bdcd..a3bb498 100644
--- a/src/gpu/d3d/GrD3DPipelineState.cpp
+++ b/src/gpu/d3d/GrD3DPipelineState.cpp
@@ -155,33 +155,34 @@
}
}
-void GrD3DPipelineState::bindBuffers(GrD3DGpu* gpu, const GrBuffer* indexBuffer,
- const GrBuffer* instanceBuffer, const GrBuffer* vertexBuffer,
+void GrD3DPipelineState::bindBuffers(GrD3DGpu* gpu, sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
GrD3DDirectCommandList* commandList) {
// Here our vertex and instance inputs need to match the same 0-based bindings they were
// assigned in the PipelineState. That is, vertex first (if any) followed by instance.
- auto* d3dVertexBuffer = static_cast<const GrD3DBuffer*>(vertexBuffer);
- auto* d3dInstanceBuffer = static_cast<const GrD3DBuffer*>(instanceBuffer);
- if (d3dVertexBuffer) {
+ if (vertexBuffer) {
+ auto* d3dVertexBuffer = static_cast<const GrD3DBuffer*>(vertexBuffer.get());
SkASSERT(!d3dVertexBuffer->isCpuBuffer());
SkASSERT(!d3dVertexBuffer->isMapped());
const_cast<GrD3DBuffer*>(d3dVertexBuffer)->setResourceState(
gpu, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);
}
- if (d3dInstanceBuffer) {
+ if (instanceBuffer) {
+ auto* d3dInstanceBuffer = static_cast<const GrD3DBuffer*>(instanceBuffer.get());
SkASSERT(!d3dInstanceBuffer->isCpuBuffer());
SkASSERT(!d3dInstanceBuffer->isMapped());
const_cast<GrD3DBuffer*>(d3dInstanceBuffer)->setResourceState(
gpu, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);
}
- commandList->setVertexBuffers(0, d3dVertexBuffer, fVertexStride,
- d3dInstanceBuffer, fInstanceStride);
+ commandList->setVertexBuffers(0, std::move(vertexBuffer), fVertexStride,
+ std::move(instanceBuffer), fInstanceStride);
- if (auto* d3dIndexBuffer = static_cast<const GrD3DBuffer*>(indexBuffer)) {
+ if (auto* d3dIndexBuffer = static_cast<const GrD3DBuffer*>(indexBuffer.get())) {
SkASSERT(!d3dIndexBuffer->isCpuBuffer());
SkASSERT(!d3dIndexBuffer->isMapped());
const_cast<GrD3DBuffer*>(d3dIndexBuffer)->setResourceState(
gpu, D3D12_RESOURCE_STATE_INDEX_BUFFER);
- commandList->setIndexBuffer(d3dIndexBuffer);
+ commandList->setIndexBuffer(std::move(indexBuffer));
}
}
diff --git a/src/gpu/d3d/GrD3DPipelineState.h b/src/gpu/d3d/GrD3DPipelineState.h
index a9253eb..1d1795f 100644
--- a/src/gpu/d3d/GrD3DPipelineState.h
+++ b/src/gpu/d3d/GrD3DPipelineState.h
@@ -57,8 +57,9 @@
const GrSurfaceProxy* const primProcTextures[],
const GrPipeline& pipeline);
- void bindBuffers(GrD3DGpu*, const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrD3DDirectCommandList* commandList);
+ void bindBuffers(GrD3DGpu*, sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer, sk_sp<const GrBuffer> vertexBuffer,
+ GrD3DDirectCommandList* commandList);
// We can only cache non dirty uniform values until we submit a command list. After that, the
// next frame will get a completely different uniform buffer and/or offset into the buffer. Thus
diff --git a/src/gpu/dawn/GrDawnOpsRenderPass.cpp b/src/gpu/dawn/GrDawnOpsRenderPass.cpp
index ba4c73e..dcaeaf6 100644
--- a/src/gpu/dawn/GrDawnOpsRenderPass.cpp
+++ b/src/gpu/dawn/GrDawnOpsRenderPass.cpp
@@ -166,18 +166,20 @@
return true;
}
-void GrDawnOpsRenderPass::onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) {
+void GrDawnOpsRenderPass::onBindBuffers(sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
+ GrPrimitiveRestart) {
if (vertexBuffer) {
- wgpu::Buffer vertex = static_cast<const GrDawnBuffer*>(vertexBuffer)->get();
+ wgpu::Buffer vertex = static_cast<const GrDawnBuffer*>(vertexBuffer.get())->get();
fPassEncoder.SetVertexBuffer(0, vertex);
}
if (instanceBuffer) {
- wgpu::Buffer instance = static_cast<const GrDawnBuffer*>(instanceBuffer)->get();
+ wgpu::Buffer instance = static_cast<const GrDawnBuffer*>(instanceBuffer.get())->get();
fPassEncoder.SetVertexBuffer(1, instance);
}
if (indexBuffer) {
- wgpu::Buffer index = static_cast<const GrDawnBuffer*>(indexBuffer)->get();
+ wgpu::Buffer index = static_cast<const GrDawnBuffer*>(indexBuffer.get())->get();
fPassEncoder.SetIndexBuffer(index);
}
}
diff --git a/src/gpu/dawn/GrDawnOpsRenderPass.h b/src/gpu/dawn/GrDawnOpsRenderPass.h
index 1f7b70f..33d6816 100644
--- a/src/gpu/dawn/GrDawnOpsRenderPass.h
+++ b/src/gpu/dawn/GrDawnOpsRenderPass.h
@@ -41,8 +41,8 @@
void onSetScissorRect(const SkIRect&) override;
bool onBindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
const GrPipeline&) override;
- void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) override;
+ void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
void onDraw(int vertexCount, int baseVertex) override;
void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
uint16_t maxIndexValue, int baseVertex) override;
diff --git a/src/gpu/gl/GrGLOpsRenderPass.cpp b/src/gpu/gl/GrGLOpsRenderPass.cpp
index 2612c53..04cc042 100644
--- a/src/gpu/gl/GrGLOpsRenderPass.cpp
+++ b/src/gpu/gl/GrGLOpsRenderPass.cpp
@@ -58,41 +58,49 @@
return true;
}
-void GrGLOpsRenderPass::onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer,
+void GrGLOpsRenderPass::onBindBuffers(sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
GrPrimitiveRestart primitiveRestart) {
SkASSERT((primitiveRestart == GrPrimitiveRestart::kNo) || indexBuffer);
GrGLProgram* program = fGpu->currentProgram();
SkASSERT(program);
+#ifdef SK_DEBUG
+ fDidBindInstanceBuffer = false;
+ fDidBindVertexBuffer = false;
+#endif
+
int numAttribs = program->numVertexAttributes() + program->numInstanceAttributes();
- fAttribArrayState = fGpu->bindInternalVertexArray(indexBuffer, numAttribs, primitiveRestart);
+ fAttribArrayState = fGpu->bindInternalVertexArray(indexBuffer.get(), numAttribs,
+ primitiveRestart);
if (indexBuffer) {
if (indexBuffer->isCpuBuffer()) {
- auto* cpuIndexBuffer = static_cast<const GrCpuBuffer*>(indexBuffer);
+ auto* cpuIndexBuffer = static_cast<const GrCpuBuffer*>(indexBuffer.get());
fIndexPointer = reinterpret_cast<const uint16_t*>(cpuIndexBuffer->data());
} else {
fIndexPointer = nullptr;
}
}
- if (!fGpu->glCaps().baseVertexBaseInstanceSupport()) {
- // This platform does not support baseInstance. Defer binding of the instance buffer.
- fActiveInstanceBuffer = sk_ref_sp(instanceBuffer);
- } else {
- this->bindInstanceBuffer(instanceBuffer, 0);
+ // If this platform does not support baseInstance, defer binding of the instance buffer.
+ if (fGpu->glCaps().baseVertexBaseInstanceSupport()) {
+ this->bindInstanceBuffer(instanceBuffer.get(), 0);
+ SkDEBUGCODE(fDidBindInstanceBuffer = true;)
}
- if (!indexBuffer && fGpu->glCaps().drawArraysBaseVertexIsBroken()) {
- // There is a driver bug affecting glDrawArrays. Defer binding of the vertex buffer.
- fActiveVertexBuffer = sk_ref_sp(vertexBuffer);
- } else if (indexBuffer && !fGpu->glCaps().baseVertexBaseInstanceSupport()) {
- // This platform does not support baseVertex with indexed draws. Defer binding of the
- // vertex buffer.
- fActiveVertexBuffer = sk_ref_sp(vertexBuffer);
- } else {
- this->bindVertexBuffer(vertexBuffer, 0);
+ fActiveInstanceBuffer = std::move(instanceBuffer);
+
+ // We differ binding the vertex buffer for one of two situations:
+ // 1) This platform does not support baseVertex with indexed draws.
+ // 2) There is a driver bug affecting glDrawArrays.
+ if ((indexBuffer && fGpu->glCaps().baseVertexBaseInstanceSupport()) ||
+ (!indexBuffer && !fGpu->glCaps().drawArraysBaseVertexIsBroken())) {
+ this->bindVertexBuffer(vertexBuffer.get(), 0);
+ SkDEBUGCODE(fDidBindVertexBuffer = true;)
}
+ fActiveVertexBuffer = std::move(vertexBuffer);
+ fActiveIndexBuffer = std::move(indexBuffer);
}
void GrGLOpsRenderPass::bindInstanceBuffer(const GrBuffer* instanceBuffer, int baseInstance) {
@@ -133,7 +141,7 @@
}
void GrGLOpsRenderPass::onDraw(int vertexCount, int baseVertex) {
- SkASSERT(!fActiveVertexBuffer || fGpu->glCaps().drawArraysBaseVertexIsBroken());
+ SkASSERT(fDidBindVertexBuffer || fGpu->glCaps().drawArraysBaseVertexIsBroken());
GrGLenum glPrimType = fGpu->prepareToDraw(fPrimitiveType);
if (fGpu->glCaps().drawArraysBaseVertexIsBroken()) {
this->bindVertexBuffer(fActiveVertexBuffer.get(), baseVertex);
@@ -147,7 +155,7 @@
GrGLenum glPrimType = fGpu->prepareToDraw(fPrimitiveType);
if (fGpu->glCaps().baseVertexBaseInstanceSupport()) {
SkASSERT(fGpu->glCaps().drawInstancedSupport());
- SkASSERT(!fActiveVertexBuffer);
+ SkASSERT(fDidBindVertexBuffer);
if (baseVertex != 0) {
GL_CALL(DrawElementsInstancedBaseVertexBaseInstance(
glPrimType, indexCount, GR_GL_UNSIGNED_SHORT,
@@ -169,7 +177,7 @@
void GrGLOpsRenderPass::onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
int baseVertex) {
- SkASSERT(!fActiveVertexBuffer || fGpu->glCaps().drawArraysBaseVertexIsBroken());
+ SkASSERT(fDidBindVertexBuffer || fGpu->glCaps().drawArraysBaseVertexIsBroken());
if (fGpu->glCaps().drawArraysBaseVertexIsBroken()) {
// We weren't able to bind the vertex buffer during onBindBuffers because of a driver bug
// affecting glDrawArrays.
@@ -181,7 +189,7 @@
int instanceCountForDraw = std::min(instanceCount - i, maxInstances);
int baseInstanceForDraw = baseInstance + i;
if (fGpu->glCaps().baseVertexBaseInstanceSupport()) {
- SkASSERT(!fActiveInstanceBuffer);
+ SkASSERT(fDidBindInstanceBuffer);
GL_CALL(DrawArraysInstancedBaseInstance(glPrimType, baseVertex, vertexCount,
instanceCountForDraw, baseInstanceForDraw));
} else {
@@ -199,8 +207,8 @@
int instanceCountForDraw = std::min(instanceCount - i, maxInstances);
int baseInstanceForDraw = baseInstance + i;
if (fGpu->glCaps().baseVertexBaseInstanceSupport()) {
- SkASSERT(!fActiveInstanceBuffer);
- SkASSERT(!fActiveVertexBuffer);
+ SkASSERT(fDidBindInstanceBuffer);
+ SkASSERT(fDidBindVertexBuffer);
GL_CALL(DrawElementsInstancedBaseVertexBaseInstance(
glPrimType, indexCount, GR_GL_UNSIGNED_SHORT,
this->offsetForBaseIndex(baseIndex), instanceCountForDraw, baseVertex,
@@ -226,7 +234,7 @@
int drawCount) {
SkASSERT(fGpu->caps()->nativeDrawIndirectSupport());
SkASSERT(fGpu->glCaps().baseVertexBaseInstanceSupport());
- SkASSERT(!fActiveVertexBuffer || fGpu->glCaps().drawArraysBaseVertexIsBroken());
+ SkASSERT(fDidBindVertexBuffer || fGpu->glCaps().drawArraysBaseVertexIsBroken());
if (fGpu->glCaps().drawArraysBaseVertexIsBroken()) {
// We weren't able to bind the vertex buffer during onBindBuffers because of a driver bug
@@ -295,7 +303,7 @@
SkASSERT(fGpu->glCaps().baseVertexBaseInstanceSupport());
// The vertex buffer should have already gotten bound (as opposed us stashing it away during
// onBindBuffers and not expecting to bind it until this point).
- SkASSERT(!fActiveVertexBuffer);
+ SkASSERT(fDidBindVertexBuffer);
if (fGpu->glCaps().ANGLEMultiDrawSupport()) {
this->multiDrawElementsANGLE(drawIndirectBuffer, offset, drawCount);
diff --git a/src/gpu/gl/GrGLOpsRenderPass.h b/src/gpu/gl/GrGLOpsRenderPass.h
index 6fb4fc9..27dc282 100644
--- a/src/gpu/gl/GrGLOpsRenderPass.h
+++ b/src/gpu/gl/GrGLOpsRenderPass.h
@@ -57,8 +57,8 @@
void onSetScissorRect(const SkIRect& scissor) override;
bool onBindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
const GrPipeline& pipeline) override;
- void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) override;
+ void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
void onDraw(int vertexCount, int baseVertex) override;
void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
uint16_t maxIndexValue, int baseVertex) override;
@@ -87,6 +87,10 @@
// the indices, or nullptr if they reside physically in GPU memory.
const uint16_t* fIndexPointer;
+ // This tracks whether or not we bound the respective buffers during the bindBuffers call.
+ SkDEBUGCODE(bool fDidBindVertexBuffer = false;)
+ SkDEBUGCODE(bool fDidBindInstanceBuffer = false;)
+
typedef GrOpsRenderPass INHERITED;
};
diff --git a/src/gpu/mock/GrMockOpsRenderPass.h b/src/gpu/mock/GrMockOpsRenderPass.h
index 703eac2..d11ad57 100644
--- a/src/gpu/mock/GrMockOpsRenderPass.h
+++ b/src/gpu/mock/GrMockOpsRenderPass.h
@@ -37,8 +37,8 @@
void onSetScissorRect(const SkIRect&) override {}
bool onBindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
const GrPipeline&) override { return true; }
- void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) override {}
+ void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override {}
void onDraw(int, int) override { this->dummyDraw(); }
void onDrawIndexed(int, int, uint16_t, uint16_t, int) override { this->dummyDraw(); }
void onDrawInstanced(int, int, int, int) override { this->dummyDraw(); }
diff --git a/src/gpu/mtl/GrMtlOpsRenderPass.h b/src/gpu/mtl/GrMtlOpsRenderPass.h
index c4cf385..bc042bc 100644
--- a/src/gpu/mtl/GrMtlOpsRenderPass.h
+++ b/src/gpu/mtl/GrMtlOpsRenderPass.h
@@ -39,8 +39,8 @@
void onSetScissorRect(const SkIRect&) override;
bool onBindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
const GrPipeline&) override;
- void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) override;
+ void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
void onDraw(int vertexCount, int baseVertex) override;
void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
uint16_t maxIndexValue, int baseVertex) override;
diff --git a/src/gpu/mtl/GrMtlOpsRenderPass.mm b/src/gpu/mtl/GrMtlOpsRenderPass.mm
index 13ef3a3..0e4f666 100644
--- a/src/gpu/mtl/GrMtlOpsRenderPass.mm
+++ b/src/gpu/mtl/GrMtlOpsRenderPass.mm
@@ -254,26 +254,28 @@
fActiveRenderCmdEncoder = nil;
}
-void GrMtlOpsRenderPass::onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer,
+void GrMtlOpsRenderPass::onBindBuffers(sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
GrPrimitiveRestart primRestart) {
SkASSERT(GrPrimitiveRestart::kNo == primRestart);
int inputBufferIndex = 0;
if (vertexBuffer) {
SkASSERT(!vertexBuffer->isCpuBuffer());
- SkASSERT(!static_cast<const GrGpuBuffer*>(vertexBuffer)->isMapped());
- fActiveVertexBuffer = sk_ref_sp(static_cast<const GrMtlBuffer*>(vertexBuffer));
+ SkASSERT(!static_cast<const GrGpuBuffer*>(vertexBuffer.get())->isMapped());
+ fActiveVertexBuffer = std::move(vertexBuffer);
++inputBufferIndex;
}
if (instanceBuffer) {
SkASSERT(!instanceBuffer->isCpuBuffer());
- SkASSERT(!static_cast<const GrGpuBuffer*>(instanceBuffer)->isMapped());
- this->setVertexBuffer(fActiveRenderCmdEncoder, instanceBuffer, 0, inputBufferIndex++);
+ SkASSERT(!static_cast<const GrGpuBuffer*>(instanceBuffer.get())->isMapped());
+ this->setVertexBuffer(fActiveRenderCmdEncoder, instanceBuffer.get(), 0, inputBufferIndex++);
+ fActiveInstanceBuffer = std::move(instanceBuffer);
}
if (indexBuffer) {
SkASSERT(!indexBuffer->isCpuBuffer());
- SkASSERT(!static_cast<const GrGpuBuffer*>(indexBuffer)->isMapped());
- fActiveIndexBuffer = sk_ref_sp(static_cast<const GrMtlBuffer*>(indexBuffer));
+ SkASSERT(!static_cast<const GrGpuBuffer*>(indexBuffer.get())->isMapped());
+ fActiveIndexBuffer = std::move(indexBuffer);
}
}
diff --git a/src/gpu/ops/GrFillRRectOp.cpp b/src/gpu/ops/GrFillRRectOp.cpp
index e458c33..25068ed 100644
--- a/src/gpu/ops/GrFillRRectOp.cpp
+++ b/src/gpu/ops/GrFillRRectOp.cpp
@@ -874,7 +874,8 @@
flushState->bindPipelineAndScissorClip(*fProgramInfo, this->bounds());
flushState->bindTextures(fProgramInfo->primProc(), nullptr, fProgramInfo->pipeline());
- flushState->bindBuffers(fIndexBuffer.get(), fInstanceBuffer.get(), fVertexBuffer.get());
+ flushState->bindBuffers(std::move(fIndexBuffer), std::move(fInstanceBuffer),
+ std::move(fVertexBuffer));
flushState->drawIndexedInstanced(fIndexCount, 0, fInstanceCount, fBaseInstance, 0);
}
diff --git a/src/gpu/ops/GrFillRectOp.cpp b/src/gpu/ops/GrFillRectOp.cpp
index 5d20400..23f5d3a 100644
--- a/src/gpu/ops/GrFillRectOp.cpp
+++ b/src/gpu/ops/GrFillRectOp.cpp
@@ -336,7 +336,7 @@
const int totalNumVertices = fQuads.count() * vertexSpec.verticesPerQuad();
flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
- flushState->bindBuffers(fIndexBuffer.get(), nullptr, fVertexBuffer.get());
+ flushState->bindBuffers(std::move(fIndexBuffer), nullptr, std::move(fVertexBuffer));
flushState->bindTextures(fProgramInfo->primProc(), nullptr, fProgramInfo->pipeline());
GrQuadPerEdgeAA::IssueDraw(flushState->caps(), flushState->opsRenderPass(), vertexSpec, 0,
fQuads.count(), totalNumVertices, fBaseVertex);
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index 982ec51..7009443 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -905,7 +905,8 @@
}
flushState->bindPipelineAndScissorClip(*fDesc->fProgramInfo, chainBounds);
- flushState->bindBuffers(fDesc->fIndexBuffer.get(), nullptr, fDesc->fVertexBuffer.get());
+ flushState->bindBuffers(std::move(fDesc->fIndexBuffer), nullptr,
+ std::move(fDesc->fVertexBuffer));
int totQuadsSeen = 0;
SkDEBUGCODE(int numDraws = 0;)
diff --git a/src/gpu/tessellate/GrDrawAtlasPathOp.cpp b/src/gpu/tessellate/GrDrawAtlasPathOp.cpp
index 90337d6..f7ad26e 100644
--- a/src/gpu/tessellate/GrDrawAtlasPathOp.cpp
+++ b/src/gpu/tessellate/GrDrawAtlasPathOp.cpp
@@ -184,6 +184,6 @@
state->bindPipelineAndScissorClip(programInfo, this->bounds());
state->bindTextures(shader, *fAtlasProxy, pipeline);
- state->bindBuffers(nullptr, fInstanceBuffer.get(), nullptr);
+ state->bindBuffers(nullptr, std::move(fInstanceBuffer), nullptr);
state->drawInstanced(fInstanceCount, fBaseInstance, 4, 0);
}
diff --git a/src/gpu/tessellate/GrTessellatePathOp.cpp b/src/gpu/tessellate/GrTessellatePathOp.cpp
index c8123de..e858e88 100644
--- a/src/gpu/tessellate/GrTessellatePathOp.cpp
+++ b/src/gpu/tessellate/GrTessellatePathOp.cpp
@@ -546,7 +546,7 @@
GrPathShader::ProgramInfo programInfo(flushState->writeView(), &pipeline,
&stencilTriangleShader);
flushState->bindPipelineAndScissorClip(programInfo, this->bounds());
- flushState->bindBuffers(nullptr, nullptr, fTriangleBuffer.get());
+ flushState->bindBuffers(nullptr, nullptr, std::move(fTriangleBuffer));
flushState->draw(fTriangleVertexCount, fBaseTriangleVertex);
}
@@ -557,11 +557,11 @@
flushState->bindPipelineAndScissorClip(programInfo, this->bounds());
if (fIndirectDrawBuffer) {
SkASSERT(fIndirectIndexBuffer);
- flushState->bindBuffers(fIndirectIndexBuffer.get(), fCubicBuffer.get(), nullptr);
+ flushState->bindBuffers(fIndirectIndexBuffer, fCubicBuffer, nullptr);
flushState->drawIndexedIndirect(fIndirectDrawBuffer.get(), fIndirectDrawOffset,
fIndirectDrawCount);
} else {
- flushState->bindBuffers(nullptr, nullptr, fCubicBuffer.get());
+ flushState->bindBuffers(nullptr, nullptr, fCubicBuffer);
flushState->draw(fCubicVertexCount, fBaseCubicVertex);
if (flushState->caps().requiresManualFBBarrierAfterTessellatedStencilDraw()) {
flushState->gpu()->insertManualFramebufferBarrier(); // http://skbug.com/9739
@@ -655,7 +655,7 @@
&fillTriangleShader);
flushState->bindPipelineAndScissorClip(programInfo, this->bounds());
flushState->bindTextures(fillTriangleShader, nullptr, pipeline);
- flushState->bindBuffers(nullptr, nullptr, fTriangleBuffer.get());
+ flushState->bindBuffers(nullptr, nullptr, fTriangleBuffer);
flushState->draw(fTriangleVertexCount, fBaseTriangleVertex);
if (fStencilCubicsShader) {
@@ -675,7 +675,7 @@
// the base vertex on an instance boundary in order to accommodate this.
SkASSERT((fCubicVertexCount % 4) == 0);
SkASSERT((fBaseCubicVertex % 4) == 0);
- flushState->bindBuffers(nullptr, fCubicBuffer.get(), nullptr);
+ flushState->bindBuffers(nullptr, fCubicBuffer, nullptr);
flushState->drawInstanced(fCubicVertexCount >> 2, fBaseCubicVertex >> 2, 4, 0);
}
return;
diff --git a/src/gpu/tessellate/GrTessellateStrokeOp.cpp b/src/gpu/tessellate/GrTessellateStrokeOp.cpp
index 19f5023..f8b274f 100644
--- a/src/gpu/tessellate/GrTessellateStrokeOp.cpp
+++ b/src/gpu/tessellate/GrTessellateStrokeOp.cpp
@@ -348,6 +348,6 @@
flushState->bindPipelineAndScissorClip(programInfo, this->bounds() /*chainBounds??*/);
flushState->bindTextures(strokeShader, nullptr, pipeline);
- flushState->bindBuffers(nullptr, nullptr, fVertexBuffer.get());
+ flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer));
flushState->draw(fVertexCount, fBaseVertex);
}
diff --git a/src/gpu/vk/GrVkCommandBuffer.cpp b/src/gpu/vk/GrVkCommandBuffer.cpp
index eba29cf..82b4436 100644
--- a/src/gpu/vk/GrVkCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkCommandBuffer.cpp
@@ -179,36 +179,39 @@
void GrVkCommandBuffer::bindInputBuffer(GrVkGpu* gpu, uint32_t binding,
- const GrVkMeshBuffer* vbuffer) {
- VkBuffer vkBuffer = vbuffer->buffer();
+ sk_sp<const GrBuffer> buffer) {
+ auto* vkMeshBuffer = static_cast<const GrVkMeshBuffer*>(buffer.get());
+ VkBuffer vkBuffer = vkMeshBuffer->buffer();
SkASSERT(VK_NULL_HANDLE != vkBuffer);
SkASSERT(binding < kMaxInputBuffers);
// TODO: once vbuffer->offset() no longer always returns 0, we will need to track the offset
// to know if we can skip binding or not.
if (vkBuffer != fBoundInputBuffers[binding]) {
- VkDeviceSize offset = vbuffer->offset();
+ VkDeviceSize offset = vkMeshBuffer->offset();
GR_VK_CALL(gpu->vkInterface(), CmdBindVertexBuffers(fCmdBuffer,
binding,
1,
&vkBuffer,
&offset));
fBoundInputBuffers[binding] = vkBuffer;
- this->addResource(vbuffer->resource());
+ this->addResource(vkMeshBuffer->resource());
+ this->addGrBuffer(std::move(buffer));
}
}
-void GrVkCommandBuffer::bindIndexBuffer(GrVkGpu* gpu, const GrVkMeshBuffer* ibuffer) {
- VkBuffer vkBuffer = ibuffer->buffer();
+void GrVkCommandBuffer::bindIndexBuffer(GrVkGpu* gpu, sk_sp<const GrBuffer> buffer) {
+ auto* vkMeshBuffer = static_cast<const GrVkMeshBuffer*>(buffer.get());
+ VkBuffer vkBuffer = vkMeshBuffer->buffer();
SkASSERT(VK_NULL_HANDLE != vkBuffer);
// TODO: once ibuffer->offset() no longer always returns 0, we will need to track the offset
// to know if we can skip binding or not.
if (vkBuffer != fBoundIndexBuffer) {
GR_VK_CALL(gpu->vkInterface(), CmdBindIndexBuffer(fCmdBuffer,
- vkBuffer,
- ibuffer->offset(),
+ vkBuffer, vkMeshBuffer->offset(),
VK_INDEX_TYPE_UINT16));
fBoundIndexBuffer = vkBuffer;
- this->addResource(ibuffer->resource());
+ this->addResource(vkMeshBuffer->resource());
+ this->addGrBuffer(std::move(buffer));
}
}
diff --git a/src/gpu/vk/GrVkCommandBuffer.h b/src/gpu/vk/GrVkCommandBuffer.h
index 19f5276..e0febac 100644
--- a/src/gpu/vk/GrVkCommandBuffer.h
+++ b/src/gpu/vk/GrVkCommandBuffer.h
@@ -46,9 +46,9 @@
BarrierType barrierType,
void* barrier);
- void bindInputBuffer(GrVkGpu* gpu, uint32_t binding, const GrVkMeshBuffer* vbuffer);
+ void bindInputBuffer(GrVkGpu* gpu, uint32_t binding, sk_sp<const GrBuffer> buffer);
- void bindIndexBuffer(GrVkGpu* gpu, const GrVkMeshBuffer* ibuffer);
+ void bindIndexBuffer(GrVkGpu* gpu, sk_sp<const GrBuffer> buffer);
void bindPipeline(const GrVkGpu* gpu, const GrVkPipeline* pipeline);
@@ -122,7 +122,7 @@
fTrackedRecycledResources.append(1, &resource);
}
- void addGpuBuffer(sk_sp<GrGpuBuffer> buffer) {
+ void addGrBuffer(sk_sp<const GrBuffer> buffer) {
fTrackedGpuBuffers.push_back(std::move(buffer));
}
@@ -149,7 +149,7 @@
SkTDArray<const GrManagedResource*> fTrackedResources;
SkTDArray<const GrRecycledResource*> fTrackedRecycledResources;
- SkSTArray<16, sk_sp<GrGpuBuffer>> fTrackedGpuBuffers;
+ SkSTArray<16, sk_sp<const GrBuffer>> fTrackedGpuBuffers;
// Tracks whether we are in the middle of a command buffer begin/end calls and thus can add
// new commands to the buffer;
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 8976b37..f64f051 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -2044,7 +2044,7 @@
}
void GrVkGpu::takeOwnershipOfStagingBuffer(sk_sp<GrGpuBuffer> buffer) {
- this->currentCommandBuffer()->addGpuBuffer(std::move(buffer));
+ this->currentCommandBuffer()->addGrBuffer(std::move(buffer));
}
bool GrVkGpu::onSubmitToGpu(bool syncCpu) {
diff --git a/src/gpu/vk/GrVkOpsRenderPass.cpp b/src/gpu/vk/GrVkOpsRenderPass.cpp
index 708bb42..17055db 100644
--- a/src/gpu/vk/GrVkOpsRenderPass.cpp
+++ b/src/gpu/vk/GrVkOpsRenderPass.cpp
@@ -541,8 +541,9 @@
this->currentCommandBuffer());
}
-void GrVkOpsRenderPass::onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer,
+void GrVkOpsRenderPass::onBindBuffers(sk_sp<const GrBuffer> indexBuffer,
+ sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer,
GrPrimitiveRestart primRestart) {
SkASSERT(GrPrimitiveRestart::kNo == primRestart);
if (!fCurrentRenderPass) {
@@ -563,20 +564,20 @@
// Here our vertex and instance inputs need to match the same 0-based bindings they were
// assigned in GrVkPipeline. That is, vertex first (if any) followed by instance.
uint32_t binding = 0;
- if (auto* vkVertexBuffer = static_cast<const GrVkMeshBuffer*>(vertexBuffer)) {
+ if (auto* vkVertexBuffer = static_cast<const GrVkMeshBuffer*>(vertexBuffer.get())) {
SkASSERT(!vkVertexBuffer->isCpuBuffer());
SkASSERT(!vkVertexBuffer->isMapped());
- currCmdBuf->bindInputBuffer(fGpu, binding++, vkVertexBuffer);
+ currCmdBuf->bindInputBuffer(fGpu, binding++, std::move(vertexBuffer));
}
- if (auto* vkInstanceBuffer = static_cast<const GrVkMeshBuffer*>(instanceBuffer)) {
+ if (auto* vkInstanceBuffer = static_cast<const GrVkMeshBuffer*>(instanceBuffer.get())) {
SkASSERT(!vkInstanceBuffer->isCpuBuffer());
SkASSERT(!vkInstanceBuffer->isMapped());
- currCmdBuf->bindInputBuffer(fGpu, binding++, vkInstanceBuffer);
+ currCmdBuf->bindInputBuffer(fGpu, binding++, std::move(instanceBuffer));
}
- if (auto* vkIndexBuffer = static_cast<const GrVkMeshBuffer*>(indexBuffer)) {
+ if (auto* vkIndexBuffer = static_cast<const GrVkMeshBuffer*>(indexBuffer.get())) {
SkASSERT(!vkIndexBuffer->isCpuBuffer());
SkASSERT(!vkIndexBuffer->isMapped());
- currCmdBuf->bindIndexBuffer(fGpu, vkIndexBuffer);
+ currCmdBuf->bindIndexBuffer(fGpu, std::move(indexBuffer));
}
}
diff --git a/src/gpu/vk/GrVkOpsRenderPass.h b/src/gpu/vk/GrVkOpsRenderPass.h
index 7db3b94..11ff36e 100644
--- a/src/gpu/vk/GrVkOpsRenderPass.h
+++ b/src/gpu/vk/GrVkOpsRenderPass.h
@@ -66,8 +66,8 @@
void onSetScissorRect(const SkIRect&) override;
bool onBindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
const GrPipeline&) override;
- void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
- const GrBuffer* vertexBuffer, GrPrimitiveRestart) override;
+ void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
+ sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
void onDraw(int vertexCount, int baseVertex) override {
this->onDrawInstanced(1, 0, vertexCount, baseVertex);
}
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 2aa049b..dd5ae2f 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -181,7 +181,7 @@
[&](DrawMeshHelper* helper) {
for (int y = 0; y < kBoxCountY; ++y) {
auto pass = helper->bindPipeline(GrPrimitiveType::kTriangles, false, true);
- pass->bindBuffers(nullptr, nullptr, helper->fVertBuffer.get());
+ pass->bindBuffers(nullptr, nullptr, helper->fVertBuffer);
pass->draw(kBoxCountX * 6, y * kBoxCountX * 6);
}
});
@@ -203,8 +203,7 @@
int repetitionCount = std::min(3 - baseRepetition, kBoxCount - i);
auto pass = helper->bindPipeline(GrPrimitiveType::kTriangles, false, true);
- pass->bindBuffers(helper->fIndexBuffer.get(), nullptr,
- helper->fVertBuffer.get());
+ pass->bindBuffers(helper->fIndexBuffer, nullptr, helper->fVertBuffer);
pass->drawIndexed(repetitionCount * 6, baseRepetition * 6, baseRepetition * 4,
(baseRepetition + repetitionCount) * 4 - 1,
(i - baseRepetition) * 4);
@@ -226,8 +225,7 @@
// not support a base index.
for (int y = 0; y < kBoxCountY; ++y) {
auto pass = helper->bindPipeline(GrPrimitiveType::kTriangles, false, true);
- pass->bindBuffers(helper->fIndexBuffer.get(), nullptr,
- helper->fVertBuffer.get());
+ pass->bindBuffers(helper->fIndexBuffer, nullptr, helper->fVertBuffer);
pass->drawIndexPattern(6, kBoxCountX, kIndexPatternRepeatCount, 4,
y * kBoxCountX * 4);
@@ -263,7 +261,7 @@
// Draw boxes one line at a time to exercise base instance, base vertex, and
// null vertex buffer.
for (int y = 0; y < kBoxCountY; ++y) {
- const GrBuffer* vertexBuffer = nullptr;
+ sk_sp<const GrBuffer> vertexBuffer;
int baseVertex = 0;
switch (y % 3) {
case 0:
@@ -272,10 +270,10 @@
}
[[fallthrough]];
case 1:
- vertexBuffer = helper->fVertBuffer.get();
+ vertexBuffer = helper->fVertBuffer;
break;
case 2:
- vertexBuffer = helper->fVertBuffer2.get();
+ vertexBuffer = helper->fVertBuffer2;
baseVertex = 2;
break;
}
@@ -285,16 +283,17 @@
auto pass = helper->bindPipeline(primitiveType, true,
SkToBool(vertexBuffer));
if (indexed) {
- const GrBuffer* indexBuffer = (y % 2) ?
- helper->fIndexBuffer2.get() : helper->fIndexBuffer.get();
+ sk_sp<const GrBuffer> indexBuffer = (y % 2) ?
+ helper->fIndexBuffer2 : helper->fIndexBuffer;
VALIDATE(indexBuffer);
int baseIndex = (y % 2);
- pass->bindBuffers(indexBuffer, helper->fInstBuffer.get(),
- vertexBuffer);
+ pass->bindBuffers(std::move(indexBuffer), helper->fInstBuffer,
+ std::move(vertexBuffer));
pass->drawIndexedInstanced(6, baseIndex, kBoxCountX, y * kBoxCountX,
baseVertex);
} else {
- pass->bindBuffers(nullptr, helper->fInstBuffer.get(), vertexBuffer);
+ pass->bindBuffers(nullptr, helper->fInstBuffer,
+ std::move(vertexBuffer));
pass->drawInstanced(kBoxCountX, y * kBoxCountY, 4, baseVertex);
}
}
@@ -373,8 +372,8 @@
GrOpsRenderPass* pass;
if (indexed) {
pass = helper->bindPipeline(GrPrimitiveType::kTriangles, true, true);
- pass->bindBuffers(helper->fIndexBuffer2.get(), helper->fInstBuffer.get(),
- helper->fVertBuffer.get());
+ pass->bindBuffers(helper->fIndexBuffer2, helper->fInstBuffer,
+ helper->fVertBuffer);
for (int i = 0; i < 3; ++i) {
int start = kBoxCountY * i / 3;
int end = kBoxCountY * (i + 1) / 3;
@@ -385,8 +384,7 @@
}
} else {
pass = helper->bindPipeline(GrPrimitiveType::kTriangleStrip, true, true);
- pass->bindBuffers(nullptr, helper->fInstBuffer.get(),
- helper->fVertBuffer.get());
+ pass->bindBuffers(nullptr, helper->fInstBuffer, helper->fVertBuffer);
for (int i = 0; i < 2; ++i) {
int start = kBoxCountY * i / 2;
int end = kBoxCountY * (i + 1) / 2;