DeviceLimits
Quick answer
DeviceLimits exposes the hard numeric ceilings of the current backend through device.limits: maximum texture dimensions, buffer sizes, vertex attributes, bindings and workgroup counts. Read the limits before allocating textures or sizing dispatch grids so code runs on every device. The values are fixed per device and never change at runtime.
device. limits → DeviceLimits
Key points
- maxTextureDimension2D caps the width and height of every new Texture.
- maxVertexAttributes bounds how many attributes a VertexArray can bind.
- maxComputeWorkgroupSizeX sizes compute dispatches safely.
Example
const limits = device.limits;
/* 纹理边长不能超过后端上限 */
const size = Math.min(requestedSize, limits.maxTextureDimension2D);
const texture = device.createTexture({
width: size,
height: size,
format: 'rgba8unorm',
usage: Texture.SAMPLE | Texture.COPY_DST
});
/* uniform 偏移必须按对齐要求取整 */
const alignedOffset = Math.ceil(byteOffset / limits.minUniformBufferOffsetAlignment)
* limits.minUniformBufferOffsetAlignment;
Notes
- WebGL limits are lower than WebGPU, so desktop-tuned values fail on fallback.
- Hard-coding 4096 textures crashes when maxTextureDimension2D is smaller.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). DeviceLimits. https://www.jingweizhi.com/en/lumagl/api/device-limits.html (accessed 2026-11-03).