Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTypes.h" |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrTexture.h" |
| 13 | #include "include/private/GrTextureProxy.h" |
| 14 | #include "src/gpu/GrContextPriv.h" |
| 15 | #include "src/gpu/GrDeinstantiateProxyTracker.h" |
| 16 | #include "src/gpu/GrGpu.h" |
| 17 | #include "src/gpu/GrProxyProvider.h" |
| 18 | #include "src/gpu/GrResourceAllocator.h" |
| 19 | #include "src/gpu/GrResourceProvider.h" |
| 20 | #include "src/gpu/GrSurfaceProxyPriv.h" |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 21 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "include/core/SkSurface.h" |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 23 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 24 | struct ProxyParams { |
| 25 | int fSize; |
| 26 | bool fIsRT; |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 27 | SkColorType fColorType; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 28 | SkBackingFit fFit; |
| 29 | int fSampleCnt; |
| 30 | GrSurfaceOrigin fOrigin; |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 31 | SkBudgeted fBudgeted; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 32 | // TODO: do we care about mipmapping |
| 33 | }; |
| 34 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 35 | static GrSurfaceProxy* make_deferred(GrProxyProvider* proxyProvider, const GrCaps* caps, |
| 36 | const ProxyParams& p) { |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 37 | GrColorType grCT = SkColorTypeToGrColorType(p.fColorType); |
| 38 | GrPixelConfig config = GrColorTypeToPixelConfig(grCT, GrSRGBEncoded::kNo); |
| 39 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 40 | GrSurfaceDesc desc; |
| 41 | desc.fFlags = p.fIsRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 42 | desc.fWidth = p.fSize; |
| 43 | desc.fHeight = p.fSize; |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 44 | desc.fConfig = config; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 45 | desc.fSampleCnt = p.fSampleCnt; |
| 46 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 47 | const GrBackendFormat format = caps->getBackendFormatFromColorType(p.fColorType); |
| 48 | |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 49 | auto tmp = proxyProvider->createProxy(format, desc, p.fOrigin, p.fFit, p.fBudgeted); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 50 | if (!tmp) { |
| 51 | return nullptr; |
| 52 | } |
| 53 | GrSurfaceProxy* ret = tmp.release(); |
| 54 | |
| 55 | // Add a read to keep the proxy around but unref it so its backing surfaces can be recycled |
| 56 | ret->addPendingRead(); |
| 57 | ret->unref(); |
| 58 | return ret; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 61 | static GrSurfaceProxy* make_backend(GrContext* context, const ProxyParams& p, |
| 62 | GrBackendTexture* backendTex) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 63 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 64 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 65 | *backendTex = context->createBackendTexture(p.fSize, p.fSize, p.fColorType, |
| 66 | SkColors::kTransparent, |
| 67 | GrMipMapped::kNo, GrRenderable::kNo); |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 68 | if (!backendTex->isValid()) { |
| 69 | return nullptr; |
| 70 | } |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 71 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 72 | auto tmp = proxyProvider->wrapBackendTexture(*backendTex, p.fOrigin, kBorrow_GrWrapOwnership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 73 | GrWrapCacheable::kNo, kRead_GrIOType); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 74 | if (!tmp) { |
| 75 | return nullptr; |
| 76 | } |
| 77 | GrSurfaceProxy* ret = tmp.release(); |
| 78 | |
| 79 | // Add a read to keep the proxy around but unref it so its backing surfaces can be recycled |
| 80 | ret->addPendingRead(); |
| 81 | ret->unref(); |
| 82 | return ret; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 83 | } |
| 84 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 85 | static void cleanup_backend(GrContext* context, const GrBackendTexture& backendTex) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 86 | context->deleteBackendTexture(backendTex); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 89 | // Basic test that two proxies with overlapping intervals and compatible descriptors are |
| 90 | // assigned different GrSurfaces. |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 91 | static void overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider, |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 92 | GrResourceCache* resourceCache, GrSurfaceProxy* p1, GrSurfaceProxy* p2, |
| 93 | bool expectedResult) { |
| 94 | GrDeinstantiateProxyTracker deinstantiateTracker(resourceCache); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 95 | GrResourceAllocator alloc(resourceProvider, &deinstantiateTracker SkDEBUGCODE(, 1)); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 96 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 97 | alloc.addInterval(p1, 0, 4, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 98 | alloc.incOps(); |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 99 | alloc.addInterval(p2, 1, 2, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 100 | alloc.incOps(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 101 | alloc.markEndOfOpList(0); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 102 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 103 | alloc.determineRecyclability(); |
| 104 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 105 | int startIndex, stopIndex; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 106 | GrResourceAllocator::AssignError error; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 107 | alloc.assign(&startIndex, &stopIndex, &error); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 108 | REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 109 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 110 | REPORTER_ASSERT(reporter, p1->peekSurface()); |
| 111 | REPORTER_ASSERT(reporter, p2->peekSurface()); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 112 | bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID(); |
| 113 | REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 114 | } |
| 115 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 116 | // Test various cases when two proxies do not have overlapping intervals. |
| 117 | // This mainly acts as a test of the ResourceAllocator's free pool. |
| 118 | static void non_overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider, |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 119 | GrResourceCache* resourceCache, GrSurfaceProxy* p1, GrSurfaceProxy* p2, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 120 | bool expectedResult) { |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 121 | GrDeinstantiateProxyTracker deinstantiateTracker(resourceCache); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 122 | GrResourceAllocator alloc(resourceProvider, &deinstantiateTracker SkDEBUGCODE(, 1)); |
| 123 | |
| 124 | alloc.incOps(); |
| 125 | alloc.incOps(); |
| 126 | alloc.incOps(); |
| 127 | alloc.incOps(); |
| 128 | alloc.incOps(); |
| 129 | alloc.incOps(); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 130 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 131 | alloc.addInterval(p1, 0, 2, GrResourceAllocator::ActualUse::kYes); |
| 132 | alloc.addInterval(p2, 3, 5, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 133 | alloc.markEndOfOpList(0); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 134 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 135 | alloc.determineRecyclability(); |
| 136 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 137 | int startIndex, stopIndex; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 138 | GrResourceAllocator::AssignError error; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 139 | alloc.assign(&startIndex, &stopIndex, &error); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 140 | REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 141 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 142 | REPORTER_ASSERT(reporter, p1->peekSurface()); |
| 143 | REPORTER_ASSERT(reporter, p2->peekSurface()); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 144 | bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID(); |
| 145 | REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch); |
| 146 | } |
| 147 | |
| 148 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 149 | const GrCaps* caps = ctxInfo.grContext()->priv().caps(); |
| 150 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider(); |
| 151 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider(); |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 152 | GrResourceCache* resourceCache = ctxInfo.grContext()->priv().getResourceCache(); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 153 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 154 | struct TestCase { |
| 155 | ProxyParams fP1; |
| 156 | ProxyParams fP2; |
| 157 | bool fExpectation; |
| 158 | }; |
| 159 | |
| 160 | constexpr bool kRT = true; |
| 161 | constexpr bool kNotRT = false; |
| 162 | |
| 163 | constexpr bool kShare = true; |
| 164 | constexpr bool kDontShare = false; |
| 165 | // Non-RT GrSurfaces are never recycled on some platforms. |
| 166 | bool kConditionallyShare = resourceProvider->caps()->reuseScratchTextures(); |
| 167 | |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 168 | const SkColorType kRGBA = kRGBA_8888_SkColorType; |
| 169 | const SkColorType kBGRA = kBGRA_8888_SkColorType; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 170 | |
| 171 | const SkBackingFit kE = SkBackingFit::kExact; |
| 172 | const SkBackingFit kA = SkBackingFit::kApprox; |
| 173 | |
| 174 | const GrSurfaceOrigin kTL = kTopLeft_GrSurfaceOrigin; |
| 175 | const GrSurfaceOrigin kBL = kBottomLeft_GrSurfaceOrigin; |
| 176 | |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 177 | const SkBudgeted kNotB = SkBudgeted::kNo; |
| 178 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 179 | //-------------------------------------------------------------------------------------------- |
| 180 | TestCase gOverlappingTests[] = { |
| 181 | //---------------------------------------------------------------------------------------- |
| 182 | // Two proxies with overlapping intervals and compatible descriptors should never share |
| 183 | // RT version |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 184 | { { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, kDontShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 185 | // non-RT version |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 186 | { { 64, kNotRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kNotRT, kRGBA, kA, 0, kTL, kNotB }, kDontShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | for (auto test : gOverlappingTests) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 190 | GrSurfaceProxy* p1 = make_deferred(proxyProvider, caps, test.fP1); |
| 191 | GrSurfaceProxy* p2 = make_deferred(proxyProvider, caps, test.fP2); |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 192 | overlap_test(reporter, resourceProvider, resourceCache, p1, p2, test.fExpectation); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 193 | p1->completedRead(); |
| 194 | p2->completedRead(); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 197 | int k2 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 198 | 2, kRGBA_8888_GrPixelConfig); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 199 | int k4 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 200 | 4, kRGBA_8888_GrPixelConfig); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 201 | |
| 202 | //-------------------------------------------------------------------------------------------- |
| 203 | TestCase gNonOverlappingTests[] = { |
| 204 | //---------------------------------------------------------------------------------------- |
| 205 | // Two non-overlapping intervals w/ compatible proxies should share |
| 206 | // both same size & approx |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 207 | { { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, kShare }, |
| 208 | { { 64, kNotRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kNotRT, kRGBA, kA, 0, kTL, kNotB }, kConditionallyShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 209 | // diffs sizes but still approx |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 210 | { { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, { 50, kRT, kRGBA, kA, 0, kTL, kNotB }, kShare }, |
| 211 | { { 64, kNotRT, kRGBA, kA, 0, kTL, kNotB }, { 50, kNotRT, kRGBA, kA, 0, kTL, kNotB }, kConditionallyShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 212 | // sames sizes but exact |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 213 | { { 64, kRT, kRGBA, kE, 0, kTL, kNotB }, { 64, kRT, kRGBA, kE, 0, kTL, kNotB }, kShare }, |
| 214 | { { 64, kNotRT, kRGBA, kE, 0, kTL, kNotB }, { 64, kNotRT, kRGBA, kE, 0, kTL, kNotB }, kConditionallyShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 215 | //---------------------------------------------------------------------------------------- |
| 216 | // Two non-overlapping intervals w/ different exact sizes should not share |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 217 | { { 56, kRT, kRGBA, kE, 0, kTL, kNotB }, { 54, kRT, kRGBA, kE, 0, kTL, kNotB }, kDontShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 218 | // Two non-overlapping intervals w/ _very different_ approx sizes should not share |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 219 | { { 255, kRT, kRGBA, kA, 0, kTL, kNotB }, { 127, kRT, kRGBA, kA, 0, kTL, kNotB }, kDontShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 220 | // Two non-overlapping intervals w/ different MSAA sample counts should not share |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 221 | { { 64, kRT, kRGBA, kA, k2, kTL, kNotB },{ 64, kRT, kRGBA, kA, k4,kTL, kNotB}, k2 == k4 }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 222 | // Two non-overlapping intervals w/ different configs should not share |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 223 | { { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kRT, kBGRA, kA, 0, kTL, kNotB }, kDontShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 224 | // Two non-overlapping intervals w/ different RT classifications should never share |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 225 | { { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kNotRT, kRGBA, kA, 0, kTL, kNotB }, kDontShare }, |
| 226 | { { 64, kNotRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, kDontShare }, |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 227 | // Two non-overlapping intervals w/ different origins should share |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 228 | { { 64, kRT, kRGBA, kA, 0, kTL, kNotB }, { 64, kRT, kRGBA, kA, 0, kBL, kNotB }, kShare }, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | for (auto test : gNonOverlappingTests) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 232 | GrSurfaceProxy* p1 = make_deferred(proxyProvider, caps, test.fP1); |
| 233 | GrSurfaceProxy* p2 = make_deferred(proxyProvider, caps, test.fP2); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 234 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 235 | if (!p1 || !p2) { |
| 236 | continue; // creation can fail (i.e., for msaa4 on iOS) |
| 237 | } |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 238 | |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 239 | non_overlap_test(reporter, resourceProvider, resourceCache, p1, p2, test.fExpectation); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 240 | |
| 241 | p1->completedRead(); |
| 242 | p2->completedRead(); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | { |
| 246 | // Wrapped backend textures should never be reused |
| 247 | TestCase t[1] = { |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 248 | { { 64, kNotRT, kRGBA, kE, 0, kTL, kNotB }, { 64, kNotRT, kRGBA, kE, 0, kTL, kNotB }, kDontShare } |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 249 | }; |
| 250 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 251 | GrBackendTexture backEndTex; |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 252 | GrSurfaceProxy* p1 = make_backend(ctxInfo.grContext(), t[0].fP1, &backEndTex); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 253 | GrSurfaceProxy* p2 = make_deferred(proxyProvider, caps, t[0].fP2); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 254 | |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 255 | non_overlap_test(reporter, resourceProvider, resourceCache, p1, p2, t[0].fExpectation); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 256 | |
| 257 | p1->completedRead(); |
| 258 | p2->completedRead(); |
| 259 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 260 | cleanup_backend(ctxInfo.grContext(), backEndTex); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 261 | } |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 262 | } |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 263 | |
| 264 | static void draw(GrContext* context) { |
| 265 | SkImageInfo ii = SkImageInfo::Make(1024, 1024, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 266 | |
| 267 | sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, |
| 268 | ii, 1, kTopLeft_GrSurfaceOrigin, nullptr); |
| 269 | |
| 270 | SkCanvas* c = s->getCanvas(); |
| 271 | |
| 272 | c->clear(SK_ColorBLACK); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorStressTest, reporter, ctxInfo) { |
| 277 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 278 | |
| 279 | int maxNum; |
| 280 | size_t maxBytes; |
| 281 | context->getResourceCacheLimits(&maxNum, &maxBytes); |
| 282 | |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 283 | context->setResourceCacheLimits(0, 0); // We'll always be overbudget |
| 284 | |
| 285 | draw(context); |
| 286 | draw(context); |
| 287 | draw(context); |
| 288 | draw(context); |
| 289 | context->flush(); |
| 290 | |
| 291 | context->setResourceCacheLimits(maxNum, maxBytes); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 292 | } |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 293 | |
| 294 | sk_sp<GrSurfaceProxy> make_lazy(GrProxyProvider* proxyProvider, const GrCaps* caps, |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 295 | const ProxyParams& p, bool deinstantiate) { |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 296 | GrColorType grCT = SkColorTypeToGrColorType(p.fColorType); |
| 297 | GrPixelConfig config = GrColorTypeToPixelConfig(grCT, GrSRGBEncoded::kNo); |
| 298 | |
| 299 | GrSurfaceDesc desc; |
| 300 | desc.fFlags = p.fIsRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; |
| 301 | desc.fWidth = p.fSize; |
| 302 | desc.fHeight = p.fSize; |
| 303 | desc.fConfig = config; |
| 304 | desc.fSampleCnt = p.fSampleCnt; |
| 305 | |
| 306 | SkBackingFit fit = p.fFit; |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 307 | auto callback = [fit, desc](GrResourceProvider* resourceProvider) { |
| 308 | sk_sp<GrTexture> texture; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 309 | if (fit == SkBackingFit::kApprox) { |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 310 | texture = resourceProvider->createApproxTexture( |
| 311 | desc, GrResourceProvider::Flags::kNoPendingIO); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 312 | } else { |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 313 | texture = resourceProvider->createTexture(desc, SkBudgeted::kNo, |
| 314 | GrResourceProvider::Flags::kNoPendingIO); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 315 | } |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 316 | return GrSurfaceProxy::LazyInstantiationResult(std::move(texture)); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 317 | }; |
| 318 | const GrBackendFormat format = caps->getBackendFormatFromColorType(p.fColorType); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 319 | auto lazyType = deinstantiate ? GrSurfaceProxy::LazyInstantiationType ::kDeinstantiate |
| 320 | : GrSurfaceProxy::LazyInstantiationType ::kSingleUse; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 321 | GrInternalSurfaceFlags flags = GrInternalSurfaceFlags::kNone; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 322 | return proxyProvider->createLazyProxy(callback, format, desc, p.fOrigin, GrMipMapped::kNo, |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 323 | flags, p.fFit, p.fBudgeted, lazyType); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(LazyDeinstantiation, reporter, ctxInfo) { |
| 327 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 328 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider(); |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 329 | GrResourceCache* resourceCache = ctxInfo.grContext()->priv().getResourceCache(); |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 330 | ProxyParams texParams; |
| 331 | texParams.fFit = SkBackingFit::kExact; |
| 332 | texParams.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 333 | texParams.fColorType = kRGBA_8888_SkColorType; |
| 334 | texParams.fIsRT = false; |
| 335 | texParams.fSampleCnt = 1; |
| 336 | texParams.fSize = 100; |
| 337 | texParams.fBudgeted = SkBudgeted::kNo; |
| 338 | ProxyParams rtParams = texParams; |
| 339 | rtParams.fIsRT = true; |
| 340 | auto proxyProvider = context->priv().proxyProvider(); |
| 341 | auto caps = context->priv().caps(); |
| 342 | auto p0 = make_lazy(proxyProvider, caps, texParams, true); |
| 343 | auto p1 = make_lazy(proxyProvider, caps, texParams, false); |
| 344 | texParams.fFit = rtParams.fFit = SkBackingFit::kApprox; |
| 345 | auto p2 = make_lazy(proxyProvider, caps, rtParams, true); |
| 346 | auto p3 = make_lazy(proxyProvider, caps, rtParams, false); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 347 | |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 348 | GrDeinstantiateProxyTracker deinstantiateTracker(resourceCache); |
| 349 | { |
| 350 | GrResourceAllocator alloc(resourceProvider, &deinstantiateTracker SkDEBUGCODE(, 1)); |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 351 | alloc.addInterval(p0.get(), 0, 1, GrResourceAllocator::ActualUse::kNo); |
| 352 | alloc.addInterval(p1.get(), 0, 1, GrResourceAllocator::ActualUse::kNo); |
| 353 | alloc.addInterval(p2.get(), 0, 1, GrResourceAllocator::ActualUse::kNo); |
| 354 | alloc.addInterval(p3.get(), 0, 1, GrResourceAllocator::ActualUse::kNo); |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 355 | alloc.incOps(); |
| 356 | alloc.markEndOfOpList(0); |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 357 | |
| 358 | alloc.determineRecyclability(); |
| 359 | |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 360 | int startIndex, stopIndex; |
| 361 | GrResourceAllocator::AssignError error; |
| 362 | alloc.assign(&startIndex, &stopIndex, &error); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 363 | } |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 364 | deinstantiateTracker.deinstantiateAllProxies(); |
| 365 | REPORTER_ASSERT(reporter, !p0->isInstantiated()); |
| 366 | REPORTER_ASSERT(reporter, p1->isInstantiated()); |
| 367 | REPORTER_ASSERT(reporter, !p2->isInstantiated()); |
| 368 | REPORTER_ASSERT(reporter, p3->isInstantiated()); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 369 | } |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 370 | |
| 371 | // Set up so there are two opLists that need to be flushed but the resource allocator thinks |
| 372 | // it is over budget. The two opLists should be flushed separately and the opList indices |
| 373 | // returned from assign should be correct. |
| 374 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorOverBudgetTest, reporter, ctxInfo) { |
| 375 | GrContext* context = ctxInfo.grContext(); |
| 376 | const GrCaps* caps = context->priv().caps(); |
| 377 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 378 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 379 | GrResourceCache* resourceCache = context->priv().getResourceCache(); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 380 | |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 381 | int origMaxNum; |
| 382 | size_t origMaxBytes; |
| 383 | context->getResourceCacheLimits(&origMaxNum, &origMaxBytes); |
| 384 | |
| 385 | // Force the resource allocator to always believe it is over budget |
| 386 | context->setResourceCacheLimits(0, 0); |
| 387 | |
| 388 | const ProxyParams params = { 64, false, kRGBA_8888_SkColorType, |
| 389 | SkBackingFit::kExact, 0, kTopLeft_GrSurfaceOrigin, |
| 390 | SkBudgeted::kYes }; |
| 391 | |
| 392 | { |
| 393 | GrSurfaceProxy* p1 = make_deferred(proxyProvider, caps, params); |
| 394 | GrSurfaceProxy* p2 = make_deferred(proxyProvider, caps, params); |
| 395 | GrSurfaceProxy* p3 = make_deferred(proxyProvider, caps, params); |
| 396 | GrSurfaceProxy* p4 = make_deferred(proxyProvider, caps, params); |
| 397 | |
Brian Salomon | 2c791fc | 2019-04-02 11:52:03 -0400 | [diff] [blame] | 398 | GrDeinstantiateProxyTracker deinstantiateTracker(resourceCache); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 399 | GrResourceAllocator alloc(resourceProvider, &deinstantiateTracker SkDEBUGCODE(, 2)); |
| 400 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 401 | alloc.addInterval(p1, 0, 0, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 402 | alloc.incOps(); |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 403 | alloc.addInterval(p2, 1, 1, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 404 | alloc.incOps(); |
| 405 | alloc.markEndOfOpList(0); |
| 406 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 407 | alloc.addInterval(p3, 2, 2, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 408 | alloc.incOps(); |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 409 | alloc.addInterval(p4, 3, 3, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 410 | alloc.incOps(); |
| 411 | alloc.markEndOfOpList(1); |
| 412 | |
| 413 | int startIndex, stopIndex; |
| 414 | GrResourceAllocator::AssignError error; |
| 415 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 416 | alloc.determineRecyclability(); |
| 417 | |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 418 | alloc.assign(&startIndex, &stopIndex, &error); |
| 419 | REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); |
| 420 | REPORTER_ASSERT(reporter, 0 == startIndex && 1 == stopIndex); |
| 421 | |
| 422 | alloc.assign(&startIndex, &stopIndex, &error); |
| 423 | REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); |
| 424 | REPORTER_ASSERT(reporter, 1 == startIndex && 2 == stopIndex); |
| 425 | |
| 426 | p1->completedRead(); |
| 427 | p2->completedRead(); |
| 428 | p3->completedRead(); |
| 429 | p4->completedRead(); |
| 430 | } |
| 431 | |
| 432 | context->setResourceCacheLimits(origMaxNum, origMaxBytes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 433 | } |