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