Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions sample/cornell/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ import {

const canvas = document.querySelector('canvas') as HTMLCanvasElement;

const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
const features: GPUFeatureName[] =
presentationFormat === 'bgra8unorm' ? ['bgra8unorm-storage'] : [];
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
quitIfAdapterNotAvailable(adapter);

for (const feature of features) {
if (!adapter.features.has(feature)) {
throw new Error(
`sample requires ${feature}, but is not supported by the adapter`
);
const features: GPUFeatureName[] = [];
let presentationFormat = navigator.gpu.getPreferredCanvasFormat();
if (presentationFormat == 'bgra8unorm') {
if (adapter.features.has('bgra8unorm-storage')) {
features.push('bgra8unorm-storage');
} else {
// If the GPU prefers BGRA for presentation but the Adapter
// doesn't support bgra8unorm-storage (e.g., Compatibility
// mode), use rgba8unorm for both. This will be slower, but will
// work.
presentationFormat = 'rgba8unorm';
}
}
const limits: Record<string, GPUSize32> = {};
Expand Down