deno icon indicating copy to clipboard operation
deno copied to clipboard

WebGPU errors are not reported

Open littledivy opened this issue 1 year ago • 4 comments

Failures are not reported to the user and lets the program sliently proceed. This is true for shader creation, pipeline and pipeline layout creation as well as device queue submission.

It's not possible to debug without re compiling Deno with a println in gfx_put! and gfx_ok! macros.

littledivy avatar Jan 27 '24 06:01 littledivy

println is not a viable solution. errors are mostly handled correctly, however the API sucks, and pushErrorScope & popErrorScope should be used for error handling. webgpu method calls themselves usually don't throw errors (with some minor exceptions)

crowlKats avatar Feb 06 '24 12:02 crowlKats

Ok, I think we still need to implement getCompilationInfo for shader errors

littledivy avatar Feb 06 '24 12:02 littledivy

shader errors should already show up in error scopes.

crowlKats avatar Feb 06 '24 12:02 crowlKats

also, getCompilationInfo is blocked by upstream wgpu.

crowlKats avatar Feb 06 '24 12:02 crowlKats

Anything?

sudokit avatar Mar 12 '24 18:03 sudokit

@sudokit are you using the pushErrorScope & popErrorScope APIs and not getting any errors? if so, could you share the code?

crowlKats avatar Mar 12 '24 19:03 crowlKats

I had no idea those existsed!? No idea on how to use them either :p. I assume something like device.pushErrorScope("validation"); for example, and then it should error on invalid shader code when calling device.createShaderModule for example? Might have understood it wrongly. Something like this, i guess?

async getModule(device: GPUDevice): Promise<Result<GPUShaderModule, Error>> {
  let code;
  code = await this.getCode();
  if (code.isErr()) return Err(code.unwrapErr());
  code = code.unwrap();
  device.pushErrorScope("validation");
  const shaderModule = device.createShaderModule({ code: code });
  device.popErrorScope(); // would error?

  return Ok(shaderModule);
  }

EDIT: ah no never miiind! device.popErrorScope(); returns with the error if it has one! And its beautiful hahaha. Thanks!! Do you constantly before every operation need to push an error scope, or can you just push it once and then pop errors as they come? And do you need to pop errors after every operation, or else they stack up (idk if im understanding this correctly)?

sudokit avatar Mar 12 '24 19:03 sudokit

ok so this is something I dont 100% understand either, but i believe it is as follows:

can you just push it once and then pop errors as they come?

yes

And do you need to pop errors after every operation, or else they stack up

they stack up

however, you need to a scope for every time you might pop an error scope.

Also from your code: device.popErrorScope(); // would error? popErrorScope is async, and it returns the error, it doesnt throw it

crowlKats avatar Mar 12 '24 19:03 crowlKats

Ah so everytime you might want to check for an potential error, you need to push a scope... And do they stack up even if you dont push a scope? And yeah figured that it returned the error. So changed it to const err = await device.popErrorScope();

sudokit avatar Mar 13 '24 06:03 sudokit

Wrapping my code within an error scope solves the issue for me. Here's how I did it:

await device.pushErrorScope("validation");
const shaderModule = device.createShaderModule({
  code: "<foo bar>",
});
const error = await device.popErrorScope();
console.log(error);

yudshj avatar Apr 01 '24 09:04 yudshj

Closing the issue because the (awkward) error management is intended as per spec

littledivy avatar Apr 01 '24 09:04 littledivy