מה חדש ב-WebGPU (Chrome 119)

François Beaufort
François Beaufort

מרקמים מסוג float ב-32 ביט שאפשר לסנן

מרקמים של נקודה צפה (floating-point) ב-32 ביט משמשים לאחסון נתונים ברמת דיוק גבוהה, כמו תמונות HDR ומפות עומק. הם חשובים במיוחד למעבדי GPU שמשמשים למשחקים מתקדמים ולאפליקציות מקצועיות.

התמיכה בסינון של טקסטורות בפורמט 32-bit float מתארת את היכולת של מעבד גרפי לסנן טקסטורות בפורמט 32-bit floating-point. המשמעות היא שה-GPU יכול להחליק את הקצוות של טקסטורות בנקודה צפה, כך שהן ייראו פחות משוננות. היא דומה לתוסף OES_texture_float_linear ב-WebGL.

לא כל המעבדים הגרפיים תומכים בטקסטורות של 32 ביט עם אפשרות סינון. אם התכונה "float32-filterable" זמינה ב-GPUAdapter, עכשיו אפשר לבקש GPUDevice באמצעות התכונה הזו ולסנן טקסטורות בפורמטים r32float,‏ rg32float ו-rgba32float. אפשר לעיין בדוגמה הבאה ובבעיה 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

נוסף פורמט חדש של קודקוד שנקרא unorm10-10-10-2, או rgb10a2, למפרט WebGPU. הוא מורכב מערך אחד ארוז של 32 ביט עם ארבעה ערכים שלמים לא מסומנים ומנורמלים, שמסודרים כ-10 ביט, 10 ביט, 10 ביט ו-2 ביט. מקרה לדוגמה: 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

פורמט חדש של טקסטורה בשם rgb10a2uint נוסף למפרט WebGPU. הוא מורכב מפורמט פיקסל דחוס של 32 ביט עם ארבעה רכיבי מספרים שלמים לא מסומנים: אדום של 10 ביט, ירוק של 10 ביט, כחול של 10 ביט ואלפא של 2 ביט. לדוגמה, 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....

עדכונים לגבי שעות השחר

שאילתות של חותמות זמן מאפשרות לאפליקציות WebGPU למדוד בדיוק (עד לרמת הננו-שנייה) כמה זמן לוקח לפקודות ה-GPU שלהן להתבצע. הצורה של ה-API לתיעוד חותמות זמן של שאילתות בתחילת המעברים ובסופם עודכנה כך שתתאים למפרט WebGPU. לדוגמה: 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);

המידע הזה כולל רק חלק מהנקודות העיקריות. רשימה מלאה של קומיטים

מה חדש ב-WebGPU

רשימה של כל הנושאים שמופיעים בסדרת המאמרים מה חדש ב-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