Skip to content

Instantly share code, notes, and snippets.

@greggman
Last active January 8, 2026 18:21
Show Gist options
  • Select an option

  • Save greggman/e2395d304fce578e2c1026bfb46fa8fe to your computer and use it in GitHub Desktop.

Select an option

Save greggman/e2395d304fce578e2c1026bfb46fa8fe to your computer and use it in GitHub Desktop.
WebGPU: primitive-index test
/*bug-in-github-api-content-can-not-be-empty*/
/*bug-in-github-api-content-can-not-be-empty*/
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice({
requiredFeatures: ['primitive-index'],
});
if (!device) {
fail('no device');
}
console.log('features:', [...device.features].join(', '));
device.addEventListener('uncapturederror', e => console.error(e.error.message));
device.createShaderModule({
code: `
requires primitive_index;
struct VSOut {
@builtin(position) p: vec4f,
}
struct FSIn {
@builtin(primitive_index) i_0: u32,
}
struct FSOut {
@location(0) color: vec4f,
}
@vertex fn vs() -> VSOut {
var o: VSOut;
o.p = vec4f(0);
return o;
}
@fragment fn fs(i: FSIn) -> FSOut {
var o: FSOut;
o.color = vec4f(0);
return o;
}
`,
})
device.queue.submit([]);
{"name":"WebGPU: primitive-index test","settings":{},"filenames":["index.html","index.css","index.js"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment