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

Add Safe GPU Api #41

Closed
wants to merge 12 commits into from
Closed

Add Safe GPU Api #41

wants to merge 12 commits into from

Conversation

cwfitzgerald
Copy link
Contributor

@cwfitzgerald cwfitzgerald commented May 25, 2022

Depends on #39

Context Wumpf/wgpu-profiler#15

This adds the GPU api to tracy_client. It merely adds safe interfaces. I am putting this up as a draft to get opinions on architecture.

TODO:

  • docs
  • doctests

Copy link
Contributor

@Ralith Ralith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see this expanded on with concise, ergonomic, non-allocating macros as has been done with e.g. span.

I'm also a bit confused about how this works. There doesn't seem to be much here that could plausibly interact with the GPU.

tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
Copy link
Owner

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the caveat that I don't deal with GPUs much, the overall shape seems quite reasonable to me. Excited to see progress here, and sorry for the delay in reviewing this.

tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
@cwfitzgerald
Copy link
Contributor Author

cwfitzgerald commented Jun 27, 2022

Pardon the delay, most of these should be addressed now. Still haven't done documentation, but will wait until we've settled on api shape.

Copy link
Owner

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good enough to me, just a couple of nits (and docs and tests) before this could be merged.

Sorry for the long delays in review here. Holidays and stuff.

tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
@cwfitzgerald
Copy link
Contributor Author

This totally got lost in my history - got this fully back up to date, an improved some of the code to make it more resilient.

Needs more documentation and the test causes tracy to crash, which I need to get a debug build of tracy to debug (this was an issue before the fix, the test just makes it trivial to reproduce.

@cwfitzgerald cwfitzgerald requested a review from nagisa July 30, 2023 07:55
@nagisa
Copy link
Owner

nagisa commented Jul 30, 2023

I would be happy to land this as soon as the doc-comments are filled in.

Tracy crashes: unfortunately those usually are an issue in the upstream project. I’m of an opinion that we’re not supposed to work around those in the bindings. The only place where any meaningful amount of complex logic is warranted is in the tracing bridge which attempts to paper over the semantic mismatches between two ecosystems. When reporting an issue upstream, do beware that the author there does not have particularly warm feelings towards the Rust ecosystem, so I found it better/easier to come up with minimal C code samples, or to straight=up provide fixes.

@cwfitzgerald
Copy link
Contributor Author

cwfitzgerald commented Jul 30, 2023

Cool! Will add the doc comments and such and some end-to-end documentation.

I want to at least get a culpret for the tracy crash, to make sure we're not somehow misusing the api, as the builtin integrations seem to work okay. Will build a c repro if it happens to be Tracy's fault, thankfully should be pretty simple.

tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Outdated Show resolved Hide resolved
tracy-client/src/gpu.rs Show resolved Hide resolved
@cwfitzgerald
Copy link
Contributor Author

Traced down the bug, it was actually an assert in tracy that was getting hit. I wasn't using the _serial version of the context naming function, which caused a failure.

From looking at the tracy's use of query ids, they have asserts that they are never re-used until the timestamps are written. As such, I'm going to add a freelist for validation and re-use prevention.

@cwfitzgerald cwfitzgerald marked this pull request as ready for review July 31, 2023 04:32
@cwfitzgerald cwfitzgerald requested a review from Ralith July 31, 2023 04:32
@cwfitzgerald
Copy link
Contributor Author

Failures unrelated.

@cwfitzgerald
Copy link
Contributor Author

I think this is good for final reviews

#[cfg(feature = "enable")]
gpu_start_timestamp: i64,
#[cfg(feature = "enable")]
span_freelist: Arc<Mutex<Vec<u16>>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we certain that span IDs are per-context and not global in tracy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they make no attempt to globally de-duplicate them in their own bindings.

@nagisa
Copy link
Owner

nagisa commented Aug 13, 2023

Merged this in 9ed943b and pushed out a new release.

@nagisa nagisa closed this Aug 13, 2023
@cwfitzgerald
Copy link
Contributor Author

The commit on main unfortunately appears to be a fairly old iteration of this PR, missing most of the doc comments and some of the fixes.

nagisa pushed a commit that referenced this pull request Aug 14, 2023
Shows you shouldn't be merging stuff late Sunday night lol :)
@nagisa
Copy link
Owner

nagisa commented Aug 14, 2023

Ah, my bad, looks like squash-merging this on a late sunday night was a mistake :)

Yanked 0.16.0, merged the rest of the PR, and released a new one. I believe it correctly contains the rest of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants