Skip to content

Instantly share code, notes, and snippets.

@slimbuck
Created May 13, 2024 08:47
Show Gist options
  • Save slimbuck/ec4500afaec6b2c5368c22a37153826d to your computer and use it in GitHub Desktop.
Save slimbuck/ec4500afaec6b2c5368c22a37153826d to your computer and use it in GitHub Desktop.
Capturing WebGPU metal trace on MacOS
1) Clone and build WebKit
git clone https://github.com/WebKit/WebKit.git WebKit
cd WebKit
Tools/Scripts/build-webkit -cmakeargs="-DENABLE_WEBGPU_BY_DEFAULT=1" --debug
2) Run your app
__XPC_METAL_CAPTURE_ENABLED=1 Tools/Scripts/run-minibrowser --debug --url http://localhost:5000/index.html#/loaders/gsplat
3) While app is running invoke WebGPU capture from a new terminal
notifyutil -p com.apple.WebKit.WebGPU.CaptureFrame
4) File is written to HD, WebKit terminal displays the path.
5) Load the file into xcode (file open) and profit.
@vorg
Copy link

vorg commented Sep 7, 2024

if you encounter error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance or similar i used this fix nodejs/node-gyp#569

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

@vorg
Copy link

vorg commented Sep 7, 2024

Also bear in mind that compiling webkit might take up to 55GB of space... (drops to 11GB once finished).

@vorg
Copy link

vorg commented Sep 7, 2024

Also needs enabling WebGPU from Menu -> Settigs -> Experimental Features -> WebGL

@artemverbo
Copy link

@vorg hello, could you please advise, where was it saving the frames for you? notifyutil -p com.apple.WebKit.WebGPU.CaptureFrame gives me no output in the Webkit process terminal or anywhere I could check, no errors anywhere, doubt it does a snapshot at all, but unsure how to debug best...

@subblue
Copy link

subblue commented Sep 24, 2024

@vorg hello, could you please advise, where was it saving the frames for you? notifyutil -p com.apple.WebKit.WebGPU.CaptureFrame gives me no output in the Webkit process terminal or anywhere I could check, no errors anywhere, doubt it does a snapshot at all, but unsure how to debug best...

For me the output path of the debug info only appeared after interacting with the app in the minibrowser to trigger a frame render.

@subblue
Copy link

subblue commented Sep 24, 2024

Thanks for writing this up - it's going to be super useful!

@vorg
Copy link

vorg commented Sep 24, 2024

For me the output path of the debug info only appeared after interacting with the app in the minibrowser to trigger a frame render.

Yes. You have to click on window / cmd+tab / give it focus somehow to trigger the capture.

@brandon-lb
Copy link

Huh, even though I compiled successfully with the full command including -cmakeargs="-DENABLE_WEBGPU_BY_DEFAULT=1", I get "Error: WebGPU is not supported (no navigator.gpu)" when I launch my app with __XPC_METAL_CAPTURE_ENABLED=1 Tools/Scripts/run-minibrowser --debug --url example.com

I'm on Sequoia 15.0.1 and can confirm that WebGPU works normally with the WebGPU feature flag set on the included version of Safari.

@brandon-lb
Copy link

Oh, I got it working by finding the flag in the minibrowser menu and enabling it! Onto the next steps

@brandon-lb
Copy link

So even though I got it working on macOS 15.0.1 on one computer, on another one with the same OS, I cannot get it to compile properly. I've tried deleting/re-cloning, restarting, it always fails at:

** BUILD FAILED **


The following build commands failed:
	PhaseScriptExecution Run\ Script /Users/brandon/Files/WebKit/WebKitBuild/WebKitLegacy.build/Debug/Generate\ Unified\ Sources.build/Script-5C9D925722D7E849008E9266.sh (in target 'Generate Unified Sources' from project 'WebKitLegacy')
	Building workspace WebKit with scheme Everything up to WebKit + Tools and configuration Debug
(2 failures)

Anyone run into something similar? I've had this computer for over a year, while the one where it worked is basically a fresh install with only Xcode on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment