API / core/graphic/gpumemorytracker
core/graphic/gpumemorytracker
GPU 메모리 셈.
- 컨텍스트에서 텍스처, 렌더버퍼, 버퍼를 짓고 크기를 정하는 함수(texImage2D, texStorage2D, renderbufferStorageMultisample, bufferData 같은 것)를 가로채, 객체마다 바이트를 적는다. 지우면 빼고, 컨텍스트를 잃으면 모두 비운다.
- 바이트는 형식과 크기로 셈한 이름값이다. (드라이버가 맞추는 줄 정렬, 타일 메모리, 멀티샘플 압축은 모른다. 멀티샘플 렌더버퍼는 샘플 수를 곱한다)
- 주인은 객체를 지은 호출 스택의 위쪽 세 칸이다. (엔진 안 지은 자리를 가려내는 개발용 이름, 스택은 지을 때 한 번만 읽는다)
- 지우지 않고 버려진 객체는 가비지 컬렉션이 올 때 FinalizationRegistry 로 뺀다. (브라우저가 그때 GL 객체를 풀어 준다)
- 같은 컨텍스트에는 하나만 건다. (기본은 꺼 둔다. 켜는 길은 EngineConfiguration.trackGpuMemory, Graphic.enableGpuMemoryTracking, 엔진 밖에서 만든 컨텍스트는 GpuMemoryTracker.attach 이고, 걸기 전에는 GL 짓기 호출을 가로채지 않는다)
GPU memory tracking.
- Intercepts the functions that create textures, renderbuffers and buffers and set their sizes (texImage2D, texStorage2D, renderbufferStorageMultisample, bufferData and so on) on the context, and records bytes per object. Deleting subtracts, and losing the context clears everything.
- Bytes are nominal values computed from format and size. (Driver row alignment, tile memory and multisample compression are unknown. Multisample renderbuffers are multiplied by the sample count)
- The owner is the top three frames of the call stack that created the object. (A development name that tells which engine part created it, the stack is read once at creation)
- Objects dropped without deleting are removed by FinalizationRegistry when garbage collection comes. (The browser releases the GL object then)
- Only one is attached per context. (Off by default. Turn it on with EngineConfiguration.trackGpuMemory, Graphic.enableGpuMemoryTracking, or GpuMemoryTracker.attach for a context made outside the engine. Before it is attached, GL create calls are not intercepted)
예제Example엔진 GPU 메모리를 종류별로 읽기Reading the engine GPU memory by kind
import { Engine, EngineConfiguration, Scene } from "./vanilla.js";
const engine = new Engine(new EngineConfiguration());
engine.run(new Scene());
const usage = engine.readGpuMemoryUsage();
console.log(usage.kindTable.texture.count, usage.totalBytes);GpuMemoryTrackerextends Object
GPU 메모리 셈 클래스.
GPU memory tracker class.
예제Example지은 텍스처의 바이트 읽기Reading the bytes of a created texture
import { GpuMemoryTracker } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const gpuMemoryTracker = GpuMemoryTracker.attach(webGL2RenderingContext);
const texture = webGL2RenderingContext.createTexture();
webGL2RenderingContext.bindTexture(webGL2RenderingContext.TEXTURE_2D, texture);
webGL2RenderingContext.texStorage2D(webGL2RenderingContext.TEXTURE_2D, 1, webGL2RenderingContext.RGBA8, 16, 16);
console.log(gpuMemoryTracker.readUsage().kindTable.texture.bytes);생성. (attach 로 건다)
Constructor. (Attach with attach)
- webGL2RenderingContextWebGL2RenderingContext
- 셈할 컨텍스트.The context to track.
컨텍스트에 셈 걸기. (없으면 만들어 건다, 같은 컨텍스트에는 하나만)
Attaches the tracker to a context. (Creates and attaches it if missing, only one per context)
- webGL2RenderingContextWebGL2RenderingContext
- 컨텍스트.The context.
반환ReturnsGpuMemoryTracker 그 컨텍스트의 GPU 메모리 셈.That context's GPU memory tracker.
예제Example엔진 밖에서 만든 컨텍스트의 GPU 메모리 읽기Reading the GPU memory of a context made outside the engine
import { GpuMemoryTracker } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const gpuMemoryTracker = GpuMemoryTracker.attach(webGL2RenderingContext);
const texture = webGL2RenderingContext.createTexture();
webGL2RenderingContext.bindTexture(webGL2RenderingContext.TEXTURE_2D, texture);
webGL2RenderingContext.texStorage2D(webGL2RenderingContext.TEXTURE_2D, 1, webGL2RenderingContext.RGBA8, 64, 64);
const usage = gpuMemoryTracker.readUsage();
console.log(usage.totalBytes);지금 쓰는 GPU 메모리 읽기.
Reads the GPU memory in use now.
반환Returns{ totalBytes: number, canvasBytes: number, kindTable: object, ownerList: Array<{ owner: string, kind: string, count: number, bytes: number }> } 합(캔버스 몫 포함), 캔버스 기본 프레임 버퍼 몫, 종류별 { count, bytes }, 주인별 몫(큰 것부터).Total (including the canvas share), default framebuffer share of the canvas, per-kind { count, bytes }, per-owner shares (largest first).
예제Example종류별과 주인별 GPU 메모리 읽기Reading GPU memory by kind and by owner
import { GpuMemoryTracker } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const gpuMemoryTracker = GpuMemoryTracker.attach(webGL2RenderingContext);
const usage = gpuMemoryTracker.readUsage();
console.log(usage.kindTable.texture.bytes, usage.ownerList.length);GpuMemoryKindenum
종류 이름.
Type name.
예제Example종류별 GPU 메모리 읽기Reading GPU memory by kind
import { GpuMemoryTracker, GpuMemoryKind } from "./vanilla.js";
const webGL2RenderingContext = document.createElement("canvas").getContext("webgl2");
const gpuMemoryTracker = GpuMemoryTracker.attach(webGL2RenderingContext);
const usage = gpuMemoryTracker.readUsage();
console.log(usage.kindTable[GpuMemoryKind.renderbuffer].bytes);| 이름Name | 값Value | 설명Description |
|---|---|---|
texture | texture | 텍스처.Texture. |
renderbuffer | renderbuffer | 렌더버퍼. (멀티샘플 렌더 타겟의 색, 깊이)Renderbuffer. (Color and depth of a multisample render target) |
buffer | buffer | 버퍼. (정점, 인덱스, 인스턴스, 유니폼)Buffer. (Vertex, index, instance, uniform) |