commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 Reed | ac9f0c9 | 2020-12-23 10:11:33 -0500 | [diff] [blame] | 8 | #include "include/core/SkBitmap.h" |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkSurface.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 11 | #include "include/gpu/GrDirectContext.h" |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 12 | #include "src/core/SkMessageBus.h" |
| 13 | #include "src/core/SkMipmap.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrGpu.h" |
| 16 | #include "src/gpu/GrGpuResourceCacheAccess.h" |
| 17 | #include "src/gpu/GrGpuResourcePriv.h" |
| 18 | #include "src/gpu/GrProxyProvider.h" |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrRecordingContextPriv.h" |
Brian Salomon | f7f5433 | 2020-07-28 09:23:35 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrResourceCache.h" |
| 22 | #include "src/gpu/GrResourceProvider.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 23 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/SkGr.h" |
| 25 | #include "tests/Test.h" |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 26 | #include "tools/gpu/GrContextFactory.h" |
| 27 | #include "tools/gpu/ManagedBackendTexture.h" |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 28 | |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 29 | #include <thread> |
| 30 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 31 | static const int gWidth = 640; |
| 32 | static const int gHeight = 480; |
| 33 | |
| 34 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 35 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 36 | auto context = ctxInfo.directContext(); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 37 | SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 38 | auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 39 | SkCanvas* canvas = surface->getCanvas(); |
| 40 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 41 | const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
| 42 | |
| 43 | SkBitmap src; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 44 | src.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 45 | src.eraseColor(SK_ColorBLACK); |
Mike Reed | f0ffb89 | 2017-10-03 14:47:21 -0400 | [diff] [blame] | 46 | size_t srcSize = src.computeByteSize(); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 48 | size_t initialCacheSize; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 49 | context->getResourceCacheUsage(nullptr, &initialCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 50 | |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 51 | size_t oldMaxBytes = context->getResourceCacheLimit(); |
skia.committer@gmail.com | 17f1ae6 | 2013-08-09 07:01:22 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 53 | // Set the cache limits so we can fit 10 "src" images and the |
| 54 | // max number of textures doesn't matter |
| 55 | size_t maxCacheSize = initialCacheSize + 10*srcSize; |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 56 | context->setResourceCacheLimit(maxCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 57 | |
| 58 | SkBitmap readback; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 59 | readback.allocN32Pixels(size.width(), size.height()); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 60 | |
| 61 | for (int i = 0; i < 100; ++i) { |
Mike Reed | 34a0c97 | 2021-01-25 17:49:32 -0500 | [diff] [blame] | 62 | canvas->drawImage(src.asImage(), 0, 0); |
Mike Reed | f194219 | 2017-07-21 14:24:29 -0400 | [diff] [blame] | 63 | surface->readPixels(readback, 0, 0); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 64 | |
| 65 | // "modify" the src texture |
| 66 | src.notifyPixelsChanged(); |
| 67 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 68 | size_t curCacheSize; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 69 | context->getResourceCacheUsage(nullptr, &curCacheSize); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 70 | |
| 71 | // we should never go over the size limit |
| 72 | REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
| 73 | } |
| 74 | |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 75 | context->setResourceCacheLimit(oldMaxBytes); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 76 | } |
| 77 | |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 78 | static bool is_rendering_and_not_angle_es3(sk_gpu_test::GrContextFactory::ContextType type) { |
| 79 | if (type == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES3_ContextType || |
| 80 | type == sk_gpu_test::GrContextFactory::kANGLE_GL_ES3_ContextType) { |
| 81 | return false; |
| 82 | } |
| 83 | return sk_gpu_test::GrContextFactory::IsRenderingContext(type); |
| 84 | } |
| 85 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 86 | static GrAttachment* get_SB(GrRenderTarget* rt) { return rt->getStencilAttachment(); } |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 87 | |
| 88 | static sk_sp<GrRenderTarget> create_RT_with_SB(GrResourceProvider* provider, |
| 89 | int size, int sampleCount, SkBudgeted budgeted) { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 90 | auto format = |
| 91 | provider->caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes); |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 92 | sk_sp<GrTexture> tex(provider->createTexture({size, size}, format, GrTextureType::k2D, |
| 93 | GrRenderable::kYes, sampleCount, GrMipmapped::kNo, |
| 94 | budgeted, GrProtected::kNo)); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 95 | if (!tex || !tex->asRenderTarget()) { |
| 96 | return nullptr; |
| 97 | } |
| 98 | |
Chris Dalton | e0fe23a | 2021-04-23 13:11:44 -0600 | [diff] [blame] | 99 | if (!provider->attachStencilAttachment(tex->asRenderTarget(), sampleCount > 1)) { |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 100 | return nullptr; |
| 101 | } |
| 102 | SkASSERT(get_SB(tex->asRenderTarget())); |
| 103 | |
| 104 | return sk_ref_sp(tex->asRenderTarget()); |
| 105 | } |
| 106 | |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 107 | // This currently fails on ES3 ANGLE contexts |
| 108 | DEF_GPUTEST_FOR_CONTEXTS(ResourceCacheStencilBuffers, &is_rendering_and_not_angle_es3, reporter, |
Robert Phillips | ec32534 | 2017-10-30 18:02:48 +0000 | [diff] [blame] | 109 | ctxInfo, nullptr) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 110 | auto context = ctxInfo.directContext(); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 111 | const GrCaps* caps = context->priv().caps(); |
| 112 | |
| 113 | if (caps->avoidStencilBuffers()) { |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 114 | return; |
| 115 | } |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 116 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 117 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 118 | |
Greg Daniel | 5c96db8 | 2019-07-09 14:06:58 -0400 | [diff] [blame] | 119 | GrColorType grColorType = GrColorType::kRGBA_8888; |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 120 | GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, GrRenderable::kYes); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 121 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 122 | sk_sp<GrRenderTarget> smallRT0 = create_RT_with_SB(resourceProvider, 4, 1, SkBudgeted::kYes); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, smallRT0); |
| 124 | |
| 125 | { |
| 126 | // Two budgeted RTs with the same desc should share a stencil buffer. |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 127 | sk_sp<GrRenderTarget> smallRT1 = create_RT_with_SB(resourceProvider, 4, 1, SkBudgeted::kYes); |
| 128 | REPORTER_ASSERT(reporter, smallRT1); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 129 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 130 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) == get_SB(smallRT1.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 133 | { |
| 134 | // An unbudgeted RT with the same desc should also share. |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 135 | sk_sp<GrRenderTarget> smallRT2 = create_RT_with_SB(resourceProvider, 4, 1, SkBudgeted::kNo); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, smallRT2); |
| 137 | |
| 138 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) == get_SB(smallRT2.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 141 | { |
| 142 | // An RT with a much larger size should not share. |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 143 | sk_sp<GrRenderTarget> bigRT = create_RT_with_SB(resourceProvider, 400, 1, SkBudgeted::kNo); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, bigRT); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 145 | |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 146 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) != get_SB(bigRT.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 147 | } |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 148 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 149 | int smallSampleCount = |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 150 | context->priv().caps()->getRenderTargetSampleCount(2, format); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 151 | if (smallSampleCount > 1) { |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 152 | // An RT with a different sample count should not share. |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 153 | sk_sp<GrRenderTarget> smallMSAART0 = create_RT_with_SB(resourceProvider, 4, |
| 154 | smallSampleCount, SkBudgeted::kNo); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, smallMSAART0); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 156 | |
| 157 | REPORTER_ASSERT(reporter, get_SB(smallRT0.get()) != get_SB(smallMSAART0.get())); |
| 158 | |
| 159 | { |
| 160 | // A second MSAA RT should share with the first MSAA RT. |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 161 | sk_sp<GrRenderTarget> smallMSAART1 = create_RT_with_SB(resourceProvider, 4, |
| 162 | smallSampleCount, |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 163 | SkBudgeted::kNo); |
| 164 | REPORTER_ASSERT(reporter, smallMSAART1); |
| 165 | |
| 166 | REPORTER_ASSERT(reporter, get_SB(smallMSAART0.get()) == get_SB(smallMSAART1.get())); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 167 | } |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 168 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 169 | // But one with a larger sample count should not. (Also check that the two requests didn't |
| 170 | // rounded up to the same actual sample count or else they could share.). |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 171 | int bigSampleCount = context->priv().caps()->getRenderTargetSampleCount(5, format); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 172 | if (bigSampleCount > 0 && bigSampleCount != smallSampleCount) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 173 | sk_sp<GrRenderTarget> smallMSAART2 = create_RT_with_SB(resourceProvider, 4, |
| 174 | bigSampleCount, |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 175 | SkBudgeted::kNo); |
| 176 | REPORTER_ASSERT(reporter, smallMSAART2); |
| 177 | |
| 178 | REPORTER_ASSERT(reporter, get_SB(smallMSAART0.get()) != get_SB(smallMSAART2.get())); |
bsalomon | 02a44a4 | 2015-02-19 09:09:00 -0800 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 183 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 184 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 185 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
| 186 | GrGpu* gpu = context->priv().getGpu(); |
jvanverth | eeb8d99 | 2015-07-15 10:16:56 -0700 | [diff] [blame] | 187 | // this test is only valid for GL |
| 188 | if (!gpu || !gpu->glContextForTesting()) { |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 189 | return; |
| 190 | } |
| 191 | |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 192 | static const int kW = 100; |
| 193 | static const int kH = 100; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 194 | |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 195 | auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( |
| 196 | context, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); |
| 197 | GrBackendTexture unmbet = context->createBackendTexture( |
| 198 | kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); |
| 199 | if (!mbet || !unmbet.isValid()) { |
| 200 | ERRORF(reporter, "Could not create backend texture."); |
Greg Daniel | 5366e59 | 2018-01-10 09:57:53 -0500 | [diff] [blame] | 201 | return; |
| 202 | } |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 203 | |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 204 | context->resetContext(); |
| 205 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 206 | sk_sp<GrTexture> borrowed(resourceProvider->wrapBackendTexture( |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 207 | mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 208 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 209 | sk_sp<GrTexture> adopted(resourceProvider->wrapBackendTexture( |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 210 | unmbet, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 211 | |
Brian Osman | 85d34b2 | 2017-05-10 12:06:26 -0400 | [diff] [blame] | 212 | REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); |
| 213 | if (!borrowed || !adopted) { |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 214 | return; |
| 215 | } |
| 216 | |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 217 | borrowed.reset(); |
| 218 | adopted.reset(); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 219 | |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 220 | context->flushAndSubmit(/*sync*/ true); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 221 | |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 222 | bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(mbet->texture()); |
| 223 | bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(unmbet); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 224 | |
| 225 | REPORTER_ASSERT(reporter, borrowedIsAlive); |
| 226 | REPORTER_ASSERT(reporter, !adoptedIsAlive); |
| 227 | |
Brian Salomon | e64b064 | 2018-03-07 11:47:54 -0500 | [diff] [blame] | 228 | if (adoptedIsAlive) { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 229 | context->deleteBackendTexture(unmbet); |
Brian Salomon | e64b064 | 2018-03-07 11:47:54 -0500 | [diff] [blame] | 230 | } |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 231 | |
| 232 | context->resetContext(); |
| 233 | } |
| 234 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 235 | class TestResource : public GrGpuResource { |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 236 | enum ScratchConstructor { kScratchConstructor }; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 237 | public: |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 238 | static const size_t kDefaultSize = 100; |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 239 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 240 | /** Property that distinctly categorizes the resource. |
| 241 | * For example, textures have width, height, ... */ |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 242 | enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 243 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 244 | TestResource(GrGpu* gpu, SkBudgeted budgeted = SkBudgeted::kYes, size_t size = kDefaultSize) |
| 245 | : INHERITED(gpu) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 246 | , fToDelete(nullptr) |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 247 | , fSize(size) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 248 | , fProperty(kA_SimulatedProperty) |
| 249 | , fIsScratch(false) { |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 250 | ++fNumAlive; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 251 | this->registerWithCache(budgeted); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 252 | } |
| 253 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 254 | static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 255 | SimulatedProperty property, size_t size = kDefaultSize) { |
| 256 | return new TestResource(gpu, budgeted, property, kScratchConstructor, size); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 257 | } |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 258 | static TestResource* CreateWrapped(GrGpu* gpu, GrWrapCacheable cacheable, |
| 259 | size_t size = kDefaultSize) { |
| 260 | return new TestResource(gpu, cacheable, size); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 263 | ~TestResource() override { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 264 | --fNumAlive; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 265 | } |
| 266 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 267 | static int NumAlive() { return fNumAlive; } |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 268 | |
Ben Wagner | 97c6a0e | 2018-07-11 14:56:22 -0400 | [diff] [blame] | 269 | void setUnrefWhenDestroyed(sk_sp<TestResource> resource) { |
| 270 | fToDelete = std::move(resource); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 271 | } |
| 272 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 273 | static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key) { |
| 274 | static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType(); |
| 275 | GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 276 | for (int i = 0; i < kScratchKeyFieldCnt; ++i) { |
| 277 | builder[i] = static_cast<uint32_t>(i + property); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | static size_t ExpectedScratchKeySize() { |
| 282 | return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt); |
| 283 | } |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 284 | private: |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 285 | static const int kScratchKeyFieldCnt = 6; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 286 | |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 287 | TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor, |
| 288 | size_t size = kDefaultSize) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 289 | : INHERITED(gpu) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 290 | , fToDelete(nullptr) |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 291 | , fSize(size) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 292 | , fProperty(property) |
| 293 | , fIsScratch(true) { |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 294 | ++fNumAlive; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 295 | this->registerWithCache(budgeted); |
| 296 | } |
| 297 | |
| 298 | // Constructor for simulating resources that wrap backend objects. |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 299 | TestResource(GrGpu* gpu, GrWrapCacheable cacheable, size_t size) |
| 300 | : INHERITED(gpu) |
| 301 | , fToDelete(nullptr) |
| 302 | , fSize(size) |
| 303 | , fProperty(kA_SimulatedProperty) |
| 304 | , fIsScratch(false) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 305 | ++fNumAlive; |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 306 | this->registerWithCacheWrapped(cacheable); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void computeScratchKey(GrScratchKey* key) const override { |
| 310 | if (fIsScratch) { |
| 311 | ComputeScratchKey(fProperty, key); |
| 312 | } |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 313 | } |
| 314 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 315 | size_t onGpuMemorySize() const override { return fSize; } |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 316 | const char* getResourceType() const override { return "Test"; } |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 317 | |
Ben Wagner | 97c6a0e | 2018-07-11 14:56:22 -0400 | [diff] [blame] | 318 | sk_sp<TestResource> fToDelete; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 319 | size_t fSize; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 320 | static int fNumAlive; |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 321 | SimulatedProperty fProperty; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 322 | bool fIsScratch; |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 323 | using INHERITED = GrGpuResource; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 324 | }; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 325 | int TestResource::fNumAlive = 0; |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 326 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 327 | class Mock { |
| 328 | public: |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 329 | Mock(size_t maxBytes) { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 330 | fDContext = GrDirectContext::MakeMock(nullptr); |
| 331 | SkASSERT(fDContext); |
| 332 | fDContext->setResourceCacheLimit(maxBytes); |
| 333 | GrResourceCache* cache = fDContext->priv().getResourceCache(); |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 334 | cache->purgeUnlockedResources(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 335 | SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 336 | } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 337 | |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 338 | GrResourceCache* cache() { return fDContext->priv().getResourceCache(); } |
| 339 | GrGpu* gpu() { return fDContext->priv().getGpu(); } |
| 340 | GrDirectContext* dContext() { return fDContext.get(); } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 341 | |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 342 | void reset() { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 343 | fDContext.reset(); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 344 | } |
| 345 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 346 | private: |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 347 | sk_sp<GrDirectContext> fDContext; |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | static void test_no_key(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 351 | Mock mock(30000); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 352 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 353 | GrGpu* gpu = mock.gpu(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 354 | |
| 355 | // Create a bunch of resources with no keys |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 356 | TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11); |
| 357 | TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12); |
| 358 | TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13 ); |
| 359 | TestResource* d = new TestResource(gpu, SkBudgeted::kYes, 14 ); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 360 | |
| 361 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 362 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 363 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() + |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 364 | d->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 365 | |
| 366 | // Should be safe to purge without deleting the resources since we still have refs. |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 367 | cache->purgeUnlockedResources(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 368 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 369 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 370 | // Since the resources have neither unique nor scratch keys, delete immediately upon unref. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 371 | |
| 372 | a->unref(); |
| 373 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 374 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 375 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() + d->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 376 | cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 377 | |
| 378 | c->unref(); |
| 379 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 380 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 381 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 382 | cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 383 | |
| 384 | d->unref(); |
| 385 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 386 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 387 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 388 | |
| 389 | b->unref(); |
| 390 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 391 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 392 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 393 | } |
| 394 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 395 | // Each integer passed as a template param creates a new domain. |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 396 | template <int> |
| 397 | static void make_unique_key(GrUniqueKey* key, int data, const char* tag = nullptr) { |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 398 | static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 399 | GrUniqueKey::Builder builder(key, d, 1, tag); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 400 | builder[0] = data; |
| 401 | } |
| 402 | |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 403 | static void test_purge_unlocked(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 404 | Mock mock(30000); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 405 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 406 | GrGpu* gpu = mock.gpu(); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 407 | |
| 408 | // Create two resource w/ a unique key and two w/o but all of which have scratch keys. |
| 409 | TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 410 | TestResource::kA_SimulatedProperty, 11); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 411 | |
| 412 | GrUniqueKey uniqueKey; |
| 413 | make_unique_key<0>(&uniqueKey, 0); |
| 414 | |
| 415 | TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 416 | TestResource::kA_SimulatedProperty, 12); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 417 | b->resourcePriv().setUniqueKey(uniqueKey); |
| 418 | |
| 419 | TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 420 | TestResource::kA_SimulatedProperty, 13); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 421 | |
| 422 | GrUniqueKey uniqueKey2; |
| 423 | make_unique_key<0>(&uniqueKey2, 1); |
| 424 | |
| 425 | TestResource* d = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 426 | TestResource::kA_SimulatedProperty, 14); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 427 | d->resourcePriv().setUniqueKey(uniqueKey2); |
| 428 | |
| 429 | |
| 430 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 431 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
| 432 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() + |
| 433 | d->gpuMemorySize() == cache->getResourceBytes()); |
| 434 | |
| 435 | // Should be safe to purge without deleting the resources since we still have refs. |
| 436 | cache->purgeUnlockedResources(false); |
| 437 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 438 | |
| 439 | // Unref them all. Since they all have keys they should remain in the cache. |
| 440 | |
| 441 | a->unref(); |
| 442 | b->unref(); |
| 443 | c->unref(); |
| 444 | d->unref(); |
| 445 | REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); |
| 446 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
| 447 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() + |
| 448 | d->gpuMemorySize() == cache->getResourceBytes()); |
| 449 | |
| 450 | // Purge only the two scratch resources |
| 451 | cache->purgeUnlockedResources(true); |
| 452 | |
| 453 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 454 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 455 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() == |
| 456 | cache->getResourceBytes()); |
| 457 | |
| 458 | // Purge the uniquely keyed resources |
| 459 | cache->purgeUnlockedResources(false); |
| 460 | |
| 461 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 462 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 463 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 464 | } |
| 465 | |
Greg Daniel | 1fd8ac8 | 2020-12-11 11:22:01 -0500 | [diff] [blame] | 466 | static void test_purge_command_buffer_usage(skiatest::Reporter* reporter) { |
| 467 | Mock mock(30000); |
| 468 | GrResourceCache* cache = mock.cache(); |
| 469 | GrGpu* gpu = mock.gpu(); |
| 470 | |
| 471 | // Create two resource w/ scratch keys. |
| 472 | TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
| 473 | TestResource::kA_SimulatedProperty, 11); |
| 474 | |
| 475 | TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
| 476 | TestResource::kA_SimulatedProperty, 12); |
| 477 | |
| 478 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 479 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 480 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == cache->getResourceBytes()); |
| 481 | |
| 482 | // Should be safe to purge without deleting the resources since we still have refs. |
| 483 | cache->purgeUnlockedResources(true); |
| 484 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 485 | |
| 486 | // Add command buffer usages to all resources |
| 487 | a->addCommandBufferUsage(); |
| 488 | b->addCommandBufferUsage(); |
| 489 | |
| 490 | // Should be safe to purge without deleting the resources since we still have refs and command |
| 491 | // buffer usages. |
| 492 | cache->purgeUnlockedResources(true); |
| 493 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 494 | |
| 495 | // Unref the first resource |
| 496 | a->unref(); |
| 497 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 498 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 499 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == cache->getResourceBytes()); |
| 500 | |
| 501 | // Should be safe to purge without deleting the resources since we still have command buffer |
| 502 | // usages and the second still has a ref. |
| 503 | cache->purgeUnlockedResources(true); |
| 504 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 505 | |
| 506 | // Remove command buffer usages |
| 507 | a->removeCommandBufferUsage(); |
| 508 | b->removeCommandBufferUsage(); |
| 509 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 510 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 511 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == cache->getResourceBytes()); |
| 512 | |
| 513 | // Purge this time should remove the first resources since it no longer has any refs or command |
| 514 | // buffer usages. |
| 515 | cache->purgeUnlockedResources(true); |
| 516 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 517 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 518 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
| 519 | |
| 520 | // Unref the second resource |
| 521 | b->unref(); |
| 522 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 523 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 524 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
| 525 | |
| 526 | // Purge the last resource |
| 527 | cache->purgeUnlockedResources(false); |
| 528 | |
| 529 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
| 530 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 531 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 532 | } |
| 533 | |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 534 | static void test_budgeting(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 535 | Mock mock(300); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 536 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 537 | GrGpu* gpu = mock.gpu(); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 538 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 539 | GrUniqueKey uniqueKey; |
| 540 | make_unique_key<0>(&uniqueKey, 0); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 541 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 542 | // Create a scratch, a unique, and a wrapped resource |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 543 | TestResource* scratch = |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 544 | TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource::kB_SimulatedProperty, |
| 545 | 10); |
| 546 | TestResource* unique = new TestResource(gpu, SkBudgeted::kYes, 11); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 547 | unique->resourcePriv().setUniqueKey(uniqueKey); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 548 | TestResource* wrappedCacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes, 12); |
| 549 | TestResource* wrappedUncacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kNo, 13); |
| 550 | TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 14); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 551 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 552 | // Make sure we can add a unique key to the wrapped resources |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 553 | GrUniqueKey uniqueKey2; |
| 554 | make_unique_key<0>(&uniqueKey2, 1); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 555 | GrUniqueKey uniqueKey3; |
| 556 | make_unique_key<0>(&uniqueKey3, 2); |
| 557 | wrappedCacheable->resourcePriv().setUniqueKey(uniqueKey2); |
| 558 | wrappedUncacheable->resourcePriv().setUniqueKey(uniqueKey3); |
| 559 | GrGpuResource* wrappedCacheableViaKey = cache->findAndRefUniqueResource(uniqueKey2); |
| 560 | REPORTER_ASSERT(reporter, wrappedCacheableViaKey); |
| 561 | GrGpuResource* wrappedUncacheableViaKey = cache->findAndRefUniqueResource(uniqueKey3); |
| 562 | REPORTER_ASSERT(reporter, wrappedUncacheableViaKey); |
Brian Osman | 0562eb9 | 2017-05-08 11:16:39 -0400 | [diff] [blame] | 563 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 564 | // Remove the extra refs we just added. |
| 565 | SkSafeUnref(wrappedCacheableViaKey); |
| 566 | SkSafeUnref(wrappedUncacheableViaKey); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 567 | |
| 568 | // Make sure sizes are as we expect |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 569 | REPORTER_ASSERT(reporter, 5 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 570 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 571 | wrappedCacheable->gpuMemorySize() + |
| 572 | wrappedUncacheable->gpuMemorySize() + |
| 573 | unbudgeted->gpuMemorySize() == |
| 574 | cache->getResourceBytes()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 575 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 576 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 577 | cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 578 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 579 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 580 | // Our refs mean that the resources are non purgeable. |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 581 | cache->purgeUnlockedResources(); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 582 | REPORTER_ASSERT(reporter, 5 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 583 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 584 | wrappedCacheable->gpuMemorySize() + |
| 585 | wrappedUncacheable->gpuMemorySize() + |
| 586 | unbudgeted->gpuMemorySize() == |
| 587 | cache->getResourceBytes()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 588 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 589 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 590 | cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 591 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 592 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 593 | // Unreffing the cacheable wrapped resource with a unique key shouldn't free it right away. |
| 594 | // However, unreffing the uncacheable wrapped resource should free it. |
| 595 | wrappedCacheable->unref(); |
| 596 | wrappedUncacheable->unref(); |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 597 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 598 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 599 | wrappedCacheable->gpuMemorySize() + |
| 600 | unbudgeted->gpuMemorySize() == |
| 601 | cache->getResourceBytes()); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 602 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 603 | |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 604 | // Now try freeing the budgeted resources first |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 605 | wrappedUncacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kNo); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 606 | unique->unref(); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 607 | REPORTER_ASSERT(reporter, 11 == cache->getPurgeableBytes()); |
| 608 | // This will free 'unique' but not wrappedCacheable which has a key. That requires the key to be |
| 609 | // removed to be freed. |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 610 | cache->purgeUnlockedResources(); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 611 | REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); |
Brian Salomon | 9bc76d9 | 2019-01-24 12:18:33 -0500 | [diff] [blame] | 612 | |
| 613 | wrappedCacheableViaKey = cache->findAndRefUniqueResource(uniqueKey2); |
| 614 | REPORTER_ASSERT(reporter, wrappedCacheableViaKey); |
| 615 | if (wrappedCacheableViaKey) { |
| 616 | wrappedCacheableViaKey->resourcePriv().removeUniqueKey(); |
| 617 | wrappedCacheable->unref(); |
| 618 | } |
| 619 | // We shouldn't have to call purgeAllUnlocked as removing the key on a wrapped cacheable |
| 620 | // resource should immediately delete it. |
| 621 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 622 | |
| 623 | wrappedCacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 624 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrappedCacheable->gpuMemorySize() + |
| 625 | wrappedUncacheable->gpuMemorySize() + |
| 626 | unbudgeted->gpuMemorySize() == |
| 627 | cache->getResourceBytes()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 628 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 629 | REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 630 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 631 | |
| 632 | scratch->unref(); |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 633 | REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes()); |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 634 | cache->purgeUnlockedResources(); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 635 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 636 | REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrappedCacheable->gpuMemorySize() + |
| 637 | wrappedUncacheable->gpuMemorySize() == |
| 638 | cache->getResourceBytes()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 639 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 640 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 641 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 642 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 643 | // Unreffing the wrapped resources (with no unique key) should free them right away. |
| 644 | wrappedUncacheable->unref(); |
| 645 | wrappedCacheable->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 646 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 647 | REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache->getResourceBytes()); |
| 648 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 649 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 650 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 651 | |
| 652 | unbudgeted->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 653 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 654 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 655 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 656 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 657 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 658 | } |
| 659 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 660 | static void test_unbudgeted(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 661 | Mock mock(30000); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 662 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 663 | GrGpu* gpu = mock.gpu(); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 664 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 665 | GrUniqueKey uniqueKey; |
| 666 | make_unique_key<0>(&uniqueKey, 0); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 667 | |
| 668 | TestResource* scratch; |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 669 | TestResource* unique; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 670 | TestResource* wrapped; |
| 671 | TestResource* unbudgeted; |
| 672 | |
| 673 | // A large uncached or wrapped resource shouldn't evict anything. |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 674 | scratch = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 675 | TestResource::kB_SimulatedProperty, 10); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 676 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 677 | scratch->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 678 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 679 | REPORTER_ASSERT(reporter, 10 == cache->getResourceBytes()); |
| 680 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 681 | REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 682 | REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 683 | |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 684 | unique = new TestResource(gpu, SkBudgeted::kYes, 11); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 685 | unique->resourcePriv().setUniqueKey(uniqueKey); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 686 | unique->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 687 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 688 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 689 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 690 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 691 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 692 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 693 | size_t large = 2 * cache->getResourceBytes(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 694 | unbudgeted = new TestResource(gpu, SkBudgeted::kNo, large); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 695 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 696 | REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 697 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 698 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 699 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 700 | |
| 701 | unbudgeted->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 702 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 703 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 704 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 705 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 706 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 707 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 708 | wrapped = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes, large); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 709 | REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
| 710 | REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
| 711 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 712 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 713 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 714 | |
| 715 | wrapped->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 716 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 717 | REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
| 718 | REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
| 719 | REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 720 | REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 721 | |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 722 | cache->purgeUnlockedResources(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 723 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 724 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 725 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 726 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 727 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 728 | } |
| 729 | |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 730 | // This method can't be static because it needs to friended in GrGpuResource::CacheAccess. |
| 731 | void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); |
| 732 | /*static*/ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 733 | Mock mock(300); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 734 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 735 | GrGpu* gpu = mock.gpu(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 736 | |
| 737 | TestResource* resource = |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 738 | TestResource::CreateScratch(gpu, SkBudgeted::kNo, TestResource::kA_SimulatedProperty); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 739 | GrScratchKey key; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 740 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 741 | |
| 742 | size_t size = resource->gpuMemorySize(); |
| 743 | for (int i = 0; i < 2; ++i) { |
| 744 | // Since this resource is unbudgeted, it should not be reachable as scratch. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 745 | REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 746 | REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 747 | REPORTER_ASSERT(reporter, GrBudgetedType::kUnbudgetedUncacheable == |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 748 | resource->resourcePriv().budgetedType()); |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 749 | REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(key)); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 750 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 751 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 752 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 753 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 754 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 755 | |
| 756 | // Once it is unrefed, it should become available as scratch. |
| 757 | resource->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 758 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 759 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 760 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 761 | REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 762 | REPORTER_ASSERT(reporter, size == cache->getPurgeableBytes()); |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 763 | resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key)); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 764 | REPORTER_ASSERT(reporter, resource); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 765 | REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 766 | REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 767 | REPORTER_ASSERT(reporter, |
| 768 | GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 769 | |
| 770 | if (0 == i) { |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 771 | // If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 772 | // the above tests again. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 773 | resource->resourcePriv().makeUnbudgeted(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 774 | } else { |
| 775 | // After the second time around, try removing the scratch key |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 776 | resource->resourcePriv().removeScratchKey(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 777 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 778 | REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); |
| 779 | REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
| 780 | REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 781 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 782 | REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey().isValid()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 783 | REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 784 | REPORTER_ASSERT(reporter, |
| 785 | GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 786 | |
| 787 | // now when it is unrefed it should die since it has no key. |
| 788 | resource->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 789 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 790 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
| 791 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 792 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 793 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 794 | } |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 795 | } |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 799 | Mock mock(30000); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 800 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 801 | GrGpu* gpu = mock.gpu(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 802 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 803 | // Create two resources that have the same scratch key. |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 804 | TestResource* a = TestResource::CreateScratch(gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 805 | SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 806 | TestResource::kB_SimulatedProperty, 11); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 807 | TestResource* b = TestResource::CreateScratch(gpu, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 808 | SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 809 | TestResource::kB_SimulatedProperty, 12); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 810 | GrScratchKey scratchKey1; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 811 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 812 | // Check for negative case consistency. (leaks upon test failure.) |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 813 | REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey1)); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 814 | |
| 815 | GrScratchKey scratchKey; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 816 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 817 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 818 | // Scratch resources are registered with GrResourceCache just by existing. There are 2. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 819 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
Greg Daniel | da64261 | 2021-02-09 18:04:02 -0500 | [diff] [blame] | 820 | // As long as there are outstanding refs on the resources they will not be in the scratch map |
| 821 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 822 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 823 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 824 | cache->getResourceBytes()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 825 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 826 | // Our refs mean that the resources are non purgeable. |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 827 | cache->purgeUnlockedResources(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 828 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 829 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 830 | |
| 831 | // Unref but don't purge |
| 832 | a->unref(); |
| 833 | b->unref(); |
| 834 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
Greg Daniel | da64261 | 2021-02-09 18:04:02 -0500 | [diff] [blame] | 835 | // Since we removed the refs to the resources they will now be in the scratch map |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 836 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 837 | |
bsalomon | 63c992f | 2015-01-23 12:47:59 -0800 | [diff] [blame] | 838 | // Purge again. This time resources should be purgeable. |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 839 | cache->purgeUnlockedResources(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 840 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 841 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 842 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 843 | } |
| 844 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 845 | static void test_remove_scratch_key(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 846 | Mock mock(30000); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 847 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 848 | GrGpu* gpu = mock.gpu(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 849 | |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 850 | // Create two resources that have the same scratch key. |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 851 | TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 852 | TestResource::kB_SimulatedProperty); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 853 | TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 854 | TestResource::kB_SimulatedProperty); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 855 | a->unref(); |
| 856 | b->unref(); |
| 857 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 858 | GrScratchKey scratchKey; |
| 859 | // Ensure that scratch key lookup is correct for negative case. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 860 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 861 | // (following leaks upon test failure). |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 862 | REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey)); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 863 | |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 864 | // Scratch resources are registered with GrResourceCache just by existing. There are 2. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 865 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 866 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 867 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache->countScratchEntriesForKey(scratchKey));) |
| 868 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 869 | |
| 870 | // Find the first resource and remove its scratch key |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 871 | GrGpuResource* find = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 872 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 873 | // It's still alive, but not cached by scratch key anymore |
| 874 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 875 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));) |
| 876 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 877 | |
| 878 | // The cache should immediately delete it when it's unrefed since it isn't accessible. |
| 879 | find->unref(); |
| 880 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 881 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));) |
| 882 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 883 | |
| 884 | // Repeat for the second resource. |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 885 | find = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 886 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 887 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 888 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 889 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 890 | |
| 891 | // Should be able to call this multiple times with no problem. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 892 | find->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 893 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 894 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 895 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 896 | |
| 897 | find->unref(); |
| 898 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 899 | SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) |
| 900 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 901 | } |
| 902 | |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 903 | static void test_scratch_key_consistency(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 904 | Mock mock(30000); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 905 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 906 | GrGpu* gpu = mock.gpu(); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 907 | |
| 908 | // Create two resources that have the same scratch key. |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 909 | TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 910 | TestResource::kB_SimulatedProperty); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 911 | TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 912 | TestResource::kB_SimulatedProperty); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 913 | a->unref(); |
| 914 | b->unref(); |
| 915 | |
| 916 | GrScratchKey scratchKey; |
| 917 | // Ensure that scratch key comparison and assignment is consistent. |
| 918 | GrScratchKey scratchKey1; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 919 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 920 | GrScratchKey scratchKey2; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 921 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey2); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 922 | REPORTER_ASSERT(reporter, scratchKey1.size() == TestResource::ExpectedScratchKeySize()); |
| 923 | REPORTER_ASSERT(reporter, scratchKey1 != scratchKey2); |
| 924 | REPORTER_ASSERT(reporter, scratchKey2 != scratchKey1); |
| 925 | scratchKey = scratchKey1; |
| 926 | REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize()); |
| 927 | REPORTER_ASSERT(reporter, scratchKey1 == scratchKey); |
| 928 | REPORTER_ASSERT(reporter, scratchKey == scratchKey1); |
| 929 | REPORTER_ASSERT(reporter, scratchKey2 != scratchKey); |
| 930 | REPORTER_ASSERT(reporter, scratchKey != scratchKey2); |
| 931 | scratchKey = scratchKey2; |
| 932 | REPORTER_ASSERT(reporter, scratchKey.size() == TestResource::ExpectedScratchKeySize()); |
| 933 | REPORTER_ASSERT(reporter, scratchKey1 != scratchKey); |
| 934 | REPORTER_ASSERT(reporter, scratchKey != scratchKey1); |
| 935 | REPORTER_ASSERT(reporter, scratchKey2 == scratchKey); |
| 936 | REPORTER_ASSERT(reporter, scratchKey == scratchKey2); |
| 937 | |
| 938 | // Ensure that scratch key lookup is correct for negative case. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 939 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 940 | // (following leaks upon test failure). |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 941 | REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey)); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 942 | |
| 943 | // Find the first resource with a scratch key and a copy of a scratch key. |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 944 | TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 945 | GrGpuResource* find = cache->findAndRefScratchResource(scratchKey); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 946 | REPORTER_ASSERT(reporter, find != nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 947 | find->unref(); |
| 948 | |
| 949 | scratchKey2 = scratchKey; |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 950 | find = cache->findAndRefScratchResource(scratchKey2); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 951 | REPORTER_ASSERT(reporter, find != nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 952 | REPORTER_ASSERT(reporter, find == a || find == b); |
| 953 | |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 954 | GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 955 | REPORTER_ASSERT(reporter, find2 != nullptr); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 956 | REPORTER_ASSERT(reporter, find2 == a || find2 == b); |
| 957 | REPORTER_ASSERT(reporter, find2 != find); |
| 958 | find2->unref(); |
| 959 | find->unref(); |
| 960 | } |
| 961 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 962 | static void test_duplicate_unique_key(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 963 | Mock mock(30000); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 964 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 965 | GrGpu* gpu = mock.gpu(); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 966 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 967 | GrUniqueKey key; |
| 968 | make_unique_key<0>(&key, 0); |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 969 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 970 | // Create two resources that we will attempt to register with the same unique key. |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 971 | TestResource* a = new TestResource(gpu, SkBudgeted::kYes, 11); |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 972 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 973 | // Set key on resource a. |
| 974 | a->resourcePriv().setUniqueKey(key); |
| 975 | REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); |
| 976 | a->unref(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 977 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 978 | // Make sure that redundantly setting a's key works. |
| 979 | a->resourcePriv().setUniqueKey(key); |
| 980 | REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 981 | a->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 982 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 983 | REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getResourceBytes()); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 984 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 985 | |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 986 | // Create resource b and set the same key. It should replace a's unique key cache entry. |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 987 | TestResource* b = new TestResource(gpu, SkBudgeted::kYes, 12); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 988 | b->resourcePriv().setUniqueKey(key); |
| 989 | REPORTER_ASSERT(reporter, b == cache->findAndRefUniqueResource(key)); |
| 990 | b->unref(); |
| 991 | |
| 992 | // Still have two resources because a is still reffed. |
| 993 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 994 | REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() == cache->getResourceBytes()); |
| 995 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 996 | |
| 997 | a->unref(); |
| 998 | // Now a should be gone. |
| 999 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 1000 | REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache->getResourceBytes()); |
| 1001 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 1002 | |
| 1003 | // Now replace b with c, but make sure c can start with one unique key and change it to b's key. |
| 1004 | // Also make b be unreffed when replacement occurs. |
| 1005 | b->unref(); |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 1006 | TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 1007 | GrUniqueKey differentKey; |
| 1008 | make_unique_key<0>(&differentKey, 1); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 1009 | c->resourcePriv().setUniqueKey(differentKey); |
| 1010 | REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
| 1011 | REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() == cache->getResourceBytes()); |
| 1012 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
| 1013 | // c replaces b and b should be immediately purged. |
| 1014 | c->resourcePriv().setUniqueKey(key); |
| 1015 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 1016 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 1017 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 1018 | |
| 1019 | // c shouldn't be purged because it is ref'ed. |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 1020 | cache->purgeUnlockedResources(); |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 1021 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 1022 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 1023 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 1024 | |
| 1025 | // Drop the ref on c, it should be kept alive because it has a unique key. |
| 1026 | c->unref(); |
| 1027 | REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); |
| 1028 | REPORTER_ASSERT(reporter, c->gpuMemorySize() == cache->getResourceBytes()); |
| 1029 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 1030 | |
| 1031 | // Verify that we can find c, then remove its unique key. It should get purged immediately. |
| 1032 | REPORTER_ASSERT(reporter, c == cache->findAndRefUniqueResource(key)); |
| 1033 | c->resourcePriv().removeUniqueKey(); |
| 1034 | c->unref(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1035 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1036 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 1037 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1038 | |
| 1039 | { |
| 1040 | GrUniqueKey key2; |
| 1041 | make_unique_key<0>(&key2, 0); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1042 | sk_sp<TestResource> d(new TestResource(gpu)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1043 | int foo = 4132; |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 1044 | key2.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo))); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1045 | d->resourcePriv().setUniqueKey(key2); |
| 1046 | } |
| 1047 | |
| 1048 | GrUniqueKey key3; |
| 1049 | make_unique_key<0>(&key3, 0); |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 1050 | sk_sp<GrGpuResource> d2(cache->findAndRefUniqueResource(key3)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1051 | REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data() == 4132); |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1054 | static void test_purge_invalidated(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1055 | Mock mock(30000); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1056 | auto dContext = mock.dContext(); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1057 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1058 | GrGpu* gpu = mock.gpu(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1059 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1060 | GrUniqueKey key1, key2, key3; |
| 1061 | make_unique_key<0>(&key1, 1); |
| 1062 | make_unique_key<0>(&key2, 2); |
| 1063 | make_unique_key<0>(&key3, 3); |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 1064 | |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1065 | // Add three resources to the cache. Only c is usable as scratch. |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1066 | TestResource* a = new TestResource(gpu); |
| 1067 | TestResource* b = new TestResource(gpu); |
| 1068 | TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1069 | TestResource::kA_SimulatedProperty); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1070 | a->resourcePriv().setUniqueKey(key1); |
| 1071 | b->resourcePriv().setUniqueKey(key2); |
| 1072 | c->resourcePriv().setUniqueKey(key3); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1073 | a->unref(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1074 | // hold b until *after* the message is sent. |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1075 | c->unref(); |
| 1076 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1077 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); |
| 1078 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); |
| 1079 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1080 | REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1081 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1082 | typedef GrUniqueKeyInvalidatedMessage Msg; |
Robert Phillips | e7a959d | 2021-03-11 14:44:42 -0500 | [diff] [blame] | 1083 | typedef SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t> Bus; |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1084 | |
| 1085 | // Invalidate two of the three, they should be purged and no longer accessible via their keys. |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1086 | Bus::Post(Msg(key1, dContext->priv().contextID())); |
| 1087 | Bus::Post(Msg(key2, dContext->priv().contextID())); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1088 | cache->purgeAsNeeded(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1089 | // a should be deleted now, but we still have a ref on b. |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1090 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); |
| 1091 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1092 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1093 | REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1094 | |
| 1095 | // Invalidate the third. |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1096 | Bus::Post(Msg(key3, dContext->priv().contextID())); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1097 | cache->purgeAsNeeded(); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1098 | // we still have a ref on b, c should be recycled as scratch. |
| 1099 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1100 | REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key3)); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1101 | |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1102 | // make b purgeable. It should be immediately deleted since it has no key. |
| 1103 | b->unref(); |
| 1104 | REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); |
| 1105 | |
| 1106 | // Make sure we actually get to c via it's scratch key, before we say goodbye. |
| 1107 | GrScratchKey scratchKey; |
| 1108 | TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 1109 | GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1110 | REPORTER_ASSERT(reporter, scratch == c); |
| 1111 | SkSafeUnref(scratch); |
| 1112 | |
| 1113 | // Get rid of c. |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 1114 | cache->purgeUnlockedResources(); |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 1115 | scratch = cache->findAndRefScratchResource(scratchKey); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1116 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1117 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1118 | REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes()); |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 1119 | REPORTER_ASSERT(reporter, !scratch); |
| 1120 | SkSafeUnref(scratch); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1123 | static void test_cache_chained_purge(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1124 | Mock mock(30000); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1125 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1126 | GrGpu* gpu = mock.gpu(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1127 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1128 | GrUniqueKey key1, key2; |
| 1129 | make_unique_key<0>(&key1, 1); |
| 1130 | make_unique_key<0>(&key2, 2); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 1131 | |
Ben Wagner | 97c6a0e | 2018-07-11 14:56:22 -0400 | [diff] [blame] | 1132 | sk_sp<TestResource> a(new TestResource(gpu)); |
| 1133 | sk_sp<TestResource> b(new TestResource(gpu)); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1134 | a->resourcePriv().setUniqueKey(key1); |
| 1135 | b->resourcePriv().setUniqueKey(key2); |
bsalomon | 820dd6c | 2014-11-05 12:09:45 -0800 | [diff] [blame] | 1136 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1137 | // Make a cycle |
| 1138 | a->setUnrefWhenDestroyed(b); |
| 1139 | b->setUnrefWhenDestroyed(a); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1140 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1141 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 1142 | |
Ben Wagner | 97c6a0e | 2018-07-11 14:56:22 -0400 | [diff] [blame] | 1143 | TestResource* unownedA = a.release(); |
| 1144 | unownedA->unref(); |
| 1145 | b.reset(); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1146 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1147 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1148 | |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 1149 | cache->purgeUnlockedResources(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1150 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1151 | |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1152 | // Break the cycle |
Ben Wagner | 97c6a0e | 2018-07-11 14:56:22 -0400 | [diff] [blame] | 1153 | unownedA->setUnrefWhenDestroyed(nullptr); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1154 | REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 1155 | |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 1156 | cache->purgeUnlockedResources(); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1157 | REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); |
commit-bot@chromium.org | bd58feb | 2014-01-17 17:56:21 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1160 | static void test_timestamp_wrap(skiatest::Reporter* reporter) { |
| 1161 | static const int kCount = 50; |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1162 | static const int kLockedFreq = 8; |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1163 | static const int kBudgetSize = 0; // always over budget |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1164 | |
| 1165 | SkRandom random; |
| 1166 | |
| 1167 | // Run the test 2*kCount times; |
| 1168 | for (int i = 0; i < 2 * kCount; ++i ) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1169 | Mock mock(kBudgetSize); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1170 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1171 | GrGpu* gpu = mock.gpu(); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1172 | |
| 1173 | // Pick a random number of resources to add before the timestamp will wrap. |
Ben Wagner | b089765 | 2018-06-15 15:37:57 +0000 | [diff] [blame] | 1174 | cache->changeTimestamp(UINT32_MAX - random.nextULessThan(kCount + 1)); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1175 | |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1176 | static const int kNumToPurge = kCount; |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1177 | |
| 1178 | SkTDArray<int> shouldPurgeIdxs; |
| 1179 | int purgeableCnt = 0; |
| 1180 | SkTDArray<GrGpuResource*> resourcesToUnref; |
| 1181 | |
| 1182 | // Add kCount resources, holding onto resources at random so we have a mix of purgeable and |
| 1183 | // unpurgeable resources. |
| 1184 | for (int j = 0; j < kCount; ++j) { |
| 1185 | GrUniqueKey key; |
| 1186 | make_unique_key<0>(&key, j); |
| 1187 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1188 | TestResource* r = new TestResource(gpu); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1189 | r->resourcePriv().setUniqueKey(key); |
| 1190 | if (random.nextU() % kLockedFreq) { |
| 1191 | // Make this is purgeable. |
| 1192 | r->unref(); |
| 1193 | ++purgeableCnt; |
| 1194 | if (purgeableCnt <= kNumToPurge) { |
| 1195 | *shouldPurgeIdxs.append() = j; |
| 1196 | } |
| 1197 | } else { |
| 1198 | *resourcesToUnref.append() = r; |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | // Verify that the correct resources were purged. |
| 1203 | int currShouldPurgeIdx = 0; |
| 1204 | for (int j = 0; j < kCount; ++j) { |
| 1205 | GrUniqueKey key; |
| 1206 | make_unique_key<0>(&key, j); |
| 1207 | GrGpuResource* res = cache->findAndRefUniqueResource(key); |
| 1208 | if (currShouldPurgeIdx < shouldPurgeIdxs.count() && |
| 1209 | shouldPurgeIdxs[currShouldPurgeIdx] == j) { |
| 1210 | ++currShouldPurgeIdx; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1211 | REPORTER_ASSERT(reporter, nullptr == res); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1212 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1213 | REPORTER_ASSERT(reporter, nullptr != res); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1214 | } |
| 1215 | SkSafeUnref(res); |
| 1216 | } |
| 1217 | |
| 1218 | for (int j = 0; j < resourcesToUnref.count(); ++j) { |
| 1219 | resourcesToUnref[j]->unref(); |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1224 | static void test_time_purge(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1225 | Mock mock(1000000); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1226 | auto dContext = mock.dContext(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1227 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1228 | GrGpu* gpu = mock.gpu(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1229 | |
| 1230 | static constexpr int kCnts[] = {1, 10, 1024}; |
| 1231 | auto nowish = []() { |
| 1232 | // We sleep so that we ensure we get a value that is greater than the last call to |
| 1233 | // GrStdSteadyClock::now(). |
| 1234 | std::this_thread::sleep_for(GrStdSteadyClock::duration(5)); |
| 1235 | auto result = GrStdSteadyClock::now(); |
| 1236 | // Also sleep afterwards so we don't get this value again. |
| 1237 | std::this_thread::sleep_for(GrStdSteadyClock::duration(5)); |
| 1238 | return result; |
| 1239 | }; |
| 1240 | |
| 1241 | for (int cnt : kCnts) { |
| 1242 | std::unique_ptr<GrStdSteadyClock::time_point[]> timeStamps( |
| 1243 | new GrStdSteadyClock::time_point[cnt]); |
| 1244 | { |
| 1245 | // Insert resources and get time points between each addition. |
| 1246 | for (int i = 0; i < cnt; ++i) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1247 | TestResource* r = new TestResource(gpu); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1248 | GrUniqueKey k; |
| 1249 | make_unique_key<1>(&k, i); |
| 1250 | r->resourcePriv().setUniqueKey(k); |
| 1251 | r->unref(); |
| 1252 | timeStamps.get()[i] = nowish(); |
| 1253 | } |
| 1254 | |
| 1255 | // Purge based on the time points between resource additions. Each purge should remove |
| 1256 | // the oldest resource. |
| 1257 | for (int i = 0; i < cnt; ++i) { |
| 1258 | cache->purgeResourcesNotUsedSince(timeStamps[i]); |
| 1259 | REPORTER_ASSERT(reporter, cnt - i - 1 == cache->getResourceCount()); |
| 1260 | for (int j = 0; j < i; ++j) { |
| 1261 | GrUniqueKey k; |
| 1262 | make_unique_key<1>(&k, j); |
| 1263 | GrGpuResource* r = cache->findAndRefUniqueResource(k); |
| 1264 | REPORTER_ASSERT(reporter, !SkToBool(r)); |
| 1265 | SkSafeUnref(r); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 1270 | cache->purgeUnlockedResources(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | // Do a similar test but where we leave refs on some resources to prevent them from being |
| 1274 | // purged. |
| 1275 | { |
| 1276 | std::unique_ptr<GrGpuResource* []> refedResources(new GrGpuResource*[cnt / 2]); |
| 1277 | for (int i = 0; i < cnt; ++i) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1278 | TestResource* r = new TestResource(gpu); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1279 | GrUniqueKey k; |
| 1280 | make_unique_key<1>(&k, i); |
| 1281 | r->resourcePriv().setUniqueKey(k); |
| 1282 | // Leave a ref on every other resource, beginning with the first. |
| 1283 | if (SkToBool(i & 0x1)) { |
| 1284 | refedResources.get()[i / 2] = r; |
| 1285 | } else { |
| 1286 | r->unref(); |
| 1287 | } |
| 1288 | timeStamps.get()[i] = nowish(); |
| 1289 | } |
| 1290 | |
| 1291 | for (int i = 0; i < cnt; ++i) { |
| 1292 | // Should get a resource purged every other frame. |
| 1293 | cache->purgeResourcesNotUsedSince(timeStamps[i]); |
| 1294 | REPORTER_ASSERT(reporter, cnt - i / 2 - 1 == cache->getResourceCount()); |
| 1295 | } |
| 1296 | |
| 1297 | // Unref all the resources that we kept refs on in the first loop. |
| 1298 | for (int i = 0; i < (cnt / 2); ++i) { |
| 1299 | refedResources.get()[i]->unref(); |
| 1300 | cache->purgeResourcesNotUsedSince(nowish()); |
| 1301 | REPORTER_ASSERT(reporter, cnt / 2 - i - 1 == cache->getResourceCount()); |
| 1302 | } |
| 1303 | |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 1304 | cache->purgeUnlockedResources(); |
| 1305 | } |
| 1306 | |
| 1307 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1308 | |
| 1309 | // Do a similar test where we alternate adding scratch and uniquely keyed resources, but |
| 1310 | // then purge old scratch resources. |
| 1311 | { |
| 1312 | for (int i = 0; i < cnt; ++i) { |
| 1313 | const bool isScratch = (i % 2 == 0); |
| 1314 | const SkBudgeted budgeted = SkBudgeted::kYes; |
| 1315 | const TestResource::SimulatedProperty property = TestResource::kA_SimulatedProperty; |
| 1316 | TestResource* r = isScratch ? TestResource::CreateScratch(gpu, budgeted, property) |
| 1317 | : new TestResource(gpu, budgeted, property); |
| 1318 | if (!isScratch) { |
| 1319 | GrUniqueKey k; |
| 1320 | make_unique_key<1>(&k, i); |
| 1321 | r->resourcePriv().setUniqueKey(k); |
| 1322 | } |
| 1323 | r->unref(); |
| 1324 | timeStamps.get()[i] = nowish(); |
| 1325 | } |
| 1326 | |
| 1327 | for (int i = 0; i < cnt; ++i) { |
| 1328 | // Should get a resource purged every other frame, since the uniquely keyed |
| 1329 | // resources will not be considered. |
| 1330 | cache->purgeResourcesNotUsedSince(timeStamps[i], /*scratchResourcesOnly=*/true); |
| 1331 | REPORTER_ASSERT(reporter, cnt - i / 2 - 1 == cache->getResourceCount()); |
| 1332 | } |
| 1333 | // Unref remaining resources |
| 1334 | cache->purgeResourcesNotUsedSince(nowish()); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1338 | |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 1339 | // Verify that calling flush() on a context with nothing to do will not trigger resource |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1340 | // eviction |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1341 | dContext->flushAndSubmit(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1342 | for (int i = 0; i < 10; ++i) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1343 | TestResource* r = new TestResource(gpu); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1344 | GrUniqueKey k; |
| 1345 | make_unique_key<1>(&k, i); |
| 1346 | r->resourcePriv().setUniqueKey(k); |
| 1347 | r->unref(); |
| 1348 | } |
| 1349 | REPORTER_ASSERT(reporter, 10 == cache->getResourceCount()); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1350 | dContext->flushAndSubmit(); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1351 | REPORTER_ASSERT(reporter, 10 == cache->getResourceCount()); |
| 1352 | cache->purgeResourcesNotUsedSince(nowish()); |
| 1353 | REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); |
| 1354 | } |
| 1355 | } |
| 1356 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1357 | static void test_partial_purge(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1358 | Mock mock(100); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1359 | auto dContext = mock.dContext(); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1360 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1361 | GrGpu* gpu = mock.gpu(); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1362 | |
| 1363 | enum TestsCase { |
| 1364 | kOnlyScratch_TestCase = 0, |
| 1365 | kPartialScratch_TestCase = 1, |
| 1366 | kAllScratch_TestCase = 2, |
| 1367 | kPartial_TestCase = 3, |
| 1368 | kAll_TestCase = 4, |
| 1369 | kNone_TestCase = 5, |
| 1370 | kEndTests_TestCase = kNone_TestCase + 1 |
| 1371 | }; |
| 1372 | |
| 1373 | for (int testCase = 0; testCase < kEndTests_TestCase; testCase++) { |
| 1374 | |
| 1375 | GrUniqueKey key1, key2, key3; |
| 1376 | make_unique_key<0>(&key1, 1); |
| 1377 | make_unique_key<0>(&key2, 2); |
| 1378 | make_unique_key<0>(&key3, 3); |
| 1379 | |
| 1380 | // Add three unique resources to the cache. |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 1381 | TestResource *unique1 = new TestResource(gpu, SkBudgeted::kYes, 10); |
| 1382 | TestResource *unique2 = new TestResource(gpu, SkBudgeted::kYes, 11); |
| 1383 | TestResource *unique3 = new TestResource(gpu, SkBudgeted::kYes, 12); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1384 | |
| 1385 | unique1->resourcePriv().setUniqueKey(key1); |
| 1386 | unique2->resourcePriv().setUniqueKey(key2); |
| 1387 | unique3->resourcePriv().setUniqueKey(key3); |
| 1388 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1389 | // Add two scratch resources to the cache. |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1390 | TestResource *scratch1 = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 1391 | TestResource::kA_SimulatedProperty, |
| 1392 | 13); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1393 | TestResource *scratch2 = TestResource::CreateScratch(gpu, SkBudgeted::kYes, |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 1394 | TestResource::kB_SimulatedProperty, |
| 1395 | 14); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1396 | |
| 1397 | REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount()); |
| 1398 | REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes()); |
| 1399 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
| 1400 | |
| 1401 | // Add resources to the purgeable queue |
| 1402 | unique1->unref(); |
| 1403 | scratch1->unref(); |
| 1404 | unique2->unref(); |
| 1405 | scratch2->unref(); |
| 1406 | unique3->unref(); |
| 1407 | |
| 1408 | REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount()); |
| 1409 | REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes()); |
| 1410 | REPORTER_ASSERT(reporter, 60 == cache->getPurgeableBytes()); |
| 1411 | |
| 1412 | switch(testCase) { |
| 1413 | case kOnlyScratch_TestCase: { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1414 | dContext->purgeUnlockedResources(14, true); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1415 | REPORTER_ASSERT(reporter, 3 == cache->getBudgetedResourceCount()); |
| 1416 | REPORTER_ASSERT(reporter, 33 == cache->getBudgetedResourceBytes()); |
| 1417 | break; |
| 1418 | } |
| 1419 | case kPartialScratch_TestCase: { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1420 | dContext->purgeUnlockedResources(3, true); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1421 | REPORTER_ASSERT(reporter, 4 == cache->getBudgetedResourceCount()); |
| 1422 | REPORTER_ASSERT(reporter, 47 == cache->getBudgetedResourceBytes()); |
| 1423 | break; |
| 1424 | } |
| 1425 | case kAllScratch_TestCase: { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1426 | dContext->purgeUnlockedResources(50, true); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1427 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 1428 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
| 1429 | break; |
| 1430 | } |
| 1431 | case kPartial_TestCase: { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1432 | dContext->purgeUnlockedResources(13, false); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1433 | REPORTER_ASSERT(reporter, 3 == cache->getBudgetedResourceCount()); |
| 1434 | REPORTER_ASSERT(reporter, 37 == cache->getBudgetedResourceBytes()); |
| 1435 | break; |
| 1436 | } |
| 1437 | case kAll_TestCase: { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1438 | dContext->purgeUnlockedResources(50, false); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1439 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 1440 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); |
| 1441 | break; |
| 1442 | } |
| 1443 | case kNone_TestCase: { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1444 | dContext->purgeUnlockedResources(0, true); |
| 1445 | dContext->purgeUnlockedResources(0, false); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1446 | REPORTER_ASSERT(reporter, 5 == cache->getBudgetedResourceCount()); |
| 1447 | REPORTER_ASSERT(reporter, 60 == cache->getBudgetedResourceBytes()); |
| 1448 | REPORTER_ASSERT(reporter, 60 == cache->getPurgeableBytes()); |
| 1449 | break; |
| 1450 | } |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 1451 | } |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1452 | |
| 1453 | // ensure all are purged before the next |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 1454 | dContext->priv().getResourceCache()->purgeUnlockedResources(); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1455 | REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); |
| 1456 | REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); |
| 1457 | |
| 1458 | } |
| 1459 | } |
| 1460 | |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1461 | static void test_custom_data(skiatest::Reporter* reporter) { |
| 1462 | GrUniqueKey key1, key2; |
| 1463 | make_unique_key<0>(&key1, 1); |
| 1464 | make_unique_key<0>(&key2, 2); |
| 1465 | int foo = 4132; |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 1466 | key1.setCustomData(SkData::MakeWithCopy(&foo, sizeof(foo))); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1467 | REPORTER_ASSERT(reporter, *(int*) key1.getCustomData()->data() == 4132); |
| 1468 | REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); |
| 1469 | |
| 1470 | // Test that copying a key also takes a ref on its custom data. |
| 1471 | GrUniqueKey key3 = key1; |
| 1472 | REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); |
| 1473 | } |
| 1474 | |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1475 | static void test_abandoned(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1476 | Mock mock(300); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1477 | auto dContext = mock.dContext(); |
| 1478 | GrGpu* gpu = mock.gpu(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1479 | |
| 1480 | sk_sp<GrGpuResource> resource(new TestResource(gpu)); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1481 | dContext->abandonContext(); |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1482 | |
| 1483 | REPORTER_ASSERT(reporter, resource->wasDestroyed()); |
| 1484 | |
| 1485 | // Call all the public methods on resource in the abandoned state. They shouldn't crash. |
| 1486 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 1487 | resource->uniqueID(); |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1488 | resource->getUniqueKey(); |
| 1489 | resource->wasDestroyed(); |
| 1490 | resource->gpuMemorySize(); |
| 1491 | resource->getContext(); |
| 1492 | |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1493 | resource->resourcePriv().getScratchKey(); |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 1494 | resource->resourcePriv().budgetedType(); |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1495 | resource->resourcePriv().makeBudgeted(); |
| 1496 | resource->resourcePriv().makeUnbudgeted(); |
| 1497 | resource->resourcePriv().removeScratchKey(); |
| 1498 | GrUniqueKey key; |
| 1499 | make_unique_key<0>(&key, 1); |
| 1500 | resource->resourcePriv().setUniqueKey(key); |
| 1501 | resource->resourcePriv().removeUniqueKey(); |
| 1502 | } |
| 1503 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1504 | static void test_tags(skiatest::Reporter* reporter) { |
| 1505 | #ifdef SK_DEBUG |
| 1506 | // We will insert 1 resource with tag "tag1", 2 with "tag2", and so on, up through kLastTagIdx. |
| 1507 | static constexpr int kLastTagIdx = 10; |
| 1508 | static constexpr int kNumResources = kLastTagIdx * (kLastTagIdx + 1) / 2; |
| 1509 | |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1510 | Mock mock(kNumResources * TestResource::kDefaultSize); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1511 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1512 | GrGpu* gpu = mock.gpu(); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1513 | |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 1514 | // tag strings are expected to be long lived |
| 1515 | std::vector<SkString> tagStrings; |
| 1516 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1517 | SkString tagStr; |
| 1518 | int tagIdx = 0; |
| 1519 | int currTagCnt = 0; |
| 1520 | |
| 1521 | for (int i = 0; i < kNumResources; ++i, ++currTagCnt) { |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 1522 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 1523 | sk_sp<GrGpuResource> resource(new TestResource(gpu)); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1524 | GrUniqueKey key; |
| 1525 | if (currTagCnt == tagIdx) { |
| 1526 | tagIdx += 1; |
| 1527 | currTagCnt = 0; |
| 1528 | tagStr.printf("tag%d", tagIdx); |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 1529 | tagStrings.emplace_back(tagStr); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1530 | } |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 1531 | make_unique_key<1>(&key, i, tagStrings.back().c_str()); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1532 | resource->resourcePriv().setUniqueKey(key); |
| 1533 | } |
| 1534 | SkASSERT(kLastTagIdx == tagIdx); |
| 1535 | SkASSERT(currTagCnt == kLastTagIdx); |
| 1536 | |
| 1537 | // Test i = 0 to exercise unused tag string. |
| 1538 | for (int i = 0; i <= kLastTagIdx; ++i) { |
| 1539 | tagStr.printf("tag%d", i); |
| 1540 | REPORTER_ASSERT(reporter, cache->countUniqueKeysWithTag(tagStr.c_str()) == i); |
| 1541 | } |
| 1542 | #endif |
| 1543 | } |
| 1544 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1545 | static void test_free_texture_messages(skiatest::Reporter* reporter) { |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1546 | Mock mock(30000); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1547 | auto dContext = mock.dContext(); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1548 | GrResourceCache* cache = mock.cache(); |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1549 | GrGpu* gpu = mock.gpu(); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1550 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1551 | GrBackendTexture backends[3]; |
| 1552 | GrTexture* wrapped[3]; |
| 1553 | int freed[3] = { 0, 0, 0 }; |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1554 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1555 | auto releaseProc = [](void* ctx) { |
| 1556 | int* index = (int*) ctx; |
| 1557 | *index = 1; |
| 1558 | }; |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1559 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1560 | for (int i = 0; i < 3; ++i) { |
Robert Phillips | 0c5bb2f | 2020-07-17 15:40:13 -0400 | [diff] [blame] | 1561 | backends[i] = dContext->createBackendTexture(16, 16, SkColorType::kRGBA_8888_SkColorType, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 1562 | GrMipmapped::kNo, GrRenderable::kNo); |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 1563 | wrapped[i] = gpu->wrapBackendTexture(backends[i], |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1564 | GrWrapOwnership::kBorrow_GrWrapOwnership, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 1565 | (i < 2) ? GrWrapCacheable::kYes : GrWrapCacheable::kNo, |
| 1566 | GrIOType::kRead_GrIOType) |
| 1567 | .release(); |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1568 | wrapped[i]->setRelease(releaseProc, &freed[i]); |
| 1569 | } |
| 1570 | |
| 1571 | cache->insertDelayedTextureUnref(wrapped[0]); |
| 1572 | cache->insertDelayedTextureUnref(wrapped[1]); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1573 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 1574 | // An uncacheable cross-context should not be purged as soon as we drop our ref. This |
| 1575 | // is because inserting it as a cross-context resource actually holds a ref until the |
| 1576 | // message is received. |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1577 | cache->insertDelayedTextureUnref(wrapped[2]); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 1578 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1579 | REPORTER_ASSERT(reporter, 0 == (freed[0] + freed[1] + freed[2])); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1580 | |
| 1581 | // Have only ref waiting on message. |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1582 | wrapped[0]->unref(); |
| 1583 | wrapped[1]->unref(); |
| 1584 | wrapped[2]->unref(); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1585 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1586 | REPORTER_ASSERT(reporter, 0 == (freed[0] + freed[1] + freed[2])); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1587 | |
| 1588 | // This should free nothing since no messages were sent. |
| 1589 | cache->purgeAsNeeded(); |
| 1590 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1591 | REPORTER_ASSERT(reporter, 0 == (freed[0] + freed[1] + freed[2])); |
| 1592 | |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1593 | // Send message to free the first resource |
Robert Phillips | d074b62 | 2021-03-15 08:49:24 -0400 | [diff] [blame] | 1594 | GrTextureFreedMessage msg1{wrapped[0], dContext->directContextID()}; |
| 1595 | SkMessageBus<GrTextureFreedMessage, GrDirectContext::DirectContextID>::Post(msg1); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 1596 | cache->purgeAsNeeded(); |
| 1597 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1598 | REPORTER_ASSERT(reporter, 1 == (freed[0] + freed[1] + freed[2])); |
| 1599 | REPORTER_ASSERT(reporter, 1 == freed[0]); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 1600 | |
Robert Phillips | d074b62 | 2021-03-15 08:49:24 -0400 | [diff] [blame] | 1601 | GrTextureFreedMessage msg2{wrapped[2], dContext->directContextID()}; |
| 1602 | SkMessageBus<GrTextureFreedMessage, GrDirectContext::DirectContextID>::Post(msg2); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1603 | cache->purgeAsNeeded(); |
| 1604 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1605 | REPORTER_ASSERT(reporter, 2 == (freed[0] + freed[1] + freed[2])); |
| 1606 | REPORTER_ASSERT(reporter, 0 == freed[1]); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1607 | |
| 1608 | mock.reset(); |
| 1609 | |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1610 | REPORTER_ASSERT(reporter, 3 == (freed[0] + freed[1] + freed[2])); |
Greg Daniel | c27eb72 | 2018-08-10 09:48:08 -0400 | [diff] [blame] | 1611 | } |
| 1612 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 1613 | DEF_GPUTEST(ResourceCacheMisc, reporter, /* options */) { |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1614 | // The below tests create their own mock contexts. |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1615 | test_no_key(reporter); |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 1616 | test_purge_unlocked(reporter); |
Greg Daniel | 1fd8ac8 | 2020-12-11 11:22:01 -0500 | [diff] [blame] | 1617 | test_purge_command_buffer_usage(reporter); |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 1618 | test_budgeting(reporter); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 1619 | test_unbudgeted(reporter); |
bsalomon | c2f35b7 | 2015-01-23 07:19:22 -0800 | [diff] [blame] | 1620 | test_unbudgeted_to_scratch(reporter); |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 1621 | test_duplicate_unique_key(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1622 | test_duplicate_scratch_key(reporter); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1623 | test_remove_scratch_key(reporter); |
bsalomon | 1c60dfe | 2015-01-21 09:32:40 -0800 | [diff] [blame] | 1624 | test_scratch_key_consistency(reporter); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 1625 | test_purge_invalidated(reporter); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1626 | test_cache_chained_purge(reporter); |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 1627 | test_timestamp_wrap(reporter); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 1628 | test_time_purge(reporter); |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 1629 | test_partial_purge(reporter); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 1630 | test_custom_data(reporter); |
bsalomon | c6363ef | 2015-09-24 07:07:40 -0700 | [diff] [blame] | 1631 | test_abandoned(reporter); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 1632 | test_tags(reporter); |
Robert Phillips | ddc2148 | 2019-10-16 14:30:09 -0400 | [diff] [blame] | 1633 | test_free_texture_messages(reporter); |
commit-bot@chromium.org | c28f555 | 2013-08-08 22:55:21 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
Robert Phillips | 1dfc77c | 2019-10-16 16:39:45 -0400 | [diff] [blame] | 1636 | // This simulates a portion of Chrome's context abandonment processing. |
| 1637 | // Please see: crbug.com/1011368 and crbug.com/1014993 |
| 1638 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceMessagesAfterAbandon, reporter, ctxInfo) { |
Robert Phillips | d074b62 | 2021-03-15 08:49:24 -0400 | [diff] [blame] | 1639 | auto dContext = ctxInfo.directContext(); |
| 1640 | GrGpu* gpu = dContext->priv().getGpu(); |
| 1641 | GrResourceCache* cache = dContext->priv().getResourceCache(); |
Robert Phillips | 1dfc77c | 2019-10-16 16:39:45 -0400 | [diff] [blame] | 1642 | |
Robert Phillips | d074b62 | 2021-03-15 08:49:24 -0400 | [diff] [blame] | 1643 | GrBackendTexture backend = dContext->createBackendTexture(16, 16, |
| 1644 | SkColorType::kRGBA_8888_SkColorType, |
| 1645 | GrMipmapped::kNo, GrRenderable::kNo); |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 1646 | GrTexture* tex = gpu->wrapBackendTexture(backend, |
Robert Phillips | 1dfc77c | 2019-10-16 16:39:45 -0400 | [diff] [blame] | 1647 | GrWrapOwnership::kBorrow_GrWrapOwnership, |
| 1648 | GrWrapCacheable::kYes, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 1649 | GrIOType::kRead_GrIOType) |
| 1650 | .release(); |
Robert Phillips | 1dfc77c | 2019-10-16 16:39:45 -0400 | [diff] [blame] | 1651 | |
| 1652 | auto releaseProc = [](void* ctx) { |
| 1653 | int* index = (int*) ctx; |
| 1654 | *index = 1; |
| 1655 | }; |
| 1656 | |
| 1657 | int freed = 0; |
| 1658 | |
| 1659 | tex->setRelease(releaseProc, &freed); |
| 1660 | |
| 1661 | cache->insertDelayedTextureUnref(tex); |
| 1662 | |
| 1663 | // Now only the cache is holding a ref to this texture |
| 1664 | tex->unref(); |
| 1665 | |
| 1666 | REPORTER_ASSERT(reporter, 0 == freed); |
| 1667 | |
Greg Daniel | 1a5d2d5 | 2019-12-04 11:14:29 -0500 | [diff] [blame] | 1668 | // We must delete the backend texture before abandoning the context in vulkan. We just do it |
| 1669 | // for all the backends for consistency. |
Robert Phillips | d074b62 | 2021-03-15 08:49:24 -0400 | [diff] [blame] | 1670 | dContext->deleteBackendTexture(backend); |
| 1671 | dContext->abandonContext(); |
Robert Phillips | 1dfc77c | 2019-10-16 16:39:45 -0400 | [diff] [blame] | 1672 | |
| 1673 | REPORTER_ASSERT(reporter, 1 == freed); |
| 1674 | |
| 1675 | // In the past, creating this message could cause an exception due to |
| 1676 | // an un-safe downcast from GrTexture to GrGpuResource |
Robert Phillips | d074b62 | 2021-03-15 08:49:24 -0400 | [diff] [blame] | 1677 | GrTextureFreedMessage msg{tex, dContext->directContextID()}; |
| 1678 | SkMessageBus<GrTextureFreedMessage, GrDirectContext::DirectContextID>::Post(msg); |
Robert Phillips | 1dfc77c | 2019-10-16 16:39:45 -0400 | [diff] [blame] | 1679 | |
Greg Daniel | f0e04f0 | 2019-12-04 15:17:54 -0500 | [diff] [blame] | 1680 | // This doesn't actually do anything but it does trigger us to read messages |
Robert Phillips | d074b62 | 2021-03-15 08:49:24 -0400 | [diff] [blame] | 1681 | dContext->purgeUnlockedResources(false); |
Robert Phillips | 1dfc77c | 2019-10-16 16:39:45 -0400 | [diff] [blame] | 1682 | } |
| 1683 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1684 | //////////////////////////////////////////////////////////////////////////////// |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 1685 | static sk_sp<GrTexture> make_normal_texture(GrResourceProvider* provider, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 1686 | GrRenderable renderable, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1687 | SkISize dims, |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1688 | int sampleCnt) { |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 1689 | auto format = provider->caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, renderable); |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 1690 | return provider->createTexture(dims, format, GrTextureType::k2D, renderable, sampleCnt, |
| 1691 | GrMipmapped::kNo, SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1692 | } |
| 1693 | |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 1694 | static sk_sp<GrTextureProxy> make_mipmap_proxy(GrRecordingContext* rContext, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 1695 | GrRenderable renderable, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1696 | SkISize dims, |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1697 | int sampleCnt) { |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 1698 | GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); |
| 1699 | const GrCaps* caps = rContext->priv().caps(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 1700 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1701 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 1702 | const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 1703 | GrRenderable::kNo); |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1704 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 1705 | return proxyProvider->createProxy(format, dims, renderable, sampleCnt, GrMipmapped::kYes, |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 1706 | SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | // Exercise GrSurface::gpuMemorySize for different combos of MSAA, RT-only, |
| 1710 | // Texture-only, both-RT-and-Texture and MIPmapped |
| 1711 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GPUMemorySize, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 1712 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1713 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 1714 | const GrCaps* caps = context->priv().caps(); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1715 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1716 | static constexpr SkISize kSize = {64, 64}; |
| 1717 | static constexpr auto kArea = kSize.area(); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1718 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1719 | // Normal versions |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1720 | { |
| 1721 | sk_sp<GrTexture> tex; |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1722 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1723 | tex = make_normal_texture(resourceProvider, GrRenderable::kYes, kSize, 1); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1724 | size_t size = tex->gpuMemorySize(); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1725 | REPORTER_ASSERT(reporter, kArea*4 == size); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1726 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 1727 | size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, tex->backendFormat()); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1728 | if (sampleCount >= 4) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1729 | tex = make_normal_texture(resourceProvider, GrRenderable::kYes, kSize, sampleCount); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1730 | size = tex->gpuMemorySize(); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1731 | REPORTER_ASSERT(reporter, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1732 | kArea*4 == size || // msaa4 failed |
| 1733 | kArea*4*sampleCount == size || // auto-resolving |
| 1734 | kArea*4*(sampleCount+1) == size); // explicit resolve buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1735 | } |
| 1736 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1737 | tex = make_normal_texture(resourceProvider, GrRenderable::kNo, kSize, 1); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1738 | size = tex->gpuMemorySize(); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1739 | REPORTER_ASSERT(reporter, kArea*4 == size); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1740 | } |
| 1741 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1742 | // Mipmapped versions |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 1743 | if (caps->mipmapSupport()) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1744 | sk_sp<GrTextureProxy> proxy; |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1745 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1746 | proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, 1); |
Greg Daniel | 0eca74c | 2020-10-01 13:46:00 -0400 | [diff] [blame] | 1747 | size_t size = proxy->gpuMemorySize(); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1748 | REPORTER_ASSERT(reporter, kArea*4 + (kArea*4)/3 == size); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1749 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 1750 | size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, proxy->backendFormat()); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 1751 | if (sampleCount >= 4) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1752 | proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, sampleCount); |
Greg Daniel | 0eca74c | 2020-10-01 13:46:00 -0400 | [diff] [blame] | 1753 | size = proxy->gpuMemorySize(); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1754 | REPORTER_ASSERT(reporter, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1755 | kArea*4 + (kArea*4)/3 == size || // msaa4 failed |
| 1756 | kArea*4*sampleCount + (kArea*4)/3 == size || // auto-resolving |
| 1757 | kArea*4*(sampleCount+1) + (kArea*4)/3 == size); // explicit resolve buffer |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1758 | } |
Robert Phillips | 1b35256 | 2017-04-05 18:56:21 +0000 | [diff] [blame] | 1759 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1760 | proxy = make_mipmap_proxy(context, GrRenderable::kNo, kSize, 1); |
Greg Daniel | 0eca74c | 2020-10-01 13:46:00 -0400 | [diff] [blame] | 1761 | size = proxy->gpuMemorySize(); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1762 | REPORTER_ASSERT(reporter, kArea*4 + (kArea*4)/3 == size); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 1763 | } |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 1764 | } |
Brian Salomon | 8cefa3e | 2019-04-04 11:39:55 -0400 | [diff] [blame] | 1765 | |
Adlai Holler | e1c8a38 | 2021-04-08 15:30:12 -0400 | [diff] [blame] | 1766 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PurgeToMakeHeadroom, reporter, ctxInfo) { |
| 1767 | constexpr size_t kTexSize = 16 * 16 * 4; |
| 1768 | |
| 1769 | auto dContext = ctxInfo.directContext(); |
| 1770 | dContext->setResourceCacheLimit(2 * kTexSize); |
| 1771 | auto resourceProvider = dContext->priv().resourceProvider(); |
| 1772 | auto resourceCache = dContext->priv().getResourceCache(); |
| 1773 | for (bool success : { true, false }) { |
| 1774 | reporter->push(SkString(success ? "success" : "failure")); |
| 1775 | |
| 1776 | resourceCache->releaseAll(); |
| 1777 | REPORTER_ASSERT(reporter, resourceCache->getBudgetedResourceBytes() == 0); |
| 1778 | |
| 1779 | // Make one unpurgeable texture and one purgeable texture. |
| 1780 | auto lockedTex = make_normal_texture(resourceProvider, GrRenderable::kNo, {16, 16}, 1); |
| 1781 | REPORTER_ASSERT(reporter, lockedTex->gpuMemorySize() == kTexSize); |
| 1782 | |
| 1783 | // N.b. this surface is renderable so "reuseScratchTextures = false" won't mess us up. |
| 1784 | auto purgeableTex = make_normal_texture(resourceProvider, GrRenderable::kYes, {16, 16}, 1); |
| 1785 | if (success) { |
| 1786 | purgeableTex = nullptr; |
| 1787 | } |
| 1788 | |
| 1789 | size_t expectedPurgeable = success ? kTexSize : 0; |
| 1790 | REPORTER_ASSERT(reporter, expectedPurgeable == resourceCache->getPurgeableBytes(), |
| 1791 | "%zu vs %zu", expectedPurgeable, resourceCache->getPurgeableBytes()); |
| 1792 | REPORTER_ASSERT(reporter, success == resourceCache->purgeToMakeHeadroom(kTexSize)); |
| 1793 | size_t expectedBudgeted = success ? kTexSize : (2 * kTexSize); |
| 1794 | REPORTER_ASSERT(reporter, expectedBudgeted == resourceCache->getBudgetedResourceBytes(), |
| 1795 | "%zu vs %zu", expectedBudgeted, resourceCache->getBudgetedResourceBytes()); |
| 1796 | reporter->pop(); |
| 1797 | } |
| 1798 | } |
| 1799 | |
Brian Salomon | 8cefa3e | 2019-04-04 11:39:55 -0400 | [diff] [blame] | 1800 | #if GR_GPU_STATS |
| 1801 | DEF_GPUTEST_FOR_MOCK_CONTEXT(OverbudgetFlush, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 1802 | auto context = ctxInfo.directContext(); |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1803 | context->setResourceCacheLimit(1); |
Brian Salomon | 8cefa3e | 2019-04-04 11:39:55 -0400 | [diff] [blame] | 1804 | |
| 1805 | // Helper that determines if cache is overbudget. |
| 1806 | auto overbudget = [context] { |
| 1807 | int uNum; |
| 1808 | size_t uSize; |
| 1809 | context->getResourceCacheUsage(&uNum, &uSize); |
Robert Phillips | cf39f37 | 2019-09-03 10:29:20 -0400 | [diff] [blame] | 1810 | size_t bSize = context->getResourceCacheLimit(); |
| 1811 | return uSize > bSize; |
Brian Salomon | 8cefa3e | 2019-04-04 11:39:55 -0400 | [diff] [blame] | 1812 | }; |
| 1813 | |
| 1814 | // Helper that does a trivial draw to a surface. |
| 1815 | auto drawToSurf = [](SkSurface* surf) { |
| 1816 | surf->getCanvas()->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 1817 | }; |
| 1818 | |
| 1819 | // Helper that checks whether a flush has occurred between calls. |
| 1820 | int baseFlushCount = 0; |
| 1821 | auto getFlushCountDelta = [context, &baseFlushCount]() { |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 1822 | int cur = context->priv().getGpu()->stats()->numSubmitToGpus(); |
Brian Salomon | 8cefa3e | 2019-04-04 11:39:55 -0400 | [diff] [blame] | 1823 | int delta = cur - baseFlushCount; |
| 1824 | baseFlushCount = cur; |
| 1825 | return delta; |
| 1826 | }; |
| 1827 | |
| 1828 | auto info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 1829 | auto surf1 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 1, nullptr); |
| 1830 | auto surf2 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 1, nullptr); |
| 1831 | |
| 1832 | drawToSurf(surf1.get()); |
| 1833 | drawToSurf(surf2.get()); |
| 1834 | |
| 1835 | // Flush each surface once to ensure that their backing stores are allocated. |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 1836 | surf1->flushAndSubmit(); |
| 1837 | surf2->flushAndSubmit(); |
Brian Salomon | 8cefa3e | 2019-04-04 11:39:55 -0400 | [diff] [blame] | 1838 | REPORTER_ASSERT(reporter, overbudget()); |
| 1839 | getFlushCountDelta(); |
| 1840 | |
| 1841 | // Nothing should be purgeable so drawing to either surface doesn't cause a flush. |
| 1842 | drawToSurf(surf1.get()); |
| 1843 | REPORTER_ASSERT(reporter, !getFlushCountDelta()); |
| 1844 | drawToSurf(surf2.get()); |
| 1845 | REPORTER_ASSERT(reporter, !getFlushCountDelta()); |
| 1846 | REPORTER_ASSERT(reporter, overbudget()); |
| 1847 | |
| 1848 | // Make surf1 purgeable. Drawing to surf2 should flush. |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 1849 | surf1->flushAndSubmit(); |
Brian Salomon | 8cefa3e | 2019-04-04 11:39:55 -0400 | [diff] [blame] | 1850 | surf1.reset(); |
| 1851 | drawToSurf(surf2.get()); |
| 1852 | REPORTER_ASSERT(reporter, getFlushCountDelta()); |
| 1853 | REPORTER_ASSERT(reporter, overbudget()); |
| 1854 | } |
| 1855 | #endif |