diff --git a/meson.build b/meson.build index ec4d97f..6bf8111 100644 --- a/meson.build +++ b/meson.build @@ -23,7 +23,7 @@ endif # Debug specific flags if buildtype == 'debug' or buildtype == 'debugoptimized' - add_project_arguments([ '-DDEBUG'], language : 'c') + add_project_arguments([ '-DVY_DEBUG'], language : 'c') endif # Gather dependencies @@ -31,6 +31,12 @@ thread_dep = dependency('threads') m_dep = compiler.find_library('m', required : false) vk_dep = dependency('vulkan', required : false) +windowing_dep = [] +if get_option('use_xlib') + windowing_dep = dependency('x11', required : true) + add_project_arguments(['-DVY_USE_XLIB'], language : 'c') +endif + # glfw_proj = subproject('glfw', default_options : 'default_library=static') # glfw_dep = glfw_proj.get_variable('glfw_dep') @@ -59,7 +65,7 @@ runtime_lib = library('vyrt', # Contrib Sources 'contrib/xxhash/xxhash.c', - dependencies : [thread_dep, m_dep], + dependencies : [thread_dep, m_dep, windowing_dep], include_directories : incdir, c_pch : 'pch/rt_pch.h') diff --git a/meson.options b/meson.options new file mode 100644 index 0000000..259479f --- /dev/null +++ b/meson.options @@ -0,0 +1 @@ +option('use_xlib', type : 'boolean', value : false, description : 'Use Xlib for window creation under linux') diff --git a/meson_options.txt b/meson_options.txt new file mode 120000 index 0000000..7b28df2 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +meson.options \ No newline at end of file diff --git a/pch/rt_pch.h b/pch/rt_pch.h index 198556f..f98d17e 100644 --- a/pch/rt_pch.h +++ b/pch/rt_pch.h @@ -1 +1,3 @@ -#include +#ifdef _WIN32 + #include +#endif diff --git a/src/game/voyage.c b/src/game/voyage.c index de7e52e..90061a5 100644 --- a/src/game/voyage.c +++ b/src/game/voyage.c @@ -2,8 +2,8 @@ #ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include + #define WIN32_LEAN_AND_MEAN + #include int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, @@ -12,4 +12,10 @@ int WINAPI wWinMain(HINSTANCE hInstance, return vyWin32Entry(hInstance, hPrevInstance, pCmdLine, nCmdShow); } -#endif \ No newline at end of file +#elif defined(__linux__) + +int main(int argc, char **argv) { + return 0; +} + +#endif diff --git a/src/renderer/vk/init.c b/src/renderer/vk/init.c index c2e8578..a009d02 100644 --- a/src/renderer/vk/init.c +++ b/src/renderer/vk/init.c @@ -1,17 +1,17 @@ -#include #include +#include #define VY_VK_DONT_DEFINE_GPU_GLOBAL #include "gpu.h" -#include "runtime/runtime.h" -#include "runtime/renderer_api.h" #include "runtime/config.h" +#include "runtime/renderer_api.h" +#include "runtime/runtime.h" -VY_CVAR_I(r_EnableAPIAllocTracking, - "Enable tracking of allocations done by the vulkan api. [0/1] Default: 0", - 0); - +VY_CVAR_I( + r_EnableAPIAllocTracking, + "Enable tracking of allocations done by the vulkan api. [0/1] Default: 0", + 0); typedef struct { size_t allocated; @@ -25,8 +25,7 @@ vy_vk_gpu g_gpu; static VkAllocationCallbacks _tracking_alloc_cbs; static vy_vk_alloc_stats _alloc_stats; -static const char *AllocationScopeToString(VkSystemAllocationScope scope) -{ +static const char *AllocationScopeToString(VkSystemAllocationScope scope) { switch (scope) { case VK_SYSTEM_ALLOCATION_SCOPE_COMMAND: return "COMMAND"; @@ -52,7 +51,10 @@ static void LogAllocationStats(const vy_vk_alloc_stats *stats) { stats->max_alignment); } -static void *TrackAllocation(void *userData, size_t size, size_t alignment, VkSystemAllocationScope scope) { +static void *TrackAllocation(void *userData, + size_t size, + size_t alignment, + VkSystemAllocationScope scope) { vy_vk_alloc_stats *stats = userData; if (alignment > stats->max_alignment) stats->max_alignment = alignment; @@ -63,7 +65,11 @@ static void *TrackAllocation(void *userData, size_t size, size_t alignment, VkSy alignment, AllocationScopeToString(scope)); LogAllocationStats(stats); +#ifdef _WIN32 return _aligned_malloc(size, alignment); +#else + return aligned_alloc(alignment, size); +#endif } static void *TrackReallocation(void *userData, @@ -81,7 +87,7 @@ static void *TrackReallocation(void *userData, alignment, AllocationScopeToString(scope)); LogAllocationStats(stats); - return _aligned_realloc(original, size, alignment); + return realloc(original, size); } static void TrackFree(void *userData, void *memory) { @@ -93,11 +99,11 @@ static void TrackFree(void *userData, void *memory) { VY_DLLEXPORT int vyInit(const vy_renderer_init_info *info) { vyLog("vk", "Init"); - + vyRegisterCVAR(&r_EnableAPIAllocTracking); - _tracking_alloc_cbs.pUserData = &_alloc_stats; - _tracking_alloc_cbs.pfnAllocation = TrackAllocation; + _tracking_alloc_cbs.pUserData = &_alloc_stats; + _tracking_alloc_cbs.pfnAllocation = TrackAllocation; _tracking_alloc_cbs.pfnReallocation = TrackReallocation; _tracking_alloc_cbs.pfnFree = TrackFree; @@ -110,11 +116,11 @@ VY_DLLEXPORT int vyInit(const vy_renderer_init_info *info) { VkResult result; VkApplicationInfo app_info = { - .apiVersion = VK_API_VERSION_1_0, + .apiVersion = VK_API_VERSION_1_0, .applicationVersion = 0x00001000, - .engineVersion = 0x00001000, - .pEngineName = "voyage", - .pApplicationName = "Voyage", + .engineVersion = 0x00001000, + .pEngineName = "voyage", + .pApplicationName = "Voyage", }; VkInstanceCreateInfo instance_info = { @@ -134,4 +140,4 @@ VY_DLLEXPORT void vyShutdown(void) { vyLog("vk", "Shutdown"); vkDestroyInstance(g_gpu.instance, g_gpu.alloc_cb); -} \ No newline at end of file +} diff --git a/src/runtime/renderer_api.h b/src/runtime/renderer_api.h index 468aef0..66fbb39 100644 --- a/src/runtime/renderer_api.h +++ b/src/runtime/renderer_api.h @@ -10,12 +10,17 @@ #ifdef _WIN32 struct HINSTANCE__; struct HWND__; +#elif defined(VY_USE_XLIB) +struct _XDisplay; #endif struct vy_renderer_init_info_s { #ifdef _WIN32 struct HINSTANCE__ *hInstance; struct HWND__ *hWnd; +#elif defined(VY_USE_XLIB) + struct _XDisplay *display; + unsigned long window; #endif }; diff --git a/src/runtime/threading.c b/src/runtime/threading.c index 4558ef3..4ca2c94 100644 --- a/src/runtime/threading.c +++ b/src/runtime/threading.c @@ -2,18 +2,18 @@ #include "runtime.h" #ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include + #define WIN32_LEAN_AND_MEAN + #include struct vy_mutex_s { HANDLE handle; ptrdiff_t next_reusable; }; -#define MAX_MUTEX 1024 + #define MAX_MUTEX 1024 static vy_mutex _mutex[MAX_MUTEX]; static ptrdiff_t _first_reusable = MAX_MUTEX; -static ptrdiff_t _next = 0; +static ptrdiff_t _next = 0; VY_DLLEXPORT vy_mutex *vyCreateMutex(void) { if (_first_reusable < MAX_MUTEX) { @@ -51,7 +51,7 @@ VY_DLLEXPORT bool vyUnlockMutex(vy_mutex *mutex) { #elif defined(__linux__) -#include + #include struct vy_mutex_s { pthread_mutex_t handle; ptrdiff_t next_reusable; @@ -70,7 +70,7 @@ VY_DLLEXPORT vy_mutex *vyCreateMutex(void) { } else if (_next < MAX_MUTEX) { vy_mutex *mtx = &_mutex[_next]; if (pthread_mutex_init(&mtx->handle, NULL) != 0) { - vyLog("core", "Mutex creation failed: %u", GetLastError()); + vyLog("core", "Mutex creation failed"); return NULL; } mtx->next_reusable = MAX_MUTEX; @@ -95,4 +95,4 @@ VY_DLLEXPORT bool vyUnlockMutex(vy_mutex *mutex) { return pthread_mutex_unlock(&mutex->handle) == 0; } -#endif \ No newline at end of file +#endif