diff --git a/bldsys/cmake/global_options.cmake b/bldsys/cmake/global_options.cmake index a6f99af325..96886817b0 100644 --- a/bldsys/cmake/global_options.cmake +++ b/bldsys/cmake/global_options.cmake @@ -74,6 +74,4 @@ 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() - -set(TRACY_ENABLE ${VKB_ENABLE_TRACY}) \ No newline at end of file +endif() \ No newline at end of file diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 09503efa24..e07832c516 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -29,9 +29,12 @@ vkb__register_component( src/profiling.cpp LINK_LIBS spdlog::spdlog - TracyClient ) +if(VKB_ENABLE_TRACY) + target_link_libraries(vkb__core PUBLIC TracyClient) +endif() + vkb__register_tests( COMPONENT core NAME utils diff --git a/components/core/include/core/util/profiling.hpp b/components/core/include/core/util/profiling.hpp index 737c7844a9..e5434c87ad 100644 --- a/components/core/include/core/util/profiling.hpp +++ b/components/core/include/core/util/profiling.hpp @@ -22,17 +22,22 @@ #include -#include +#ifdef TRACY_ENABLE +# include // 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) +# define PROFILE_SCOPE(name) ZoneScopedN(name) // Trace a function -#define PROFILE_FUNCTION() ZoneScoped +# define PROFILE_FUNCTION() ZoneScoped +#else +# define PROFILE_SCOPE(name) +# define PROFILE_FUNCTION() +#endif // The type of plot to use enum class PlotType @@ -42,11 +47,11 @@ enum class PlotType Memory, }; +namespace +{ // 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) @@ -61,18 +66,31 @@ inline tracy::PlotFormatType to_tracy_plot_format(PlotType type) return tracy::PlotFormatType::Number; } } -} // namespace - -# define TO_TRACY_PLOT_FORMAT(name) to_tracy_plot_format(name) -#else -# define TO_TRACY_PLOT_FORMAT(name) #endif +} // namespace // Create plots template class Plot { public: +#ifndef TRACY_ENABLE + static void plot(const char *name, T value) + { + } + + static void increment(const char *name, T amount) + { + } + + static void decrement(const char *name, T amount) + { + } + + static void reset(const char *name) + { + } +#else static void plot(const char *name, T value) { auto *p = get_instance(); @@ -105,8 +123,9 @@ class Plot static void update_tracy_plot(const char *name, T value) { TracyPlot(name, value); - TracyPlotConfig(name, TO_TRACY_PLOT_FORMAT(PT), true, true, 0); + TracyPlotConfig(name, to_tracy_plot_format(PT), true, true, 0); } +#endif static Plot *get_instance() { diff --git a/components/core/src/profiling.cpp b/components/core/src/profiling.cpp index 8cda489f2d..20d2b2e8a2 100644 --- a/components/core/src/profiling.cpp +++ b/components/core/src/profiling.cpp @@ -19,6 +19,7 @@ #include +#ifdef TRACY_ENABLE void *operator new(size_t count) { auto ptr = malloc(count); @@ -31,3 +32,4 @@ void operator delete(void *ptr) noexcept TracyFree(ptr); free(ptr); } +#endif \ No newline at end of file diff --git a/framework/common/error.h b/framework/common/error.h index 8130756283..a670260c0c 100644 --- a/framework/common/error.h +++ b/framework/common/error.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2018-2022, Arm Limited and Contributors +/* Copyright (c) 2018-2023, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -18,20 +18,21 @@ #pragma once #include +#include #include #include #include "common/strings.h" #include "logging.h" -#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_DISABLE_WARNINGS() \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wall\"") \ + _Pragma("clang diagnostic ignored \"-Wextra\"") \ + _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") \ + _Pragma("clang diagnostic ignored \"-Wtautological-compare\"") # define VKBP_ENABLE_WARNINGS() \ _Pragma("clang diagnostic pop") @@ -54,6 +55,8 @@ __pragma(warning(pop)) #endif +#include "vk_common.h" + namespace vkb { /** diff --git a/framework/common/vk_common.h b/framework/common/vk_common.h index 0a66731dfd..76ef47ce4c 100644 --- a/framework/common/vk_common.h +++ b/framework/common/vk_common.h @@ -25,8 +25,12 @@ #include #include +#include "common/error.h" + +VKBP_DISABLE_WARNINGS() #include #include +VKBP_ENABLE_WARNINGS() #define VK_FLAGS_NONE 0 // Custom define for better code readability diff --git a/framework/core/device.cpp b/framework/core/device.cpp index 8631ff0a8b..3202f56e0e 100644 --- a/framework/core/device.cpp +++ b/framework/core/device.cpp @@ -18,6 +18,8 @@ #include "device.h" +#include "common/error.h" + VKBP_DISABLE_WARNINGS() #define VMA_IMPLEMENTATION #include diff --git a/framework/core/hpp_buffer.h b/framework/core/hpp_buffer.h index bad47406df..cfc6f53a0f 100644 --- a/framework/core/hpp_buffer.h +++ b/framework/core/hpp_buffer.h @@ -20,7 +20,12 @@ #include "hpp_vulkan_resource.h" #include + +#include + +VKBP_DISABLE_WARNINGS() #include +VKBP_ENABLE_WARNINGS() namespace vkb { @@ -53,8 +58,8 @@ class HPPBuffer : public vkb::core::HPPVulkanResource HPPBuffer &operator=(const HPPBuffer &) = delete; HPPBuffer &operator=(HPPBuffer &&) = delete; - VmaAllocation get_allocation() const; - const uint8_t *get_data() const; + VmaAllocation get_allocation() const; + const uint8_t *get_data() const; vk::DeviceMemory get_memory() const; /** diff --git a/framework/core/hpp_image.h b/framework/core/hpp_image.h index 39277d6a1c..0df3eedb15 100644 --- a/framework/core/hpp_image.h +++ b/framework/core/hpp_image.h @@ -19,7 +19,12 @@ #include "core/hpp_vulkan_resource.h" #include + +#include + +VKBP_DISABLE_WARNINGS() #include +VKBP_ENABLE_WARNINGS() namespace vkb { diff --git a/framework/stats/stats.cpp b/framework/stats/stats.cpp index e92a40d31e..f1c50ca063 100644 --- a/framework/stats/stats.cpp +++ b/framework/stats/stats.cpp @@ -18,9 +18,13 @@ #include "stats/stats.h" +#include #include + +VKBP_DISABLE_WARNINGS() #include #include +VKBP_ENABLE_WARNINGS() #include "core/device.h" #include "frame_time_stats_provider.h" diff --git a/samples/performance/pipeline_barriers/pipeline_barriers.cpp b/samples/performance/pipeline_barriers/pipeline_barriers.cpp index 619ea90e8d..83c61bfa2a 100644 --- a/samples/performance/pipeline_barriers/pipeline_barriers.cpp +++ b/samples/performance/pipeline_barriers/pipeline_barriers.cpp @@ -68,9 +68,9 @@ bool PipelineBarriers::prepare(const vkb::ApplicationOptions &options) { pos.y = pos.y + (k * 100); - light_color.x = static_cast(rand()) / (RAND_MAX); - light_color.y = static_cast(rand()) / (RAND_MAX); - light_color.z = static_cast(rand()) / (RAND_MAX); + light_color.x = static_cast(rand()) / static_cast(RAND_MAX); + light_color.y = static_cast(rand()) / static_cast(RAND_MAX); + light_color.z = static_cast(rand()) / static_cast(RAND_MAX); vkb::sg::LightProperties props; props.color = light_color; diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index ed7203545e..8c4c3d6bab 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -363,6 +363,14 @@ set_property(TARGET Catch2 PROPERTY FOLDER "ThirdParty") set_property(TARGET Catch2WithMain PROPERTY FOLDER "ThirdParty") # Tracy -set(TRACY_TIMER_FALLBACK ON) +set(TRACY_ENABLE ${VKB_ENABLE_TRACY}) +set(TRACY_TIMER_FALLBACK ${VKB_ENABLE_TRACY}) + add_subdirectory(tracy) -set_property(TARGET TracyClient PROPERTY FOLDER "ThirdParty") \ No newline at end of file +set_property(TARGET TracyClient PROPERTY FOLDER "ThirdParty") + +# Global definitions are a bad practice +# However, in this case, as Tracy is a global dependency, and this is wrapped by VKB_ENABLE_TRACY. We should be fine :) +if (NOT VKB_ENABLE_TRACY) + add_definitions(-DTRACY_ENABLE=0) +endif() \ No newline at end of file