import { Observable, ReplaySubject } from 'rxjs'; /** * This register enables monitoring of memory (de)allocations and is intended for use in WebGL context for internal GPU * memory allocation tracking. For it, a unique identifier for registration has to be created: * ``` * let gpuAllocReg = this.context.gpuAllocationRegister; * const identifier = gpuAllocReg.createUniqueIdentifier('gpu-object'); * ``` * * Then allocations, deallocations, and reallocations can be registered: * ``` * gpuAllocReg.allocate(identifier, this.sizeofRGBAColorAttachment()); * gpuAllocReg.allocate(identifier, this.sizeofDepthStencilAttachment()); * // ... reallocation * gpuAllocReg.reallocate(identifier, * this.sizeofRGBAColorAttachment() + this.sizeofDepthStencilAttachment()); * // ... uninitialize * gpuAllocReg.reallocate(identifier, 0); * ``` * * Requesting the allocated memory can be done as follows: * ``` * // memory allocated by identifier: * console.log(mfCanvas.context.gpuAllocationRegister.toString()); * //> IntermediateFBO: 10.582MiB, AccumulationPingFBO: 21.163MiB, AccumulationPongFBO: 21.163MiB * * // memory allocated over all identifiers: * console.log(mfCanvas.context.gpuAllocationRegister.bytesToString()); * //> 52.908MiB * ``` */ export declare class AllocationRegister { /** * Map that provides access to the accumulated memory allocations for all registered identifiers. */ protected _bytesByIdentifier: Map; /** @see {@link bytes} */ protected _bytes: GLsizei; protected _bytesSubject: ReplaySubject<[number, string]>; /** * Utility for communicating this._bytes changes to its associated subject. */ protected bytesNext(): void; /** * Asserts existence of an identifier. * @param identifier - Identifier to assert the existence of. */ protected assertIdentifier(identifier: string): void; /** * Creates a unique identifier based on a given identifier: if the identifier is already unique it is returned as * is. If not, an enumerated identifier is returned, e.g., 'TempFBO-2' when 'TempFBO' already exists. This also * enables tracking for the identifier, thus, it should always be called before tracking/monitoring. * @param identifier - Requested identifier for allocation registration. * @returns - Unique identifier (might differ from given identifier) for which allocation registration is enabled. */ createUniqueIdentifier(identifier: string): string; /** * Removes a previously created unique identifier from the allocation registry. * @param identifier - Identifier that is to be deleted from allocation registration. */ deleteUniqueIdentifier(identifier: string): void; /** * Registers allocated bytes for a given identifier. * @param identifier - Identifier to register the allocated bytes for. * @param allocate - Allocated bytes to register for identifier. */ allocate(identifier: string, allocate: number): void; /** * Registers deallocated bytes for a given identifier. * @param identifier - Identifier to register the deallocated bytes for. * @param allocate - Number of deallocated bytes to register for identifier. */ deallocate(identifier: string, deallocate: number): void; /** * Resets the previously allocated bytes for the given identifier and registers the given allocated bytes instead. * @param identifier - Identifier to register the reallocated bytes for. * @param allocate - Number of reallocated bytes to register for identifier. */ reallocate(identifier: string, reallocate: number): void; /** * Provides access to the allocated bytes for an identifier as well as the overall allocated bytes (when identifier * is undefined, default). If the identifier is undefined, the overall allocated number of bytes is returned. * @param identifier - Identifier to return the allocated bytes for. * @param allocate - Number of allocated bytes registered for identifier. */ allocated(identifier?: string): number; /** * Provides a pretty printed string of the allocated bytes of this register and their identifier. The output for a * register of three objects could be as follows: * ``` * IntermediateFBO: 10.582MiB, AccumulationPingFBO: 21.163MiB, AccumulationPongFBO: 21.163MiB * ``` * @returns - Pretty printed string of all memory allocations. */ toString(): string; /** * Provides a pretty printed string of the overall number of bytes or a specific identifier. If the identifier is * undefined, the overall number of bytes is pretty printed. * @param identifier - Identifier to pretty print the bytes for. * @returns - Pretty printed string of the requested number of bytes. */ bytesToString(identifier?: string): string; /** * Cache for the overall number of allocated bytes (over all identifiers). This should always be the sum of the * bytes allocated over each identifier, which can be validated using validate(). * * This property can be observed, e.g., `allocationRegister.bytesObservable.subscribe()`. */ get bytes(): GLsizei; /** * Observable that can be used to subscribe to bytes value changes. Yields a 2-tuple of overall allocated bytes as * number and pretty printed string. */ get bytes$(): Observable<[GLsizei, string]>; }