primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTraceMemoryDump.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 9 | #include "include/gpu/GrDirectContext.h" |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "tests/Test.h" |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 12 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrDirectContextPriv.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrRenderTarget.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 15 | #include "src/gpu/GrTexture.h" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 16 | #ifdef SK_GL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/gl/GrGLBuffer.h" |
| 18 | #include "src/gpu/gl/GrGLDefines.h" |
| 19 | #include "src/gpu/gl/GrGLGpu.h" |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 20 | #include "src/gpu/gl/GrGLTextureRenderTarget.h" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 21 | #endif |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 22 | |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Build test for SkTraceMemoryDump. |
| 25 | */ |
| 26 | class TestSkTraceMemoryDump : public SkTraceMemoryDump { |
| 27 | public: |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 28 | TestSkTraceMemoryDump(bool shouldDumpWrappedObjects) |
| 29 | : fShouldDumpWrappedObjects(shouldDumpWrappedObjects) {} |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 30 | ~TestSkTraceMemoryDump() override { } |
| 31 | |
| 32 | void dumpNumericValue(const char* dumpName, const char* valueName, const char* units, |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 33 | uint64_t value) override { |
| 34 | // Only count "size" dumps, others are just providing metadata. |
| 35 | if (SkString("size") == SkString(valueName)) { |
| 36 | ++fNumDumpedObjects; |
| 37 | fDumpedObjectsSize += value; |
| 38 | } |
| 39 | } |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 40 | void setMemoryBacking(const char* dumpName, const char* backingType, |
| 41 | const char* backingObjectId) override { } |
| 42 | void setDiscardableMemoryBacking( |
| 43 | const char* dumpName, |
| 44 | const SkDiscardableMemory& discardableMemoryObject) override { } |
ssid | f0c9865 | 2015-09-30 04:31:23 -0700 | [diff] [blame] | 45 | LevelOfDetail getRequestedDetails() const override { |
| 46 | return SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail; |
| 47 | } |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 48 | bool shouldDumpWrappedObjects() const override { return fShouldDumpWrappedObjects; } |
| 49 | |
| 50 | size_t numDumpedObjects() const { return fNumDumpedObjects; } |
| 51 | size_t dumpedObjectsSize() const { return fDumpedObjectsSize; } |
| 52 | |
| 53 | private: |
| 54 | bool fShouldDumpWrappedObjects; |
| 55 | size_t fNumDumpedObjects = 0; |
| 56 | size_t fDumpedObjectsSize = 0; |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 59 | void ValidateMemoryDumps(skiatest::Reporter* reporter, GrDirectContext* dContext, |
| 60 | size_t numDumpedObjects, size_t size, bool isOwned) { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 61 | // Note than one entry in the dumped objects is expected for the text blob cache. |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 62 | TestSkTraceMemoryDump dump_with_wrapped(true /* shouldDumpWrappedObjects */); |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 63 | dContext->dumpMemoryStatistics(&dump_with_wrapped); |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, numDumpedObjects == dump_with_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 65 | REPORTER_ASSERT(reporter, size == dump_with_wrapped.dumpedObjectsSize()); |
| 66 | |
| 67 | TestSkTraceMemoryDump dump_no_wrapped(false /* shouldDumpWrappedObjects */); |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 68 | dContext->dumpMemoryStatistics(&dump_no_wrapped); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 69 | if (isOwned) { |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, numDumpedObjects == dump_no_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, size == dump_no_wrapped.dumpedObjectsSize()); |
| 72 | } else { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 73 | REPORTER_ASSERT(reporter, 1 == dump_no_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 74 | REPORTER_ASSERT(reporter, 0 == dump_no_wrapped.dumpedObjectsSize()); |
ssid | f0c9865 | 2015-09-30 04:31:23 -0700 | [diff] [blame] | 75 | } |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 76 | } |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 77 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 78 | #ifdef SK_GL |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 79 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter, ctxInfo) { |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 80 | auto dContext = ctxInfo.directContext(); |
| 81 | GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 82 | const size_t kMemorySize = 1024; |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 83 | sk_sp<GrGLBuffer> buffer = |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 84 | GrGLBuffer::Make(gpu, kMemorySize, GrGpuBufferType::kVertex, kDynamic_GrAccessPattern); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 85 | |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 86 | ValidateMemoryDumps(reporter, dContext, 2, kMemorySize, true /* isOwned */); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTexture, reporter, ctxInfo) { |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 90 | auto dContext = ctxInfo.directContext(); |
| 91 | GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 92 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 93 | GrGLTexture::Desc desc; |
| 94 | desc.fTarget = GR_GL_TEXTURE_2D; |
| 95 | desc.fID = 7; // Arbitrary, we don't actually use the texture. |
| 96 | desc.fFormat = GrGLFormat::kRGBA8; |
| 97 | desc.fOwnership = GrBackendObjectOwnership::kOwned; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 98 | desc.fSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 99 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 100 | auto texture = |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 101 | sk_make_sp<GrGLTexture>(gpu, SkBudgeted::kNo, desc, GrMipmapStatus::kNotAllocated); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 102 | |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 103 | ValidateMemoryDumps(reporter, dContext, 2, texture->gpuMemorySize(), true /* isOwned */); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, reporter, ctxInfo) { |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 107 | auto dContext = ctxInfo.directContext(); |
| 108 | GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 109 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 110 | GrGLTexture::Desc desc; |
| 111 | desc.fTarget = GR_GL_TEXTURE_2D; |
| 112 | desc.fID = 7; // Arbitrary, we don't actually use the texture. |
| 113 | desc.fFormat = GrGLFormat::kRGBA8; |
| 114 | desc.fOwnership = GrBackendObjectOwnership::kBorrowed; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 115 | desc.fSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 116 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 117 | auto params = sk_make_sp<GrGLTextureParameters>(); |
| 118 | |
| 119 | auto texture = |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 120 | GrGLTexture::MakeWrapped(gpu, GrMipmapStatus::kNotAllocated, desc, std::move(params), |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 121 | GrWrapCacheable::kNo, kRead_GrIOType); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 122 | |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 123 | ValidateMemoryDumps(reporter, dContext, 2, texture->gpuMemorySize(), false /* isOwned */); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLRenderTarget, reporter, ctxInfo) { |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 127 | auto dContext = ctxInfo.directContext(); |
| 128 | GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 129 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 130 | static constexpr auto kSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 131 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 132 | GrGLRenderTarget::IDs rtIDs; |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 133 | rtIDs.fMultisampleFBOID = 0; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 134 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kOwned; |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 135 | rtIDs.fSingleSampleFBOID = 20; |
| 136 | rtIDs.fMSColorRenderbufferID = 0; |
| 137 | rtIDs.fTotalMemorySamplesPerPixel = 1; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 138 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 139 | sk_sp<GrGLRenderTarget> rt = |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 140 | GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 1, rtIDs, 0); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 141 | |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 142 | ValidateMemoryDumps(reporter, dContext, 2, rt->gpuMemorySize(), true /* isOwned */); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLRenderTarget, reporter, ctxInfo) { |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 146 | auto dContext = ctxInfo.directContext(); |
| 147 | GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 148 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 149 | static constexpr auto kSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 150 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 151 | GrGLRenderTarget::IDs rtIDs; |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 152 | rtIDs.fMultisampleFBOID = 12; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 153 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed; |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 154 | rtIDs.fSingleSampleFBOID = 0; |
| 155 | rtIDs.fMSColorRenderbufferID = 0; |
| 156 | rtIDs.fTotalMemorySamplesPerPixel = 4; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 157 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 158 | sk_sp<GrGLRenderTarget> rt = |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 159 | GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 4, rtIDs, 0); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 160 | |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 161 | ValidateMemoryDumps(reporter, dContext, 2, rt->gpuMemorySize(), false /* isOwned */); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 162 | } |
Chris Dalton | a655a33 | 2021-04-07 15:04:22 -0600 | [diff] [blame] | 163 | |
| 164 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTextureRenderTarget, reporter, |
| 165 | ctxInfo) { |
| 166 | auto dContext = ctxInfo.directContext(); |
| 167 | GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu()); |
| 168 | |
| 169 | static constexpr auto kSize = SkISize::Make(64, 64); |
| 170 | |
| 171 | GrGLTexture::Desc texDesc; |
| 172 | texDesc.fSize = kSize; |
| 173 | texDesc.fTarget = GR_GL_TEXTURE_2D; |
| 174 | texDesc.fID = 17; |
| 175 | texDesc.fFormat = GrGLFormat::kRGBA8; |
| 176 | texDesc.fOwnership = GrBackendObjectOwnership::kOwned; |
| 177 | |
| 178 | GrGLRenderTarget::IDs rtIDs; |
| 179 | rtIDs.fMultisampleFBOID = 12; |
| 180 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kOwned; |
| 181 | rtIDs.fSingleSampleFBOID = 20; |
| 182 | rtIDs.fMSColorRenderbufferID = 22; |
| 183 | rtIDs.fTotalMemorySamplesPerPixel = 9; |
| 184 | |
| 185 | auto texRT = sk_make_sp<GrGLTextureRenderTarget>(gpu, SkBudgeted::kYes, 8, texDesc, rtIDs, |
| 186 | GrMipmapStatus::kNotAllocated); |
| 187 | |
| 188 | ValidateMemoryDumps(reporter, dContext, 3, texRT->gpuMemorySize(), true /* isOwned */); |
| 189 | } |
| 190 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 191 | #endif // SK_GL |