Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AllocationRegister

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

Hierarchy

  • AllocationRegister

Index

Properties

Protected _bytes

_bytes: GLsizei = 0
see

bytes

Protected _bytesByIdentifier

_bytesByIdentifier: Map<string, number> = new Map<string, GLsizei>()

Map that provides access to the accumulated memory allocations for all registered identifiers.

Protected _bytesSubject

_bytesSubject: ReplaySubject<Object> = new ReplaySubject<[GLsizei, string]>(1)

Accessors

bytes

  • get bytes(): GLsizei
  • 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().

    Returns GLsizei

bytes$

  • get bytes$(): Observable<[GLsizei, string]>
  • 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.

    Returns Observable<[GLsizei, string]>

Methods

allocate

  • allocate(identifier: string, allocate: number): void
  • Registers allocated bytes for a given identifier.

    Parameters

    • identifier: string

      Identifier to register the allocated bytes for.

    • allocate: number

      Allocated bytes to register for identifier.

    Returns void

allocated

  • allocated(identifier?: undefined | string): number
  • 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.

    Parameters

    • Optional identifier: undefined | string

      Identifier to return the allocated bytes for.

    Returns number

Protected assertIdentifier

  • assertIdentifier(identifier: string): void
  • Asserts existence of an identifier.

    Parameters

    • identifier: string

      Identifier to assert the existence of.

    Returns void

Protected bytesNext

  • bytesNext(): void
  • Utility for communicating this._bytes changes to its associated subject.

    Returns void

bytesToString

  • bytesToString(identifier?: undefined | string): 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.

    Parameters

    • Optional identifier: undefined | string

      Identifier to pretty print the bytes for.

    Returns string

    • Pretty printed string of the requested number of bytes.

createUniqueIdentifier

  • createUniqueIdentifier(identifier: string): string
  • 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.

    Parameters

    • identifier: string

      Requested identifier for allocation registration.

    Returns string

    • Unique identifier (might differ from given identifier) for which allocation registration is enabled.

deallocate

  • deallocate(identifier: string, deallocate: number): void
  • Registers deallocated bytes for a given identifier.

    Parameters

    • identifier: string

      Identifier to register the deallocated bytes for.

    • deallocate: number

    Returns void

deleteUniqueIdentifier

  • deleteUniqueIdentifier(identifier: string): void
  • Removes a previously created unique identifier from the allocation registry.

    Parameters

    • identifier: string

      Identifier that is to be deleted from allocation registration.

    Returns void

reallocate

  • reallocate(identifier: string, reallocate: number): void
  • Resets the previously allocated bytes for the given identifier and registers the given allocated bytes instead.

    Parameters

    • identifier: string

      Identifier to register the reallocated bytes for.

    • reallocate: number

    Returns void

toString

  • toString(): string
  • 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 string

    • Pretty printed string of all memory allocations.