UNPKG

@itwin/core-frontend

Version:
213 lines • 10.4 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Rendering */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RenderMemory = void 0; /** APIs for querying memory consumed by the [[RenderSystem]]. * Use methods like [[Viewport.collectStatistics]] and [[TileTreeReference.collectStatistics]] to query this memory usage. * @public */ var RenderMemory; (function (RenderMemory) { /** Describes memory consumed by a particular type of resource. * @internal */ class Consumers { totalBytes = 0; // total number of bytes consumed by all consumers maxBytes = 0; // largest number of bytes consumed by a single consumer count = 0; // total number of consumers of this type addConsumer(numBytes) { this.totalBytes += numBytes; this.maxBytes = Math.max(this.maxBytes, numBytes); ++this.count; } clear() { this.totalBytes = this.maxBytes = this.count = 0; } } RenderMemory.Consumers = Consumers; /** @internal */ let BufferType; (function (BufferType) { BufferType[BufferType["Surfaces"] = 0] = "Surfaces"; BufferType[BufferType["VisibleEdges"] = 1] = "VisibleEdges"; BufferType[BufferType["SilhouetteEdges"] = 2] = "SilhouetteEdges"; BufferType[BufferType["PolylineEdges"] = 3] = "PolylineEdges"; BufferType[BufferType["IndexedEdges"] = 4] = "IndexedEdges"; BufferType[BufferType["Polylines"] = 5] = "Polylines"; BufferType[BufferType["PointStrings"] = 6] = "PointStrings"; BufferType[BufferType["PointClouds"] = 7] = "PointClouds"; BufferType[BufferType["Instances"] = 8] = "Instances"; BufferType[BufferType["Terrain"] = 9] = "Terrain"; BufferType[BufferType["RealityMesh"] = 10] = "RealityMesh"; BufferType[BufferType["COUNT"] = 11] = "COUNT"; })(BufferType = RenderMemory.BufferType || (RenderMemory.BufferType = {})); /** Describes memory consumed by GPU-allocated buffers. * @internal */ class Buffers extends Consumers { consumers; constructor() { super(); this.consumers = []; for (let i = 0; i < BufferType.COUNT; i++) this.consumers[i] = new Consumers(); } get surfaces() { return this.consumers[BufferType.Surfaces]; } get visibleEdges() { return this.consumers[BufferType.VisibleEdges]; } get indexedEdges() { return this.consumers[BufferType.IndexedEdges]; } get silhouetteEdges() { return this.consumers[BufferType.SilhouetteEdges]; } get polylineEdges() { return this.consumers[BufferType.PolylineEdges]; } get polylines() { return this.consumers[BufferType.Polylines]; } get pointStrings() { return this.consumers[BufferType.PointStrings]; } get pointClouds() { return this.consumers[BufferType.PointClouds]; } get instances() { return this.consumers[BufferType.Instances]; } get terrain() { return this.consumers[BufferType.Terrain]; } get reality() { return this.consumers[BufferType.RealityMesh]; } clear() { for (const consumer of this.consumers) consumer.clear(); super.clear(); } addBuffer(type, numBytes) { this.addConsumer(numBytes); this.consumers[type].addConsumer(numBytes); } } RenderMemory.Buffers = Buffers; /** @internal */ let ConsumerType; (function (ConsumerType) { ConsumerType[ConsumerType["Textures"] = 0] = "Textures"; ConsumerType[ConsumerType["VertexTables"] = 1] = "VertexTables"; ConsumerType[ConsumerType["EdgeTables"] = 2] = "EdgeTables"; ConsumerType[ConsumerType["FeatureTables"] = 3] = "FeatureTables"; ConsumerType[ConsumerType["FeatureOverrides"] = 4] = "FeatureOverrides"; ConsumerType[ConsumerType["ClipVolumes"] = 5] = "ClipVolumes"; ConsumerType[ConsumerType["PlanarClassifiers"] = 6] = "PlanarClassifiers"; ConsumerType[ConsumerType["ShadowMaps"] = 7] = "ShadowMaps"; ConsumerType[ConsumerType["TextureAttachments"] = 8] = "TextureAttachments"; ConsumerType[ConsumerType["ThematicTextures"] = 9] = "ThematicTextures"; ConsumerType[ConsumerType["COUNT"] = 10] = "COUNT"; })(ConsumerType = RenderMemory.ConsumerType || (RenderMemory.ConsumerType = {})); /** Contains statistics about the amount and type of memory consumed by the [[RenderSystem]]. * Use methods like [[Viewport.collectStatistics]] and [[TileTreeReference.collectStatistics]] to query this memory usage. * @see [[Statistics.create]] to instantiate an instance of this class. * @public */ class Statistics { _totalBytes = 0; /** @internal */ consumers; /** @internal */ buffers = new Buffers(); /** Create a new, empty statistics object. */ static create() { return new Statistics(); } /** @internal */ constructor() { this.consumers = []; for (let i = 0; i < ConsumerType.COUNT; i++) this.consumers[i] = new Consumers(); } /** The total reported memory consumption, in bytes. * @note A web browser provides no direct access to actual memory used by the host device or its graphics hardware. The reported memory usage * is an estimate based on the number of bytes of data requested via WebGL APIs. It is always an *under-estimate* as each WebGL implementation imposes * its own additional overhead. */ get totalBytes() { return this._totalBytes; } /** @internal */ get textures() { return this.consumers[ConsumerType.Textures]; } /** @internal */ get vertexTables() { return this.consumers[ConsumerType.VertexTables]; } /** @internal */ get edgeTables() { return this.consumers[ConsumerType.EdgeTables]; } /** @internal */ get featureTables() { return this.consumers[ConsumerType.FeatureTables]; } /** @internal */ get thematicTextures() { return this.consumers[ConsumerType.ThematicTextures]; } /** @internal */ get featureOverrides() { return this.consumers[ConsumerType.FeatureOverrides]; } /** @internal */ get clipVolumes() { return this.consumers[ConsumerType.ClipVolumes]; } /** @internal */ get planarClassifiers() { return this.consumers[ConsumerType.PlanarClassifiers]; } /** @internal */ get shadowMaps() { return this.consumers[ConsumerType.ShadowMaps]; } /** @internal */ get textureAttachments() { return this.consumers[ConsumerType.TextureAttachments]; } /** @internal */ addBuffer(type, numBytes) { this._totalBytes += numBytes; this.buffers.addBuffer(type, numBytes); } /** @internal */ addConsumer(type, numBytes) { this._totalBytes += numBytes; this.consumers[type].addConsumer(numBytes); } /** @internal */ clear() { this._totalBytes = 0; this.buffers.clear(); for (const consumer of this.consumers) consumer.clear(); } /** @internal */ addTexture(numBytes) { this.addConsumer(ConsumerType.Textures, numBytes); } /** @internal */ addVertexTable(numBytes) { this.addConsumer(ConsumerType.VertexTables, numBytes); } /** @internal */ addEdgeTable(numBytes) { this.addConsumer(ConsumerType.EdgeTables, numBytes); } /** @internal */ addFeatureTable(numBytes) { this.addConsumer(ConsumerType.FeatureTables, numBytes); } /** @internal */ addThematicTexture(numBytes) { this.addConsumer(ConsumerType.ThematicTextures, numBytes); } /** @internal */ addFeatureOverrides(numBytes) { this.addConsumer(ConsumerType.FeatureOverrides, numBytes); } /** @internal */ addContours(numBytes) { this.addConsumer(ConsumerType.FeatureOverrides, numBytes); } /** @internal */ addClipVolume(numBytes) { this.addConsumer(ConsumerType.ClipVolumes, numBytes); } /** @internal */ addPlanarClassifier(numBytes) { this.addConsumer(ConsumerType.PlanarClassifiers, numBytes); } /** @internal */ addShadowMap(numBytes) { this.addConsumer(ConsumerType.ShadowMaps, numBytes); } /** @internal */ addTextureAttachment(numBytes) { this.addConsumer(ConsumerType.TextureAttachments, numBytes); } /** @internal */ addSurface(numBytes) { this.addBuffer(BufferType.Surfaces, numBytes); } /** @internal */ addVisibleEdges(numBytes) { this.addBuffer(BufferType.VisibleEdges, numBytes); } /** @internal */ addIndexedEdges(numBytes) { this.addBuffer(BufferType.IndexedEdges, numBytes); } /** @internal */ addSilhouetteEdges(numBytes) { this.addBuffer(BufferType.SilhouetteEdges, numBytes); } /** @internal */ addPolylineEdges(numBytes) { this.addBuffer(BufferType.PolylineEdges, numBytes); } /** @internal */ addPolyline(numBytes) { this.addBuffer(BufferType.Polylines, numBytes); } /** @internal */ addPointString(numBytes) { this.addBuffer(BufferType.PointStrings, numBytes); } /** @internal */ addPointCloud(numBytes) { this.addBuffer(BufferType.PointClouds, numBytes); } /** @internal */ addTerrain(numBytes) { this.addBuffer(BufferType.Terrain, numBytes); } /** @internal */ addRealityMesh(numBytes) { this.addBuffer(BufferType.RealityMesh, numBytes); } /** @internal */ addInstances(numBytes) { this.addBuffer(BufferType.Instances, numBytes); } } RenderMemory.Statistics = Statistics; })(RenderMemory || (exports.RenderMemory = RenderMemory = {})); //# sourceMappingURL=RenderMemory.js.map