aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2025-12-24 15:35:21 +0100
committerladevieq <ladevie.quentin@gmail.com>2025-12-24 15:35:21 +0100
commitb4d24e8f2cb4838acc0b827f007e7faa609039ba (patch)
treeba6504b67923789d84b2473eb4e14f7002e34ab7 /include
parentc29105b461135f3909cca0308fb05715cee45763 (diff)
Use build.bat for building
Everything is included in main.cpp Do not rely on vcpkg anymore
Diffstat (limited to 'include')
-rw-r--r--include/aabb.hpp15
-rw-r--r--include/api-test/freelist.hpp56
-rw-r--r--include/api-test/handle.hpp2
-rw-r--r--include/api-test/vk-device-types.hpp11
-rw-r--r--include/api-test/vk-device.hpp12
-rw-r--r--include/mat4.hpp12
-rw-r--r--include/scene.hpp2
-rw-r--r--include/utils.hpp18
-rw-r--r--include/vec3.hpp13
-rw-r--r--include/vulkan-loader.hpp5
-rw-r--r--include/window.hpp38
11 files changed, 126 insertions, 58 deletions
diff --git a/include/aabb.hpp b/include/aabb.hpp
index 9862355..adeb1fb 100644
--- a/include/aabb.hpp
+++ b/include/aabb.hpp
@@ -1,9 +1,6 @@
#ifndef __AABB_HPP_
#define __AABB_HPP_
-#include <cmath>
-#include <climits>
-
#include "vec3.hpp"
#include "triangle.hpp"
@@ -33,11 +30,14 @@ class aabb {
int32_t maximum_axis() const {
vec3 diag = diagonal();
+ float v0 = diag.get<0>();
+ float v1 = diag.get<1>();
+ float v2 = diag.get<2>();
- if (diag.v[0] > diag.v[1] && diag.v[0] > diag.v[2]) {
+ if (v0 > v1 && v0 > v2) {
return 0;
}
- if (diag.v[1] > diag.v[2]) {
+ if (v1 > v2) {
return 1;
}
return 2;
@@ -53,7 +53,10 @@ class aabb {
float surface_area() const {
auto diag = diagonal();
- return 2.f * (diag.v[0] * diag.v[1] + diag.v[0] * diag.v[2] + diag.v[1] * diag.v[2]);
+ float v0 = diag.get<0>();
+ float v1 = diag.get<1>();
+ float v2 = diag.get<2>();
+ return 2.f * (v0 * v1 + v0 * v2 + v1 * v2);
}
vec3 minimum = vec3(std::numeric_limits<float>::max());
diff --git a/include/api-test/freelist.hpp b/include/api-test/freelist.hpp
index 3d0324d..cbcd56d 100644
--- a/include/api-test/freelist.hpp
+++ b/include/api-test/freelist.hpp
@@ -15,17 +15,20 @@ class freelist {
}
handle<T> add(const T& item) {
- auto id = elements[0U].next_free;
+ // auto id = elements[0U].next_free;
+ auto id = next_free_id;
- if (id == invalid_id) {
+ if (id == freelist<T>::invalid_id) {
grow(elements.size());
- id = elements[0U].next_free;
+ // id = elements[0U].next_free;
+ id = next_free_id;
}
auto& element = elements[id];
- elements[0U].next_free = element.next_free;
+ next_free_id = element.next_free;
+ // elements[0U].next_free = element.next_free;
element.item = std::move(item);
return { id, ++element.generation };
@@ -33,8 +36,10 @@ class freelist {
void remove(handle<T> handle) {
assert(handle.generation == elements[handle.id].generation);
- elements[handle.id].next_free = elements[0U].next_free;
- elements[0U].next_free = handle.id;
+ // elements[handle.id].next_free = elements[0U].next_free;
+ // elements[0U].next_free = handle.id;
+ elements[handle.id].next_free = next_free_id;
+ next_free_id = handle.id;
}
T& operator[](handle<T> handle) {
@@ -47,12 +52,13 @@ class freelist {
return elements[handle.id].item;
}
- static constexpr uint32_t invalid_id = -1;
+ static constexpr uint32_t invalid_id = UINT32_MAX;
private:
void grow(size_t grow_size) {
auto size = elements.size();
- uint32_t next_free = size;
+ uint32_t next_free = static_cast<uint32_t>(size);
+ next_free_id = next_free;
elements.reserve(size + grow_size);
@@ -64,18 +70,19 @@ private:
);
}
- elements.back().next_free = -1U;
+ elements.back().next_free = freelist<T>::invalid_id;
}
struct element {
union {
T item;
- uint32_t next_free = -1;
+ uint32_t next_free = freelist<T>::invalid_id;
};
uint32_t generation = 0U;
};
std::vector<element> elements;
+ uint32_t next_free_id;
};
template<const size_t initial_size = default_element_count>
@@ -87,51 +94,58 @@ class idlist {
}
handle<void> add() {
- auto id = elements[0U].next_free;
+ // auto id = elements[0U].next_free;
+ auto id = next_free_id;
- if (id == invalid_id) {
+ if (id == idlist<T>::invalid_id) {
grow(elements.size());
- id = elements[0U].next_free;
+ // id = elements[0U].next_free;
+ id = next_free_id;
}
auto& element = elements[id];
+ next_free_id = element.next_free;
elements[0U].next_free = element.next_free;
- element.next_free = -1;
+ element.next_free = idlist<T>::invalid_id;
return { id, ++element.generation };
}
void remove(handle<void> handle) {
assert(handle.generation == elements[handle.id].generation);
- elements[handle.id].next_free = elements[0U].next_free;
- elements[0U].next_free = handle.id;
+ // elements[handle.id].next_free = elements[0U].next_free;
+ // elements[0U].next_free = handle.id;
+ elements[handle.id].next_free = next_free_id;
+ next_free_id = handle.id;
}
- static constexpr uint32_t invalid_id = -1;
+ static constexpr uint32_t invalid_id = UINT32_MAX;
private:
void grow(size_t grow_size) {
auto size = elements.size();
- uint32_t next_free = size;
+ uint32_t next_free = static_cast<uint32_t>(size);
+ next_free_id = next_free;
elements.reserve(size + grow_size);
for (auto id { 0U }; id < initial_size; id++) {
elements.push_back(
{
- .next_free = static_cast<uint32_t>(++next_free % initial_size),
+ .next_free = static_cast<uint32_t>(++next_free% initial_size),
}
);
}
- elements.back().next_free = -1U;
+ elements.back().next_free = idlist<T>::invalid_id;
}
struct element {
- uint32_t next_free = -1;
+ uint32_t next_free = idlist<T>::invalid_id;
uint32_t generation = 0U;
};
std::vector<element> elements;
+ uint32_t next_free_id;
};
diff --git a/include/api-test/handle.hpp b/include/api-test/handle.hpp
index f07776b..2c52c01 100644
--- a/include/api-test/handle.hpp
+++ b/include/api-test/handle.hpp
@@ -18,7 +18,7 @@ struct handle {
[[nodiscard]] inline bool is_valid() const { return id != handle::invalid_id; }
- static constexpr uint32_t invalid_id = -1U;
+ static constexpr uint32_t invalid_id = UINT32_MAX;
// static constexpr handle<U> invalid_handle {};
};
diff --git a/include/api-test/vk-device-types.hpp b/include/api-test/vk-device-types.hpp
index dd8348b..eddf40c 100644
--- a/include/api-test/vk-device-types.hpp
+++ b/include/api-test/vk-device-types.hpp
@@ -24,6 +24,7 @@ struct texture_desc {
VkFormat format;
VkImageType type;
VkImage vk_image = nullptr;
+ const char* name = nullptr;
static constexpr auto max_mips = 16U;
};
@@ -111,11 +112,14 @@ struct buffer_desc {
uint32_t memory_usage;
};
+#define ALIGN(value, alignment) \
+ (((value) + ((alignment) - 1)) & ~((alignment) - 1))
+
struct device_buffer {
template<typename T>
T* allocate() {
// size_t alloc_size = (sizeof(T) + 0x100) & 0xffffff00;
- size_t alloc_size = sizeof(T);
+ size_t alloc_size = ALIGN(sizeof(T), 16);
if (offset + alloc_size > size) {
reset();
}
@@ -127,6 +131,7 @@ struct device_buffer {
void* allocate(uint64_t alloc_size) {
// size_t alloc_size = (sizeof(T) + 0x100) & 0xffffff00;
+ alloc_size = ALIGN(alloc_size, 16);
if (offset + alloc_size > size) {
reset();
}
@@ -140,7 +145,7 @@ struct device_buffer {
offset = 0U;
}
- uint32_t offset = 0U;
+ uint64_t offset = 0U;
VkBuffer vk_buffer;
VmaAllocation alloc;
VkDeviceAddress device_address = 0U;
@@ -154,10 +159,12 @@ struct graphics_pipeline_desc {
std::span<VkFormat> color_attachments_format;
VkFormat depth_attachment_format;
VkFormat stencil_attachment_format;
+ const char* name;
};
struct compute_pipeline_desc {
std::span<uint8_t> cs_code;
+ const char* name;
};
struct device_pipeline {
diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp
index dc46e1a..1b04bb3 100644
--- a/include/api-test/vk-device.hpp
+++ b/include/api-test/vk-device.hpp
@@ -42,7 +42,7 @@ class vkdevice {
handle<device_surface> create_surface(const surface_desc& desc);
- handle<device_semaphore> create_semaphore(const semaphore_desc& desc);
+ handle<device_semaphore> create_semaphore(const semaphore_desc& desc, const char* name);
void destroy_texture(handle<device_texture> handle);
@@ -57,8 +57,8 @@ class vkdevice {
void destroy_surface(handle<device_surface> handle);
template<typename buffer_type>
- void allocate_command_buffers(buffer_type* buffers, size_t count, QueueType queue_type) {
- allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type);
+ void allocate_command_buffers(buffer_type* buffers, size_t count, QueueType queue_type, const char* name) {
+ allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type, name);
}
[[nodiscard]] inline device_texture& get_texture(handle<device_texture> handle) {
@@ -99,8 +99,8 @@ class vkdevice {
// uint64_t submit(std::span<command_buffer> buffers, handle<device_semaphore> wait_handle, handle<device_semaphore> signal_handle, handle<device_semaphore> fence_handle);
uint32_t acquire_image_index(handle<device_surface> surface_handle);
- uint32_t submit_before_present(handle<device_surface> surface_handle, command_buffer* buffers, uint32_t count);
- uint32_t submit(command_buffer* buffers, uint32_t count);
+ uint64_t submit_before_present(handle<device_surface> surface_handle, command_buffer* buffers, uint32_t count);
+ uint64_t submit(command_buffer* buffers, uint32_t count);
void present(handle<device_surface> surface_handle);
@@ -110,7 +110,7 @@ class vkdevice {
vkdevice() = default;
~vkdevice() = default;
- void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type);
+ void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type, const char* name);
VkShaderModule create_shader_module(const std::span<uint8_t>& shader_code);
diff --git a/include/mat4.hpp b/include/mat4.hpp
new file mode 100644
index 0000000..672c83a
--- /dev/null
+++ b/include/mat4.hpp
@@ -0,0 +1,12 @@
+#ifndef __MAT4_HPP_
+#define __MAT4_HPP_
+
+#include <xmmintrin.h>
+
+class mat4 {
+ static mat4 projection();
+
+ __m128 r1, r2, r3, r4;
+};
+
+#endif // __MAT4_HPP_
diff --git a/include/scene.hpp b/include/scene.hpp
index ad298da..091e4fc 100644
--- a/include/scene.hpp
+++ b/include/scene.hpp
@@ -25,7 +25,7 @@ class scene {
uint32_t enable_dof = (uint32_t)false;
uint32_t debug_bvh = (uint32_t)false;
- int32_t downscale_factor = 1;
+ int32_t downscale_factor = 2;
metadata(const camera &cam, uint32_t width, uint32_t height);
};
diff --git a/include/utils.hpp b/include/utils.hpp
index 83a867f..e49b218 100644
--- a/include/utils.hpp
+++ b/include/utils.hpp
@@ -1,21 +1,15 @@
#pragma once
#include <vector>
-#include <functional>
#include <unordered_map>
-#include <string>
std::vector<uint8_t> read_file(const char* path);
#define PI 3.14159265359
#define EPSILON 0.000001
-namespace std::filesystem {
- class path;
-}
-
inline float deg_to_rad(float deg) {
- return deg * PI / 180.f;
+ return static_cast<float>(deg * PI / 180.f);
}
inline float randd() {
@@ -45,9 +39,11 @@ void log_last_error();
class watcher {
public:
- static bool watch_file(std::filesystem::path&& filepath, std::function<void()> callback);
+ typedef void(*func)(void);
+
+ static bool watch_file(const char* filepath, func callback);
- static bool watch_dir(std::filesystem::path&& dir_path);
+ static bool watch_dir(const char* dir_path);
static void pull_changes();
@@ -59,7 +55,7 @@ private:
DWORD buffer[512];
};
- inline static std::unordered_map<std::string, std::function<void()>> callbacks;
- inline static std::unordered_map<std::string, watch_data> watched_dirs;
+ inline static std::unordered_map<const char*, func> callbacks;
+ inline static std::unordered_map<const char*, watch_data> watched_dirs;
};
#endif
diff --git a/include/vec3.hpp b/include/vec3.hpp
index 968f3ed..42172e6 100644
--- a/include/vec3.hpp
+++ b/include/vec3.hpp
@@ -41,7 +41,13 @@ class vec3 {
[[nodiscard]]vec3 (min)(const vec3& vec) const;
[[nodiscard]]vec3 (max)(const vec3& vec) const;
- float operator[](int axis);
+ template<int axis>
+ [[nodiscard]] float get() const;
+
+ template<int axis>
+ void set(float val);
+
+ [[nodiscard]] float operator[](int axis) const;
[[nodiscard]] float length() const;
@@ -61,7 +67,10 @@ class vec3 {
static vec3 random(float min, float max);
- __m128 v;
+ union {
+ __m128 v;
+ float arr[4];
+ };
};
vec3 lerp(const vec3& u, const vec3& v, float t);
diff --git a/include/vulkan-loader.hpp b/include/vulkan-loader.hpp
index f229509..ec1464d 100644
--- a/include/vulkan-loader.hpp
+++ b/include/vulkan-loader.hpp
@@ -1,6 +1,8 @@
#ifndef __VULKAN_LOADER_HPP_
#define __VULKAN_LOADER_HPP_
+#define VK_NO_PROTOTYPES
+
#if defined(WINDOWS)
#include <vulkan/vk_platform.h>
#include <vulkan/vulkan_core.h>
@@ -8,10 +10,12 @@ typedef unsigned long DWORD;
typedef const wchar_t* LPCWSTR;
typedef void* HANDLE;
typedef struct HINSTANCE__* HINSTANCE;
+typedef HINSTANCE HMODULE;
typedef struct HWND__* HWND;
typedef struct HMONITOR__* HMONITOR;
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
#include <vulkan/vulkan_win32.h>
+#define VK_USE_PLATFORM_WIN32_KHR
#else
#include <vulkan/vulkan.h>
#endif
@@ -58,6 +62,7 @@ typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
X(vkGetPhysicalDeviceMemoryProperties) \
X(vkCreateDevice) \
X(vkEnumerateDeviceExtensionProperties) \
+ X(vkSetDebugUtilsObjectNameEXT) \
X(vkCreateDebugUtilsMessengerEXT) \
X(vkDestroyDebugUtilsMessengerEXT)
diff --git a/include/window.hpp b/include/window.hpp
index 33fce4f..2484742 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -10,7 +10,14 @@ class vkrenderer;
#include <xkbcommon/xkbcommon.h>
#elif defined(WINDOWS)
-#include <Windows.h>
+// #include <Windows.h>
+typedef struct HWND__* HWND;
+typedef int64_t LRESULT;
+typedef int64_t LPARAM;
+typedef uint64_t WPARAM;
+typedef unsigned int UINT;
+typedef void* LPVOID;
+#define CALLBACK __stdcall
#endif
// enum MODIFIERS: uint32_t {
@@ -122,13 +129,28 @@ enum EVENT_TYPES: int32_t {
MOUSE_MOVE
};
+// struct event {
+// uint32_t width;
+// uint32_t height;
+// KEYS key;
+// BUTTONS button;
+// int32_t x;
+// int32_t y;
+// EVENT_TYPES type;
+// };
struct event {
- uint32_t width;
- uint32_t height;
- KEYS key;
- BUTTONS button;
- int32_t x;
- int32_t y;
+ union {
+ struct {
+ uint32_t width;
+ uint32_t height;
+ } size;
+ struct {
+ int32_t x;
+ int32_t y;
+ } position;
+ KEYS key;
+ BUTTONS button;
+ } data;
EVENT_TYPES type;
};
@@ -147,7 +169,7 @@ class window {
static LRESULT CALLBACK window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);
HWND handle {};
- WNDCLASS window_class {};
+ const char* window_class_name;
LPVOID main_fiber;
LPVOID message_loop_fiber;
#elif defined(LINUX)