From b4d24e8f2cb4838acc0b827f007e7faa609039ba Mon Sep 17 00:00:00 2001 From: ladevieq Date: Wed, 24 Dec 2025 15:35:21 +0100 Subject: Use build.bat for building Everything is included in main.cpp Do not rely on vcpkg anymore --- include/aabb.hpp | 15 ++++++---- include/api-test/freelist.hpp | 56 ++++++++++++++++++++++-------------- include/api-test/handle.hpp | 2 +- include/api-test/vk-device-types.hpp | 11 +++++-- include/api-test/vk-device.hpp | 12 ++++---- include/mat4.hpp | 12 ++++++++ include/scene.hpp | 2 +- include/utils.hpp | 18 +++++------- include/vec3.hpp | 13 +++++++-- include/vulkan-loader.hpp | 5 ++++ include/window.hpp | 38 ++++++++++++++++++------ 11 files changed, 126 insertions(+), 58 deletions(-) create mode 100644 include/mat4.hpp (limited to 'include') 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 -#include - #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::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 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::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 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 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(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::invalid_id; } struct element { union { T item; - uint32_t next_free = -1; + uint32_t next_free = freelist::invalid_id; }; uint32_t generation = 0U; }; std::vector elements; + uint32_t next_free_id; }; template @@ -87,51 +94,58 @@ class idlist { } handle 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::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::invalid_id; return { id, ++element.generation }; } void remove(handle 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(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(++next_free % initial_size), + .next_free = static_cast(++next_free% initial_size), } ); } - elements.back().next_free = -1U; + elements.back().next_free = idlist::invalid_id; } struct element { - uint32_t next_free = -1; + uint32_t next_free = idlist::invalid_id; uint32_t generation = 0U; }; std::vector 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 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 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 color_attachments_format; VkFormat depth_attachment_format; VkFormat stencil_attachment_format; + const char* name; }; struct compute_pipeline_desc { std::span 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 create_surface(const surface_desc& desc); - handle create_semaphore(const semaphore_desc& desc); + handle create_semaphore(const semaphore_desc& desc, const char* name); void destroy_texture(handle handle); @@ -57,8 +57,8 @@ class vkdevice { void destroy_surface(handle handle); template - void allocate_command_buffers(buffer_type* buffers, size_t count, QueueType queue_type) { - allocate_command_buffers(static_cast(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(buffers), count, queue_type, name); } [[nodiscard]] inline device_texture& get_texture(handle handle) { @@ -99,8 +99,8 @@ class vkdevice { // uint64_t submit(std::span buffers, handle wait_handle, handle signal_handle, handle fence_handle); uint32_t acquire_image_index(handle surface_handle); - uint32_t submit_before_present(handle surface_handle, command_buffer* buffers, uint32_t count); - uint32_t submit(command_buffer* buffers, uint32_t count); + uint64_t submit_before_present(handle surface_handle, command_buffer* buffers, uint32_t count); + uint64_t submit(command_buffer* buffers, uint32_t count); void present(handle 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& 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 + +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 -#include #include -#include std::vector 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(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 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> callbacks; - inline static std::unordered_map watched_dirs; + inline static std::unordered_map callbacks; + inline static std::unordered_map 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 + [[nodiscard]] float get() const; + + template + 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 #include @@ -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 +#define VK_USE_PLATFORM_WIN32_KHR #else #include #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 #elif defined(WINDOWS) -#include +// #include +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) -- cgit v1.3