Skip to content

Commit

Permalink
fix android and windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
tomadamatkinson committed Aug 22, 2023
1 parent 09b022b commit 7dd36c6
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 29 deletions.
4 changes: 1 addition & 3 deletions bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
endif()
5 changes: 4 additions & 1 deletion components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 30 additions & 11 deletions components/core/include/core/util/profiling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@

#include <unordered_map>

#include <tracy/Tracy.hpp>
#ifdef TRACY_ENABLE
# include <tracy/Tracy.hpp>

// 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
Expand All @@ -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)
Expand All @@ -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 <typename T, PlotType PT = PlotType::Number>
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();
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions components/core/src/profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cstdlib>

#ifdef TRACY_ENABLE
void *operator new(size_t count)
{
auto ptr = malloc(count);
Expand All @@ -31,3 +32,4 @@ void operator delete(void *ptr) noexcept
TracyFree(ptr);
free(ptr);
}
#endif
17 changes: 10 additions & 7 deletions framework/common/error.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -18,20 +18,21 @@
#pragma once

#include <cassert>
#include <cstdint>
#include <stdexcept>
#include <string>

#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")
Expand All @@ -54,6 +55,8 @@
__pragma(warning(pop))
#endif

#include "vk_common.h"

namespace vkb
{
/**
Expand Down
4 changes: 4 additions & 0 deletions framework/common/vk_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
#include <unordered_map>
#include <vector>

#include "common/error.h"

VKBP_DISABLE_WARNINGS()
#include <vk_mem_alloc.h>
#include <volk.h>
VKBP_ENABLE_WARNINGS()

#define VK_FLAGS_NONE 0 // Custom define for better code readability

Expand Down
2 changes: 2 additions & 0 deletions framework/core/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "device.h"

#include "common/error.h"

VKBP_DISABLE_WARNINGS()
#define VMA_IMPLEMENTATION
#include <vk_mem_alloc.h>
Expand Down
9 changes: 7 additions & 2 deletions framework/core/hpp_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
#include "hpp_vulkan_resource.h"

#include <unordered_map>

#include <common/error.h>

VKBP_DISABLE_WARNINGS()
#include <vk_mem_alloc.h>
VKBP_ENABLE_WARNINGS()

namespace vkb
{
Expand Down Expand Up @@ -53,8 +58,8 @@ class HPPBuffer : public vkb::core::HPPVulkanResource<vk::Buffer>
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;

/**
Expand Down
5 changes: 5 additions & 0 deletions framework/core/hpp_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

#include "core/hpp_vulkan_resource.h"
#include <unordered_set>

#include <common/error.h>

VKBP_DISABLE_WARNINGS()
#include <vk_mem_alloc.h>
VKBP_ENABLE_WARNINGS()

namespace vkb
{
Expand Down
4 changes: 4 additions & 0 deletions framework/stats/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

#include "stats/stats.h"

#include <common/error.h>
#include <core/util/profiling.hpp>

VKBP_DISABLE_WARNINGS()
#include <vk_mem_alloc.h>
#include <vulkan/vulkan.hpp>
VKBP_ENABLE_WARNINGS()

#include "core/device.h"
#include "frame_time_stats_provider.h"
Expand Down
6 changes: 3 additions & 3 deletions samples/performance/pipeline_barriers/pipeline_barriers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ bool PipelineBarriers::prepare(const vkb::ApplicationOptions &options)
{
pos.y = pos.y + (k * 100);

light_color.x = static_cast<float>(rand()) / (RAND_MAX);
light_color.y = static_cast<float>(rand()) / (RAND_MAX);
light_color.z = static_cast<float>(rand()) / (RAND_MAX);
light_color.x = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
light_color.y = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
light_color.z = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);

vkb::sg::LightProperties props;
props.color = light_color;
Expand Down
12 changes: 10 additions & 2 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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()

0 comments on commit 7dd36c6

Please sign in to comment.