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 Tracy Profiler Support #757

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tomadamatkinson
Copy link
Collaborator

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 tomadamatkinson added framework This is relevant to the framework v2.0 Work relating to the framework v2.0 project labels Jul 17, 2023
@tomadamatkinson tomadamatkinson self-assigned this Jul 17, 2023
@tomadamatkinson tomadamatkinson requested review from SaschaWillems, gpx1000 and asuessenbach and removed request for SaschaWillems July 17, 2023 20:26
@tomadamatkinson tomadamatkinson force-pushed the v2.0/profiling branch 10 times, most recently from f7f2080 to 3e2b3be Compare July 17, 2023 23:14
Copy link
Contributor

@asuessenbach asuessenbach left a comment

Choose a reason for hiding this comment

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

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?

{
average += v;
}
average /= c.second.size();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe: float average = std::accumulate( c.second.begin(), c.second.end(), 0.0f ) / c.second.size();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice, yeah a bit more concise

@tomadamatkinson
Copy link
Collaborator Author

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

@asuessenbach
Copy link
Contributor

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.

@SaschaWillems
Copy link
Collaborator

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 ;)

@tomadamatkinson
Copy link
Collaborator Author

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)

@gary-sweet
Copy link
Contributor

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 )
      |                                              ^~~~~~~~~~~~~~~~

@asuessenbach
Copy link
Contributor

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

@tomadamatkinson
Copy link
Collaborator Author

@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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

Moved concurrency changes to another PR

Copy link
Contributor

@asuessenbach asuessenbach left a comment

Choose a reason for hiding this comment

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

Works nice now with Tracy 0.9.1 on Win10!

framework/stats/stats.cpp Show resolved Hide resolved
framework/stats/stats.cpp Outdated Show resolved Hide resolved
@SaschaWillems
Copy link
Collaborator

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
Copy link
Collaborator

SaschaWillems commented Jul 27, 2023

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.

@tomadamatkinson
Copy link
Collaborator Author

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 tomadamatkinson force-pushed the v2.0/profiling branch 2 times, most recently from b66167a to fd7189d Compare August 1, 2023 22:21
Copy link
Collaborator

@SaschaWillems SaschaWillems left a comment

Choose a reason for hiding this comment

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

The android build fails for me with hundreds of errors from VMA:

V:/Vulkan-KHR-Samples/Vulkan-Samples/third_party/vma/include/vk_mem_alloc.h:2767:12: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
  static void* vma_aligned_alloc(size_t alignment, size_t size)
             ^
  V:/Vulkan-KHR-Samples/Vulkan-Samples/third_party/vma/include/vk_mem_alloc.h:2767:12: note: insert '_Nullable' if the pointer may be null
  static void* vma_aligned_alloc(size_t alignment, size_t size)
             ^
               _Nullable
  V:/Vulkan-KHR-Samples/Vulkan-Samples/third_party/vma/include/vk_mem_alloc.h:2767:12: note: insert '_Nonnull' if the pointer should never be null
  static void* vma_aligned_alloc(size_t alignment, size_t size)
             ^
               _Nonnull

Btw. I think we also need to adjust our documentation so people know that we have tracy support.

@SaschaWillems
Copy link
Collaborator

SaschaWillems commented Aug 3, 2023

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

asuessenbach
asuessenbach previously approved these changes Aug 14, 2023
Copy link
Contributor

@asuessenbach asuessenbach left a comment

Choose a reason for hiding this comment

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

It compiles fine, both with and without VKB_ENABLE_TRACY defined.
But I get the same protocol mismatch error as Sascha got three weeks ago.

Android fixes

document tracy
@tomadamatkinson
Copy link
Collaborator Author

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)

@asuessenbach
Copy link
Contributor

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.

@@ -21,39 +21,12 @@
#include <stdexcept>
#include <string>

#include "core/util/error.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you separate error.hpp for the other headers?

@@ -29,6 +29,8 @@ VKBP_DISABLE_WARNINGS()
#include <glm/gtc/type_ptr.hpp>
VKBP_ENABLE_WARNINGS()

#include <core/util/profiling.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you separate profiling.hpp from the other headers below?

@tomadamatkinson
Copy link
Collaborator Author

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

@SaschaWillems
Copy link
Collaborator

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

@asuessenbach
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework This is relevant to the framework v2.0 Work relating to the framework v2.0 project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants