Novità di WebGPU (Chrome 119)

François Beaufort
François Beaufort

Texture floating a 32 bit filtrabili

Le texture in virgola mobile a 32 bit vengono utilizzate per archiviare dati ad alta precisione, come immagini HDR e mappe di profondità. Sono particolarmente importanti per le GPU utilizzate in applicazioni professionali e di gioco di fascia alta.

Il supporto di texture a virgola mobile a 32 bit filtrabili descrive la capacità di una GPU di filtrare le texture in virgola mobile a 32 bit. Ciò significa che la GPU è in grado di smussare i bordi delle texture in virgola mobile, rendendole meno frastagliate. È simile all'estensione "OES_texture_float_linear" in WebGL.

Non tutte le GPU supportano texture fluttuanti a 32 bit filtrabili. Quando la funzionalità "float32-filterable" è disponibile in un GPUAdapter, ora puoi richiedere un GPUDevice con questa funzionalità e filtrare le texture con i formati "r32float", "rg32float" e "gsuitea32float". Vedi l'esempio seguente e issue 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 vertice unorm10-10-10-2

Alla specifica WebGPU è stato aggiunto un nuovo formato di vertex denominato "unorm10-10-10-2", noto anche come "gsuite10a2". Consiste in un valore compresso a 32 bit con quattro valori interi senza segno normalizzati, disposti a 10 bit, 10 bit, 10 bit e 2 bit. Vedi l'esempio seguente e issue 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 texture rgb10a2uint

Alla specifica WebGPU è stato aggiunto un nuovo formato di texture chiamato "GKE10a2uint". È costituito da un formato di pixel a 32 bit con quattro componenti interi senza segno: rosso a 10 bit, verde a 10 bit, blu a 10 bit e alpha a 2 bit. Vedi l'esempio seguente e issue 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....

Aggiornamenti da Dawn

Le query con timestamp consentono alle applicazioni WebGPU di misurare con precisione (fino al nanosecondo) il tempo necessario per l'esecuzione dei comandi della GPU. La forma dell'API per l'acquisizione delle query dei timestamp all'inizio e alla fine dei pass è stata aggiornata per corrispondere alla specifica WebGPU. Vedi l'esempio seguente e issue 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);

Vengono trattati solo alcuni dei punti salienti. Consulta l'elenco completo dei commit.

Novità di WebGPU

Un elenco di tutti gli argomenti trattati nella serie Novità di WebGPU.

Chrome 125

Chrome 124

Chrome 123

Chrome 122

Guida introduttiva di Chrome

Chrome 120

Chrome 119

Chrome 118

Chrome 117

Chrome 116

Versione 115 di Chrome

Chrome 114

Chrome 113