Skip to content
Open
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
50 changes: 0 additions & 50 deletions engine/common/include/tempeh/common/sbstd.hpp

This file was deleted.

7 changes: 7 additions & 0 deletions engine/common/include/tempeh/common/typedefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

#include <cstdint>

#define FUNCTION_ALIAS(NEW_NAME, ...) \
inline auto NEW_NAME = [](auto &&... args) \
noexcept(noexcept(__VA_ARGS__(std::forward<decltype(args)>(args)...))) \
-> decltype(auto) { \
return __VA_ARGS__(std::forward<decltype(args)>(args)...); \
};

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
Expand Down
10 changes: 4 additions & 6 deletions engine/common/include/tempeh/util/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ namespace Tempeh::Util
class Result
{
public:
constexpr Result()
{
}
constexpr Result() = default;

constexpr Result(T&& value) noexcept :
constexpr explicit Result(T&& value) noexcept :
m_var(std::move(value))
{
}

constexpr Result(E&& err) noexcept :
constexpr explicit Result(E&& err) noexcept :
m_var(std::move(err))
{
}
Expand Down Expand Up @@ -57,7 +55,7 @@ namespace Tempeh::Util
return *this;
}

bool is_ok() const
[[nodiscard]] bool is_ok() const
{
return std::holds_alternative<T>(m_var);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

namespace Tempeh::Util
{
class RefCount
// Atomically Reference Counted
class Arc
{
public:
RefCount() :
Arc() :
m_counter(1)
{
}

virtual ~RefCount()
virtual ~Arc()
{
}

Expand Down Expand Up @@ -59,8 +60,18 @@ namespace Tempeh::Util
return ptr;
}

// Reference Counted
template<typename T>
using Ref = std::shared_ptr<T>;
using Rc = std::shared_ptr<T>;

template<typename T>
using Box = std::unique_ptr<T>;

template<typename T>
FUNCTION_ALIAS(make_rc, std::make_shared<T>);
Copy link
Member

@native-m native-m Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make_shared & make_unique requires you to provide the constructor parameters, this is probably wont work for classes that don't have a default constructor.

template<typename T>
FUNCTION_ALIAS(make_box, std::make_unique<T>);

}

#endif
40 changes: 25 additions & 15 deletions engine/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ if(NOT(DEFINED ENV{MONO_INCLUDE_DIR}))
endif()

set(TEMPEH_USE_VULKAN_BACKEND ON)
set(TEMPEH_USE_WEBGPU_BACKEND ON)

if (TEMPEH_USE_VULKAN_BACKEND)
set(TEMPEH_GPU_VULKAN_BACKEND_SOURCES
"src/gpu/vk/backend_vk.hpp"
"src/gpu/vk/device_vk.cpp"
"src/gpu/vk/device_vk.hpp"
"src/gpu/vk/surface_vk.cpp"
"src/gpu/vk/surface_vk.hpp"
"src/gpu/vk/vk.hpp"
"src/gpu/vk/volk_stub.cpp")
"src/gpu/vk/device.cpp"
"src/gpu/vk/surface.cpp"
"src/gpu/vk/volk_stub.cpp"

"include/tempeh/gpu/vk/device.hpp"
"include/tempeh/gpu/vk/vk.hpp"
"include/tempeh/gpu/vk/volk.h")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volk.h should not be here

endif()

if (TEMPEH_USE_WEBGPU_BACKEND)
set(TEMPEH_GPU_WEBGPU_BACKEND_SOURCES
"src/gpu/wgpu/device.cpp"

"include/tempeh/gpu/wgpu/device.hpp")
endif()

set(TEMPEH_GPU_SOURCES
Expand All @@ -26,8 +34,10 @@ set(TEMPEH_GPU_SOURCES
"include/tempeh/gpu/resource.hpp"
"include/tempeh/gpu/surface.hpp"
"include/tempeh/gpu/types.hpp"
"include/tempeh/gpu/wgpu/device.hpp"

"src/gpu/instance.cpp")
"src/gpu/instance.cpp"
"src/gpu/wgpu/device.cpp" include/tempeh/gpu/wgpu/surface.hpp include/tempeh/gpu/vk/instance.hpp src/gpu/vk/instance.cpp include/tempeh/gpu/wgpu/instance.hpp src/gpu/wgpu/instance.cpp)

add_library(tempeh_core STATIC
"include/tempeh/window/window.hpp"
Expand All @@ -38,20 +48,14 @@ add_library(tempeh_core STATIC
"src/scripting/mono.cpp"

"include/tempeh/renderer/camera.hpp"
"include/tempeh/renderer/backend/framebuffer.hpp"
"include/tempeh/renderer/backend/texture.hpp"
"include/tempeh/renderer/backend/uniform_buffer.hpp"
"include/tempeh/renderer/camera.hpp"
"include/tempeh/renderer/backend/vulkan/texture.hpp"
"include/tempeh/renderer/backend/vulkan/instance.hpp"
"include/tempeh/renderer/backend/opengl_es/texture.hpp"
"include/tempeh/renderer/backend/opengl_es/instance.hpp"

"src/renderer/orthogonal_camera.cpp"
"src/renderer/perspective_camera.cpp"
"src/event/input_manager.cpp"

${TEMPEH_GPU_SOURCES}
${TEMPEH_GPU_WEBGPU_BACKEND_SOURCES}
${TEMPEH_GPU_VULKAN_BACKEND_SOURCES})

target_include_directories(tempeh_core
Expand All @@ -63,6 +67,12 @@ target_compile_definitions(tempeh_core
PRIVATE NOMINMAX)

target_link_libraries(tempeh_core
PUBLIC "webgpu_dawn"
PUBLIC "dawn_native"
PUBLIC "dawn_utils"
PUBLIC "dawn_proc"
PUBLIC "dawncpp"
PUBLIC "dawncpp_headers"
PUBLIC tempeh_common
PUBLIC tempeh_math
PUBLIC tempeh_log
Expand Down
2 changes: 1 addition & 1 deletion engine/core/include/tempeh/gpu/command_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Tempeh::GPU
{
class CommandList
INTERFACE class CommandList
{
public:
CommandList();
Expand Down
21 changes: 5 additions & 16 deletions engine/core/include/tempeh/gpu/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@
#include <tempeh/gpu/surface.hpp>
#include <tempeh/window/window.hpp>

#include <tempeh/util/ref_count.hpp>
#include <tempeh/util/smart_ptr.hpp>

namespace Tempeh::GPU
{
template<typename T>
using RefDeviceResult = DeviceResult<Util::Ref<T>>;
using RefDeviceResult = DeviceResult<Util::Rc<T>>;

class Device
INTERFACE class Device
{
public:
Device(BackendType type, const char* name) :
m_backend_type(type),
m_backend_name(name)
{
}

virtual ~Device() { }
virtual ~Device() = default;

virtual RefDeviceResult<Surface> create_surface(
const std::shared_ptr<Window::Window>& window,
Expand All @@ -35,12 +29,7 @@ namespace Tempeh::GPU
virtual void begin_frame() = 0;
virtual void end_frame() = 0;

BackendType type() const;
const char* name() const;

protected:
BackendType m_backend_type;
const char* m_backend_name;
[[nodiscard]] virtual BackendType type() const = 0;
};
}

Expand Down
12 changes: 7 additions & 5 deletions engine/core/include/tempeh/gpu/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

namespace Tempeh::GPU
{
class Instance
INTERFACE class Instance
{
public:
static void initialize(BackendType type, bool prefer_high_performance);
static Util::Ref<Device> get_device();

inline Util::Rc<Device> get_device() { return m_device; }
inline BackendType get_type() { return m_type; }
private:
static Util::Ref<Device> device_;
Util::Rc<Device> m_device;
BackendType m_type;
};

Util::Rc<Instance> create_instance(BackendType type, bool prefer_high_performance);
}

#endif
10 changes: 5 additions & 5 deletions engine/core/include/tempeh/gpu/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@

namespace Tempeh::GPU
{
class Texture
INTERFACE class Texture
{
public:
Texture();
virtual ~Texture();
};

class Buffer
INTERFACE class Buffer
{
public:
Buffer();
virtual ~Buffer();
};

class Framebuffer
INTERFACE class Framebuffer
{
public:
Framebuffer();
virtual ~Framebuffer();
};

class RenderPass
INTERFACE class RenderPass
{
RenderPass();
virtual ~RenderPass();
};

class GraphicsPipeline
INTERFACE class GraphicsPipeline
{
public:
GraphicsPipeline() { }
Expand Down
4 changes: 2 additions & 2 deletions engine/core/include/tempeh/gpu/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace Tempeh::GPU
{
class Surface
INTERFACE class Surface
{
public:
Surface(const SurfaceDesc& desc) :
m_desc(desc)
{
}

virtual ~Surface() { }
virtual ~Surface() = default;

virtual void swap_buffer() = 0;
virtual void resize(u32 width, u32 height) = 0;
Expand Down
Loading