Novità di WebGPU (Chrome 119)

François Beaufort
François Beaufort

Texture a virgola mobile 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 delle texture filtrabili a virgola mobile a 32 bit descrive la capacità di una GPU di filtrare le texture a virgola mobile a 32 bit. Ciò significa che la GPU può smussare i bordi delle texture in virgola mobile, rendendoli meno frastagliati. È simile all'estensione "OES_texture_float_linear" in WebGL.

Non tutte le GPU supportano le texture a virgola mobile 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 "rgba32float". Vedi l'esempio seguente e il 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 vertice unorm10-10-10-2

È stato aggiunto un nuovo formato dei vertici denominato "unorm10-10-10-2", noto anche come "rgb10a2", alla specifica WebGPU. È costituito da un valore compresso a 32 bit con quattro valori interi non firmati normalizzati, disposti come 10 bit, 10 bit, 10 bit e 2 bit. Vedi l'esempio seguente e il 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 texture rgb10a2uint

È stato aggiunto un nuovo formato di texture denominato "rgb10a2uint" alla specifica WebGPU. Consiste in un formato pixel compresso a 32 bit con quattro componenti interi senza segno: rosso a 10 bit, verde a 10 bit, blu a 10 bit e alfa 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 all'alba

Le query sui 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 acquisire le query dei timestamp all'inizio e alla fine delle tessere è stata aggiornata in modo che corrisponda 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);

Questi sono 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 140

Chrome 139

Chrome 138

Chrome 137

Chrome 136

Chrome 135

Chrome 134

Chrome 133

Chrome 132

Chrome 131

Chrome 130

Chrome 129

Chrome 128

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