Pin the quad index buffer in GrResourceProvider.

This can get purged under memory pressure, but it is highly unlikely that
it will not be quickly recreated. It is only 32K.

Change-Id: Ia1fd404d8a57968aa26ff24f5a407e79fb78cc74
Reviewed-on: https://skia-review.googlesource.com/c/190260
Commit-Queue: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Salomon 2019-02-07 13:27:18 -05:00 committed by Skia Commit-Bot
parent 8619a34bb8
commit a29dd9d0cb
2 changed files with 17 additions and 19 deletions

View File

@ -25,8 +25,6 @@
#include "SkGr.h"
#include "SkMathPriv.h"
GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
const uint32_t GrResourceProvider::kMinScratchTextureSize = 16;
#ifdef SK_DISABLE_EXPLICIT_GPU_RESOURCE_ALLOCATION
@ -55,9 +53,6 @@ GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSin
}
fCaps = sk_ref_sp(fGpu->caps());
GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
fQuadIndexBufferKey = gQuadIndexBufferKey;
}
sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
@ -306,7 +301,7 @@ sk_sp<const GrGpuBuffer> GrResourceProvider::createPatternedIndexBuffer(const ui
int patternSize,
int reps,
int vertCount,
const GrUniqueKey& key) {
const GrUniqueKey* key) {
size_t bufferSize = patternSize * reps * sizeof(uint16_t);
// This is typically used in GrMeshDrawOps, so we assume kNoPendingIO.
@ -335,7 +330,10 @@ sk_sp<const GrGpuBuffer> GrResourceProvider::createPatternedIndexBuffer(const ui
} else {
buffer->unmap();
}
this->assignUniqueKeyToResource(key, buffer.get());
if (key) {
SkASSERT(key->isValid());
this->assignUniqueKeyToResource(*key, buffer.get());
}
return std::move(buffer);
}
@ -344,7 +342,7 @@ static constexpr int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1;
sk_sp<const GrGpuBuffer> GrResourceProvider::createQuadIndexBuffer() {
GR_STATIC_ASSERT(4 * kMaxQuads <= 65535);
static const uint16_t kPattern[] = { 0, 1, 2, 2, 1, 3 };
return this->createPatternedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadIndexBufferKey);
return this->createPatternedIndexBuffer(kPattern, 6, kMaxQuads, 4, nullptr);
}
int GrResourceProvider::QuadCountOfQuadBuffer() { return kMaxQuads; }

View File

@ -163,10 +163,10 @@ public:
int reps,
int vertCount,
const GrUniqueKey& key) {
if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(key)) {
return std::move(buffer);
if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) {
return buffer;
}
return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, key);
return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, &key);
}
/**
@ -177,10 +177,10 @@ public:
* @ return the quad index buffer
*/
sk_sp<const GrGpuBuffer> refQuadIndexBuffer() {
if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(fQuadIndexBufferKey)) {
return buffer;
if (!fQuadIndexBuffer) {
fQuadIndexBuffer = this->createQuadIndexBuffer();
}
return this->createQuadIndexBuffer();
return fQuadIndexBuffer;
}
static int QuadCountOfQuadBuffer();
@ -287,15 +287,15 @@ private:
int patternSize,
int reps,
int vertCount,
const GrUniqueKey& key);
const GrUniqueKey* key);
sk_sp<const GrGpuBuffer> createQuadIndexBuffer();
GrResourceCache* fCache;
GrGpu* fGpu;
GrResourceCache* fCache;
GrGpu* fGpu;
sk_sp<const GrCaps> fCaps;
GrUniqueKey fQuadIndexBufferKey;
bool fExplicitlyAllocateGPUResources;
sk_sp<const GrGpuBuffer> fQuadIndexBuffer;
bool fExplicitlyAllocateGPUResources;
// In debug builds we guard against improper thread handling
SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)