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