VirtualGPU API Reference
Complete method reference for VirtualGPU and all subsystem managers.
Source: engine/core/gpu/VirtualGPU.js (2300 lines).
Guide first: If you're new to vGPU, read the Virtual GPU Guide before this reference.
Global Functions
Returns the global VirtualGPU singleton. Creates it on first call. Subsequent calls return the same instance.
| Param | Type | Description |
|---|---|---|
options | Object? | Passed to GpuDevice.create() — powerPreference, requiredFeatures, etc. |
Synchronous access to the global singleton. Throws if getVGPU() hasn't been called yet.
Alias for getVGPU(). Provided for semantic clarity in initialization code.
Creates a new (non-singleton) VirtualGPU instance.
Wraps an existing GpuDevice instance in a VirtualGPU.
vgpu.buffer — VGPUBufferManager
Create a GPU buffer with simplified usage strings and optional pooling.
| Param | Type | Description |
|---|---|---|
options.size | number | Buffer size in bytes |
options.usage | string|number | Usage string ('vertex', 'storage', 'uniform', 'index', 'indirect', 'map-read', 'map-write') or raw flags. Pipe-separated for combinations: 'storage|vertex' |
options.label | string? | Debug label |
options.data | TypedArray? | Initial data to upload |
options.pooled | boolean? | If true, allocate from buffer pool for reuse |
Write data to a buffer via queue.writeBuffer().
| Param | Type | Description |
|---|---|---|
buffer | GPUBuffer | Target buffer |
data | TypedArray | Data to write |
offset | number? | Byte offset into buffer (default 0) |
Release a managed buffer. Pooled buffers return to the pool; non-pooled are destroyed.
vgpu.bindings — VGPUBindingManager
Define a named bind group layout. Returns cached layout if already defined.
| Param | Type | Description |
|---|---|---|
name | string | Layout name for caching |
entries[] | Object[] | Array of entry descriptors |
entry.binding | number | Binding index |
entry.type | string | 'uniform', 'storage', 'read-only-storage', 'texture', 'sampler', 'storage-texture' |
entry.visibility | string? | Pipe-separated: 'vertex', 'fragment', 'compute', 'vertex|fragment'. Default: all stages. |
Create a bind group using a named or direct layout. Cached by entry hash.
| Param | Type | Description |
|---|---|---|
layout | string|GPUBindGroupLayout | Layout name (from defineLayout) or raw layout |
entries[] | Object[] | Standard GPUBindGroupEntry array |
label | string? | Debug label |
Retrieve a previously defined layout by name.
vgpu.shader — VGPUShaderManager
Compile a WGSL shader module. Cached by name — second call returns cached module.
| Param | Type | Description |
|---|---|---|
name | string | Unique name for caching |
code | string | WGSL source code |
defines | Object? | Preprocessor defines: { MAX_LIGHTS: 16 } |
Hot-reload a shader. Replaces the cached module.
Retrieve a compiled module by name without recompiling.
vgpu.pipeline — VGPUPipelineManager
Create (or return cached) render pipeline. Cached by full configuration hash.
| Param | Type | Description |
|---|---|---|
options.vertex | Object | { module, entryPoint?, buffers? } |
options.fragment | Object | { module, entryPoint?, targets } |
options.blend | string? | 'none', 'alpha', 'additive', 'premultiplied'. Applied to all targets. |
options.depthStencil | boolean|Object? | true = depth24plus with less/write. Or full descriptor. |
options.topology | string? | Default 'triangle-list' |
options.layout | GPUPipelineLayout|string? | Default 'auto' |
options.label | string? | Debug label |
Non-blocking pipeline creation. Ideal for loading screens.
Create (or return cached) compute pipeline.
| Param | Type | Description |
|---|---|---|
options.module | GPUShaderModule | Compiled shader |
options.entryPoint | string? | Default 'main' |
options.layout | GPUPipelineLayout|string? | Default 'auto' |
options.label | string? | Debug label |
Non-blocking compute pipeline creation.
vgpu.texture — VGPUTextureManager
Create a GPU texture with simplified usage strings.
| Param | Type | Description |
|---|---|---|
options.width | number | Texture width |
options.height | number | Texture height |
options.depth | number? | Depth for 3D textures |
options.format | string | GPU texture format (e.g., 'rgba8unorm') |
options.usage | string|number | 'render', 'texture', 'storage', 'copy-src', 'copy-dst'. Pipe-separated. |
options.label | string? | Debug label |
Create or return a cached sampler.
| Param | Type | Description |
|---|---|---|
options.filter | string? | 'linear' or 'nearest' (default 'linear') |
options.wrap | string? | 'repeat', 'clamp', 'mirror' (default 'clamp-to-edge') |
Destroy a managed texture.
vgpu.command — VGPUCommandManager
Create a new command encoder.
Submit one or more command buffers to the GPU queue.
One-shot compute dispatch: creates encoder, runs pass, submits immediately.
| Param | Type | Description |
|---|---|---|
options.pipeline | GPUComputePipeline | Pipeline to use |
options.bindGroups | GPUBindGroup|GPUBindGroup[] | Bind group(s) — array sets group 0, 1, 2... |
options.workgroups | number|number[] | Workgroup count(s) [x, y?, z?] |
options.label | string? | Debug label |
GPU-side buffer-to-buffer copy.
Read GPU buffer contents back to CPU. Creates a staging buffer, copies, maps, and returns the data.
Lifecycle Methods
Mark the start of a frame. Resets per-frame stats counters.
Mark the end of a frame. Finalizes per-frame profiling data.
Returns comprehensive statistics: buffer counts/sizes, shader cache size, pipeline counts, texture counts, memory usage, and profiler data.
Release all managed resources (buffers, textures, pipelines) and destroy the GPU device.
Factory Methods (Lazy)
These create heavy modules on first call and return cached instances thereafter.
Automatic render pass scheduling and resource aliasing.
GPU-driven indirect draw calls for large instance counts.
Hierarchical-Z occlusion culling.
Texture and mesh streaming with priority queues.
Immediate-mode debug line and shape rendering (boxes, spheres, frustums, arrows).
Properties
| Property | Type | Description |
|---|---|---|
vgpu.device | GPUDevice | Underlying WebGPU device |
vgpu.queue | GPUQueue | GPU command queue |
vgpu.adapter | GPUAdapter | GPU adapter info |
vgpu.limits | Object | Device limits (maxBufferSize, etc.) |
vgpu.features | Set | Supported feature strings |
vgpu.capabilities | Object | Full capability descriptor |