Skip to content

Commit

Permalink
Compatibility Mode, the easy part. (#488)
Browse files Browse the repository at this point in the history
Enable WebGPU Compatibility Mode for all samples that can run
unmodified in that mode.

* Reformat.

* Add comma after last item in dictionary.
  • Loading branch information
SenorBlanco authored Jan 17, 2025
1 parent c6783d7 commit 0ce1ef2
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 26 deletions.
4 changes: 3 additions & 1 deletion sample/animometer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import animometerWGSL from './animometer.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/blending/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { GUI } from 'dat.gui';
import { quitIfWebGPUNotAvailable } from '../util';
import texturedQuadWGSL from './texturedQuad.wgsl';

const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/cameras/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ gui.add(params, 'type', ['arcball', 'WASD']).onChange(() => {
oldCameraType = newCameraType;
});

const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);
const context = canvas.getContext('webgpu') as GPUCanvasContext;
Expand Down
4 changes: 3 additions & 1 deletion sample/computeBoids/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import updateSpritesWGSL from './updateSprites.wgsl';
import { GUI } from 'dat.gui';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
quitIfAdapterNotAvailable(adapter);

const hasTimestampQuery = adapter.features.has('timestamp-query');
Expand Down
4 changes: 3 additions & 1 deletion sample/fractalCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import sampleSelfWGSL from './sampleSelf.frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/gameOfLife/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import fragWGSL from './frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/helloTriangle/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import redFragWGSL from '../../shaders/red.frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/helloTriangleMSAA/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import redFragWGSL from '../../shaders/red.frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/imageBlur/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const tileDim = 128;
const batch = [4, 4];

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/instancedCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import vertexPositionColorWGSL from '../../shaders/vertexPositionColor.frag.wgsl
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/multipleCanvases/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function createVertexAndIndexBuffer(
};
}

const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/normalMap/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ enum TextureAtlas {
}

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);
const context = canvas.getContext('webgpu') as GPUCanvasContext;
Expand Down
4 changes: 3 additions & 1 deletion sample/occlusionQuery/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export type TypedArrayConstructor =

const info = document.querySelector('#info');

const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/points/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ function createFibonacciSphereVertices({
return new Float32Array(vertices);
}

const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/renderBundles/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ interface Renderable {
}

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/resizeCanvas/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import redFragWGSL from '../../shaders/red.frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/resizeObserverHDDPI/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import checkerWGSL from './checker.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/rotatingCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import vertexPositionColorWGSL from '../../shaders/vertexPositionColor.frag.wgsl
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/shadowMapping/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { quitIfWebGPUNotAvailable } from '../util';
const shadowDepthTextureSize = 1024;

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/texturedCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import sampleTextureMixColorWGSL from './sampleTextureMixColor.frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/transparentCanvas/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import vertexPositionColorWGSL from '../../shaders/vertexPositionColor.frag.wgsl
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/twoCubes/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import vertexPositionColorWGSL from '../../shaders/vertexPositionColor.frag.wgsl
import { quitIfWebGPUNotAvailable } from '../util';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/videoUploading/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import fullscreenTexturedQuadWGSL from '../../shaders/fullscreenTexturedQuad.wgs
import sampleExternalTextureWGSL from '../../shaders/sampleExternalTexture.frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';

const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

Expand Down
4 changes: 3 additions & 1 deletion sample/volumeRenderingTexture3D/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ gui.add(params, 'rotateCamera', true);
gui.add(params, 'near', 2.0, 7.0);
gui.add(params, 'far', 2.0, 7.0);

const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);
const context = canvas.getContext('webgpu') as GPUCanvasContext;
Expand Down
4 changes: 3 additions & 1 deletion sample/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ self.addEventListener('message', (ev) => {
// to the init() method for all the other samples. The remainder of this file is largely identical
// to the rotatingCube sample.
async function init(canvas) {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);
const context = canvas.getContext('webgpu');
Expand Down
4 changes: 3 additions & 1 deletion sample/workloadSimulator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ <h2><center>Web graphics workload simulator</center></h2>
try {
if (deviceRequested) return;
deviceRequested = true;
let adapter = await navigator.gpu.requestAdapter();
let adapter = await navigator.gpu.requestAdapter({
featureLevel: 'compatibility',
});
featuresAndLimits.textContent = JSON.stringify(
{
name: adapter.name,
Expand Down

0 comments on commit 0ce1ef2

Please sign in to comment.