Skip to content

Instantly share code, notes, and snippets.

@greggman
Created June 6, 2025 22:07
Show Gist options
  • Save greggman/98e2766376048f434757e87a8d0ddb32 to your computer and use it in GitHub Desktop.
Save greggman/98e2766376048f434757e87a8d0ddb32 to your computer and use it in GitHub Desktop.
WebGPU: Show error using createBindGroup when you forget to call createView on a texture binding

WebGPU: Show error using createBindGroup when you forget to call createView on a texture binding

view on jsgist

:root { color-scheme: light dark; }
/*bug-in-github-api-content-can-not-be-empty*/
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const layout = device.createBindGroupLayout({
entries: [
{
binding: 0,
visibility: GPUShaderStage.FRAGMENT,
texture: {},
},
],
});
const texture = device.createTexture({
format: 'rgba8unorm',
usage: GPUTextureUsage.TEXTURE_BINDING,
size: [1, 1],
});
try {
const bg = device.createBindGroup({
layout,
entries: [
{ binding: 0, resource: texture }, // error, should be texture.createView()
],
});
} catch (ex) {
log(ex.message);
}
function log(...args) {
const elem = document.createElement('code')
elem.textContent = args.join(' ');
document.body.append(elem);
}
{"name":"WebGPU: Show error using createBindGroup when you forget to call createView on a texture binding","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