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