Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 1 addition & 10 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
[submodule "Engine/cpp/ThirdParty/bx"]
path = Engine/cpp/ThirdParty/bx
url = https://github.com/bkaradzic/bx
[submodule "Engine/cpp/ThirdParty/bimg"]
path = Engine/cpp/ThirdParty/bimg
url = https://github.com/bkaradzic/bimg
[submodule "Engine/cpp/ThirdParty/bgfx"]
path = Engine/cpp/ThirdParty/bgfx
url = https://github.com/bkaradzic/bgfx
[submodule "Engine/cpp/ThirdParty/sdl"]
[submodule "Engine/cpp/thirdparty/sdl"]
path = Engine/cpp/ThirdParty/sdl
url = https://github.com/libsdl-org/SDL
25 changes: 1 addition & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(DraconicEngine LANGUAGES C CXX)

find_package(Git QUIET)
find_package(Threads REQUIRED)
find_package(Vulkan REQUIRED)

if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
message(STATUS "Updating submodules...")
Expand All @@ -20,36 +21,12 @@ endif()

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

option(BUILD_BENCHMARKS "Build micro-benchmarks (nanobench)" OFF)

include(CTest)
include(Compiler)
include(Modules)
include(Shaders)

# Engine runtime (C++)
add_subdirectory(Engine/cpp)

# Samples (C++)
add_subdirectory(Samples/cpp)

# Aggregate benchmark targets: `benchmarks` builds them all, `run-benchmarks`
# builds and runs each in turn.
if(BUILD_BENCHMARKS)
get_property(DRACO_BENCH_TARGETS GLOBAL PROPERTY DRACO_BENCH_TARGETS)
if(DRACO_BENCH_TARGETS)
add_custom_target(benchmarks)
add_dependencies(benchmarks ${DRACO_BENCH_TARGETS})

set(BENCH_RUN_CMDS "")
foreach(BENCH_TARGET IN LISTS DRACO_BENCH_TARGETS)
list(APPEND BENCH_RUN_CMDS COMMAND $<TARGET_FILE:${BENCH_TARGET}>)
endforeach()
add_custom_target(run-benchmarks
${BENCH_RUN_CMDS}
DEPENDS ${DRACO_BENCH_TARGETS}
USES_TERMINAL
VERBATIM
)
endif()
endif()
5 changes: 1 addition & 4 deletions Engine/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
add_subdirectory(ThirdParty SYSTEM)

add_modules_library(Runtime SHARED)
# Runtime exposes the whole engine through the `draconic` module. Shell (the single
# library holding both backends) is linked PUBLIC, so a consumer only links Runtime and
# does `import draconic;`; createShell() resolves from Shell.
target_link_libraries(Runtime PUBLIC Core Shell Scene Rendering)
target_link_libraries(Runtime PUBLIC Core)

# TODO: binding library
53 changes: 48 additions & 5 deletions Engine/cpp/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
add_modules_library(Core PIC)
add_modules_library(Shell)
add_modules_library(Rendering PIC)
add_modules_library(Scene)
add_modules_library(Rendering/Shaders)
add_modules_library(Rendering/RHI PIC)
add_modules_library(Rendering/RHI/Null)
add_modules_library(Rendering/RHI/Validation)
add_modules_library(Rendering/RHI/Vulkan)
if(WIN32)
add_modules_library(Rendering/RHI/DX12)
endif()
add_modules_library(Rendering/Shaders/System)
add_modules_library(Rendering/Graphics)
add_modules_library(Rendering/RenderGraph)

target_link_libraries(Core PUBLIC Definitions Math IO Memory Logging)

# Shell is a single library: the interface plus both backends, separated only by folder
# (Desktop/ = SDL3, Null/ = headless). SDL3 is a PRIVATE implementation detail; nothing
# outside Shell sees it. createShell() dispatches to the backend chosen at compile time
Expand Down Expand Up @@ -33,5 +41,40 @@ if(CMAKE_TESTING_ENABLED)
add_test(NAME ${SHELL_TEST_TARGET} COMMAND ${SHELL_TEST_TARGET} --reporter junit --out "Testing/${SHELL_TEST_TARGET}.xml")
endforeach()
endif()
target_link_libraries(Rendering PUBLIC RHI RenderGraph Mesh Material QuadRenderer Renderer)
target_link_libraries(Scene PUBLIC Renderable TransformComponent Camera)
# Rendering: RHI is the backend-agnostic interface module; Null is the headless
# no-op backend (for tests/tools). GPU backends (Vulkan, DX12) come later.
# Shaders: HLSL compilation via DXC. DXC's headers come from Draco::DXCHeaders
# (which also carries DRACO_DXC_PATH); the runtime library is dlopen'd, so only
# the platform's dl library is linked.
target_link_libraries(Rendering_Shaders PUBLIC Core Draco::DXCHeaders PRIVATE ${CMAKE_DL_LIBS})
# ShaderSystem: variant compile-on-demand + cache. Needs the RHI (to create GPU
# modules) on top of the RHI-free shaders module. Its test uses the Null backend.
target_link_libraries(Rendering_Shaders_System PUBLIC Rendering_Shaders Rendering_RHI Rendering_RHI_Null)
target_link_libraries(Rendering_RHI PUBLIC Core)
target_link_libraries(Rendering_RHI_Null PUBLIC Rendering_RHI)
# Validation wraps any backend; its test wraps the Null backend, so Null is
# PUBLIC here to give the test the rhi.null module interface.
target_link_libraries(Rendering_RHI_Validation PUBLIC Rendering_RHI Rendering_RHI_Null)
# Vulkan GPU backend. The Vulkan loader is PRIVATE: VkIncludes.h/vulkan.h live in
# the module's global fragment, so importers of rhi.vk don't need the headers, but
# the static lib's loader symbols still propagate to the final link.
target_link_libraries(Rendering_RHI_Vulkan PUBLIC Rendering_RHI PRIVATE Vulkan::Vulkan)
# DX12 GPU backend (Windows only). Links the D3D12/DXGI system libraries privately;
# IID_PPV_ARGS uses __uuidof, which Clang flags as a language extension.
if(WIN32)
target_link_libraries(Rendering_RHI_DX12 PUBLIC Rendering_RHI PRIVATE d3d12 dxgi dxguid d3dcompiler)
target_compile_options(Rendering_RHI_DX12 PRIVATE $<$<CXX_COMPILER_ID:Clang>:-Wno-language-extension-token>)
endif()
# Graphics render host: one target holding the graphics / graphics.null / graphics.gpu
# modules. The core `graphics` interface imports only base RHI + Shell; graphics.gpu
# pulls the backends. Shell is PUBLIC for the headless test. DX12 is added
# (with DRACO_HAS_DX12) only on Windows.
# RenderGraph: pass dependency resolution, transient aliasing, automatic barriers
# over the RHI. Backend-agnostic (base RHI only); Null is PUBLIC for its headless tests.
target_link_libraries(Rendering_RenderGraph PUBLIC Core Rendering_RHI Rendering_RHI_Null)
target_link_libraries(Rendering_Graphics PUBLIC
Rendering_RHI Rendering_RHI_Null Rendering_RHI_Vulkan Rendering_RHI_Validation Shell)
if(WIN32)
target_link_libraries(Rendering_Graphics PUBLIC Rendering_RHI_DX12)
target_compile_definitions(Rendering_Graphics PUBLIC DRACO_HAS_DX12)
endif()
17 changes: 9 additions & 8 deletions Engine/cpp/Runtime/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
add_modules_library(Definitions)
add_modules_library(Math)
add_modules_library(IO)
add_modules_library(Memory)
add_modules_library(Logging)
add_modules_library(Containers)
# PIC: these are linked into the shared Runtime library (via Core), so their objects
# must be position-independent - a non-PIC static (e.g. Quaternion::identity) otherwise
# fails to relocate when making the shared object.
add_modules_library(Definitions PIC)
add_modules_library(Math PIC)
add_modules_library(IO PIC)
add_modules_library(Memory PIC)
add_modules_library(Logging PIC)

target_link_libraries(Math PUBLIC Definitions bx)
target_link_libraries(Math PUBLIC Definitions)
target_link_libraries(IO PUBLIC Definitions stb_image)
target_link_libraries(Memory PUBLIC Definitions Math)
target_link_libraries(Logging PUBLIC Definitions)
target_link_libraries(Containers PUBLIC Definitions Memory Math)
1 change: 1 addition & 0 deletions Engine/cpp/Runtime/Core/Definitions/Definitions.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module;

export module core.defs;
export import core.stdtypes;
export import core.status;

static_assert(__cplusplus >= 202207L, "Minimum of C++23 required.");

Expand Down
38 changes: 38 additions & 0 deletions Engine/cpp/Runtime/Core/Definitions/Status.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Status / ErrorCode - success or an error code, no payload. For operations
// that return a value-or-error, use std::expected instead.

export module core.status;

import core.stdtypes;

export namespace draco
{
enum class ErrorCode : u32
{
Ok = 0,
Unknown,
InvalidArgument,
OutOfRange,
OutOfMemory,
NotFound,
NotSupported,
AlreadyExists,
Internal,
};

class Status
{
public:
constexpr Status() = default;
constexpr Status(ErrorCode code) : m_code(code) {}

[[nodiscard]] constexpr ErrorCode code() const { return m_code; }
[[nodiscard]] constexpr bool isOk() const { return m_code == ErrorCode::Ok; }
[[nodiscard]] constexpr explicit operator bool() const { return isOk(); }

friend constexpr bool operator==(Status a, Status b) { return a.m_code == b.m_code; }

private:
ErrorCode m_code = ErrorCode::Ok;
};
}
18 changes: 17 additions & 1 deletion Engine/cpp/Runtime/Core/Math/Functions.cppm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module;

#include <numbers>
#include <cmath>
#include <concepts>
#include <limits>
Expand Down Expand Up @@ -114,6 +115,21 @@ export namespace draco::math {
return static_cast<T>(std::pow(x, y));
}

// Trigonometry (radians) and square root.
[[nodiscard]] inline f32 sin(f32 x) noexcept { return std::sin(x); }
[[nodiscard]] inline f32 cos(f32 x) noexcept { return std::cos(x); }
[[nodiscard]] inline f32 tan(f32 x) noexcept { return std::tan(x); }
[[nodiscard]] inline f32 acos(f32 x) noexcept { return std::acos(x); }
[[nodiscard]] inline f32 sqrt(f32 x) noexcept { return std::sqrt(x); }

// Approximate comparisons against an epsilon (defaults to CMP_EPSILON).
[[nodiscard]] constexpr bool nearlyEqual(f32 a, f32 b, f32 epsilon = CMP_EPSILON) noexcept {
return abs(a - b) <= epsilon;
}
[[nodiscard]] constexpr bool nearlyZero(f32 v, f32 epsilon = CMP_EPSILON) noexcept {
return abs(v) <= epsilon;
}

template <std::floating_point T>
constexpr T lerp(T from, T to, T weight) noexcept {
return std::lerp(from, to, weight);
Expand Down Expand Up @@ -202,4 +218,4 @@ export namespace draco::math {
T d = (control_1 - start) * T{3.} * omt2 + (control_2 - control_1) * T{6.} * omt * t + (end - control_2) * T{3.} * t2;
return d;
}
}
}
2 changes: 2 additions & 0 deletions Engine/cpp/Runtime/Core/Math/Math.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export import core.defs;
export import core.math.constants;
export import core.math.functions;
export import core.math.types;
export import core.math.matrix4;
export import core.math.quaternion;
export import core.math.transform;
Loading
Loading