2015-08-20 15:00:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTraceMemoryDump.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2015-08-20 15:00:32 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2015-08-20 15:00:32 +00:00
|
|
|
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrRenderTarget.h"
|
|
|
|
#include "src/gpu/ganesh/GrTexture.h"
|
2019-11-08 21:18:15 +00:00
|
|
|
#ifdef SK_GL
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/gl/GrGLBuffer.h"
|
|
|
|
#include "src/gpu/ganesh/gl/GrGLDefines_impl.h"
|
|
|
|
#include "src/gpu/ganesh/gl/GrGLGpu.h"
|
|
|
|
#include "src/gpu/ganesh/gl/GrGLTextureRenderTarget.h"
|
2019-11-08 21:18:15 +00:00
|
|
|
#endif
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2015-08-20 15:00:32 +00:00
|
|
|
/*
|
|
|
|
* Build test for SkTraceMemoryDump.
|
|
|
|
*/
|
|
|
|
class TestSkTraceMemoryDump : public SkTraceMemoryDump {
|
|
|
|
public:
|
2018-03-19 20:04:03 +00:00
|
|
|
TestSkTraceMemoryDump(bool shouldDumpWrappedObjects)
|
|
|
|
: fShouldDumpWrappedObjects(shouldDumpWrappedObjects) {}
|
2015-08-20 15:00:32 +00:00
|
|
|
~TestSkTraceMemoryDump() override { }
|
|
|
|
|
|
|
|
void dumpNumericValue(const char* dumpName, const char* valueName, const char* units,
|
2018-03-19 20:04:03 +00:00
|
|
|
uint64_t value) override {
|
|
|
|
// Only count "size" dumps, others are just providing metadata.
|
|
|
|
if (SkString("size") == SkString(valueName)) {
|
|
|
|
++fNumDumpedObjects;
|
|
|
|
fDumpedObjectsSize += value;
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 15:00:32 +00:00
|
|
|
void setMemoryBacking(const char* dumpName, const char* backingType,
|
|
|
|
const char* backingObjectId) override { }
|
|
|
|
void setDiscardableMemoryBacking(
|
|
|
|
const char* dumpName,
|
|
|
|
const SkDiscardableMemory& discardableMemoryObject) override { }
|
2015-09-30 11:31:23 +00:00
|
|
|
LevelOfDetail getRequestedDetails() const override {
|
|
|
|
return SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail;
|
|
|
|
}
|
2018-03-19 20:04:03 +00:00
|
|
|
bool shouldDumpWrappedObjects() const override { return fShouldDumpWrappedObjects; }
|
|
|
|
|
|
|
|
size_t numDumpedObjects() const { return fNumDumpedObjects; }
|
|
|
|
size_t dumpedObjectsSize() const { return fDumpedObjectsSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fShouldDumpWrappedObjects;
|
|
|
|
size_t fNumDumpedObjects = 0;
|
|
|
|
size_t fDumpedObjectsSize = 0;
|
2015-08-20 15:00:32 +00:00
|
|
|
};
|
|
|
|
|
2021-04-07 21:04:22 +00:00
|
|
|
void ValidateMemoryDumps(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
|
|
|
size_t numDumpedObjects, size_t size, bool isOwned) {
|
2018-10-29 20:05:36 +00:00
|
|
|
// Note than one entry in the dumped objects is expected for the text blob cache.
|
2018-03-19 20:04:03 +00:00
|
|
|
TestSkTraceMemoryDump dump_with_wrapped(true /* shouldDumpWrappedObjects */);
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->dumpMemoryStatistics(&dump_with_wrapped);
|
2021-04-07 21:04:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, numDumpedObjects == dump_with_wrapped.numDumpedObjects());
|
2018-03-19 20:04:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, size == dump_with_wrapped.dumpedObjectsSize());
|
|
|
|
|
|
|
|
TestSkTraceMemoryDump dump_no_wrapped(false /* shouldDumpWrappedObjects */);
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->dumpMemoryStatistics(&dump_no_wrapped);
|
2018-03-19 20:04:03 +00:00
|
|
|
if (isOwned) {
|
2021-04-07 21:04:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, numDumpedObjects == dump_no_wrapped.numDumpedObjects());
|
2018-03-19 20:04:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, size == dump_no_wrapped.dumpedObjectsSize());
|
|
|
|
} else {
|
2018-10-29 20:05:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == dump_no_wrapped.numDumpedObjects());
|
2018-03-19 20:04:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == dump_no_wrapped.dumpedObjectsSize());
|
2015-09-30 11:31:23 +00:00
|
|
|
}
|
2015-08-20 15:00:32 +00:00
|
|
|
}
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-11-08 21:18:15 +00:00
|
|
|
#ifdef SK_GL
|
2018-03-19 20:04:03 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLBuffer, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
const size_t kMemorySize = 1024;
|
2019-01-29 19:38:50 +00:00
|
|
|
sk_sp<GrGLBuffer> buffer =
|
2019-02-05 14:41:37 +00:00
|
|
|
GrGLBuffer::Make(gpu, kMemorySize, GrGpuBufferType::kVertex, kDynamic_GrAccessPattern);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2021-04-07 21:04:22 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, 2, kMemorySize, true /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTexture, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLTexture::Desc desc;
|
|
|
|
desc.fTarget = GR_GL_TEXTURE_2D;
|
|
|
|
desc.fID = 7; // Arbitrary, we don't actually use the texture.
|
|
|
|
desc.fFormat = GrGLFormat::kRGBA8;
|
|
|
|
desc.fOwnership = GrBackendObjectOwnership::kOwned;
|
|
|
|
desc.fSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2022-04-08 20:22:16 +00:00
|
|
|
auto texture = sk_make_sp<GrGLTexture>(
|
|
|
|
gpu, SkBudgeted::kNo, desc, GrMipmapStatus::kNotAllocated, /*label=*/"");
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2021-04-07 21:04:22 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, 2, texture->gpuMemorySize(), true /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLTexture::Desc desc;
|
|
|
|
desc.fTarget = GR_GL_TEXTURE_2D;
|
|
|
|
desc.fID = 7; // Arbitrary, we don't actually use the texture.
|
|
|
|
desc.fFormat = GrGLFormat::kRGBA8;
|
|
|
|
desc.fOwnership = GrBackendObjectOwnership::kBorrowed;
|
|
|
|
desc.fSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-06-04 19:58:31 +00:00
|
|
|
auto params = sk_make_sp<GrGLTextureParameters>();
|
|
|
|
|
|
|
|
auto texture =
|
2020-07-21 13:56:23 +00:00
|
|
|
GrGLTexture::MakeWrapped(gpu, GrMipmapStatus::kNotAllocated, desc, std::move(params),
|
2019-08-07 17:04:55 +00:00
|
|
|
GrWrapCacheable::kNo, kRead_GrIOType);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2021-04-07 21:04:22 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, 2, texture->gpuMemorySize(), false /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLRenderTarget, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
static constexpr auto kSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLRenderTarget::IDs rtIDs;
|
2021-04-07 21:04:22 +00:00
|
|
|
rtIDs.fMultisampleFBOID = 0;
|
2019-08-07 17:04:55 +00:00
|
|
|
rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kOwned;
|
2021-04-07 21:04:22 +00:00
|
|
|
rtIDs.fSingleSampleFBOID = 20;
|
|
|
|
rtIDs.fMSColorRenderbufferID = 0;
|
|
|
|
rtIDs.fTotalMemorySamplesPerPixel = 1;
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
sk_sp<GrGLRenderTarget> rt =
|
2020-01-22 21:53:38 +00:00
|
|
|
GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 1, rtIDs, 0);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2021-04-07 21:04:22 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, 2, rt->gpuMemorySize(), true /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLRenderTarget, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
static constexpr auto kSize = SkISize::Make(64, 64);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
GrGLRenderTarget::IDs rtIDs;
|
2021-04-07 21:04:22 +00:00
|
|
|
rtIDs.fMultisampleFBOID = 12;
|
2019-08-07 17:04:55 +00:00
|
|
|
rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
|
2021-04-07 21:04:22 +00:00
|
|
|
rtIDs.fSingleSampleFBOID = 0;
|
|
|
|
rtIDs.fMSColorRenderbufferID = 0;
|
|
|
|
rtIDs.fTotalMemorySamplesPerPixel = 4;
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2019-08-07 17:04:55 +00:00
|
|
|
sk_sp<GrGLRenderTarget> rt =
|
2021-04-07 21:04:22 +00:00
|
|
|
GrGLRenderTarget::MakeWrapped(gpu, kSize, GrGLFormat::kRGBA8, 4, rtIDs, 0);
|
2018-03-19 20:04:03 +00:00
|
|
|
|
2021-04-07 21:04:22 +00:00
|
|
|
ValidateMemoryDumps(reporter, dContext, 2, rt->gpuMemorySize(), false /* isOwned */);
|
2018-03-19 20:04:03 +00:00
|
|
|
}
|
2021-04-07 21:04:22 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_ownedGLTextureRenderTarget, reporter,
|
|
|
|
ctxInfo) {
|
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
|
|
|
|
|
|
|
static constexpr auto kSize = SkISize::Make(64, 64);
|
|
|
|
|
|
|
|
GrGLTexture::Desc texDesc;
|
|
|
|
texDesc.fSize = kSize;
|
|
|
|
texDesc.fTarget = GR_GL_TEXTURE_2D;
|
|
|
|
texDesc.fID = 17;
|
|
|
|
texDesc.fFormat = GrGLFormat::kRGBA8;
|
|
|
|
texDesc.fOwnership = GrBackendObjectOwnership::kOwned;
|
|
|
|
|
|
|
|
GrGLRenderTarget::IDs rtIDs;
|
|
|
|
rtIDs.fMultisampleFBOID = 12;
|
|
|
|
rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kOwned;
|
|
|
|
rtIDs.fSingleSampleFBOID = 20;
|
|
|
|
rtIDs.fMSColorRenderbufferID = 22;
|
|
|
|
rtIDs.fTotalMemorySamplesPerPixel = 9;
|
|
|
|
|
2022-03-10 22:39:45 +00:00
|
|
|
auto texRT = sk_make_sp<GrGLTextureRenderTarget>(
|
2022-04-08 20:22:16 +00:00
|
|
|
gpu, SkBudgeted::kYes, 8, texDesc, rtIDs, GrMipmapStatus::kNotAllocated, /*label=*/"");
|
2021-04-07 21:04:22 +00:00
|
|
|
|
|
|
|
ValidateMemoryDumps(reporter, dContext, 3, texRT->gpuMemorySize(), true /* isOwned */);
|
|
|
|
}
|
|
|
|
|
2019-11-08 21:18:15 +00:00
|
|
|
#endif // SK_GL
|