From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/canvas/WebGLMemoryTracker.cpp | 138 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 dom/canvas/WebGLMemoryTracker.cpp (limited to 'dom/canvas/WebGLMemoryTracker.cpp') diff --git a/dom/canvas/WebGLMemoryTracker.cpp b/dom/canvas/WebGLMemoryTracker.cpp new file mode 100644 index 0000000000..936d93cd3e --- /dev/null +++ b/dom/canvas/WebGLMemoryTracker.cpp @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebGLMemoryTracker.h" + +#include "HostWebGLContext.h" +#include "WebGLBuffer.h" +#include "WebGLRenderbuffer.h" +#include "WebGLShader.h" +#include "WebGLTexture.h" + +namespace mozilla { + +MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf) + +NS_IMETHODIMP +WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport, + nsISupports* aData, bool) { + const auto locked = HostWebGLContext::OutstandingContexts(); + const auto& contexts = locked->contexts; + + const auto contextCount = contexts.size(); + + size_t bufferCount = 0; + int64_t bufferGpuSize = 0; + int64_t bufferCacheSize = 0; + + size_t rbCount = 0; + int64_t rbGpuSize = 0; + + size_t shaderCount = 0; + int64_t shaderCpuSize = 0; + + size_t texCount = 0; + int64_t texGpuSize = 0; + + for (const auto& context : contexts) { + bufferCount += context->mBufferMap.size(); + for (const auto& pair : context->mBufferMap) { + const auto& buffer = *pair.second; + bufferGpuSize += buffer.mByteLength; + + if (buffer.mIndexCache) { + bufferCacheSize += buffer.mByteLength; + } + bufferCacheSize += buffer.mIndexRanges.size() * + sizeof(decltype(buffer.mIndexRanges)::value_type); + } + + // - + + rbCount += context->mRenderbufferMap.size(); + for (const auto& pair : context->mRenderbufferMap) { + const auto& rb = pair.second; + rbGpuSize += rb->MemoryUsage(); + } + + // - + + shaderCount += context->mShaderMap.size(); + for (const auto& pair : context->mShaderMap) { + const auto& shader = pair.second; + shaderCpuSize += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf); + } + + // - + + texCount += context->mTextureMap.size(); + for (const auto& pair : context->mTextureMap) { + const auto& texture = pair.second; + texGpuSize += texture->MemoryUsage(); + } + } + + // - + + MOZ_COLLECT_REPORT( + "webgl-texture-memory", KIND_OTHER, UNITS_BYTES, texGpuSize, + "Memory used by WebGL textures. The OpenGL implementation is free to " + "store these textures in either video memory or main memory. This " + "measurement is only a lower bound, actual memory usage may be higher " + "for example if the storage is strided."); + + MOZ_COLLECT_REPORT("webgl-texture-count", KIND_OTHER, UNITS_COUNT, + static_cast(texCount), + "Number of WebGL textures."); + + MOZ_COLLECT_REPORT( + "webgl-buffer-memory", KIND_OTHER, UNITS_BYTES, bufferGpuSize, + "Memory used by WebGL buffers. The OpenGL implementation is free to " + "store these buffers in either video memory or main memory. This " + "measurement is only a lower bound, actual memory usage may be higher " + "for example if the storage is strided."); + + MOZ_COLLECT_REPORT( + "explicit/webgl/buffer-cache-memory", KIND_HEAP, UNITS_BYTES, + bufferCacheSize, + "Memory used by WebGL buffer caches. The WebGL implementation caches " + "the contents of element array buffers only. This adds up with the " + "'webgl-buffer-memory' value, but contrary to it, this one represents " + "bytes on the heap, not managed by OpenGL."); + + MOZ_COLLECT_REPORT("webgl-buffer-count", KIND_OTHER, UNITS_COUNT, + static_cast(bufferCount), + "Number of WebGL buffers."); + + MOZ_COLLECT_REPORT( + "webgl-renderbuffer-memory", KIND_OTHER, UNITS_BYTES, rbGpuSize, + "Memory used by WebGL renderbuffers. The OpenGL implementation is free " + "to store these renderbuffers in either video memory or main memory. " + "This measurement is only a lower bound, actual memory usage may be " + "higher, for example if the storage is strided."); + + MOZ_COLLECT_REPORT("webgl-renderbuffer-count", KIND_OTHER, UNITS_COUNT, + static_cast(rbCount), + "Number of WebGL renderbuffers."); + + MOZ_COLLECT_REPORT( + "explicit/webgl/shader", KIND_HEAP, UNITS_BYTES, shaderCpuSize, + "Combined size of WebGL shader ASCII sources and translation logs " + "cached on the heap."); + + MOZ_COLLECT_REPORT("webgl-shader-count", KIND_OTHER, UNITS_COUNT, + static_cast(shaderCount), + "Number of WebGL shaders."); + + MOZ_COLLECT_REPORT("webgl-context-count", KIND_OTHER, UNITS_COUNT, + static_cast(contextCount), + "Number of WebGL contexts."); + + return NS_OK; +} + +NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter) + +} // namespace mozilla -- cgit v1.2.3