Skip to content
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

Device capture not working in metal backend #6255

Open
mikialex opened this issue Sep 12, 2024 · 4 comments
Open

Device capture not working in metal backend #6255

mikialex opened this issue Sep 12, 2024 · 4 comments
Labels
api: metal Issues with Metal type: bug Something isn't working

Comments

@mikialex
Copy link

Description

The device capture API (device.start_capture or device.stop_capture) not working in the metal backend.

Repro steps

Place any pair of device.start_capture and device.stop_capture between any GPU work doesn't have any effect.

Expected vs observed behavior

As the current capture implementation in metal's backend, the metal's GPU capture should be triggered. Maybe the report should be dumped after stop_capture.

Platform

os: macos 14.5, hardware: m2 pro

@mikialex
Copy link
Author

According to https://developer.apple.com/documentation/xcode/capturing-a-metal-workload-programmatically. I did such modifications in metal's capture implementation and the GPU trace is correctly dumped at the given path.

diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs
index efafc98e1..fa8c3d553 100644
--- a/wgpu-hal/src/metal/device.rs
+++ b/wgpu-hal/src/metal/device.rs
@@ -1369,6 +1369,14 @@ impl crate::Device for super::Device {
         shared_capture_manager.set_default_capture_scope(&default_capture_scope);
         shared_capture_manager.start_capture_with_scope(&default_capture_scope);
         default_capture_scope.begin_scope();
+
+        let capture_desc = metal::CaptureDescriptor::new();
+        capture_desc.set_capture_device(&device);
+        capture_desc.set_destination(metal::MTLCaptureDestination::GpuTraceDocument);
+        capture_desc.set_output_url("/Users/myusername/myproject/testtrace.gputrace");
+
+        shared_capture_manager.start_capture(&capture_desc).unwrap();
+

The destination mush be GpuTraceDocument and the path must be end with the gputrace extension name, or capture will not work.I'm not familiar with the metal so this is just a simple test for reference.

@Wumpf Wumpf added type: bug Something isn't working api: metal Issues with Metal labels Sep 12, 2024
@cwfitzgerald
Copy link
Member

Are you running inside xcode? The assumption with the existing code is that it was running under xcode.

@mikialex
Copy link
Author

no, and I assume this api not required running under xcode. and indeed it should not required running under xcode. I'm using this api to dump metal trace when debug unit test code like this https://github.com/mikialex/rendiation/blob/master/shader/task-graph/src/test.rs.

@cwfitzgerald
Copy link
Member

Interesting, I didn't know this could work outside of xcode, and have always run inside xcode (even unit tests) that I wanted to capture.

We probably need some scheme for communicating a path the user wants to save this under, particularly if they want to save multiple paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: metal Issues with Metal type: bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants