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

François Beaufort
François Beaufort

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

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

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

לא כל יחידות ה-GPU תומכות במרקמים צפים של 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 ביטים. אפשר לראות את הדוגמה הבאה ואת הבעיה 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 סיביות. אפשר לראות את הדוגמה הבאה ואת הבעיה 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. אפשר לעיין בדוגמה הבאה ואת הבעיה 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 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