Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tags
# vim backup and temp files
*~
.*.sw*
.sw*
.sw*
.tracy
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@
[submodule "third_party/fmt"]
path = third_party/fmt
url = https://github.com/fmtlib/fmt
[submodule "third_party/tracy"]
path = third_party/tracy
url = https://github.com/wolfpld/tracy.git
10 changes: 9 additions & 1 deletion bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ set(VKB_BUILD_TESTS OFF CACHE BOOL "Enable generation and building of Vulkan bes
set(VKB_WSI_SELECTION "XCB" CACHE STRING "Select WSI target (XCB, XLIB, WAYLAND, D2D)")
set(VKB_CLANG_TIDY OFF CACHE STRING "Use CMake Clang Tidy integration")
set(VKB_CLANG_TIDY_EXTRAS "-header-filter=framework,samples,app;-checks=-*,google-*,-google-runtime-references;--fix;--fix-errors" CACHE STRING "Clang Tidy Parameters")
set(VKB_PROFILING OFF CACHE BOOL "Enable Tracy profiling")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
Expand All @@ -73,4 +74,11 @@ set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=0 ${CMAKE_CXX_FLAGS_DEBUG}")
if (VKB_CLANG_TIDY)
find_program(CLANG_TIDY "clang-tidy" "clang-tidy-15" REQUIRED)
set(VKB_DO_CLANG_TIDY ${CLANG_TIDY} ${VKB_CLANG_TIDY_EXTRAS})
endif()
endif()

if (ANDROID AND VKB_PROFILING)
message(WARNING "Tracy Profiling is not supported on android yet")
set(VKB_PROFILING OFF)
endif()

set(TRACY_ENABLE ${VKB_PROFILING})
8 changes: 8 additions & 0 deletions components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ vkb__register_component(
include/core/util/error.hpp
include/core/util/hash.hpp
include/core/util/logging.hpp
include/core/util/profiling.hpp
SRC
src/strings.cpp
src/logging.cpp
src/profiling.cpp
LINK_LIBS
spdlog::spdlog
)

if (VKB_PROFILING)
target_link_libraries(vkb__core PUBLIC TracyClient)
target_compile_definitions(vkb__core PUBLIC TRACY_ENABLE)
endif()


vkb__register_tests(
COMPONENT core
NAME utils
Expand Down
16 changes: 8 additions & 8 deletions components/core/include/core/util/error.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2024, Thomas Atkinson
/* Copyright (c) 2023-2024, Thomas Atkinson
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -23,12 +23,12 @@

#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_DISABLE_WARNINGS() \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wall\"") \
_Pragma("clang diagnostic ignored \"-Wextra\"") \
_Pragma("clang diagnostic ignored \"-Wtautological-compare\"") \
_Pragma("clang diagnostic ignored \"-Wnullability-completeness\"")
# define VKBP_ENABLE_WARNINGS() \
_Pragma("clang diagnostic pop")
#elif defined(__GNUC__) || defined(__GNUG__)
Expand Down Expand Up @@ -66,4 +66,4 @@ inline void ERRORF(const std::string &message)
throw std::runtime_error(message);
}

#define NOT_IMPLEMENTED() ERRORF("not implemented")
#define NOT_IMPLEMENTED() ERRORF("not implemented")
130 changes: 130 additions & 0 deletions components/core/include/core/util/profiling.hpp
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;
};
Comment thread
asuessenbach marked this conversation as resolved.
35 changes: 35 additions & 0 deletions components/core/src/profiling.cpp
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
13 changes: 13 additions & 0 deletions docs/build.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ Treat all warnings as errors

*Default:* `ON`

=== VKB_PROFILING

Enable profiling using the xref:https://github.com/wolfpld/tracy[Tracy profiler].

We currently use Tracy v0.10.0 if you do not use the correct Tracy Profiler version as the Tracy Client version used in Sample you will get a protocol mismatch error.

Windows users can download the profiler from the xref:https://github.com/wolfpld/tracy/releases/tag/v0.10[Tracy v0.10.0 release page]
Other platforms require the user to build the profiler from source see the xref:https://github.com/wolfpld/tracy/releases/tag/v0.10[Tracy.pdf documentation] for more information on how to build for your platform.

Tracy is not currently enabled for Android builds. In the future, we may add support for this.

*Default:* `OFF`

== Quality Assurance

We use a small set of tools to provide a level of quality to the project.
Expand Down
10 changes: 9 additions & 1 deletion framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,12 @@ endif()

if(VKB_DO_CLANG_TIDY)
set_target_properties(framework PROPERTIES CXX_CLANG_TIDY "${VKB_DO_CLANG_TIDY}")
endif()
endif()

if (VKB_PROFILING)
## Enable profling
target_compile_definitions(${PROJECT_NAME} PUBLIC VKB_PROFILING=1)
else()
## Disable profiling
target_compile_definitions(${PROJECT_NAME} PUBLIC VKB_PROFILING=0)
endif()
31 changes: 2 additions & 29 deletions framework/common/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,12 @@
#include <stdexcept>
#include <string>

#include "core/util/error.hpp"
Copy link
Copy Markdown
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?


#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
{
/**
Expand Down
12 changes: 12 additions & 0 deletions framework/gltf_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "common/glm_common.h"
#include <glm/gtc/type_ptr.hpp>

#include <core/util/profiling.hpp>
Copy link
Copy Markdown
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?


#include "api_vulkan_sample.h"
#include "common/utils.h"
#include "common/vk_common.h"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion framework/hpp_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct HPPFont
}

std::vector<uint8_t> data;
ImFont *handle = nullptr;
ImFont *handle = nullptr;
std::string name;
float size = 0.0f;
};
Expand Down
Loading