-
Notifications
You must be signed in to change notification settings - Fork 811
Add Tracy Profiler Support #757
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
Merged
marty-johnson59
merged 5 commits into
KhronosGroup:main
from
tomadamatkinson:v2.0/profiling
Aug 9, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1d20af2
Add Tracy Profiler Support
tomadamatkinson f16e9c0
add VKB_PROFILING
tomadamatkinson 10123f2
do not enable on android
tomadamatkinson 7afbca4
remove implementation when VKB_PROFILING is off
tomadamatkinson 1e16cb9
qa
tomadamatkinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,4 +13,5 @@ tags | |
| # vim backup and temp files | ||
| *~ | ||
| .*.sw* | ||
| .sw* | ||
| .sw* | ||
| .tracy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /* Copyright (c) 2023-2024, Thomas Atkinson | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 the "License"; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <cstdio> | ||
|
|
||
| #include <unordered_map> | ||
|
|
||
| #include "core/util/error.hpp" | ||
|
|
||
| #ifdef TRACY_ENABLE | ||
| # include <tracy/Tracy.hpp> | ||
| #endif | ||
|
|
||
| #ifdef TRACY_ENABLE | ||
| // malloc and free are used by Tracy to provide memory profiling | ||
| void *operator new(size_t count); | ||
| void operator delete(void *ptr) noexcept; | ||
|
|
||
| // Tracy a scope | ||
| # define PROFILE_SCOPE(name) ZoneScopedN(name) | ||
|
|
||
| // Trace a function | ||
| # define PROFILE_FUNCTION() ZoneScoped | ||
| #else | ||
| # define PROFILE_SCOPE(name) | ||
| # define PROFILE_FUNCTION() | ||
| #endif | ||
|
|
||
| // The type of plot to use | ||
| enum class PlotType | ||
| { | ||
| Number, | ||
| Percentage, | ||
| Memory, | ||
| }; | ||
|
|
||
| // tracy::PlotFormatType is not defined if TRACY_ENABLE is not defined | ||
| // so we need to define a function to convert our enum to the tracy enum | ||
| #ifdef TRACY_ENABLE | ||
| namespace | ||
| { | ||
| inline tracy::PlotFormatType to_tracy_plot_format(PlotType type) | ||
| { | ||
| switch (type) | ||
| { | ||
| case PlotType::Number: | ||
| return tracy::PlotFormatType::Number; | ||
| case PlotType::Percentage: | ||
| return tracy::PlotFormatType::Percentage; | ||
| case PlotType::Memory: | ||
| return tracy::PlotFormatType::Memory; | ||
| default: | ||
| return tracy::PlotFormatType::Number; | ||
| } | ||
| } | ||
| } // namespace | ||
|
|
||
| # define TO_TRACY_PLOT_FORMAT(name) to_tracy_plot_format(name) | ||
| #else | ||
| # define TO_TRACY_PLOT_FORMAT(name) | ||
| #endif | ||
|
|
||
| // Create plots | ||
| template <typename T, PlotType PT = PlotType::Number> | ||
| class Plot | ||
| { | ||
| public: | ||
| static void plot(const char *name, T value) | ||
| { | ||
| auto *p = get_instance(); | ||
| p->plots[name] = value; | ||
| update_tracy_plot(name, value); | ||
| } | ||
|
|
||
| static void increment(const char *name, T amount) | ||
| { | ||
| auto *p = get_instance(); | ||
| p->plots[name] += amount; | ||
| update_tracy_plot(name, p->plots[name]); | ||
| } | ||
|
|
||
| static void decrement(const char *name, T amount) | ||
| { | ||
| auto *p = get_instance(); | ||
| p->plots[name] -= amount; | ||
| update_tracy_plot(name, p->plots[name]); | ||
| } | ||
|
|
||
| static void reset(const char *name) | ||
| { | ||
| auto *p = get_instance(); | ||
| p->plots[name] = T{}; | ||
| update_tracy_plot(name, p->plots[name]); | ||
| } | ||
|
|
||
| private: | ||
| static void update_tracy_plot(const char *name, T value) | ||
| { | ||
| #ifdef TRACY_ENABLE | ||
| TracyPlot(name, value); | ||
| TracyPlotConfig(name, TO_TRACY_PLOT_FORMAT(PT), true, true, 0); | ||
| #endif | ||
| } | ||
|
|
||
| static Plot *get_instance() | ||
| { | ||
| static_assert((std::is_same<T, int64_t>::value || std::is_same<T, double>::value || std::is_same<T, float>::value), "PlotStore only supports int64_t, double and float"); | ||
| static Plot instance; | ||
| return &instance; | ||
| } | ||
|
|
||
| std::unordered_map<const char *, T> plots; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* Copyright (c) 2023-2024, Thomas Atkinson | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 the "License"; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "core/util/profiling.hpp" | ||
|
|
||
| #include <cstdlib> | ||
|
|
||
| #ifdef TRACY_ENABLE | ||
| void *operator new(size_t count) | ||
| { | ||
| auto ptr = malloc(count); | ||
| TracyAlloc(ptr, count); | ||
| return ptr; | ||
| } | ||
|
|
||
| void operator delete(void *ptr) noexcept | ||
| { | ||
| TracyFree(ptr); | ||
| free(ptr); | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,39 +21,12 @@ | |
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| #include "core/util/error.hpp" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you separate error.hpp for the other headers? |
||
|
|
||
| #include "common/strings.h" | ||
| #include "core/util/logging.hpp" | ||
| #include "vk_common.h" | ||
|
|
||
| #if defined(__clang__) | ||
| // CLANG ENABLE/DISABLE WARNING DEFINITION | ||
| # define VKBP_DISABLE_WARNINGS() \ | ||
| _Pragma("clang diagnostic push") \ | ||
| _Pragma("clang diagnostic ignored \"-Wall\"") \ | ||
| _Pragma("clang diagnostic ignored \"-Wextra\"") \ | ||
| _Pragma("clang diagnostic ignored \"-Wtautological-compare\"") | ||
|
|
||
| # define VKBP_ENABLE_WARNINGS() \ | ||
| _Pragma("clang diagnostic pop") | ||
| #elif defined(__GNUC__) || defined(__GNUG__) | ||
| // GCC ENABLE/DISABLE WARNING DEFINITION | ||
| # define VKBP_DISABLE_WARNINGS() \ | ||
| _Pragma("GCC diagnostic push") \ | ||
| _Pragma("GCC diagnostic ignored \"-Wall\"") \ | ||
| _Pragma("GCC diagnostic ignored \"-Wextra\"") \ | ||
| _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") | ||
|
|
||
| # define VKBP_ENABLE_WARNINGS() \ | ||
| _Pragma("GCC diagnostic pop") | ||
| #elif defined(_MSC_VER) | ||
| // MSVC ENABLE/DISABLE WARNING DEFINITION | ||
| # define VKBP_DISABLE_WARNINGS() \ | ||
| __pragma(warning(push, 0)) | ||
|
|
||
| # define VKBP_ENABLE_WARNINGS() \ | ||
| __pragma(warning(pop)) | ||
| #endif | ||
|
|
||
| namespace vkb | ||
| { | ||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ | |
| #include "common/glm_common.h" | ||
| #include <glm/gtc/type_ptr.hpp> | ||
|
|
||
| #include <core/util/profiling.hpp> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you separate profiling.hpp from the other headers below? |
||
|
|
||
| #include "api_vulkan_sample.h" | ||
| #include "common/utils.h" | ||
| #include "common/vk_common.h" | ||
|
|
@@ -408,6 +410,8 @@ GLTFLoader::GLTFLoader(Device &device) : | |
|
|
||
| std::unique_ptr<sg::Scene> GLTFLoader::read_scene_from_file(const std::string &file_name, int scene_index) | ||
| { | ||
| PROFILE_SCOPE("Load GLTF Scene"); | ||
|
|
||
| std::string err; | ||
| std::string warn; | ||
|
|
||
|
|
@@ -450,6 +454,8 @@ std::unique_ptr<sg::Scene> GLTFLoader::read_scene_from_file(const std::string &f | |
|
|
||
| std::unique_ptr<sg::SubMesh> GLTFLoader::read_model_from_file(const std::string &file_name, uint32_t index, bool storage_buffer) | ||
| { | ||
| PROFILE_SCOPE("Load GLTF Model"); | ||
|
|
||
| std::string err; | ||
| std::string warn; | ||
|
|
||
|
|
@@ -492,6 +498,8 @@ std::unique_ptr<sg::SubMesh> GLTFLoader::read_model_from_file(const std::string | |
|
|
||
| sg::Scene GLTFLoader::load_scene(int scene_index) | ||
| { | ||
| PROFILE_SCOPE("Process Scene"); | ||
|
|
||
| auto scene = sg::Scene(); | ||
|
|
||
| scene.set_name("gltf_scene"); | ||
|
|
@@ -727,6 +735,8 @@ sg::Scene GLTFLoader::load_scene(int scene_index) | |
|
|
||
| for (auto &gltf_mesh : model.meshes) | ||
| { | ||
| PROFILE_SCOPE("Processing Mesh"); | ||
|
|
||
| auto mesh = parse_mesh(gltf_mesh); | ||
|
|
||
| for (size_t i_primitive = 0; i_primitive < gltf_mesh.primitives.size(); i_primitive++) | ||
|
|
@@ -1087,6 +1097,8 @@ sg::Scene GLTFLoader::load_scene(int scene_index) | |
|
|
||
| std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage_buffer) | ||
| { | ||
| PROFILE_SCOPE("Process Model"); | ||
|
|
||
| auto submesh = std::make_unique<sg::SubMesh>(); | ||
|
|
||
| std::vector<core::Buffer> transient_buffers; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.