Add checks that the GrResourceAllocator is operating as expected

With explicit resource allocation there should be no explicit instantiating at flush time. There are, however, still several instances where instantiate is called outside of testing (e.g., readSurfacePixels and writeSurfacePixels).

Change-Id: Ic459a550ca85048f66d6a1eb7d601411f83c6e32
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/204721
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2019-03-29 07:26:46 -04:00 committed by Skia Commit-Bot
parent d04d3ae3b7
commit 7eeb74fdfd
16 changed files with 74 additions and 33 deletions

View File

@ -431,8 +431,14 @@ public:
bool operator!=(const TextureSampler& other) const { return !(*this == other); }
// 'instantiate' should only ever be called at flush time.
// TODO: this can go away once explicit allocation has stuck
bool instantiate(GrResourceProvider* resourceProvider) const {
return SkToBool(fProxyRef.get()->instantiate(resourceProvider));
if (resourceProvider->explicitlyAllocateGPUResources()) {
SkASSERT(fProxyRef.get()->isInstantiated());
return true;
} else {
return SkToBool(fProxyRef.get()->instantiate(resourceProvider));
}
}
// 'peekTexture' should only ever be called after a successful 'instantiate' call

View File

@ -54,8 +54,11 @@ bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPi
return false;
}
if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures;
for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
if (!fixedDynamicState->fPrimitiveProcessorTextures[i]->instantiate(resourceProvider)) {
if (resourceProvider->explicitlyAllocateGPUResources()) {
SkASSERT(processorProxies[i]->isInstantiated());
} else if (!processorProxies[i]->instantiate(resourceProvider)) {
return false;
}
}
@ -64,7 +67,9 @@ bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPi
int n = primProc.numTextureSamplers() * meshCount;
const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures;
for (int i = 0; i < n; ++i) {
if (!textures[i]->instantiate(resourceProvider)) {
if (resourceProvider->explicitlyAllocateGPUResources()) {
SkASSERT(textures[i]->isInstantiated());
} else if (!textures[i]->instantiate(resourceProvider)) {
return false;
}
}

View File

@ -64,6 +64,8 @@ sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey(
}
bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) {
SkASSERT(proxy->priv().requiresNoPendingIO());
// TODO: this class should probably just get a GrDirectContext
auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
if (!direct) {

View File

@ -66,13 +66,6 @@ class GrOnFlushResourceProvider {
public:
explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
#if 0
sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc&,
GrSurfaceOrigin,
sk_sp<SkColorSpace>,
const SkSurfaceProps*);
#endif
sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
sk_sp<SkColorSpace>,
const SkSurfaceProps*);

View File

@ -54,8 +54,14 @@ GrOpList::~GrOpList() {
}
}
// TODO: this can go away when explicit allocation has stuck
bool GrOpList::instantiate(GrResourceProvider* resourceProvider) {
return SkToBool(fTarget.get()->instantiate(resourceProvider));
if (resourceProvider->explicitlyAllocateGPUResources()) {
SkASSERT(fTarget.get()->isInstantiated());
return true;
} else {
return SkToBool(fTarget.get()->instantiate(resourceProvider));
}
}
void GrOpList::endFlush() {

View File

@ -39,7 +39,9 @@ GrPipeline::GrPipeline(const InitArgs& args,
fXferProcessor = processors.refXferProcessor();
if (args.fDstProxy.proxy()) {
if (!args.fDstProxy.proxy()->instantiate(args.fResourceProvider)) {
if (args.fResourceProvider->explicitlyAllocateGPUResources()) {
SkASSERT(args.fDstProxy.proxy()->isInstantiated());
} else if (!args.fDstProxy.proxy()->instantiate(args.fResourceProvider)) {
this->markAsBad();
}

View File

@ -92,10 +92,10 @@ bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
}
sk_sp<GrSurface> GrTextureProxy::createSurface(GrResourceProvider* resourceProvider) const {
sk_sp<GrSurface> surface= this->createSurfaceImpl(resourceProvider, 1,
/* needsStencil = */ false,
kNone_GrSurfaceFlags,
fMipMapped);
sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, 1,
/* needsStencil = */ false,
kNone_GrSurfaceFlags,
fMipMapped);
if (!surface) {
return nullptr;
}

View File

@ -95,10 +95,6 @@ public:
}
}
bool instantiate(GrResourceProvider* resourceProvider) {
return SkToBool(fProxy->instantiate(resourceProvider));
}
private:
sk_sp<GrTextureProxy> fProxy;
SkIPoint fOffset;

View File

@ -87,7 +87,9 @@ std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrRecordingContext* context,
}
void GrCopySurfaceOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
if (!fSrc.get()->instantiate(state->resourceProvider())) {
if (state->resourceProvider()->explicitlyAllocateGPUResources()) {
SkASSERT(fSrc.get()->isInstantiated());
} else if (!fSrc.get()->instantiate(state->resourceProvider())) {
return;
}

View File

@ -437,7 +437,9 @@ private:
for (unsigned p = 0; p < op.fProxyCnt; ++p) {
numTotalQuads += op.fProxies[p].fQuadCnt;
auto* proxy = op.fProxies[p].fProxy;
if (!proxy->instantiate(target->resourceProvider())) {
if (target->resourceProvider()->explicitlyAllocateGPUResources()) {
SkASSERT(proxy->isInstantiated());
} else if (!proxy->instantiate(target->resourceProvider())) {
return;
}
SkASSERT(proxy->config() == config);

View File

@ -203,7 +203,8 @@ static sk_sp<GrTextureProxy> create_proxy(GrProxyProvider* proxyProvider) {
SkBitmap srcBM = create_bm();
sk_sp<SkImage> srcImage(SkImage::MakeFromBitmap(srcBM));
return proxyProvider->createTextureProxy(srcImage, kNone_GrSurfaceFlags, 1,
SkBudgeted::kYes, SkBackingFit::kExact);
SkBudgeted::kYes, SkBackingFit::kExact,
GrInternalSurfaceFlags::kNoPendingIO);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) {

View File

@ -173,7 +173,7 @@ DEF_GPUTEST(OpChainTest, reporter, /*ctxInfo*/) {
auto proxy = context->priv().proxyProvider()->createProxy(
format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact,
SkBudgeted::kNo, GrInternalSurfaceFlags::kNone);
SkBudgeted::kNo, GrInternalSurfaceFlags::kNoPendingIO);
SkASSERT(proxy);
proxy->instantiate(context->priv().resourceProvider());
int result[result_width()];

View File

@ -286,7 +286,9 @@ void render_fp(GrContext* context, GrRenderTargetContext* rtc, GrFragmentProcess
}
/** Initializes the two test texture proxies that are available to the FP test factories. */
bool init_test_textures(GrProxyProvider* proxyProvider, SkRandom* random,
bool init_test_textures(GrResourceProvider* resourceProvider,
GrProxyProvider* proxyProvider,
SkRandom* random,
sk_sp<GrTextureProxy> proxies[2]) {
static const int kTestTextureSize = 256;
@ -305,7 +307,12 @@ bool init_test_textures(GrProxyProvider* proxyProvider, SkRandom* random,
SkPixmap pixmap(ii, rgbaData.get(), ii.minRowBytes());
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap);
proxies[0] = proxyProvider->createTextureProxy(img, kNone_GrSurfaceFlags, 1,
SkBudgeted::kYes, SkBackingFit::kExact);
SkBudgeted::kYes, SkBackingFit::kExact,
GrInternalSurfaceFlags::kNoPendingIO);
if (resourceProvider->explicitlyAllocateGPUResources()) {
proxies[0]->instantiate(resourceProvider);
}
}
{
@ -322,7 +329,12 @@ bool init_test_textures(GrProxyProvider* proxyProvider, SkRandom* random,
SkPixmap pixmap(ii, alphaData.get(), ii.minRowBytes());
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap);
proxies[1] = proxyProvider->createTextureProxy(img, kNone_GrSurfaceFlags, 1,
SkBudgeted::kYes, SkBackingFit::kExact);
SkBudgeted::kYes, SkBackingFit::kExact,
GrInternalSurfaceFlags::kNoPendingIO);
if (resourceProvider->explicitlyAllocateGPUResources()) {
proxies[1]->instantiate(resourceProvider);
}
}
return proxies[0] && proxies[1];
@ -433,6 +445,10 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
auto resourceProvider = context->priv().resourceProvider();
using FPFactory = GrFragmentProcessorTestFactory;
// This test side-steps the GrResourceAllocator thus violates some assumptions and
// asserts
bool orig = resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(false);
uint32_t seed = FLAGS_processorSeed;
if (FLAGS_randomProcessorTest) {
std::random_device rd;
@ -452,7 +468,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
nullptr);
sk_sp<GrTextureProxy> proxies[2];
if (!init_test_textures(proxyProvider, &random, proxies)) {
if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies)) {
ERRORF(reporter, "Could not create test textures");
return;
}
@ -672,6 +688,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
}
}
}
resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(orig);
}
// Tests that fragment processors returned by GrFragmentProcessor::clone() are equivalent to their
@ -681,6 +699,10 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
auto resourceProvider = context->priv().resourceProvider();
// This test side-steps the GrResourceAllocator thus violates some assumptions and
// asserts
bool orig = resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(false);
SkRandom random;
const GrBackendFormat format =
@ -693,7 +715,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) {
nullptr);
sk_sp<GrTextureProxy> proxies[2];
if (!init_test_textures(proxyProvider, &random, proxies)) {
if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies)) {
ERRORF(reporter, "Could not create test textures");
return;
}
@ -751,6 +773,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) {
}
}
}
resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(orig);
}
#endif // GR_TEST_UTILS

View File

@ -141,7 +141,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
sk_sp<GrTexture> tex;
if (SkBackingFit::kApprox == fit) {
tex = resourceProvider->createApproxTexture(
desc, GrResourceProvider::Flags::kNone);
desc, GrResourceProvider::Flags::kNoPendingIO);
} else {
tex = resourceProvider->createTexture(desc, budgeted);
}

View File

@ -46,7 +46,7 @@ static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter, GrContex
sk_sp<GrTextureProxy> proxy =
proxyProvider->createProxy(format, desc, kBottomLeft_GrSurfaceOrigin, fit,
SkBudgeted::kYes);
SkBudgeted::kYes, GrInternalSurfaceFlags::kNoPendingIO);
// Only budgeted & wrapped external proxies get to carry uniqueKeys
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
return proxy;
@ -59,7 +59,8 @@ static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter, GrCont
ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
sk_sp<GrTextureProxy> proxy =
proxyProvider->createProxy(format, desc, kBottomLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes);
proxyProvider->createProxy(format, desc, kBottomLeft_GrSurfaceOrigin, fit,
SkBudgeted::kYes, GrInternalSurfaceFlags::kNoPendingIO);
// Only budgeted & wrapped external proxies get to carry uniqueKeys
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
return proxy;

View File

@ -533,7 +533,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixelsPendingIO, reporter, ctxInfo) {
context->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
sk_sp<GrTextureProxy> temp = proxyProvider->createProxy(
format, desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
format, desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes,
GrInternalSurfaceFlags::kNoPendingIO);
temp->instantiate(context->priv().resourceProvider());
}