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
|
||||
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')
|
||||
|
||||
|
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
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
@ -12,4 +12,10 @@ int WINAPI wWinMain(HINSTANCE hInstance,
|
||||
return vyWin32Entry(hInstance, hPrevInstance, pCmdLine, nCmdShow);
|
||||
}
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,17 +1,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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) {
|
||||
@ -96,8 +102,8 @@ VY_DLLEXPORT int vyInit(const vy_renderer_init_info *info) {
|
||||
|
||||
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 = {
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -2,18 +2,18 @@
|
||||
#include "runtime.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
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 <pthread.h>
|
||||
#include <pthread.h>
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user