Vulkan-Samples icon indicating copy to clipboard operation
Vulkan-Samples copied to clipboard

Add Tracy Profiler Support

Open tomadamatkinson opened this issue 1 year ago • 26 comments

Description

Adds Tracy Profiler support. This will allow samples to show the stats and usage that they want to show to users without needing to clutter the Sample GUI

This can be extended in the future to instrument up core parts of the framework and samples that we want to draw the users attention too. It can also be used to show how multi-threading can be used with Vulkan

For now I have hooked this into our stats system so that we can show more stat information to users without worrying about cluttering the main GUI. We can still use the main sample GUI to show stats aswell!! I also added support for VMA Memory Budgets to show heap usage

We can use this to track other useful information such as the amount of vertices we expect to render for a given frame or the amount of geometry in the scene graph

Tracy also has Vulkan support however I have not played around with this yet

image

String names for VkMemoryTypeFlags are taking from vulkan.hpp instead of adding to the existing vkb::to_string() set

General Checklist:

Please ensure the following points are checked:

  • [ ] My code follows the coding style
  • [ ] I have reviewed file licenses
  • [ ] I have commented any added functions (in line with Doxygen)
  • [ ] I have commented any code that could be hard to understand
  • [ ] My changes do not add any new compiler warnings
  • [ ] My changes do not add any new validation layer errors or warnings
  • [ ] I have used existing framework/helper functions where possible
  • [ ] My changes do not add any regressions
  • [ ] I have tested every sample to ensure everything runs correctly
  • [ ] This PR describes the scope and expected impact of the changes I am making

Note: The Samples CI runs a number of checks including:

  • [ ] I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)
  • [ ] My changes build on Windows, Linux, macOS and Android. Otherwise I have documented any exceptions

Sample Checklist

If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist:

  • [ ] I have tested the sample on at least one compliant Vulkan implementation
  • [ ] If the sample is vendor-specific, I have tagged it appropriately
  • [ ] I have stated on what implementation the sample has been tested so that others can test on different implementations and platforms
  • [ ] Any dependent assets have been merged and published in downstream modules
  • [ ] For new samples, I have added a paragraph with a summary to the appropriate chapter in the samples readme
  • [ ] For new samples, I have added a tutorial README.md file to guide users through what they need to know to implement code using this feature. For example, see conditional_rendering

tomadamatkinson avatar Jul 17 '23 18:07 tomadamatkinson

Is the concurrency stuff in the *.yml files related to adding tracy?

Besides that, I'm not familiar with tracy. How would I get that nice little tracy window?

The concurrency stuff isn't related, I can make a small PR for these changes if needed. Just threw it in here as I had lots of jobs running and not automatically cancelling outdated ones.

To use Tracy you should be able to run './scripts/tracy.py' and it will build and run the window. I have only tested this on Linux and you do need to install system libraries.

I can give it a go on windows at some point this week and make sure it works. It is likely that it won't work first time

tomadamatkinson avatar Jul 20 '23 07:07 tomadamatkinson

It is likely that it won't work first time

And you're right, tracy on windows is not supported.

The concurrency stuff isn't related,

You can keep it in, if you like. I just wanted to make that I didn't miss something here.

asuessenbach avatar Jul 24 '23 14:07 asuessenbach

It is likely that it won't work first time

And you're right, tracy on windows is not supported.

I'm pretty sure tracy works on Windows. I'm using it in one of my projects and I mainly develop on windows ;)

SaschaWillems avatar Jul 24 '23 14:07 SaschaWillems

Tracy is supported. It is likely my script doesn't work on windows - Yet!

The script was meant as a build helper as you need the same Tracy version as TracyClient version used in the app.

I've only had chance to get this helper working on Linux but i should have some free time tonight to test it out on windows.

The latest Tracy download from GitHub should also work (again not tested this as I was focused on the script)

tomadamatkinson avatar Jul 24 '23 14:07 tomadamatkinson

The build script for Tracy doesn't work for me in Linux sadly:

../../../server/TracySourceView.cpp: In member function ‘bool tracy::SourceView::Disassemble(uint64_t, const tracy::Worker&)’:
../../../server/TracySourceView.cpp:736:46: error: ‘CS_GRP_BRANCH_RELATIVE’ was not declared in this scope
  736 |                 else if( detail.groups[j] == CS_GRP_BRANCH_RELATIVE && opType < OpType::Branch ) opType = OpType::Branch;
      |                                              ^~~~~~~~~~~~~~~~~~~~~~
../../../server/TracySourceView.cpp:739:46: error: ‘CS_GRP_PRIVILEGE’ was not declared in this scope
  739 |                 else if( detail.groups[j] == CS_GRP_PRIVILEGE && opType < OpType::Privileged )
      |                                              ^~~~~~~~~~~~~~~~

gary-sweet avatar Jul 25 '23 09:07 gary-sweet

The latest Tracy download from GitHub should also work (again not tested this as I was focused on the script)

Not exactly. I get this error: image

asuessenbach avatar Jul 25 '23 12:07 asuessenbach

@asuessenbach sorry for the delay on this. Each time I have thought I would have time I've had a distraction

I'm going to pin the submodule version to v9.1.0 https://github.com/wolfpld/tracy/tree/v0.9.1

This would make the versions compatible. I think I am currently on v.9.2.0 (using main)

Will also try the Windows build now with the script

@gary-sweet what is the version of your capstone library? I believe that build issue is coming from a missing dependency. The first printout at the top of the script is some install dependencies. It may work after building those

tomadamatkinson avatar Jul 25 '23 20:07 tomadamatkinson

Wow, the Windows build is much more involved. Pinning the Tracy version to v0.9.1 makes our client compatible with the profiler

Added some download instructions to the script

image

I would download automatically but as the release page packages Tracy in a 7zip archive I feel like it is best to let the user do this

After rebuilding samples I get this

image

tomadamatkinson avatar Jul 25 '23 21:07 tomadamatkinson

Moved concurrency changes to another PR

tomadamatkinson avatar Jul 25 '23 21:07 tomadamatkinson

@gary-sweet what is the version of your capstone library? I believe that build issue is coming from a missing dependency. The first printout at the top of the script is some install dependencies. It may work after building those

libcapstone-dev:
  Installed: 4.0.1+really+3.0.5-1build1

I literally just used the "sudo apt install libglfw3-dev libcapstone-dev libdbus-glib-1-dev libfreetype-dev" instruction from the script.

gary-sweet avatar Jul 26 '23 07:07 gary-sweet

It's a bit weird though. The capstone change log would indicate that CS_GRP_BRANCH_RELATIVE was introduced in version 4.0. Grepping for that in /usr/include/capstone (which is where the build is looking) yields nothing however, despite Ubuntu claiming to have version 4.0.1.

gary-sweet avatar Jul 26 '23 07:07 gary-sweet

Locally I have

libcapstone-dev/jammy,jammy,now 4.0.2-5 amd64 [installed]
libcapstone4/jammy,jammy,now 4.0.2-5 amd64 [installed,automatic]

Interesting how your lib says 4.0.1+really+3.0.5-1build1 as in its 4.0.1 but actually 3.0.5? What OS are you using?

tomadamatkinson avatar Jul 26 '23 08:07 tomadamatkinson

Interesting how your lib says 4.0.1+really+3.0.5-1build1 as in its 4.0.1 but actually 3.0.5? What OS are you using?

It's Ubuntu 20.04

gary-sweet avatar Jul 26 '23 08:07 gary-sweet

Looking at making an Ubuntu docker build to export a usable executable. Here are the system dependencies for each platform as stated in the Tracy docs. I think the latest version of Tracy has revisions to the build system to make this work better but in general the build process is very much system specific.

image

Will post an update later

tomadamatkinson avatar Jul 26 '23 08:07 tomadamatkinson

Support for tracy would be great addition 👍

But on windows you'll get a firewall notification when running the samples (at least for the first time), which may irritate users.

image

So I'm not sure if we should always enable it by default, or if it's better to hide it behind a build time or runtime flag.

SaschaWillems avatar Jul 27 '23 17:07 SaschaWillems

I would download automatically but as the release page packages Tracy in a 7zip archive I feel like it is best to let the user do this

Can we do that in the python script? There should be 7z libraries for python, so maybe we can make use of them to unpack the Windows version.

SaschaWillems avatar Jul 27 '23 17:07 SaschaWillems

I'd be happy to add that if you believe it would make the process easier! It's a little frustrating that Tracy doesn't have a cmake build for their profiler

Happy to hide this behind a VKB_ENABLE_TRACY=ON flag

tomadamatkinson avatar Jul 27 '23 18:07 tomadamatkinson

Last time I checked on Windows this worked fine with Tracy 0.9.1, but if I try to connect now I get an error a protocol mismatch error? Did anything change recently? image

SaschaWillems avatar Aug 03 '23 16:08 SaschaWillems

Picked this branch back up as the Tracy support does work. This branch got stalled on that fact that Tracy is hard to build for different platforms - this is a known limitation of the project.

I have created this pr in an attempt to help improve Tracy in this area. Unfortunately you will not be able to use this branch to build Tracy due to the strict protocol constraints. If you would like to test this PR you will need to install Tracy from the release page or by following the Tracy.pdf guide.

If you are using version of ubuntu that does not include capstone 4+ you will need to manually build and install capstone 4+ in your distro for Tracy to build.

VKB_PROFILING was added to make Tracy's usage opt in. By default this option is OFF

For now I have only instrumented up the GLTF Loader. We do not need to instrument all functions with Tracy. It is useful to track the performance of high level systems such as scene iterations or multi threaded scenarios.

I have tested on Ubuntu 23.04, Windows 11 and Android. Tracy is disabled for Android for now as there are some networking considerations

(I will be addressing any CI issues over the next few days, There are likely going to be some nuances between actual machines and github runners)

tomadamatkinson avatar Mar 11 '24 21:03 tomadamatkinson

Unfortunately, I get an "Incompatible protocol" error, again: image

I just downloaded the release v0.10 from https://github.com/wolfpld/tracy/tags, started the Tracy.exe and got this.

asuessenbach avatar Mar 12 '24 13:03 asuessenbach

Hey @asuessenbach, this branch is pinned to v0.10 can you confirm that you updated your submodules before building?

Before this branch was v0.9.1 so it may be that you still have that version checked out

tomadamatkinson avatar Mar 12 '24 18:03 tomadamatkinson

Works fine for me 👍🏻. Will try to do a proper review this weekend.

SaschaWillems avatar Mar 13 '24 20:03 SaschaWillems

@tomadamatkinson You're right, I somehow missed to get the check out the right version. Works now!

asuessenbach avatar Mar 18 '24 09:03 asuessenbach

@tomadamatkinson: Could you fix the the merge conflicts? Would' love to see this merged, so we can add additional functionality based on your work. If you can't find the time, I'll happily try to help :)

SaschaWillems avatar Jun 17 '24 15:06 SaschaWillems

@SaschaWillems ill take a look!

tomadamatkinson avatar Jun 19 '24 18:06 tomadamatkinson

image

Rebased and tested on linux. To work with android devices i believe we need to port forward with adb and also give the application local network permissions. I have not tested this in this PR. On desktop this should work fine out of the box.

Works with Tracy version 0.10. When Tracy has a new official release with the CMake build system i helped with we can bump the submodule and point to that allowing users to seamlessly build the profiler.

I cannot test on Windows or Mac today but may be able too in the near future

@SaschaWillems let me know if there are any tweaks you want adding to this

tomadamatkinson avatar Jun 24 '24 16:06 tomadamatkinson

Merging - 3 approvals

marty-johnson59 avatar Aug 09 '24 14:08 marty-johnson59