-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regression: web gpu working incorrectly #24857
Comments
Here is a self contained example async function addWithWebGPU(a: number, b: number) {
if (!navigator.gpu) {
throw new Error("WebGPU not supported on this browser.");
}
console.log("Requesting adapter...");
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw new Error("No appropriate GPUAdapter found.");
}
console.log("Requesting device...");
const device = await adapter.requestDevice();
console.log("Creating buffer...");
const bufferSize = 3 * Float32Array.BYTES_PER_ELEMENT;
const buffer = device.createBuffer({
size: bufferSize,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC |
GPUBufferUsage.COPY_DST,
});
console.log("Writing input data...");
const input = new Float32Array([a, b, 0]);
device.queue.writeBuffer(buffer, 0, input);
console.log("Creating shader module...");
const shaderModule = device.createShaderModule({
code: `
@group(0) @binding(0) var<storage, read_write> data: array<f32>;
@compute @workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id : vec3<u32>) {
data[2] = data[0] + data[1];
}
`,
});
console.log("Creating compute pipeline...");
const pipeline = device.createComputePipeline({
layout: "auto",
compute: {
module: shaderModule,
entryPoint: "main",
},
});
console.log("Creating bind group...");
const bindGroup = device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [{ binding: 0, resource: { buffer: buffer } }],
});
console.log("Encoding commands...");
const commandEncoder = device.createCommandEncoder();
const passEncoder = commandEncoder.beginComputePass();
passEncoder.setPipeline(pipeline);
passEncoder.setBindGroup(0, bindGroup);
passEncoder.dispatchWorkgroups(1);
passEncoder.end();
console.log("Creating read buffer...");
const gpuReadBuffer = device.createBuffer({
size: bufferSize,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
});
console.log("Encoding copy command...");
commandEncoder.copyBufferToBuffer(buffer, 0, gpuReadBuffer, 0, bufferSize);
console.log("Submitting GPU commands...");
const gpuCommands = commandEncoder.finish();
device.queue.submit([gpuCommands]);
console.log("Mapping read buffer...");
await gpuReadBuffer.mapAsync(GPUMapMode.READ);
const resultArrayBuffer = gpuReadBuffer.getMappedRange();
const result = new Float32Array(resultArrayBuffer);
console.log("Raw result array:", result);
// Extract the result before unmapping
const finalResult = result[2];
gpuReadBuffer.unmap();
console.log("Computation complete.");
return finalResult;
}
// Usage
async function testAddition() {
try {
const result = await addWithWebGPU(5, 7);
console.log(`5 + 7 = ${result}`);
} catch (error) {
console.error("An error occurred:", error);
}
}
// Run the test
testAddition().then(() => console.log("Test completed")).catch((error) =>
console.error("Test failed:", error)
); it outputs 0 instead of 12 but this works on firefox nightly 131.0a1 |
All the other examples work, it seems like the issue is specifically with compute |
If I run the rust wgpu compute example, I get
|
if I run with |
the issue seem to be specifically with |
the same happens in rust webgpu, so its a webgpu bug |
I guess the only thing deno can do better here is surface such errors |
wgpu now doesn't support incomplete vulkan implementation, that's why it stopped working, it works on xorg because for some reason its picking llvmpipe (vulkan cpu implemtation) as the adapter which workarounds this issue |
outputs [ "1", "4", "3", "295" ] instead of ["0", "2", "7", "55"]
This works with version 1.43.0 but not 1.44.0 @crowlKats suspects #23684
meta:
Linux 1E-55-11-07-05-2E 6.9.11-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 25 18:17:34 UTC 2024 x86_64 GNU/Linux
Brand Raw: Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
The text was updated successfully, but these errors were encountered: