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
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ option(GFX_BUILD_VULKAN "Build the vulkan backend" ON)
option(GFX_ENABLE_IMGUI "Build with imgui capabilities" OFF)
option(GFX_ENABLE_GLFW "Build with glfw capabilities" OFF)
option(GFX_BUILD_EXAMPLES "Build Graphics examples executables" OFF)
option(GFX_BUILD_TRACY "Build the tracy client" OFF)
option(GFX_INSTALL "Enable the install command" ON)

if(GFX_BUILD_EXAMPLES)
Expand Down Expand Up @@ -115,6 +116,21 @@ if (GFX_BUILD_VULKAN)
set_target_properties(VulkanMemoryAllocator PROPERTIES FOLDER "dependencies")
endif()

if (GFX_BUILD_TRACY)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.13.0
GIT_SHALLOW 1
GIT_PROGRESS TRUE
)
set(TRACY_LTO ON)
FetchContent_MakeAvailable(tracy)
if(NOT MSVC)
target_compile_options(TracyClient PRIVATE -Wno-deprecated-declarations)
endif()
set_target_properties(TracyClient PROPERTIES FOLDER "dependencies")
endif()

add_library(Graphics ${GFX_LIB_TYPE}) # Use GFX_LIB_TYPE to override BUILD_SHARED_LIBS for `Graphics`

target_compile_features(Graphics PUBLIC cxx_std_23)
Expand Down Expand Up @@ -178,6 +194,10 @@ if (GFX_ENABLE_GLFW)
target_compile_definitions(Graphics PUBLIC "GFX_GLFW_ENABLED")
endif()

if (GFX_BUILD_TRACY)
target_compile_definitions(Graphics PUBLIC "GFX_BUILD_TRACY")
endif()

if (GFX_BUILD_METAL)
target_link_libraries(Graphics PRIVATE ${METAL_FRAMEWORK} ${QUARTZ_CORE_FRAMEWORK} ${FOUNDATION_FRAMEWORK})
endif()
Expand All @@ -190,6 +210,10 @@ if (GFX_ENABLE_GLFW OR GFX_ENABLE_IMGUI)
target_link_libraries(Graphics PRIVATE dlLoad)
endif()

if (GFX_BUILD_TRACY)
target_link_libraries(Graphics PUBLIC TracyClient)
endif()

add_subdirectory("tools")

if(GFX_BUILD_EXAMPLES)
Expand Down
4 changes: 2 additions & 2 deletions examples/imgui_usage/imgui_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#if __XCODE__
#include <unistd.h>
#endif
#if (defined(__GNUC__) || defined(__clang__))
#define GFX_EXPORT __attribute__((visibility("default")))
#if defined(__GNUC__)
#define GFX_EXPORT __attribute__((used, visibility("default")))
#elif defined(_MSC_VER)
#define GFX_EXPORT __declspec(dllexport)
#else
Expand Down
4 changes: 2 additions & 2 deletions examples/mc_cube/mc_cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#include <unistd.h>
#endif

#if (defined(__GNUC__) || defined(__clang__))
#define GFX_EXPORT __attribute__((visibility("default")))
#if defined(__GNUC__)
#define GFX_EXPORT __attribute__((used, visibility("default")))
#elif defined(_MSC_VER)
#define GFX_EXPORT __declspec(dllexport)
#else
Expand Down
47 changes: 34 additions & 13 deletions examples/scop/AssetLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,27 @@
#include <Graphics/Buffer.hpp>

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/types.h>
#include <glm/ext/matrix_transform.hpp>
#include <glm/glm.hpp>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/types.h>
#include <glm/ext/matrix_transform.hpp>
#else
#include "math/math.hpp"
#include "ObjParser/ObjParser.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#include "ObjParser/ObjParser.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif
#include <stb_image/stb_image.h>
#if defined (GFX_BUILD_TRACY)
#include <tracy/Tracy.hpp>
#else
#define ZoneScoped
#define ZoneScopedN(x)
#endif

#include <algorithm>
#include <bit> // IWYU pragma: keep
Expand Down Expand Up @@ -374,6 +380,7 @@ Mesh AssetLoader::builtinCube(const std::shared_ptr<Material>& material)
#if !defined (SCOP_MANDATORY)
Mesh AssetLoader::loadMesh(const std::filesystem::path& path, std::optional<std::shared_ptr<Material>> overrideMaterial)
{
ZoneScoped;
assert(std::filesystem::is_regular_file(path));

Assimp::Importer importer;
Expand All @@ -392,7 +399,11 @@ Mesh AssetLoader::loadMesh(const std::filesystem::path& path, std::optional<std:
if (overrideMaterial.has_value()) {
materials.assign(scene->mNumMaterials, *overrideMaterial);
} else {
std::unique_ptr<gfx::ParameterBlockPool> parameterBlockPool = m_device->newParameterBlockPool({ .maxUniformBuffers = 130, .maxTextures = 380, .maxSamplers = 130 });
std::unique_ptr<gfx::ParameterBlockPool> parameterBlockPool = m_device->newParameterBlockPool({
.maxUniformBuffers = 500,
.maxTextures = 500,
.maxSamplers = 500
});
assert(parameterBlockPool);

std::map<std::string, std::shared_ptr<gfx::Texture>> textureCache;
Expand All @@ -416,6 +427,8 @@ Mesh AssetLoader::loadMesh(const std::filesystem::path& path, std::optional<std:
};

materials = std::span(scene->mMaterials, scene->mNumMaterials) | std::views::transform([&](aiMaterial* aiMaterial) -> std::shared_ptr<Material> {
ZoneScopedN("makeMaterial");

auto material = std::make_shared<scop::TexturedMaterial>(*m_device);

aiColor4D diffuseColor{};
Expand Down Expand Up @@ -612,6 +625,8 @@ using UniqueStbiUc = std::unique_ptr<stbi_uc, decltype(&stbi_image_free)>;
#if !defined (SCOP_MANDATORY)
std::shared_ptr<gfx::Texture> AssetLoader::loadEmbeddedTexture(const aiTexture* aiTex, gfx::CommandBuffer& commandBuffer)
{
ZoneScoped;

int width = 0;
int height = 0;
UniqueStbiUc bytes(nullptr, stbi_image_free);
Expand Down Expand Up @@ -661,6 +676,8 @@ std::shared_ptr<gfx::Texture> AssetLoader::loadEmbeddedTexture(const aiTexture*

std::shared_ptr<gfx::Texture> AssetLoader::loadTexture(const std::filesystem::path& path, gfx::CommandBuffer& commandBuffer)
{
ZoneScoped;

int width = 0;
int height = 0;
UniqueStbiUc bytes = UniqueStbiUc(stbi_load(path.string().c_str(), &width, &height, nullptr, STBI_rgb_alpha), stbi_image_free);
Expand Down Expand Up @@ -693,6 +710,8 @@ std::shared_ptr<gfx::Texture> AssetLoader::loadTexture(const std::filesystem::pa

std::shared_ptr<gfx::Texture> AssetLoader::loadCubeTexture(const std::filesystem::path& right, const std::filesystem::path& left, const std::filesystem::path& top, const std::filesystem::path& bottom, const std::filesystem::path& front, const std::filesystem::path& back, gfx::CommandBuffer& commandBuffer)
{
ZoneScoped;

int width = 0;
int height = 0;
std::map<std::filesystem::path, UniqueStbiUc> bytes;
Expand Down Expand Up @@ -748,6 +767,8 @@ std::shared_ptr<gfx::Texture> AssetLoader::loadCubeTexture(const std::filesystem

std::shared_ptr<gfx::Texture> AssetLoader::getSolidColorTexture(const glm::vec4& color, gfx::CommandBuffer& commandBuffer)
{
ZoneScoped;

std::scoped_lock lock(m_solidColorTextureCacheMtx);

auto it =std::ranges::find_if(m_solidColorTextureCache, [&](const auto& e){ return e.first == color; });
Expand Down
12 changes: 6 additions & 6 deletions examples/scop/AssetLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include <Graphics/Buffer.hpp>

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/glm.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

#include <cstdint>
Expand Down
3 changes: 3 additions & 0 deletions examples/scop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ if (SCOP_MANDATORY)
file(GLOB EXE_SRCS "math/*.cpp" "math/*.hpp" "ObjParser/*.cpp" "ObjParser/*.hpp")
target_sources(scop PRIVATE ${EXE_SRCS})
endif()
if(GFX_BUILD_TRACY)
target_sources(scop PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/tracy_allocations.cpp")
endif()

target_include_directories(scop PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

Expand Down
14 changes: 7 additions & 7 deletions examples/scop/Entity/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

#include <GLFW/glfw3.h>
#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

#include <set>
Expand Down
12 changes: 6 additions & 6 deletions examples/scop/Entity/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include <string>

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/glm.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

namespace scop
Expand Down
12 changes: 6 additions & 6 deletions examples/scop/Entity/Light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "Entity/Entity.hpp"

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/glm.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

namespace scop
Expand Down
18 changes: 9 additions & 9 deletions examples/scop/Entity/RenderableEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include "Mesh.hpp"

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/glm.hpp>
#include <glm/ext/matrix_transform.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

#include <future>
Expand All @@ -37,7 +37,7 @@ class RenderableEntity : public Entity
RenderableEntity(const RenderableEntity&) = delete;
RenderableEntity(RenderableEntity&&) = default;

RenderableEntity(std::future<Mesh>&& meshFuture) : m_meshFuture(std::move(meshFuture)) {};
RenderableEntity(std::shared_future<Mesh> meshFuture) : m_meshFuture(std::move(meshFuture)) {};

inline const std::optional<Mesh>& mesh()
{
Expand All @@ -64,7 +64,7 @@ class RenderableEntity : public Entity
~RenderableEntity() override = default;

private:
std::future<Mesh> m_meshFuture;
std::shared_future<Mesh> m_meshFuture;
std::optional<Mesh> m_mesh;

public:
Expand Down
12 changes: 6 additions & 6 deletions examples/scop/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#include <Graphics/Enums.hpp>

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/glm.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

#include <cassert>
Expand Down
12 changes: 6 additions & 6 deletions examples/scop/Material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#include <Graphics/Device.hpp>

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/glm.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

#include <memory>
Expand Down
12 changes: 6 additions & 6 deletions examples/scop/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#include <Graphics/Buffer.hpp>

#if !defined (SCOP_MANDATORY)
#include <glm/glm.hpp>
#include <glm/glm.hpp>
#else
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif
#endif

#include <string>
Expand Down
5 changes: 2 additions & 3 deletions examples/scop/ObjParser/ObjParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

#include "math/math.hpp"
#ifndef SCOP_MATH_GLM_ALIAS_DEFINED
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#define SCOP_MATH_GLM_ALIAS_DEFINED
namespace glm = scop::math;
#endif

#include <vector>
#include <filesystem>
#include <cstdint>
#include <utility>
#include <optional>

namespace scop
Expand Down
Loading