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 | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame^] | 44 | GrSwizzle swizzle = caps->getReadSwizzle(format, p.fColorType); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 45 | |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame^] | 46 | return proxyProvider->createProxy(format, desc, swizzle, p.fRenderable, p.fSampleCnt, p.fOrigin, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 47 | GrMipMapped::kNo, p.fFit, p.fBudgeted, GrProtected::kNo); |
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 | c80b0e9 | 2019-07-23 10:27:09 -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 | c80b0e9 | 2019-07-23 10:27:09 -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) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 79 | GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 1)); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 80 | |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 81 | alloc.addInterval(p1.get(), 0, 4, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 82 | alloc.incOps(); |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 83 | alloc.addInterval(p2.get(), 1, 2, GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 84 | alloc.incOps(); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 85 | alloc.markEndOfOpsTask(0); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 86 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 87 | alloc.determineRecyclability(); |
| 88 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 89 | int startIndex, stopIndex; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 90 | GrResourceAllocator::AssignError error; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 91 | alloc.assign(&startIndex, &stopIndex, &error); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 92 | REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 93 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 94 | REPORTER_ASSERT(reporter, p1->peekSurface()); |
| 95 | REPORTER_ASSERT(reporter, p2->peekSurface()); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 96 | bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID(); |
| 97 | REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 100 | // Test various cases when two proxies do not have overlapping intervals. |
| 101 | // This mainly acts as a test of the ResourceAllocator's free pool. |
| 102 | static void non_overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider, |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 103 | sk_sp<GrSurfaceProxy> p1, sk_sp<GrSurfaceProxy> p2, |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 104 | bool expectedResult) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 105 | GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 1)); |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 106 | |
| 107 | alloc.incOps(); |
| 108 | alloc.incOps(); |
| 109 | alloc.incOps(); |
| 110 | alloc.incOps(); |
| 111 | alloc.incOps(); |
| 112 | alloc.incOps(); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 113 | |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 114 | alloc.addInterval(p1.get(), 0, 2, GrResourceAllocator::ActualUse::kYes); |
| 115 | alloc.addInterval(p2.get(), 3, 5, GrResourceAllocator::ActualUse::kYes); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 116 | alloc.markEndOfOpsTask(0); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 117 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 118 | alloc.determineRecyclability(); |
| 119 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 120 | int startIndex, stopIndex; |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 121 | GrResourceAllocator::AssignError error; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 122 | alloc.assign(&startIndex, &stopIndex, &error); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 124 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 125 | REPORTER_ASSERT(reporter, p1->peekSurface()); |
| 126 | REPORTER_ASSERT(reporter, p2->peekSurface()); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 127 | bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID(); |
| 128 | REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch); |
| 129 | } |
| 130 | |
| 131 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 132 | const GrCaps* caps = ctxInfo.grContext()->priv().caps(); |
| 133 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider(); |
| 134 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider(); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 135 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 136 | struct TestCase { |
| 137 | ProxyParams fP1; |
| 138 | ProxyParams fP2; |
| 139 | bool fExpectation; |
| 140 | }; |
| 141 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 142 | constexpr GrRenderable kRT = GrRenderable::kYes; |
| 143 | constexpr GrRenderable kNotRT = GrRenderable::kNo; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 144 | |
| 145 | constexpr bool kShare = true; |
| 146 | constexpr bool kDontShare = false; |
| 147 | // Non-RT GrSurfaces are never recycled on some platforms. |
| 148 | bool kConditionallyShare = resourceProvider->caps()->reuseScratchTextures(); |
| 149 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 150 | const GrColorType kRGBA = GrColorType::kRGBA_8888; |
| 151 | const GrColorType kBGRA = GrColorType::kBGRA_8888; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 152 | |
| 153 | const SkBackingFit kE = SkBackingFit::kExact; |
| 154 | const SkBackingFit kA = SkBackingFit::kApprox; |
| 155 | |
| 156 | const GrSurfaceOrigin kTL = kTopLeft_GrSurfaceOrigin; |
| 157 | const GrSurfaceOrigin kBL = kBottomLeft_GrSurfaceOrigin; |
| 158 | |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 159 | const SkBudgeted kNotB = SkBudgeted::kNo; |
| 160 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 161 | //-------------------------------------------------------------------------------------------- |
| 162 | TestCase gOverlappingTests[] = { |
| 163 | //---------------------------------------------------------------------------------------- |
| 164 | // Two proxies with overlapping intervals and compatible descriptors should never share |
| 165 | // RT version |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 166 | { { 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] | 167 | // non-RT version |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 168 | { { 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] | 169 | }; |
| 170 | |
| 171 | for (auto test : gOverlappingTests) { |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 172 | sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, caps, test.fP1); |
| 173 | sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, test.fP2); |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 174 | overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), test.fExpectation); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 177 | auto beFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes); |
| 178 | int k2 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(2, beFormat); |
| 179 | int k4 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(4, beFormat); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 180 | |
| 181 | //-------------------------------------------------------------------------------------------- |
| 182 | TestCase gNonOverlappingTests[] = { |
| 183 | //---------------------------------------------------------------------------------------- |
| 184 | // Two non-overlapping intervals w/ compatible proxies should share |
| 185 | // both same size & approx |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 186 | { { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, kShare }, |
| 187 | { { 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] | 188 | // diffs sizes but still approx |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 189 | { { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 50, kRT, kRGBA, kA, 1, kTL, kNotB }, kShare }, |
| 190 | { { 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] | 191 | // sames sizes but exact |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 192 | { { 64, kRT, kRGBA, kE, 1, kTL, kNotB }, { 64, kRT, kRGBA, kE, 1, kTL, kNotB }, kShare }, |
| 193 | { { 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] | 194 | //---------------------------------------------------------------------------------------- |
| 195 | // Two non-overlapping intervals w/ different exact sizes should not share |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 196 | { { 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] | 197 | // Two non-overlapping intervals w/ _very different_ approx sizes should not share |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 198 | { { 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] | 199 | // Two non-overlapping intervals w/ different MSAA sample counts should not share |
Robert Phillips | c476e5d | 2019-03-26 14:50:08 -0400 | [diff] [blame] | 200 | { { 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] | 201 | // Two non-overlapping intervals w/ different configs should not share |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 202 | { { 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] | 203 | // Two non-overlapping intervals w/ different RT classifications should never share |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 204 | { { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, kDontShare }, |
| 205 | { { 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] | 206 | // Two non-overlapping intervals w/ different origins should share |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 207 | { { 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] | 208 | }; |
| 209 | |
| 210 | for (auto test : gNonOverlappingTests) { |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 211 | sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, caps, test.fP1); |
| 212 | sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, test.fP2); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 213 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 214 | if (!p1 || !p2) { |
| 215 | continue; // creation can fail (i.e., for msaa4 on iOS) |
| 216 | } |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 217 | |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 218 | non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), |
| 219 | test.fExpectation); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | { |
| 223 | // Wrapped backend textures should never be reused |
| 224 | TestCase t[1] = { |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 225 | { { 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] | 226 | }; |
| 227 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 228 | GrBackendTexture backEndTex; |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 229 | sk_sp<GrSurfaceProxy> p1 = make_backend(ctxInfo.grContext(), t[0].fP1, &backEndTex); |
| 230 | sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, t[0].fP2); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 231 | |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 232 | non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), |
| 233 | t[0].fExpectation); |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 234 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 235 | cleanup_backend(ctxInfo.grContext(), backEndTex); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 236 | } |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 237 | } |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 238 | |
| 239 | static void draw(GrContext* context) { |
| 240 | SkImageInfo ii = SkImageInfo::Make(1024, 1024, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 241 | |
| 242 | sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, |
| 243 | ii, 1, kTopLeft_GrSurfaceOrigin, nullptr); |
| 244 | |
| 245 | SkCanvas* c = s->getCanvas(); |
| 246 | |
| 247 | c->clear(SK_ColorBLACK); |
| 248 | } |
| 249 | |
| 250 | |
| 251 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorStressTest, reporter, ctxInfo) { |
| 252 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 253 | |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 254 | size_t maxBytes = context->getResourceCacheLimit(); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 255 | |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 256 | context->setResourceCacheLimit(0); // We'll always be overbudget |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 257 | |
| 258 | draw(context); |
| 259 | draw(context); |
| 260 | draw(context); |
| 261 | draw(context); |
| 262 | context->flush(); |
| 263 | |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 264 | context->setResourceCacheLimit(maxBytes); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 265 | } |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 266 | |
| 267 | sk_sp<GrSurfaceProxy> make_lazy(GrProxyProvider* proxyProvider, const GrCaps* caps, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 268 | const ProxyParams& p) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 269 | GrPixelConfig config = GrColorTypeToPixelConfig(p.fColorType); |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 270 | const auto format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable); |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 271 | |
| 272 | GrSurfaceDesc desc; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 273 | desc.fWidth = p.fSize; |
| 274 | desc.fHeight = p.fSize; |
| 275 | desc.fConfig = config; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 276 | |
| 277 | SkBackingFit fit = p.fFit; |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 278 | auto callback = [fit, desc, format, p](GrResourceProvider* resourceProvider) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 279 | sk_sp<GrTexture> texture; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 280 | if (fit == SkBackingFit::kApprox) { |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 281 | texture = resourceProvider->createApproxTexture( |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 282 | desc, format, p.fRenderable, p.fSampleCnt, GrProtected::kNo); |
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 | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 285 | GrMipMapped::kNo, SkBudgeted::kNo, |
| 286 | GrProtected::kNo); |
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 | |