Created
May 6, 2024 09:00
-
-
Save greggman/67ae771375e1c77fc9e18a116596c1d0 to your computer and use it in GitHub Desktop.
WebGPU misleading createBindGroup error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*bug-in-github-api-content-can-not-be-empty*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*bug-in-github-api-content-can-not-be-empty*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function main() { | |
const adapter = await navigator.gpu?.requestAdapter(); | |
const device = await adapter?.requestDevice(); | |
const module = device.createShaderModule({code: ` | |
@vertex fn vs() -> @builtin(position) vec4f { | |
return vec4f(0); | |
} | |
@group(0) @binding(0) var tex: texture_2d<f32>; | |
@group(0) @binding(1) var smp: sampler; | |
@group(0) @binding(2) var<storage, read_write> data: array<vec4f>; | |
@fragment fn fs(v: Vertex) -> @location(0) vec4f { | |
data[0] = textureSample(tex, smp, vec2f(0)); | |
return vec4f(0); | |
} | |
`, | |
}); | |
const pipeline = device.createRenderPipeline({ | |
layout: 'auto', | |
vertex: { module }, | |
fragment: { | |
module, | |
targets: [ | |
{format: 'rgba8unorm'}, | |
], | |
}, | |
}); | |
const outBuffer = device.createBuffer({ | |
size: 128, | |
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC, | |
}); | |
const sampler = device.createSampler({}); | |
const texture = device.createTexture({ | |
size: [2, 2], | |
format: 'rgba8unorm', | |
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING, | |
}); | |
try { | |
const bindGroup = device.createBindGroup({ | |
layout: pipeline.getBindGroupLayout(0), | |
entries: [ | |
{ binding: 0, resource: texture }, | |
{ binding: 1, resource: sampler }, | |
{ binding: 2, resource: { buffer: outBuffer }}, | |
], | |
}); | |
} catch (e) { | |
log(e); | |
} | |
} | |
function fail(msg) { | |
const elem = document.querySelector('#fail'); | |
const contentElem = elem.querySelector('.content'); | |
elem.style.display = ''; | |
contentElem.textContent = msg; | |
} | |
function log(...args) { | |
const elem = document.createElement('code'); | |
elem.textContent = args.join(' '); | |
document.body.appendChild(elem); | |
} | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"WebGPU misleading createBindGroup error","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