createTexture method
Any shape — webgpuCreateTextureWithDescriptor checks what the browser
would otherwise refuse asynchronously; the features each shape needs are
refused here first.
A RenderTargetDescriptor is the pool's 2D target, made as it always
was; any other descriptor is the general form, textureWrites.
Implementation
@override
TextureHandle createTexture(TextureDescriptor descriptor) {
if (descriptor is RenderTargetDescriptor) return _createTarget(descriptor);
features.require(DeviceFeature.textureWrites, backend: _backend);
final shape = switch (descriptor.dimension) {
TextureDimension.d2Array => DeviceFeature.textureArrays,
TextureDimension.d3 => DeviceFeature.texture3D,
TextureDimension.cube => DeviceFeature.cubeTextures,
TextureDimension.cubeArray => DeviceFeature.cubeArrayTextures,
TextureDimension.d1 || TextureDimension.d2 => null,
_ => throw UnsupportedError(
'WebGPU cannot allocate a ${descriptor.dimension} texture',
),
};
if (shape != null) features.require(shape, backend: _backend);
if (descriptor.usage.contains(TextureUsage.storage)) {
features.require(DeviceFeature.storageTextures, backend: _backend);
}
descriptor.checkFeatures(features, backend: _backend);
return _guard(
'a texture $descriptor',
() => webgpuCreateTextureWithDescriptor(
_gpuDevice,
_textures,
descriptor,
limits: limits,
support: textureFormatSupport(descriptor.format),
),
);
}