Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 426274b

Browse files
egdanielSkia Commit-Bot
authored andcommitted
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 <[email protected]> Commit-Queue: Greg Daniel <[email protected]>
1 parent c8ae494 commit 426274b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+230
-194
lines changed

gm/clockwise.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class ClockwiseTestOp : public GrDrawOp {
216216
}
217217

218218
flushState->bindPipeline(*fProgramInfo, SkRect::MakeXYWH(0, fY, 100, 100));
219-
flushState->bindBuffers(nullptr, nullptr, fVertexBuffer.get());
219+
flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer));
220220
flushState->draw(4, 0);
221221
}
222222

gm/fwidth_squircle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class FwidthSquircleTestOp : public GrDrawOp {
226226
}
227227

228228
flushState->bindPipeline(*fProgramInfo, SkRect::MakeIWH(kWidth, kHeight));
229-
flushState->bindBuffers(nullptr, nullptr, fVertexBuffer.get());
229+
flushState->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer));
230230
flushState->draw(4, 0);
231231

232232
}

gm/tessellation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class TessellationTestOp : public GrDrawOp {
348348
tessellationPatchVertexCount);
349349

350350
state->bindPipeline(programInfo, SkRect::MakeIWH(kWidth, kHeight));
351-
state->bindBuffers(nullptr, nullptr, fVertexBuffer.get());
351+
state->bindBuffers(nullptr, nullptr, std::move(fVertexBuffer));
352352
state->draw(tessellationPatchVertexCount, fBaseVertex);
353353
}
354354

samplecode/SampleCCPRGeometry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state,
371371
GrGpuBufferType::kVertex, kDynamic_GrAccessPattern,
372372
fView->fQuadPointInstances.begin()));
373373
if (!fView->fQuadPointInstances.empty() && instBuff) {
374-
proc->bindBuffers(renderPass, instBuff.get());
374+
proc->bindBuffers(renderPass, std::move(instBuff));
375375
proc->drawInstances(renderPass, fView->fQuadPointInstances.count(), 0);
376376
}
377377
} else {
@@ -380,7 +380,7 @@ void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state,
380380
GrGpuBufferType::kVertex, kDynamic_GrAccessPattern,
381381
fView->fTriPointInstances.begin()));
382382
if (!fView->fTriPointInstances.empty() && instBuff) {
383-
proc->bindBuffers(renderPass, instBuff.get());
383+
proc->bindBuffers(renderPass, std::move(instBuff));
384384
proc->drawInstances(renderPass, fView->fTriPointInstances.count(), 0);
385385
}
386386
}

src/gpu/GrOpFlushState.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,10 @@ GrAtlasManager* GrOpFlushState::atlasManager() const {
209209
void GrOpFlushState::drawMesh(const GrSimpleMesh& mesh) {
210210
SkASSERT(mesh.fIsInitialized);
211211
if (!mesh.fIndexBuffer) {
212-
this->bindBuffers(nullptr, nullptr, mesh.fVertexBuffer.get());
212+
this->bindBuffers(nullptr, nullptr, mesh.fVertexBuffer);
213213
this->draw(mesh.fVertexCount, mesh.fBaseVertex);
214214
} else {
215-
this->bindBuffers(mesh.fIndexBuffer.get(), nullptr, mesh.fVertexBuffer.get(),
216-
mesh.fPrimitiveRestart);
215+
this->bindBuffers(mesh.fIndexBuffer, nullptr, mesh.fVertexBuffer, mesh.fPrimitiveRestart);
217216
if (0 == mesh.fPatternRepeatCount) {
218217
this->drawIndexed(mesh.fIndexCount, mesh.fBaseIndex, mesh.fMinIndexValue,
219218
mesh.fMaxIndexValue, mesh.fBaseVertex);

src/gpu/GrOpFlushState.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,11 @@ class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp:
198198
const GrSurfaceProxy* const primProcTextures[], const GrPipeline& pipeline) {
199199
fOpsRenderPass->bindTextures(primProc, primProcTextures, pipeline);
200200
}
201-
void bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
202-
const GrBuffer* vertexBuffer,
201+
void bindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
202+
sk_sp<const GrBuffer> vertexBuffer,
203203
GrPrimitiveRestart primitiveRestart = GrPrimitiveRestart::kNo) {
204-
fOpsRenderPass->bindBuffers(indexBuffer, instanceBuffer, vertexBuffer, primitiveRestart);
204+
fOpsRenderPass->bindBuffers(std::move(indexBuffer), std::move(instanceBuffer),
205+
std::move(vertexBuffer), primitiveRestart);
205206
}
206207
void draw(int vertexCount, int baseVertex) {
207208
fOpsRenderPass->draw(vertexCount, baseVertex);

src/gpu/GrOpsRenderPass.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ void GrOpsRenderPass::bindTextures(const GrPrimitiveProcessor& primProc,
184184
SkDEBUGCODE(fTextureBindingStatus = DynamicStateStatus::kConfigured);
185185
}
186186

187-
void GrOpsRenderPass::bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
188-
const GrBuffer* vertexBuffer, GrPrimitiveRestart primRestart) {
187+
void GrOpsRenderPass::bindBuffers(sk_sp<const GrBuffer> indexBuffer,
188+
sk_sp<const GrBuffer> instanceBuffer,
189+
sk_sp<const GrBuffer> vertexBuffer,
190+
GrPrimitiveRestart primRestart) {
189191
if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
190192
SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
191193
return;
@@ -211,7 +213,8 @@ void GrOpsRenderPass::bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* i
211213
}
212214
#endif
213215

214-
this->onBindBuffers(indexBuffer, instanceBuffer, vertexBuffer, primRestart);
216+
this->onBindBuffers(std::move(indexBuffer), std::move(instanceBuffer), std::move(vertexBuffer),
217+
primRestart);
215218
}
216219

217220
bool GrOpsRenderPass::prepareToDraw() {

src/gpu/GrOpsRenderPass.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class GrOpsRenderPass {
7171
void bindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[],
7272
const GrPipeline&);
7373

74-
void bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
75-
const GrBuffer* vertexBuffer, GrPrimitiveRestart = GrPrimitiveRestart::kNo);
74+
void bindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
75+
sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart = GrPrimitiveRestart::kNo);
7676

7777
// The next several draw*() methods issue draws using the current pipeline state. Before
7878
// drawing, the caller must configure the pipeline and dynamic state:
@@ -180,8 +180,8 @@ class GrOpsRenderPass {
180180
virtual bool onBindTextures(const GrPrimitiveProcessor&,
181181
const GrSurfaceProxy* const primProcTextures[],
182182
const GrPipeline&) = 0;
183-
virtual void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer,
184-
const GrBuffer* vertexBuffer, GrPrimitiveRestart) = 0;
183+
virtual void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
184+
sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) = 0;
185185
virtual void onDraw(int vertexCount, int baseVertex) = 0;
186186
virtual void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
187187
uint16_t maxIndexValue, int baseVertex) = 0;

src/gpu/ccpr/GrAutoMapVertexBuffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class GrAutoMapVertexBuffer : SkNoncopyable {
2222
}
2323
}
2424

25-
const GrGpuBuffer* gpuBuffer() const { return fGpuBuffer.get(); }
25+
bool hasGpuBuffer() const { return SkToBool(fGpuBuffer.get()); }
26+
sk_sp<const GrGpuBuffer> gpuBuffer() const { return fGpuBuffer; }
2627
bool isMapped() const { return SkToBool(fData); }
2728
void* data() const { SkASSERT(this->isMapped()); return fData; }
2829

src/gpu/ccpr/GrCCCoverageProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class GrCCCoverageProcessor : public GrGeometryProcessor {
117117
virtual int numSubpasses() const = 0;
118118
virtual void reset(PrimitiveType, int subpassIdx, GrResourceProvider*) = 0;
119119
void bindPipeline(GrOpFlushState*, const GrPipeline&, const SkRect& drawBounds) const;
120-
virtual void bindBuffers(GrOpsRenderPass*, const GrBuffer* instanceBuffer) const = 0;
120+
virtual void bindBuffers(GrOpsRenderPass*, sk_sp<const GrBuffer> instanceBuffer) const = 0;
121121
virtual void drawInstances(GrOpsRenderPass*, int instanceCount, int baseInstance) const = 0;
122122

123123
// The Shader provides code to calculate each pixel's coverage in a RenderPass. It also

0 commit comments

Comments
 (0)