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