Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vulkan renderer #710

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

runlevel5
Copy link

Following up on the green light given in the forum, I take liberty in extracting the vulkan renderer from vkQuake3 port (commit 5300b32803c1c61bc3b6bdf86a084c1db1a217ad) (all credits go to @suijingfeng)

@runlevel5 runlevel5 force-pushed the renderer_vulkan branch 3 times, most recently from a0883ef to 3e41b76 Compare March 13, 2025 13:25
Copied from vkQuake3 which is in turn based on Quake III Kenny Edition
@jackharrhy
Copy link

Managed to get this PR to compile / run on a M4 Pro under MoltenVK just fine, seems like the existing vkQuake3 port didn't add one tiny little flag that's needed though:

diff --git a/code/renderervk/vk_instance.c b/code/renderervk/vk_instance.c
index df8ef2b2..3f7b1433 100644
--- a/code/renderervk/vk_instance.c
+++ b/code/renderervk/vk_instance.c
@@ -194,7 +194,7 @@ static void vk_createInstance(void)
     // pNext is NULL or a pointer to an extension-specific structure.
 	instanceCreateInfo.pNext = NULL;
     // flags is reserved for future use.
-    instanceCreateInfo.flags = 0;
+    instanceCreateInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
     // pApplicationInfo is NULL or a pointer to an instance of
     // VkApplicationInfo. If not NULL, this information helps 
     // implementations recognize behavior inherent to classes
diff --git a/code/renderervk/vulkan/vulkan_core.h b/code/renderervk/vulkan/vulkan_core.h
index d5110159..6a1dd2ab 100644
--- a/code/renderervk/vulkan/vulkan_core.h
+++ b/code/renderervk/vulkan/vulkan_core.h
@@ -207,6 +207,7 @@ typedef enum VkStructureType {
     VK_STRUCTURE_TYPE_MEMORY_BARRIER = 46,
     VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO = 47,
     VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO = 48,
+    VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR = 395,
     VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES = 1000094000,
     VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO = 1000157000,
     VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO = 1000157001,

Probably not a very kosher way of adding this to the codebase, but always nice to go from not booting, to a perfectly fine running game, in a two line patch.

Just a heads up! Thought this made sense to leave here rather than just keeping this to myself.

@runlevel5
Copy link
Author

@jackharrhy great thanks for the input. Wondering if you could also share the logs of the error / vulkan headers version for my own investigation?

@jackharrhy
Copy link

jackharrhy commented Mar 17, 2025

@runlevel5 np, here's how I can reproduce the error:

build for macos arm64: ./make-macosx.sh arm64

works just fine

run game: ./ioquake3.arm64 +set cl_renderer vulkan +set r_fullscreen 0 +set r_mode 3

output

ioq3 1.36_GIT_15ff4847-2025-03-13 macosx-arm64 Mar 17 2025
----- FS_Startup -----
We are looking in the current search path:
/Users/jack/Library/Application Support/Quake3/baseq3
./baseq3
./baseq3/pak8.pk3 (9 files)
./baseq3/pak7.pk3 (4 files)
./baseq3/pak6.pk3 (64 files)
./baseq3/pak5.pk3 (7 files)
./baseq3/pak4.pk3 (272 files)
./baseq3/pak3.pk3 (4 files)
./baseq3/pak2.pk3 (148 files)
./baseq3/pak1.pk3 (26 files)
./baseq3/pak0.pk3 (3539 files)

----------------------
4073 files in pk3 files
execing default.cfg
execing q3config.cfg
couldn't exec autoexec.cfg
Hunk_Clear: reset the hunk ok
----- Client Initialization -----
----- Initializing Renderer ----
Trying to load "renderer_vulkan_arm64.dylib" from "."...
-------------------------------
QKEY found.
----- Client Initialization Complete -----
----- R_Init -----
 backend state cleared.
--- R_glConfigInit() ---

...Creating window (using SDL2)...
 Found SDL version 2.24.0
 Video is not initialized before, so initial it.
 SDL using driver "cocoa"

...VKimp_SetMode()...
 bpp 32 SDL_PIXELFORMAT_ARGB8888        1728 x 1117, refresh_rate: 120Hz
 MODE: 3, 640 x 480, refresh rate: 60hz
 Available modes: '3456x2234 3456x2160 2992x1934 2992x1870 2624x1696 2624x1640 2560x1600 2336x1510 2336x1460 2056x1329 2056x1285 1920x1200 1728x1117 1728x1080 1496x967 1496x935 1312x848 1312x820 1280x800 1168x755 1168x730 960x600'
 Loading vulkan instance functions
 *** Vulkan Initialization ***
 Get instance proc address. (using SDL2)
 Creating instance: vk.instance
--- Total 17 instance extensions. ---
----- Client Shutdown (Client fatal crashed: The requested version of Vulkan is not supported by the driver.) -----

RE_Shutdown( 1 )
tty]fish: Job 1, './ioquake3.arm64 +set cl_render…' terminated by signal SIGSEGV (Address boundary error)

with my tiny patch, runs just fine

pkg-config --modversion vulkan reports 1.4.304.1

@runlevel5
Copy link
Author

@jackharrhy wondering if you could re-produce the same issue with the vkQuake3 port?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants