From 9f2ef576b994e4609191f03523ea8f397c6063c9 Mon Sep 17 00:00:00 2001 From: James Bulman Date: Fri, 3 Oct 2025 20:42:04 +0100 Subject: [PATCH] Red screen on Linux Oddly no validation error --- code/core/platform.h | 2 ++ code/vulkan/core.c | 40 +++++++++++++++++++++++++++++++++ code/vulkan/functions.h | 8 +++++++ linux | 50 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100755 linux diff --git a/code/core/platform.h b/code/core/platform.h index fb8d4ce..995e76d 100644 --- a/code/core/platform.h +++ b/code/core/platform.h @@ -68,6 +68,8 @@ #if OS_WINDOWS #define WIN32_LEAN_AND_MEAN 1 #include +#elif OS_LINUX + #include #endif #endif // LD_CORE_PLATFORM_H_ diff --git a/code/vulkan/core.c b/code/vulkan/core.c index 742c8b6..e22392f 100644 --- a/code/vulkan/core.c +++ b/code/vulkan/core.c @@ -23,6 +23,46 @@ static void Vk_CreateSurface(SDL_Window *window) { vk.err = vk.CreateWin32SurfaceKHR(vk.instance, &create_info, 0, &vk.surface); } +#elif OS_LINUX + +#define VK_PLATFORM_SURFACE_EXTENSION \ + VK_KHR_XLIB_SURFACE_EXTENSION_NAME, \ + VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME + +static void *Vk_LoadLibrary() { + void *result = dlopen("libvulkan.so", RTLD_LAZY); + + if (result != 0) { + vk.GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) dlsym(result, "vkGetInstanceProcAddr"); + } + + return result; +} + +static void Vk_CreateSurface(SDL_Window *window) { + SDL_PropertiesID prop_id = SDL_GetWindowProperties(window); + + struct wl_display *wl_display = SDL_GetPointerProperty(prop_id, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, 0); + if (wl_display == 0) { + // Assume we are running via X11 if there isn't a vaild Wayland display + // + VkXlibSurfaceCreateInfoKHR create_info = { 0 }; + create_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; + create_info.dpy = SDL_GetPointerProperty(prop_id, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, 0); + create_info.window = SDL_GetNumberProperty(prop_id, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); + + vk.err = vk.CreateXlibSurfaceKHR(vk.instance, &create_info, 0, &vk.surface); + } + else { + VkWaylandSurfaceCreateInfoKHR create_info = { 0 }; + create_info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; + create_info.display = wl_display; + create_info.surface = SDL_GetPointerProperty(prop_id, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, 0); + + vk.err = vk.CreateWaylandSurfaceKHR(vk.instance, &create_info, 0, &vk.surface); + } +} + #endif Vk_Context vk; diff --git a/code/vulkan/functions.h b/code/vulkan/functions.h index 1a59d2a..45288df 100644 --- a/code/vulkan/functions.h +++ b/code/vulkan/functions.h @@ -10,6 +10,14 @@ #if defined(VK_USE_PLATFORM_WIN32_KHR) VK_FUNC(CreateWin32SurfaceKHR); #endif + +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) + VK_FUNC(CreateWaylandSurfaceKHR); +#endif +#if defined(VK_USE_PLATFORM_XLIB_KHR) + VK_FUNC(CreateXlibSurfaceKHR); +#endif + #undef VK_INSTANCE_FUNCTIONS #endif diff --git a/linux b/linux new file mode 100755 index 0000000..b44be73 --- /dev/null +++ b/linux @@ -0,0 +1,50 @@ +#!/bin/sh +set -e + +pushd "$(dirname $0)" > /dev/null + +if [[ ! -d "build" ]]; +then + mkdir "build" +fi + +pushd "build" > /dev/null + +release=0 +deps=0 + +for a in $* +do + let $a=1 +done + +if [[ ! -d "deps" ]] +then + deps=1 +fi + +if [[ $deps == 1 ]] +then + # We don't build SDL3 like on windows, this assumes you have it installed instead. We can't + # just ship with the version of SDL3 we want because the shared object system is bad + echo "[Building dependencies]" + + rm -rf "deps" + mkdir -p "deps/stb" + + cp ../thirdparty/stb/*.h deps/stb +fi + +echo "[Building source]" + +COMPILER_OPTS="-Wall -Wno-missing-braces -I'deps/stb'" +LINKER_OPTS="-lSDL3" + +if [[ $release == 1 ]] +then + echo "[Release build]" + gcc -O2 -Werror $COMPILER_OPTS -DLD_RELEASE=1 $(realpath "../code/first.c") -o "ludum" $LINKER_OPTS +else + echo "[Debug build]" + gcc -O0 -g -ggdb $COMPILER_OPTS $(realpath "../code/first.c") -o "ldebug" $LINKER_OPTS +fi