Skip to content
Closed
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion sample/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// MAINTENANCE_TODO: remove when @webgpu/types is updated to support this.
declare global {
interface GPUSupportedLimits {
maxStorageBuffersInVertexStage: number;
}
}

/** Shows an error dialog if getting an adapter wasn't successful. */
export function quitIfAdapterNotAvailable(
adapter: GPUAdapter | null
Expand Down Expand Up @@ -34,7 +41,7 @@ export function quitIfWebGPUNotAvailable(
}

/** Fail by showing a console error, and dialog box if possible. */
const fail = (() => {
export const fail = (() => {
type ErrorOutput = { show(msg: string): void };

function createErrorOutput() {
Expand Down
15 changes: 12 additions & 3 deletions sample/wireframe/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { modelData } from './models';
import { randElement, randColor } from './utils';
import solidColorLitWGSL from './solidColorLit.wgsl';
import wireframeWGSL from './wireframe.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';
import { fail, quitIfWebGPUNotAvailable } from '../util';

const settings = {
barycentricCoordinatesBased: false,
Expand Down Expand Up @@ -61,8 +61,17 @@ function createVertexAndIndexBuffer(
};
}

const adapter = await navigator.gpu?.requestAdapter();
const device = await adapter?.requestDevice();
const adapter = await navigator.gpu?.requestAdapter({
featureLevel: 'compatibility',
});
if (adapter.limits.maxStorageBuffersInVertexStage < 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be undefined (if not in chrome with compat enabled). Technically this would work because undefined < 2 == NaN < 2 == false but we should be somehow explicit about it.

I made the limit members optional in gpuweb/types#168 which I think would catch this issue (but not the other one).

fail('maxStorageBuffersInVertexStage is < 2');
}
const device = await adapter?.requestDevice({
requiredLimits: {
maxStorageBuffersInVertexStage: 2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will produce an error in standard browsers. It should only be set if the limit exists in adapter.limits.

},
});
quitIfWebGPUNotAvailable(adapter, device);

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