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

François Beaufort
François Beaufort

טקסטורות צפות ב-32 סיביות הניתנות לסינון

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

תמיכה במרקמים צפים של 32 סיביות שניתנים לסינון, מתארת את היכולת של GPU לסנן מרקמים של נקודה צפה ב-32 סיביות. כלומר, ה-GPU יכול להחליק את הקצוות של מרקמים המבוססים על נקודה צפה ולגרום להם להיראות פחות משוננים. היא דומה לתוסף "OES_texture_float_לינארי" ב-WebGL.

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

Chrome 124

Chrome 123

גרסה 122 של Chrome

גרסה 121 של Chrome

Chrome 120

גרסה 119 של Chrome

גרסה 118 של Chrome

גרסה 117 של Chrome

גרסה 116 של Chrome

Chrome 115

Chrome 114

גרסה 113 של Chrome