fix: Linux build
- Prepare for supporting Xlib and Wayland (in the future), by having a option for 'use_xlib' - Fixed a few compile errors
This commit is contained in:
parent
81798df3e9
commit
4b97f8ff33
10
meson.build
10
meson.build
@ -23,7 +23,7 @@ endif
|
|||||||
|
|
||||||
# Debug specific flags
|
# Debug specific flags
|
||||||
if buildtype == 'debug' or buildtype == 'debugoptimized'
|
if buildtype == 'debug' or buildtype == 'debugoptimized'
|
||||||
add_project_arguments([ '-DDEBUG'], language : 'c')
|
add_project_arguments([ '-DVY_DEBUG'], language : 'c')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Gather dependencies
|
# Gather dependencies
|
||||||
@ -31,6 +31,12 @@ thread_dep = dependency('threads')
|
|||||||
m_dep = compiler.find_library('m', required : false)
|
m_dep = compiler.find_library('m', required : false)
|
||||||
vk_dep = dependency('vulkan', 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_proj = subproject('glfw', default_options : 'default_library=static')
|
||||||
# glfw_dep = glfw_proj.get_variable('glfw_dep')
|
# glfw_dep = glfw_proj.get_variable('glfw_dep')
|
||||||
|
|
||||||
@ -59,7 +65,7 @@ runtime_lib = library('vyrt',
|
|||||||
|
|
||||||
# Contrib Sources
|
# Contrib Sources
|
||||||
'contrib/xxhash/xxhash.c',
|
'contrib/xxhash/xxhash.c',
|
||||||
dependencies : [thread_dep, m_dep],
|
dependencies : [thread_dep, m_dep, windowing_dep],
|
||||||
include_directories : incdir,
|
include_directories : incdir,
|
||||||
c_pch : 'pch/rt_pch.h')
|
c_pch : 'pch/rt_pch.h')
|
||||||
|
|
||||||
|
1
meson.options
Normal file
1
meson.options
Normal file
@ -0,0 +1 @@
|
|||||||
|
option('use_xlib', type : 'boolean', value : false, description : 'Use Xlib for window creation under linux')
|
1
meson_options.txt
Symbolic link
1
meson_options.txt
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
meson.options
|
@ -1 +1,3 @@
|
|||||||
#include <Windows.h>
|
#ifdef _WIN32
|
||||||
|
#include <Windows.h>
|
||||||
|
#endif
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
int WINAPI wWinMain(HINSTANCE hInstance,
|
int WINAPI wWinMain(HINSTANCE hInstance,
|
||||||
HINSTANCE hPrevInstance,
|
HINSTANCE hPrevInstance,
|
||||||
@ -12,4 +12,10 @@ int WINAPI wWinMain(HINSTANCE hInstance,
|
|||||||
return vyWin32Entry(hInstance, hPrevInstance, pCmdLine, nCmdShow);
|
return vyWin32Entry(hInstance, hPrevInstance, pCmdLine, nCmdShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#elif defined(__linux__)
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define VY_VK_DONT_DEFINE_GPU_GLOBAL
|
#define VY_VK_DONT_DEFINE_GPU_GLOBAL
|
||||||
#include "gpu.h"
|
#include "gpu.h"
|
||||||
|
|
||||||
#include "runtime/runtime.h"
|
|
||||||
#include "runtime/renderer_api.h"
|
|
||||||
#include "runtime/config.h"
|
#include "runtime/config.h"
|
||||||
|
#include "runtime/renderer_api.h"
|
||||||
|
#include "runtime/runtime.h"
|
||||||
|
|
||||||
VY_CVAR_I(r_EnableAPIAllocTracking,
|
VY_CVAR_I(
|
||||||
"Enable tracking of allocations done by the vulkan api. [0/1] Default: 0",
|
r_EnableAPIAllocTracking,
|
||||||
0);
|
"Enable tracking of allocations done by the vulkan api. [0/1] Default: 0",
|
||||||
|
0);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t allocated;
|
size_t allocated;
|
||||||
@ -25,8 +25,7 @@ vy_vk_gpu g_gpu;
|
|||||||
static VkAllocationCallbacks _tracking_alloc_cbs;
|
static VkAllocationCallbacks _tracking_alloc_cbs;
|
||||||
static vy_vk_alloc_stats _alloc_stats;
|
static vy_vk_alloc_stats _alloc_stats;
|
||||||
|
|
||||||
static const char *AllocationScopeToString(VkSystemAllocationScope scope)
|
static const char *AllocationScopeToString(VkSystemAllocationScope scope) {
|
||||||
{
|
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
case VK_SYSTEM_ALLOCATION_SCOPE_COMMAND:
|
case VK_SYSTEM_ALLOCATION_SCOPE_COMMAND:
|
||||||
return "COMMAND";
|
return "COMMAND";
|
||||||
@ -52,7 +51,10 @@ static void LogAllocationStats(const vy_vk_alloc_stats *stats) {
|
|||||||
stats->max_alignment);
|
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;
|
vy_vk_alloc_stats *stats = userData;
|
||||||
if (alignment > stats->max_alignment)
|
if (alignment > stats->max_alignment)
|
||||||
stats->max_alignment = alignment;
|
stats->max_alignment = alignment;
|
||||||
@ -63,7 +65,11 @@ static void *TrackAllocation(void *userData, size_t size, size_t alignment, VkSy
|
|||||||
alignment,
|
alignment,
|
||||||
AllocationScopeToString(scope));
|
AllocationScopeToString(scope));
|
||||||
LogAllocationStats(stats);
|
LogAllocationStats(stats);
|
||||||
|
#ifdef _WIN32
|
||||||
return _aligned_malloc(size, alignment);
|
return _aligned_malloc(size, alignment);
|
||||||
|
#else
|
||||||
|
return aligned_alloc(alignment, size);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *TrackReallocation(void *userData,
|
static void *TrackReallocation(void *userData,
|
||||||
@ -81,7 +87,7 @@ static void *TrackReallocation(void *userData,
|
|||||||
alignment,
|
alignment,
|
||||||
AllocationScopeToString(scope));
|
AllocationScopeToString(scope));
|
||||||
LogAllocationStats(stats);
|
LogAllocationStats(stats);
|
||||||
return _aligned_realloc(original, size, alignment);
|
return realloc(original, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TrackFree(void *userData, void *memory) {
|
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) {
|
VY_DLLEXPORT int vyInit(const vy_renderer_init_info *info) {
|
||||||
vyLog("vk", "Init");
|
vyLog("vk", "Init");
|
||||||
|
|
||||||
vyRegisterCVAR(&r_EnableAPIAllocTracking);
|
vyRegisterCVAR(&r_EnableAPIAllocTracking);
|
||||||
|
|
||||||
_tracking_alloc_cbs.pUserData = &_alloc_stats;
|
_tracking_alloc_cbs.pUserData = &_alloc_stats;
|
||||||
_tracking_alloc_cbs.pfnAllocation = TrackAllocation;
|
_tracking_alloc_cbs.pfnAllocation = TrackAllocation;
|
||||||
_tracking_alloc_cbs.pfnReallocation = TrackReallocation;
|
_tracking_alloc_cbs.pfnReallocation = TrackReallocation;
|
||||||
_tracking_alloc_cbs.pfnFree = TrackFree;
|
_tracking_alloc_cbs.pfnFree = TrackFree;
|
||||||
|
|
||||||
@ -110,11 +116,11 @@ VY_DLLEXPORT int vyInit(const vy_renderer_init_info *info) {
|
|||||||
VkResult result;
|
VkResult result;
|
||||||
|
|
||||||
VkApplicationInfo app_info = {
|
VkApplicationInfo app_info = {
|
||||||
.apiVersion = VK_API_VERSION_1_0,
|
.apiVersion = VK_API_VERSION_1_0,
|
||||||
.applicationVersion = 0x00001000,
|
.applicationVersion = 0x00001000,
|
||||||
.engineVersion = 0x00001000,
|
.engineVersion = 0x00001000,
|
||||||
.pEngineName = "voyage",
|
.pEngineName = "voyage",
|
||||||
.pApplicationName = "Voyage",
|
.pApplicationName = "Voyage",
|
||||||
};
|
};
|
||||||
|
|
||||||
VkInstanceCreateInfo instance_info = {
|
VkInstanceCreateInfo instance_info = {
|
||||||
@ -134,4 +140,4 @@ VY_DLLEXPORT void vyShutdown(void) {
|
|||||||
vyLog("vk", "Shutdown");
|
vyLog("vk", "Shutdown");
|
||||||
|
|
||||||
vkDestroyInstance(g_gpu.instance, g_gpu.alloc_cb);
|
vkDestroyInstance(g_gpu.instance, g_gpu.alloc_cb);
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,17 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct HINSTANCE__;
|
struct HINSTANCE__;
|
||||||
struct HWND__;
|
struct HWND__;
|
||||||
|
#elif defined(VY_USE_XLIB)
|
||||||
|
struct _XDisplay;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct vy_renderer_init_info_s {
|
struct vy_renderer_init_info_s {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct HINSTANCE__ *hInstance;
|
struct HINSTANCE__ *hInstance;
|
||||||
struct HWND__ *hWnd;
|
struct HWND__ *hWnd;
|
||||||
|
#elif defined(VY_USE_XLIB)
|
||||||
|
struct _XDisplay *display;
|
||||||
|
unsigned long window;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,18 +2,18 @@
|
|||||||
#include "runtime.h"
|
#include "runtime.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
struct vy_mutex_s {
|
struct vy_mutex_s {
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
ptrdiff_t next_reusable;
|
ptrdiff_t next_reusable;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_MUTEX 1024
|
#define MAX_MUTEX 1024
|
||||||
static vy_mutex _mutex[MAX_MUTEX];
|
static vy_mutex _mutex[MAX_MUTEX];
|
||||||
static ptrdiff_t _first_reusable = 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) {
|
VY_DLLEXPORT vy_mutex *vyCreateMutex(void) {
|
||||||
if (_first_reusable < MAX_MUTEX) {
|
if (_first_reusable < MAX_MUTEX) {
|
||||||
@ -51,7 +51,7 @@ VY_DLLEXPORT bool vyUnlockMutex(vy_mutex *mutex) {
|
|||||||
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
struct vy_mutex_s {
|
struct vy_mutex_s {
|
||||||
pthread_mutex_t handle;
|
pthread_mutex_t handle;
|
||||||
ptrdiff_t next_reusable;
|
ptrdiff_t next_reusable;
|
||||||
@ -70,7 +70,7 @@ VY_DLLEXPORT vy_mutex *vyCreateMutex(void) {
|
|||||||
} else if (_next < MAX_MUTEX) {
|
} else if (_next < MAX_MUTEX) {
|
||||||
vy_mutex *mtx = &_mutex[_next];
|
vy_mutex *mtx = &_mutex[_next];
|
||||||
if (pthread_mutex_init(&mtx->handle, NULL) != 0) {
|
if (pthread_mutex_init(&mtx->handle, NULL) != 0) {
|
||||||
vyLog("core", "Mutex creation failed: %u", GetLastError());
|
vyLog("core", "Mutex creation failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mtx->next_reusable = MAX_MUTEX;
|
mtx->next_reusable = MAX_MUTEX;
|
||||||
@ -95,4 +95,4 @@ VY_DLLEXPORT bool vyUnlockMutex(vy_mutex *mutex) {
|
|||||||
return pthread_mutex_unlock(&mutex->handle) == 0;
|
return pthread_mutex_unlock(&mutex->handle) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user