Novedades de WebGPU (Chrome 119)

François Beaufort
François Beaufort

Texturas de número de punto flotante de 32 bits filtrables

Las texturas de punto flotante de 32 bits se utilizan para almacenar datos de alta precisión, como imágenes HDR y mapas de profundidad. Son particularmente importantes para las GPU que se usan en videojuegos de alta gama y aplicaciones profesionales.

La compatibilidad con texturas flotantes de 32 bits filtrables describe la capacidad de una GPU para filtrar texturas de punto flotante de 32 bits. Esto significa que la GPU puede suavizar los bordes de las texturas de punto flotante, lo que hace que parezcan menos irregulares. Es similar a "OES_texture_float_linear" en WebGL.

No todas las GPU admiten texturas flotantes de 32 bits que se pueden filtrar. Cuando la función "float32-filterable" está disponible en un GPUAdapter, ahora puedes solicitar un GPUDevice con esta función y filtrar texturas con "r32float", "rg32float" y "RGBa32float" formatos. Consulta el siguiente ejemplo y el problema dawn:1664.

const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has("float32-filterable")) {
  throw new Error("Filterable 32-bit float textures support is not available");
}
// Explicitly request filterable 32-bit float textures support.
const device = await adapter.requestDevice({
  requiredFeatures: ["float32-filterable"],
});

// Create a sampler with linear filtering.
const sampler = device.createSampler({
  magFilter: "linear",
});

// Create a texture with rgba32float format.
const texture = device.createTexture({
  size: [100, 100],
  format: "rgba32float",
  usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
});

// Write data to texture, create a bindgroup with sampler and texture and
// send the appropriate commands to the GPU....

Formato de vértices unorm10-10-10-2

Un nuevo formato de vértices llamado "unorm10-10-10-2" también conocido como “RGB10a2” se agregó a la especificación de WebGPU. Consiste en un valor empaquetado de 32 bits con cuatro valores enteros normalizados sin firma, organizados en 10 bits, 10 bits, 10 bits y 2 bits. Consulta el siguiente ejemplo y el problema dawn:2044.

// Define the layout of vertex attribute data with unorm10-10-10-2 format.
const buffers = [
  {
    arrayStride: 0,
    attributes: [
      { format: "unorm10-10-10-2", offset: 0, shaderLocation: 0 },
    ],
  },
];

// Describe the vertex shader entry point and its input buffer layouts.
const vertex = {
  module: myVertexShaderModule,
  entryPoint: "main",
  buffers,
};

// Pass vertex to device.createRenderPipeline() and
// use vec4<f32> type in WGSL shader code to manipulate data.

formato de textura rgb10a2uint

Un nuevo formato de textura llamado “RGB10a2uint” se agregó a la especificación de WebGPU. Consta de un formato de píxeles empaquetado de 32 bits con cuatro componentes enteros sin firma: rojo de 10 bits, verde de 10 bits, azul de 10 bits y alfa de 2 bits. Consulta el siguiente ejemplo y el problema dawn:1936.

// Create a texture with rgb10a2uint format.
const texture = device.createTexture({
  size: [100, 100],
  format: "rgb10a2uint",
  usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
});

// Write data to texture, create a bindgroup with texture and
// send the appropriate commands to the GPU....

Actualizaciones del amanecer

Las consultas de marcas de tiempo permiten que las aplicaciones WebGPU midan con precisión (hasta un nanosegundo) el tiempo que tardan en ejecutarse sus comandos de GPU. Se actualizó la forma de la API para capturar consultas de marcas de tiempo al comienzo y al final de los pases para que coincidan con la especificación de WebGPU. Consulta el siguiente ejemplo y el problema dawn:1800.

// Create a timestamp query set that will store the timestamp values.
wgpu::QuerySetDescriptor querySetDescriptor = {
    .count = 2,
    .type = wgpu::QueryType::Timestamp};
wgpu::QuerySet querySet = device.CreateQuerySet(&querySetDescriptor);

wgpu::RenderPassTimestampWrites timestampWrites = {
    .querySet = querySet,
    .beginningOfPassWriteIndex = 0,
    .endOfPassWriteIndex = 1};
wgpu::ComputePassDescriptor pass{.timestampWrites = &timestampWrites};

// Write the queue timestamp into beginningOfPassWriteIndex and
// endOfPassWriteIndex of myQuerySet respectively before and after the pass
// commands execute.
myEncoder.BeginComputePass(&pass);

Esto abarca solo algunos de los aspectos más destacados. Consulta la lista exhaustiva de confirmaciones.

Novedades de WebGPU

Una lista de todo lo que se ha abordado en la serie Novedades de WebGPU.

Chrome 127

Chrome 126

Chrome 125

Chrome 124

Chrome 123

Chrome 122

Chrome 121

Chrome 120

Chrome 119

Chrome 118

Chrome 117

Chrome 116

Chrome 115

Chrome 114

Chrome 113