Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Test.h" |
| 9 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 10 | #include "GrClip.h" |
| 11 | #include "GrContextPriv.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 12 | #include "GrMemoryPool.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 13 | #include "GrOnFlushResourceProvider.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 14 | #include "GrProxyProvider.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 15 | #include "GrRenderTargetContext.h" |
| 16 | #include "GrRenderTargetContextPriv.h" |
| 17 | #include "GrSurfaceProxy.h" |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 18 | #include "GrSurfaceProxyPriv.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 19 | #include "GrTexture.h" |
| 20 | #include "GrTextureProxy.h" |
| 21 | #include "GrTextureProxyPriv.h" |
| 22 | #include "SkMakeUnique.h" |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 23 | #include "SkRectPriv.h" |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 24 | #include "mock/GrMockGpu.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 25 | #include "mock/GrMockTypes.h" |
| 26 | |
| 27 | // This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks, |
| 28 | // but before Ops are executed. It also ensures that lazy proxy callbacks are invoked both for |
| 29 | // regular Ops and for clips. |
| 30 | class LazyProxyTest final : public GrOnFlushCallbackObject { |
| 31 | public: |
| 32 | LazyProxyTest(skiatest::Reporter* reporter) |
| 33 | : fReporter(reporter) |
| 34 | , fHasOpTexture(false) |
| 35 | , fHasClipTexture(false) { |
| 36 | } |
| 37 | |
| 38 | ~LazyProxyTest() override { |
| 39 | REPORTER_ASSERT(fReporter, fHasOpTexture); |
| 40 | REPORTER_ASSERT(fReporter, fHasClipTexture); |
| 41 | } |
| 42 | |
| 43 | void preFlush(GrOnFlushResourceProvider*, const uint32_t*, int, |
| 44 | SkTArray<sk_sp<GrRenderTargetContext>>*) override { |
| 45 | REPORTER_ASSERT(fReporter, !fHasOpTexture); |
| 46 | REPORTER_ASSERT(fReporter, !fHasClipTexture); |
| 47 | } |
| 48 | |
| 49 | void postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, int numOpListIDs) override { |
| 50 | REPORTER_ASSERT(fReporter, fHasOpTexture); |
| 51 | REPORTER_ASSERT(fReporter, fHasClipTexture); |
| 52 | } |
| 53 | |
| 54 | class Op final : public GrDrawOp { |
| 55 | public: |
| 56 | DEFINE_OP_CLASS_ID |
| 57 | |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 58 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 59 | GrProxyProvider* proxyProvider, |
| 60 | LazyProxyTest* test, |
| 61 | bool nullTexture) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 62 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 63 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 64 | return pool->allocate<Op>(context, proxyProvider, test, nullTexture); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 67 | void visitProxies(const VisitProxyFunc& func, VisitorType) const override { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 68 | func(fProxy.get()); |
| 69 | } |
| 70 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 71 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 72 | REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture); |
| 73 | REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture); |
| 74 | } |
| 75 | |
| 76 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 77 | friend class GrOpMemoryPool; // for ctor |
| 78 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 79 | Op(GrContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test, bool nullTexture) |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 80 | : GrDrawOp(ClassID()), fTest(test) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 81 | const GrBackendFormat format = |
| 82 | ctx->contextPriv().caps()->getBackendFormatFromColorType(kRGB_565_SkColorType); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 83 | fProxy = GrProxyProvider::MakeFullyLazyProxy( |
| 84 | [this, nullTexture](GrResourceProvider* rp) { |
| 85 | if (!rp) { |
| 86 | return sk_sp<GrTexture>(); |
| 87 | } |
| 88 | REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture); |
| 89 | fTest->fHasOpTexture = true; |
| 90 | if (nullTexture) { |
| 91 | return sk_sp<GrTexture>(); |
| 92 | } else { |
| 93 | GrSurfaceDesc desc; |
| 94 | desc.fWidth = 1234; |
| 95 | desc.fHeight = 567; |
| 96 | desc.fConfig = kRGB_565_GrPixelConfig; |
| 97 | sk_sp<GrTexture> texture = rp->createTexture(desc, SkBudgeted::kYes); |
| 98 | REPORTER_ASSERT(fTest->fReporter, texture); |
| 99 | return texture; |
| 100 | } |
| 101 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 102 | format, GrProxyProvider::Renderable::kNo, kTopLeft_GrSurfaceOrigin, |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 103 | kRGB_565_GrPixelConfig, *proxyProvider->caps()); |
| 104 | |
| 105 | this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo, |
| 106 | GrOp::IsZeroArea::kNo); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 109 | const char* name() const override { return "LazyProxyTest::Op"; } |
| 110 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 111 | RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 112 | return RequiresDstTexture::kNo; |
| 113 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 114 | void onPrepare(GrOpFlushState*) override {} |
| 115 | |
| 116 | LazyProxyTest* const fTest; |
| 117 | sk_sp<GrTextureProxy> fProxy; |
| 118 | }; |
| 119 | |
| 120 | class ClipFP : public GrFragmentProcessor { |
| 121 | public: |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 122 | ClipFP(GrContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test, |
| 123 | GrTextureProxy* atlas) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 124 | : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 125 | , fContext(ctx) |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 126 | , fProxyProvider(proxyProvider) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 127 | , fTest(test) |
| 128 | , fAtlas(atlas) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 129 | const GrBackendFormat format = |
| 130 | ctx->contextPriv().caps()->getBackendFormatFromGrColorType(GrColorType::kAlpha_F16, |
| 131 | GrSRGBEncoded::kNo); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 132 | fLazyProxy = GrProxyProvider::MakeFullyLazyProxy( |
Robert Phillips | ce5209a | 2018-02-13 11:13:51 -0500 | [diff] [blame] | 133 | [this](GrResourceProvider* rp) { |
| 134 | if (!rp) { |
| 135 | return sk_sp<GrTexture>(); |
| 136 | } |
| 137 | REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture); |
| 138 | fTest->fHasClipTexture = true; |
| 139 | fAtlas->instantiate(rp); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 140 | return sk_ref_sp(fAtlas->peekTexture()); |
Robert Phillips | ce5209a | 2018-02-13 11:13:51 -0500 | [diff] [blame] | 141 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 142 | format, |
Robert Phillips | ce5209a | 2018-02-13 11:13:51 -0500 | [diff] [blame] | 143 | GrProxyProvider::Renderable::kYes, |
| 144 | kBottomLeft_GrSurfaceOrigin, |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 145 | kAlpha_half_GrPixelConfig, *proxyProvider->caps()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 146 | fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 147 | GrSamplerState::WrapMode::kClamp); |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 148 | this->setTextureSamplerCnt(1); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | private: |
| 152 | const char* name() const override { return "LazyProxyTest::ClipFP"; } |
| 153 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 154 | return skstd::make_unique<ClipFP>(fContext, fProxyProvider, fTest, fAtlas); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 155 | } |
| 156 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; } |
| 157 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
| 158 | bool onIsEqual(const GrFragmentProcessor&) const override { return false; } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 159 | const TextureSampler& onTextureSampler(int) const override { return fAccess; } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 160 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 161 | GrContext* const fContext; |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 162 | GrProxyProvider* const fProxyProvider; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 163 | LazyProxyTest* const fTest; |
| 164 | GrTextureProxy* const fAtlas; |
| 165 | sk_sp<GrTextureProxy> fLazyProxy; |
| 166 | TextureSampler fAccess; |
| 167 | }; |
| 168 | |
| 169 | |
| 170 | class Clip : public GrClip { |
| 171 | public: |
| 172 | Clip(LazyProxyTest* test, GrTextureProxy* atlas) |
| 173 | : fTest(test) |
| 174 | , fAtlas(atlas) {} |
| 175 | |
| 176 | private: |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 177 | bool apply(GrContext* context, GrRenderTargetContext*, bool, bool, GrAppliedClip* out, |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 178 | SkRect* bounds) const override { |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 179 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 180 | out->addCoverageFP(skstd::make_unique<ClipFP>(context, proxyProvider, fTest, fAtlas)); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 181 | return true; |
| 182 | } |
| 183 | bool quickContains(const SkRect&) const final { return false; } |
| 184 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; } |
| 185 | void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final { |
| 186 | rect->set(0, 0, width, height); |
| 187 | if (iior) { |
| 188 | *iior = false; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | LazyProxyTest* const fTest; |
| 193 | GrTextureProxy* fAtlas; |
| 194 | }; |
| 195 | |
| 196 | private: |
| 197 | skiatest::Reporter* fReporter; |
| 198 | bool fHasOpTexture; |
| 199 | bool fHasClipTexture; |
| 200 | }; |
| 201 | |
| 202 | DEF_GPUTEST(LazyProxyTest, reporter, /* options */) { |
| 203 | GrMockOptions mockOptions; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 204 | mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderability = |
| 205 | GrMockOptions::ConfigOptions::Renderability::kNonMSAA; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 206 | mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true; |
| 207 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 208 | GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 209 | for (bool nullTexture : {false, true}) { |
| 210 | LazyProxyTest test(reporter); |
| 211 | ctx->contextPriv().addOnFlushCallbackObject(&test); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 212 | GrBackendFormat format = |
| 213 | ctx->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 214 | sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 215 | format, SkBackingFit::kExact, 100, 100, |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 216 | kRGBA_8888_GrPixelConfig, nullptr); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 217 | REPORTER_ASSERT(reporter, rtc); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 218 | format = |
| 219 | ctx->contextPriv().caps()->getBackendFormatFromGrColorType(GrColorType::kAlpha_F16, |
| 220 | GrSRGBEncoded::kNo); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 221 | sk_sp<GrRenderTargetContext> mockAtlas = ctx->contextPriv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 222 | format, SkBackingFit::kExact, 10, 10, |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 223 | kAlpha_half_GrPixelConfig, nullptr); |
| 224 | REPORTER_ASSERT(reporter, mockAtlas); |
| 225 | rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()), |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 226 | LazyProxyTest::Op::Make(ctx.get(), proxyProvider, &test, nullTexture)); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 227 | ctx->contextPriv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test); |
| 228 | } |
| 229 | } |
| 230 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 231 | static const int kSize = 16; |
| 232 | |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 233 | DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { |
| 234 | GrMockOptions mockOptions; |
| 235 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 236 | auto proxyProvider = ctx->contextPriv().proxyProvider(); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 237 | |
| 238 | GrSurfaceDesc desc; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 239 | desc.fWidth = kSize; |
| 240 | desc.fHeight = kSize; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 241 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 242 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 243 | GrBackendFormat format = |
| 244 | ctx->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
| 245 | |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 246 | using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 247 | for (bool doInstantiate : {true, false}) { |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 248 | for (auto lazyType : {LazyInstantiationType::kSingleUse, |
Greg Daniel | a8d9211 | 2018-03-09 12:05:04 -0500 | [diff] [blame] | 249 | LazyInstantiationType::kMultipleUse, |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 250 | LazyInstantiationType::kDeinstantiate}) { |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 251 | int testCount = 0; |
| 252 | int* testCountPtr = &testCount; |
| 253 | sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy( |
Robert Phillips | ce5209a | 2018-02-13 11:13:51 -0500 | [diff] [blame] | 254 | [testCountPtr](GrResourceProvider* resourceProvider) { |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 255 | if (!resourceProvider) { |
| 256 | *testCountPtr = -1; |
| 257 | return sk_sp<GrTexture>(); |
| 258 | } |
| 259 | *testCountPtr = 1; |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 260 | return sk_sp<GrTexture>(); |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 261 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 262 | format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 263 | GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, lazyType); |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 264 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 265 | REPORTER_ASSERT(reporter, proxy.get()); |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 266 | REPORTER_ASSERT(reporter, 0 == testCount); |
| 267 | |
| 268 | if (doInstantiate) { |
| 269 | proxy->priv().doLazyInstantiation(ctx->contextPriv().resourceProvider()); |
| 270 | if (LazyInstantiationType::kSingleUse == proxy->priv().lazyInstantiationType()) { |
| 271 | // In SingleUse we will call the cleanup and delete the callback in the |
| 272 | // doLazyInstantiationCall. |
| 273 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 274 | } else { |
| 275 | REPORTER_ASSERT(reporter, 1 == testCount); |
| 276 | } |
| 277 | proxy.reset(); |
| 278 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 279 | } else { |
| 280 | proxy.reset(); |
| 281 | REPORTER_ASSERT(reporter, -1 == testCount); |
| 282 | } |
Greg Daniel | 94a6ce8 | 2018-01-16 16:14:41 -0500 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 287 | class LazyFailedInstantiationTestOp : public GrDrawOp { |
| 288 | public: |
| 289 | DEFINE_OP_CLASS_ID |
| 290 | |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 291 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 292 | GrProxyProvider* proxyProvider, |
| 293 | int* testExecuteValue, |
| 294 | bool shouldFailInstantiation) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 295 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 296 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 297 | return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 298 | testExecuteValue, |
| 299 | shouldFailInstantiation); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 302 | void visitProxies(const VisitProxyFunc& func, VisitorType) const override { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 303 | func(fLazyProxy.get()); |
| 304 | } |
| 305 | |
| 306 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 307 | friend class GrOpMemoryPool; // for ctor |
| 308 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 309 | LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider, |
| 310 | int* testExecuteValue, bool shouldFailInstantiation) |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 311 | : INHERITED(ClassID()) |
| 312 | , fTestExecuteValue(testExecuteValue) { |
| 313 | GrSurfaceDesc desc; |
| 314 | desc.fWidth = kSize; |
| 315 | desc.fHeight = kSize; |
| 316 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 317 | GrBackendFormat format = |
| 318 | ctx->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 319 | |
| 320 | fLazyProxy = proxyProvider->createLazyProxy( |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 321 | [testExecuteValue, shouldFailInstantiation, desc](GrResourceProvider* rp) { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 322 | if (!rp) { |
| 323 | return sk_sp<GrTexture>(); |
| 324 | } |
| 325 | if (shouldFailInstantiation) { |
| 326 | *testExecuteValue = 1; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 327 | return sk_sp<GrTexture>(); |
| 328 | } |
| 329 | return rp->createTexture(desc, SkBudgeted::kNo); |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 330 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 331 | format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 332 | SkBackingFit::kExact, SkBudgeted::kNo); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 333 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 334 | SkASSERT(fLazyProxy.get()); |
| 335 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 336 | this->setBounds(SkRect::MakeIWH(kSize, kSize), |
| 337 | HasAABloat::kNo, IsZeroArea::kNo); |
| 338 | } |
| 339 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 340 | const char* name() const override { return "LazyFailedInstantiationTestOp"; } |
| 341 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 342 | RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 343 | return RequiresDstTexture::kNo; |
| 344 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 345 | void onPrepare(GrOpFlushState*) override {} |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 346 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 347 | *fTestExecuteValue = 2; |
| 348 | } |
| 349 | |
| 350 | int* fTestExecuteValue; |
| 351 | sk_sp<GrSurfaceProxy> fLazyProxy; |
| 352 | |
| 353 | typedef GrDrawOp INHERITED; |
| 354 | }; |
| 355 | |
| 356 | // Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was |
| 357 | // associated with. |
| 358 | DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) { |
| 359 | GrMockOptions mockOptions; |
| 360 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 361 | GrResourceProvider* resourceProvider = ctx->contextPriv().resourceProvider(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 362 | GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 363 | GrBackendFormat format = |
| 364 | ctx->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 365 | for (bool failInstantiation : {false, true}) { |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 366 | sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 367 | format, SkBackingFit::kExact, 100, 100, |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 368 | kRGBA_8888_GrPixelConfig, nullptr); |
| 369 | REPORTER_ASSERT(reporter, rtc); |
| 370 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 371 | rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad), |
| 372 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 373 | |
| 374 | int executeTestValue = 0; |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 375 | rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make( |
| 376 | ctx.get(), proxyProvider, &executeTestValue, failInstantiation)); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 377 | ctx->flush(); |
| 378 | |
| 379 | if (failInstantiation) { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 380 | if (resourceProvider->explicitlyAllocateGPUResources()) { |
| 381 | REPORTER_ASSERT(reporter, 1 == executeTestValue); |
| 382 | } else { |
| 383 | // When we disable explicit gpu resource allocation we don't throw away ops that |
| 384 | // have uninstantiated proxies. |
| 385 | REPORTER_ASSERT(reporter, 2 == executeTestValue); |
| 386 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 387 | } else { |
| 388 | REPORTER_ASSERT(reporter, 2 == executeTestValue); |
| 389 | } |
| 390 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 391 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 392 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 393 | class LazyDeinstantiateTestOp : public GrDrawOp { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 394 | public: |
| 395 | DEFINE_OP_CLASS_ID |
| 396 | |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 397 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, sk_sp<GrTextureProxy> proxy) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 398 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 399 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 400 | return pool->allocate<LazyDeinstantiateTestOp>(std::move(proxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 401 | } |
| 402 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 403 | void visitProxies(const VisitProxyFunc& func, VisitorType) const override { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 404 | func(fLazyProxy.get()); |
| 405 | } |
| 406 | |
| 407 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 408 | friend class GrOpMemoryPool; // for ctor |
| 409 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 410 | LazyDeinstantiateTestOp(sk_sp<GrTextureProxy> proxy) |
| 411 | : INHERITED(ClassID()), fLazyProxy(std::move(proxy)) { |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 412 | this->setBounds(SkRect::MakeIWH(kSize, kSize), HasAABloat::kNo, IsZeroArea::kNo); |
| 413 | } |
| 414 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 415 | const char* name() const override { return "LazyDeinstantiateTestOp"; } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 416 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 417 | RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 418 | return RequiresDstTexture::kNo; |
| 419 | } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 420 | void onPrepare(GrOpFlushState*) override {} |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 421 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override {} |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 422 | |
| 423 | sk_sp<GrSurfaceProxy> fLazyProxy; |
| 424 | |
| 425 | typedef GrDrawOp INHERITED; |
| 426 | }; |
| 427 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 428 | static void DeinstantiateReleaseProc(void* releaseValue) { (*static_cast<int*>(releaseValue))++; } |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 429 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 430 | // Test that lazy proxies with the Deinstantiate LazyCallbackType are deinstantiated and released as |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 431 | // expected. |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 432 | DEF_GPUTEST(LazyProxyDeinstantiateTest, reporter, /* options */) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 433 | GrMockOptions mockOptions; |
| 434 | sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); |
| 435 | GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); |
| 436 | GrGpu* gpu = ctx->contextPriv().getGpu(); |
| 437 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 438 | GrBackendFormat format = |
| 439 | ctx->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
| 440 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 441 | using LazyType = GrSurfaceProxy::LazyInstantiationType; |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 442 | for (auto lazyType : {LazyType::kSingleUse, LazyType::kMultipleUse, LazyType::kDeinstantiate}) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 443 | sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 444 | format, SkBackingFit::kExact, 100, 100, |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 445 | kRGBA_8888_GrPixelConfig, nullptr); |
| 446 | REPORTER_ASSERT(reporter, rtc); |
| 447 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 448 | rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad), |
| 449 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 450 | |
| 451 | int instantiateTestValue = 0; |
| 452 | int releaseTestValue = 0; |
| 453 | int* instantiatePtr = &instantiateTestValue; |
| 454 | int* releasePtr = &releaseTestValue; |
| 455 | GrSurfaceDesc desc; |
| 456 | desc.fWidth = kSize; |
| 457 | desc.fHeight = kSize; |
| 458 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 459 | |
| 460 | GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 461 | nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 462 | |
| 463 | sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy( |
| 464 | [instantiatePtr, releasePtr, backendTex](GrResourceProvider* rp) { |
| 465 | if (!rp) { |
| 466 | return sk_sp<GrTexture>(); |
| 467 | } |
| 468 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 469 | sk_sp<GrTexture> texture = rp->wrapBackendTexture( |
| 470 | backendTex, kBorrow_GrWrapOwnership, kRead_GrIOType); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 471 | if (!texture) { |
| 472 | return sk_sp<GrTexture>(); |
| 473 | } |
| 474 | (*instantiatePtr)++; |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 475 | texture->setRelease(DeinstantiateReleaseProc, releasePtr); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 476 | return texture; |
| 477 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 478 | format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 479 | GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, SkBudgeted::kNo, lazyType); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 480 | |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 481 | REPORTER_ASSERT(reporter, lazyProxy.get()); |
| 482 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 483 | rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 484 | |
| 485 | ctx->flush(); |
| 486 | |
| 487 | REPORTER_ASSERT(reporter, 1 == instantiateTestValue); |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 488 | if (LazyType::kDeinstantiate == lazyType) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 489 | REPORTER_ASSERT(reporter, 1 == releaseTestValue); |
| 490 | } else { |
| 491 | REPORTER_ASSERT(reporter, 0 == releaseTestValue); |
| 492 | } |
| 493 | |
| 494 | // This should cause the uninstantiate proxies to be instantiated again but have no effect |
| 495 | // on the others |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 496 | rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 497 | // Add a second op to make sure we only instantiate once. |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 498 | rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 499 | ctx->flush(); |
| 500 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 501 | if (LazyType::kDeinstantiate == lazyType) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 502 | REPORTER_ASSERT(reporter, 2 == instantiateTestValue); |
| 503 | REPORTER_ASSERT(reporter, 2 == releaseTestValue); |
| 504 | } else { |
| 505 | REPORTER_ASSERT(reporter, 1 == instantiateTestValue); |
| 506 | REPORTER_ASSERT(reporter, 0 == releaseTestValue); |
| 507 | } |
| 508 | |
| 509 | lazyProxy.reset(); |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 510 | if (LazyType::kDeinstantiate == lazyType) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 511 | REPORTER_ASSERT(reporter, 2 == releaseTestValue); |
| 512 | } else { |
| 513 | REPORTER_ASSERT(reporter, 1 == releaseTestValue); |
| 514 | } |
| 515 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 516 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 517 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 518 | } |