denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.17k stars 5.4k forks source link

Add JS binding for wgpu's start_capture and stop_capture #26766

Open jowens opened 3 weeks ago

jowens commented 3 weeks ago

I would like to use Deno to profile WebGPU compute workloads within Xcode without any need for graphics. Currently, to capture a Metal trace within Xcode for a Deno workload, I'm having to create a window and canvas, invoke my compute workload, and then present the canvas, and then I can (manually) capture the Metal layer and see my compute-workload profile. This is not ideal; I don't want or need graphics at all. I'd like to do this at the command line and/or completely headless.

I believe I can do this if I have JS bindings to the wgpu calls start_capture and stop_capture. With JS bindings to those calls, I can then start and stop capture around my compute workload, then run within Xcode and see profile information.

What would make this even better is if I could write that trace to a file (and this was exposed in JS). Metal has a MTLCaptureManager and https://github.com/gfx-rs/wgpu/pull/3504 appears relevant here.

Also please note https://github.com/gfx-rs/wgpu/issues/6255, which notes Metal backend device capture issues in wgpu.

cc: @raphlinus

crowlKats commented 3 weeks ago

@jowens this is definitively interesting, however am not sure yet how we can exponse this to users as we cnanot add to the web-standard APIs. maybe some form of namespace in the deno namespace (ie Deno.webgpu.*) could work, but not sure if this is desireable. this will need some further discussion; I will bring this up in next week's wgpu meeting, as this is not a singleton for extending the standard APIs.

jowens commented 3 weeks ago

Thank you (in advance) for discussing it! It is definitely a pain point to use the (very fine) Xcode tools with WebGPU and Deno could be a very fine platform for WebGPU development with this, but of course I appreciate the namespace challenges here. I look forward to hearing the outcomes of what you discuss next week!