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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrContextPriv.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" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 20 | #endif |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 21 | |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 22 | /* |
| 23 | * Build test for SkTraceMemoryDump. |
| 24 | */ |
| 25 | class TestSkTraceMemoryDump : public SkTraceMemoryDump { |
| 26 | public: |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 27 | TestSkTraceMemoryDump(bool shouldDumpWrappedObjects) |
| 28 | : fShouldDumpWrappedObjects(shouldDumpWrappedObjects) {} |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 29 | ~TestSkTraceMemoryDump() override { } |
| 30 | |
| 31 | void dumpNumericValue(const char* dumpName, const char* valueName, const char* units, |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 32 | uint64_t value) override { |
| 33 | // Only count "size" dumps, others are just providing metadata. |
| 34 | if (SkString("size") == SkString(valueName)) { |
| 35 | ++fNumDumpedObjects; |
| 36 | fDumpedObjectsSize += value; |
| 37 | } |
| 38 | } |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 39 | void setMemoryBacking(const char* dumpName, const char* backingType, |
| 40 | const char* backingObjectId) override { } |
| 41 | void setDiscardableMemoryBacking( |
| 42 | const char* dumpName, |
| 43 | const SkDiscardableMemory& discardableMemoryObject) override { } |
ssid | f0c9865 | 2015-09-30 04:31:23 -0700 | [diff] [blame] | 44 | LevelOfDetail getRequestedDetails() const override { |
| 45 | return SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail; |
| 46 | } |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 47 | bool shouldDumpWrappedObjects() const override { return fShouldDumpWrappedObjects; } |
| 48 | |
| 49 | size_t numDumpedObjects() const { return fNumDumpedObjects; } |
| 50 | size_t dumpedObjectsSize() const { return fDumpedObjectsSize; } |
| 51 | |
| 52 | private: |
| 53 | bool fShouldDumpWrappedObjects; |
| 54 | size_t fNumDumpedObjects = 0; |
| 55 | size_t fDumpedObjectsSize = 0; |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 58 | void ValidateMemoryDumps(skiatest::Reporter* reporter, GrContext* context, size_t size, |
| 59 | bool isOwned) { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 60 | // 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] | 61 | TestSkTraceMemoryDump dump_with_wrapped(true /* shouldDumpWrappedObjects */); |
| 62 | context->dumpMemoryStatistics(&dump_with_wrapped); |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, 2 == dump_with_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, size == dump_with_wrapped.dumpedObjectsSize()); |
| 65 | |
| 66 | TestSkTraceMemoryDump dump_no_wrapped(false /* shouldDumpWrappedObjects */); |
| 67 | context->dumpMemoryStatistics(&dump_no_wrapped); |
| 68 | if (isOwned) { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 69 | REPORTER_ASSERT(reporter, 2 == dump_no_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, size == dump_no_wrapped.dumpedObjectsSize()); |
| 71 | } else { |
Khushal | 71652e2 | 2018-10-29 13:05:36 -0700 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, 1 == dump_no_wrapped.numDumpedObjects()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 73 | REPORTER_ASSERT(reporter, 0 == dump_no_wrapped.dumpedObjectsSize()); |
ssid | f0c9865 | 2015-09-30 04:31:23 -0700 | [diff] [blame] | 74 | } |
primiano | 9a5bd7e | 2015-08-20 08:00:32 -0700 | [diff] [blame] | 75 | } |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 76 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 77 | #ifdef SK_GL |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 78 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 79 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 80 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 81 | const size_t kMemorySize = 1024; |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 82 | sk_sp<GrGLBuffer> buffer = |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 83 | GrGLBuffer::Make(gpu, kMemorySize, GrGpuBufferType::kVertex, kDynamic_GrAccessPattern); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 84 | |
| 85 | ValidateMemoryDumps(reporter, context, kMemorySize, true /* isOwned */); |
| 86 | } |
| 87 | |
| 88 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTexture, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 89 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 90 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 91 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 92 | GrGLTexture::Desc desc; |
| 93 | desc.fTarget = GR_GL_TEXTURE_2D; |
| 94 | desc.fID = 7; // Arbitrary, we don't actually use the texture. |
| 95 | desc.fFormat = GrGLFormat::kRGBA8; |
| 96 | desc.fOwnership = GrBackendObjectOwnership::kOwned; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 97 | desc.fSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 98 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 99 | auto texture = |
| 100 | sk_make_sp<GrGLTexture>(gpu, SkBudgeted::kNo, desc, GrMipMapsStatus::kNotAllocated); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 101 | |
| 102 | ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), true /* isOwned */); |
| 103 | } |
| 104 | |
| 105 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 106 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 107 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 108 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 109 | GrGLTexture::Desc desc; |
| 110 | desc.fTarget = GR_GL_TEXTURE_2D; |
| 111 | desc.fID = 7; // Arbitrary, we don't actually use the texture. |
| 112 | desc.fFormat = GrGLFormat::kRGBA8; |
| 113 | desc.fOwnership = GrBackendObjectOwnership::kBorrowed; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 114 | desc.fSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 115 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 116 | auto params = sk_make_sp<GrGLTextureParameters>(); |
| 117 | |
| 118 | auto texture = |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 119 | GrGLTexture::MakeWrapped(gpu, GrMipMapsStatus::kNotAllocated, desc, std::move(params), |
| 120 | GrWrapCacheable::kNo, kRead_GrIOType); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 121 | |
| 122 | ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), false /* isOwned */); |
| 123 | } |
| 124 | |
| 125 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLRenderTarget, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 126 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 127 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 128 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 129 | static constexpr auto kSize = SkISize::Make(64, 64); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 130 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 131 | GrGLRenderTarget::IDs rtIDs; |
| 132 | rtIDs.fRTFBOID = 20; |
| 133 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kOwned; |
| 134 | rtIDs.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 135 | rtIDs.fMSColorRenderbufferID = 22; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 136 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 137 | sk_sp<GrGLRenderTarget> rt = |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 138 | GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 1, rtIDs, 0); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 139 | |
| 140 | ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), true /* isOwned */); |
| 141 | } |
| 142 | |
| 143 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLRenderTarget, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 144 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 145 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 146 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 147 | static constexpr auto kSize = SkISize::Make(64, 64); |
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 | GrGLRenderTarget::IDs rtIDs; |
| 150 | rtIDs.fRTFBOID = 20; |
| 151 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed; |
| 152 | rtIDs.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 153 | rtIDs.fMSColorRenderbufferID = 22; |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 154 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 155 | sk_sp<GrGLRenderTarget> rt = |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 156 | GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 1, rtIDs, 0); |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 157 | |
| 158 | ValidateMemoryDumps(reporter, context, rt->gpuMemorySize(), false /* isOwned */); |
| 159 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 160 | #endif // SK_GL |