Wat is er nieuw in WebGPU (Chrome 119)

François Beaufort
François Beaufort

Filterbare 32-bits float-texturen

32-bits floating-point texturen worden gebruikt om zeer nauwkeurige data op te slaan, zoals HDR-afbeeldingen en dieptekaarten. Ze zijn vooral belangrijk voor GPU's die worden gebruikt in high-end gaming en professionele toepassingen.

Ondersteuning voor filterbare 32-bits float-texturen beschrijft de mogelijkheid van een GPU om 32-bits floating-point texturen te filteren. Dit betekent dat de GPU de randen van floating-point texturen kan gladstrijken, waardoor ze er minder gekarteld uitzien. Het is vergelijkbaar met de extensie "OES_texture_float_linear" in WebGL.

Niet alle GPU's ondersteunen filterbare 32-bits float-texturen. Wanneer de functie "float32-filterable" beschikbaar is in een GPUAdapter , kunt u nu een GPUDevice met deze functie aanvragen en texturen filteren met de formaten "r32float", "rg32float" en "rgba32float". Zie het volgende voorbeeld en 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....

unorm10-10-10-2 vertex-formaat

Een nieuw vertexformaat genaamd "unorm10-10-10-2", ook wel "rgb10a2" genoemd, is toegevoegd aan de WebGPU-specificatie . Het bestaat uit één gepakte 32-bits waarde met vier genormaliseerde unsigned integer-waarden, gerangschikt als 10 bits, 10 bits, 10 bits en 2 bits. Zie het volgende voorbeeld en 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.

rgb10a2uint textuurformaat

Een nieuw textuurformaat genaamd "rgb10a2uint" is toegevoegd aan de WebGPU-specificatie . Het bestaat uit een 32-bits gepakte pixelindeling met vier unsigned integer-componenten: 10-bits rood, 10-bits groen, 10-bits blauw en 2-bits alfa. Zie het volgende voorbeeld en 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....

Dawn-updates

Met tijdstempelquery's kunnen WebGPU-applicaties nauwkeurig (tot op de nanoseconde) meten hoe lang het duurt om hun GPU-opdrachten uit te voeren. De API-vorm om tijdstempelquery's aan het begin en einde van passes vast te leggen, is bijgewerkt en voldoet nu aan de WebGPU-specificatie. Zie het volgende voorbeeld en 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);

Dit behandelt slechts enkele van de belangrijkste hoogtepunten. Bekijk de volledige lijst met commits .

Wat is er nieuw in WebGPU

Een lijst met alles wat in de serie Wat is er nieuw in WebGPU aan bod is gekomen.

Chroom 139

Chroom 138

Chroom 137

Chroom 136

Chroom 135

Chroom 134

Chroom 133

Chroom 132

Chroom 131

Chroom 130

Chroom 129

Chroom 128

Chroom 127

Chroom 126

Chroom 125

Chroom 124

Chroom 123

Chroom 122

Chroom 121

Chroom 120

Chroom 119

Chroom 118

Chroom 117

Chroom 116

Chroom 115

Chroom 114

Chroom 113