Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ option(BUILD_SERVER "Build dedicated server" ON)
option(BUILD_CLIENT "Build client" ON)
option(BUILD_RENDERER_GL1 "Build GL1 renderer" ON)
option(BUILD_RENDERER_GL2 "Build GL2 renderer" ON)
option(BUILD_RENDERER_VULKAN "Build Vulkan renderer" OFF)
option(BUILD_GAME_LIBRARIES "Build game module libraries" ON)
option(BUILD_GAME_QVMS "Build game module qvms" ON)
option(BUILD_STANDALONE "Build binaries for standalone games" OFF)
Expand All @@ -36,6 +37,7 @@ option(USE_INTERNAL_JPEG "Use internal copy of libjpeg" ${USE_INTERNAL_LIBS})
option(USE_INTERNAL_OGG "Use internal copy of ogg" ${USE_INTERNAL_LIBS})
option(USE_INTERNAL_VORBIS "Use internal copy of vorbis" ${USE_INTERNAL_LIBS})
option(USE_INTERNAL_OPUS "Use internal copy of opus" ${USE_INTERNAL_LIBS})
option(USE_INTERNAL_VULKAN_HEADERS "Use internal copy of Vulkan headers" ${USE_INTERNAL_LIBS})

# Release build by default, set externally if you want something else
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -99,6 +101,7 @@ include(libraries/all)
include(server)
include(renderer_gl1)
include(renderer_gl2)
include(renderer_vulkan)
include(client)
include(basegame)
include(missionpack)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ For macOS,
7. Copy the resulting `ioquake3.app` in `/build/`
to your `/Applications/ioquake3` folder.

To build with the Vulkan renderer, add `-DBUILD_RENDERER_VULKAN=ON` to the
cmake command in step 5. The Vulkan renderer requires MoltenVK at runtime:

`brew install molten-vk`

See `docs/vulkan-readme.md` for more details on macOS Vulkan setup.

For Emscripten,
1. Follow the installation instructions for the Emscripten SDK including
setting up the environment with emsdk_env. https://emscripten.org/
Expand Down Expand Up @@ -163,6 +170,7 @@ The following CMake variables may be set, using `-D` on the command line.
BUILD_CLIENT - build the 'ioquake3' client binary
BUILD_RENDERER_OPENGL1 - build the opengl1 client / renderer library
BUILD_RENDERER_OPENGL2 - build the opengl2 client / renderer library
BUILD_RENDERER_VULKAN - build the vulkan client / renderer library (default OFF)
BUILD_GAME_LIBRARIES - build the game shared libraries
BUILD_GAME_QVMS - build the game qvms
BUILD_STANDALONE - build binaries suited for stand-alone games
Expand All @@ -186,6 +194,8 @@ The following CMake variables may be set, using `-D` on the command line.
USE_INTERNAL_OGG - build and link against internal ogg library
USE_INTERNAL_VORBIS - build and link against internal Vorbis library
USE_INTERNAL_OPUS - build and link against internal opus/opusfile libraries
USE_INTERNAL_VULKAN_HEADERS - use bundled Vulkan headers instead of system-provided
ones; only relevant when BUILD_RENDERER_VULKAN is ON

EMSCRIPTEN_PRELOAD_FILE - set to 1 to package 'baseq3' (BASEGAME) directory
containing pk3s and loose files as a single
Expand Down
3 changes: 2 additions & 1 deletion cmake/client.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ if(NOT USE_RENDERER_DLOPEN)
target_sources(${CLIENT_BINARY} PRIVATE
# These are never simultaneously populated
${RENDERER_GL1_BINARY_SOURCES}
${RENDERER_GL2_BINARY_SOURCES})
${RENDERER_GL2_BINARY_SOURCES}
${RENDERER_VULKAN_BINARY_SOURCES})

target_include_directories( ${CLIENT_BINARY} PRIVATE ${RENDERER_INCLUDE_DIRS})
target_compile_definitions( ${CLIENT_BINARY} PRIVATE ${RENDERER_DEFINITIONS})
Expand Down
2 changes: 1 addition & 1 deletion cmake/libraries/freetype.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if(NOT USE_FREETYPE)
return()
endif()

if(NOT BUILD_RENDERER_GL1 AND NOT BUILD_RENDERER_GL2)
if(NOT BUILD_RENDERER_GL1 AND NOT BUILD_RENDERER_GL2 AND NOT BUILD_RENDERER_VULKAN)
return()
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/libraries/jpeg.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(NOT BUILD_RENDERER_GL1 AND NOT BUILD_RENDERER_GL2)
if(NOT BUILD_RENDERER_GL1 AND NOT BUILD_RENDERER_GL2 AND NOT BUILD_RENDERER_VULKAN)
return()
endif()

Expand Down
5 changes: 5 additions & 0 deletions cmake/platforms/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function(finish_macos_app)
set_output_dirs(${RENDERER_GL2_BINARY} SUBDIRECTORY ${MACOS_APP_BINARY_DIR})
add_dependencies(${CLIENT_BINARY} ${RENDERER_GL2_BINARY})
endif()

if(BUILD_RENDERER_VULKAN)
set_output_dirs(${RENDERER_VULKAN_BINARY} SUBDIRECTORY ${MACOS_APP_BINARY_DIR})
add_dependencies(${CLIENT_BINARY} ${RENDERER_VULKAN_BINARY})
endif()
endif()
endfunction()

Expand Down
21 changes: 17 additions & 4 deletions cmake/renderer_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,23 @@ endif()

if(USE_RENDERER_DLOPEN)
list(APPEND RENDERER_DEFINITIONS USE_RENDERER_DLOPEN)
elseif(BUILD_RENDERER_GL1 AND BUILD_RENDERER_GL2)
message(FATAL_ERROR "Multiple static renderers enabled; choose one")
elseif(NOT BUILD_RENDERER_GL1 AND NOT BUILD_RENDERER_GL2)
message(FATAL_ERROR "Zero static renderers enabled; choose one")
else()
# Count how many static renderers are enabled
set(_STATIC_RENDERER_COUNT 0)
if(BUILD_RENDERER_GL1)
math(EXPR _STATIC_RENDERER_COUNT "${_STATIC_RENDERER_COUNT} + 1")
endif()
if(BUILD_RENDERER_GL2)
math(EXPR _STATIC_RENDERER_COUNT "${_STATIC_RENDERER_COUNT} + 1")
endif()
if(BUILD_RENDERER_VULKAN)
math(EXPR _STATIC_RENDERER_COUNT "${_STATIC_RENDERER_COUNT} + 1")
endif()
if(_STATIC_RENDERER_COUNT GREATER 1)
message(FATAL_ERROR "Multiple static renderers enabled; choose one")
elseif(_STATIC_RENDERER_COUNT EQUAL 0)
message(FATAL_ERROR "Zero static renderers enabled; choose one")
endif()
endif()

list(APPEND RENDERER_LIBRARIES ${COMMON_LIBRARIES})
137 changes: 137 additions & 0 deletions cmake/renderer_vulkan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
if(NOT BUILD_CLIENT OR NOT BUILD_RENDERER_VULKAN)
return()
endif()

include(utils/set_output_dirs)
include(renderer_common)

set(RENDERER_VULKAN_SOURCES
${SOURCE_DIR}/renderer_vulkan/glConfig.c
${SOURCE_DIR}/renderer_vulkan/matrix_multiplication.c
${SOURCE_DIR}/renderer_vulkan/RB_DrawNormals.c
${SOURCE_DIR}/renderer_vulkan/RB_DrawTris.c
${SOURCE_DIR}/renderer_vulkan/RB_ShowImages.c
${SOURCE_DIR}/renderer_vulkan/RB_SurfaceAnim.c
${SOURCE_DIR}/renderer_vulkan/R_DebugGraphics.c
${SOURCE_DIR}/renderer_vulkan/RE_RegisterModel.c
${SOURCE_DIR}/renderer_vulkan/R_FindShader.c
${SOURCE_DIR}/renderer_vulkan/R_ImageBMP.c
${SOURCE_DIR}/renderer_vulkan/R_ImageJPG.c
${SOURCE_DIR}/renderer_vulkan/R_ImagePCX.c
${SOURCE_DIR}/renderer_vulkan/R_ImagePNG.c
${SOURCE_DIR}/renderer_vulkan/R_ImageProcess.c
${SOURCE_DIR}/renderer_vulkan/R_ImageTGA.c
${SOURCE_DIR}/renderer_vulkan/R_LerpTag.c
${SOURCE_DIR}/renderer_vulkan/R_ListShader.c
${SOURCE_DIR}/renderer_vulkan/R_LoadImage.c
${SOURCE_DIR}/renderer_vulkan/R_LoadImage2.c
${SOURCE_DIR}/renderer_vulkan/R_LoadMD3.c
${SOURCE_DIR}/renderer_vulkan/R_LoadMDR.c
${SOURCE_DIR}/renderer_vulkan/R_ModelBounds.c
${SOURCE_DIR}/renderer_vulkan/R_Parser.c
${SOURCE_DIR}/renderer_vulkan/R_PortalPlane.c
${SOURCE_DIR}/renderer_vulkan/R_PrintMat.c
${SOURCE_DIR}/renderer_vulkan/R_StretchRaw.c
${SOURCE_DIR}/renderer_vulkan/ref_import.c
${SOURCE_DIR}/renderer_vulkan/render_export.c
${SOURCE_DIR}/renderer_vulkan/tr_animation.c
${SOURCE_DIR}/renderer_vulkan/tr_backend.c
${SOURCE_DIR}/renderer_vulkan/tr_bsp.c
${SOURCE_DIR}/renderer_vulkan/tr_cmds.c
${SOURCE_DIR}/renderer_vulkan/tr_Cull.c
${SOURCE_DIR}/renderer_vulkan/tr_curve.c
${SOURCE_DIR}/renderer_vulkan/tr_cvar.c
${SOURCE_DIR}/renderer_vulkan/tr_flares.c
${SOURCE_DIR}/renderer_vulkan/tr_fog.c
${SOURCE_DIR}/renderer_vulkan/tr_fonts.c
${SOURCE_DIR}/renderer_vulkan/tr_globals.c
${SOURCE_DIR}/renderer_vulkan/tr_image.c
${SOURCE_DIR}/renderer_vulkan/tr_init.c
${SOURCE_DIR}/renderer_vulkan/tr_light.c
${SOURCE_DIR}/renderer_vulkan/tr_main.c
${SOURCE_DIR}/renderer_vulkan/tr_marks.c
${SOURCE_DIR}/renderer_vulkan/tr_mesh.c
${SOURCE_DIR}/renderer_vulkan/tr_model.c
${SOURCE_DIR}/renderer_vulkan/tr_model_iqm.c
${SOURCE_DIR}/renderer_vulkan/tr_noise.c
${SOURCE_DIR}/renderer_vulkan/tr_scene.c
${SOURCE_DIR}/renderer_vulkan/tr_shade.c
${SOURCE_DIR}/renderer_vulkan/tr_shade_calc.c
${SOURCE_DIR}/renderer_vulkan/tr_shader.c
${SOURCE_DIR}/renderer_vulkan/tr_shadows.c
${SOURCE_DIR}/renderer_vulkan/tr_sky.c
${SOURCE_DIR}/renderer_vulkan/tr_surface.c
${SOURCE_DIR}/renderer_vulkan/tr_world.c
${SOURCE_DIR}/renderer_vulkan/vk_cmd.c
${SOURCE_DIR}/renderer_vulkan/vk_create_window_SDL.c
${SOURCE_DIR}/renderer_vulkan/vk_depth_attachment.c
${SOURCE_DIR}/renderer_vulkan/vk_frame.c
${SOURCE_DIR}/renderer_vulkan/vk_image.c
${SOURCE_DIR}/renderer_vulkan/vk_image_sampler2.c
${SOURCE_DIR}/renderer_vulkan/vk_init.c
${SOURCE_DIR}/renderer_vulkan/vk_instance.c
${SOURCE_DIR}/renderer_vulkan/vk_pipelines.c
${SOURCE_DIR}/renderer_vulkan/vk_screenshot.c
${SOURCE_DIR}/renderer_vulkan/vk_shade_geometry.c
${SOURCE_DIR}/renderer_vulkan/vk_shaders.c
${SOURCE_DIR}/renderer_vulkan/vk_swapchain.c
)

# Pre-compiled SPIR-V shaders embedded as C byte arrays
set(RENDERER_VULKAN_SHADER_SOURCES
${SOURCE_DIR}/renderer_vulkan/shaders/Compiled/multi_texture_clipping_plane_vert.c
${SOURCE_DIR}/renderer_vulkan/shaders/Compiled/multi_texture_frag.c
${SOURCE_DIR}/renderer_vulkan/shaders/Compiled/multi_texture_vert.c
${SOURCE_DIR}/renderer_vulkan/shaders/Compiled/single_texture_clipping_plane_vert.c
${SOURCE_DIR}/renderer_vulkan/shaders/Compiled/single_texture_frag.c
${SOURCE_DIR}/renderer_vulkan/shaders/Compiled/single_texture_vert.c
)

set(RENDERER_VULKAN_BASENAME renderer_vulkan)
set(RENDERER_VULKAN_BINARY ${RENDERER_VULKAN_BASENAME})

# The Vulkan renderer is self-contained: it has its own image loaders, font
# rendering, noise functions, and Com_Printf/Com_Error wrappers (in ref_import.c)
# rather than using renderercommon. It only needs puff.c for PNG decompression.
list(APPEND RENDERER_VULKAN_BINARY_SOURCES
${RENDERER_VULKAN_SOURCES}
${RENDERER_VULKAN_SHADER_SOURCES}
${SOURCE_DIR}/renderercommon/puff.c
${RENDERER_LIBRARY_SOURCES})

# Vulkan headers: use bundled copy or system-provided headers.
# The renderer loads Vulkan dynamically via SDL, so we only need the headers
# at compile time -- no link-time dependency on libvulkan.
if(USE_INTERNAL_VULKAN_HEADERS)
set(VULKAN_INCLUDE_DIRS ${SOURCE_DIR}/renderer_vulkan)
else()
find_path(VULKAN_INCLUDE_DIR vulkan/vulkan.h)
if(NOT VULKAN_INCLUDE_DIR)
message(FATAL_ERROR "System Vulkan headers not found. "
"Install vulkan-headers (e.g. 'brew install vulkan-headers' on macOS, "
"'sudo apt install libvulkan-dev' on Debian/Ubuntu, "
"'sudo dnf install vulkan-headers' on Fedora) "
"or set USE_INTERNAL_VULKAN_HEADERS=ON to use the bundled copy.")
endif()
set(VULKAN_INCLUDE_DIRS ${VULKAN_INCLUDE_DIR})
endif()

if(USE_RENDERER_DLOPEN)
# The Vulkan renderer's ref_import.c already provides Com_Printf and
# Com_Error, so we cannot include tr_subs.c from DYNAMIC_RENDERER_SOURCES.
# Include only q_shared.c and q_math.c directly.
list(APPEND RENDERER_VULKAN_BINARY_SOURCES
${SOURCE_DIR}/qcommon/q_shared.c
${SOURCE_DIR}/qcommon/q_math.c)

add_library(${RENDERER_VULKAN_BINARY} SHARED ${RENDERER_VULKAN_BINARY_SOURCES})

target_link_libraries( ${RENDERER_VULKAN_BINARY} PRIVATE ${RENDERER_LIBRARIES})
target_include_directories( ${RENDERER_VULKAN_BINARY} PRIVATE ${RENDERER_INCLUDE_DIRS}
${VULKAN_INCLUDE_DIRS})
target_compile_definitions( ${RENDERER_VULKAN_BINARY} PRIVATE ${RENDERER_DEFINITIONS})
target_compile_options( ${RENDERER_VULKAN_BINARY} PRIVATE ${RENDERER_COMPILE_OPTIONS})
target_link_options( ${RENDERER_VULKAN_BINARY} PRIVATE ${RENDERER_LINK_OPTIONS})

set_output_dirs(${RENDERER_VULKAN_BINARY})
endif()
43 changes: 43 additions & 0 deletions code/renderer_vulkan/RB_DrawNormals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "tr_backend.h"
#include "vk_shade_geometry.h"
#include "tr_globals.h"
#include "vk_pipelines.h"

/*
================
Draws vertex normals for debugging
================
*/
void RB_DrawNormals (shaderCommands_t* pTess, int numVertexes )
{
// VULKAN
// int numVertexes = tess.numVertexes;
vec4_t xyz[SHADER_MAX_VERTEXES];
memcpy(xyz, pTess->xyz, numVertexes * sizeof(vec4_t));

memset(pTess->svars.colors, tr.identityLightByte, SHADER_MAX_VERTEXES * sizeof(color4ub_t));

int i = 0;
while (i < numVertexes)
{
int count = numVertexes - i;
if (count >= SHADER_MAX_VERTEXES/2 - 1)
count = SHADER_MAX_VERTEXES/2 - 1;

int k;
for (k = 0; k < count; k++)
{
VectorCopy(xyz[i + k], pTess->xyz[2*k]);
VectorMA(xyz[i + k], 2, pTess->normal[i + k], pTess->xyz[2*k + 1]);
}
pTess->numVertexes = 2 * count;
pTess->numIndexes = 0;

vk_UploadXYZI(pTess->xyz, pTess->numVertexes, NULL, 0);

updateMVP(backEnd.viewParms.isPortal, backEnd.projection2D, getptr_modelview_matrix());
vk_shade_geometry(g_stdPipelines.normals_debug_pipeline, VK_FALSE, DEPTH_RANGE_ZERO, VK_FALSE);

i += count;
}
}
8 changes: 8 additions & 0 deletions code/renderer_vulkan/RB_DrawNormals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef RB_SHOW_NORMALS_H_
#define RB_SHOW_NORMALS_H_

struct shaderCommands_s;

void RB_DrawNormals (struct shaderCommands_s* input , int numVertexes );

#endif
30 changes: 30 additions & 0 deletions code/renderer_vulkan/RB_DrawTris.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "RB_DrawTris.h"
#include "tr_globals.h"
#include "vk_shade_geometry.h"
#include "vk_pipelines.h"
#include "tr_backend.h"
/*
================
Draws triangle outlines for debugging
================
*/
void RB_DrawTris (shaderCommands_t * pInput)
{
if (vk.features.fillModeNonSolid == VK_FALSE) {
static qboolean printed = qfalse;
if (!printed) {
ri.Printf(PRINT_WARNING, "RB_ShowTris: fillModeNonSolid not supported.\n");
printed = qtrue;
}
return;
}


updateCurDescriptor( tr.whiteImage->descriptor_set, 0);

// VULKAN

memset(pInput->svars.colors, 255, pInput->numVertexes * 4 );
VkPipeline pipeline = backEnd.viewParms.isMirror ? g_stdPipelines.tris_mirror_debug_pipeline : g_stdPipelines.tris_debug_pipeline;
vk_shade_geometry(pipeline, VK_FALSE, DEPTH_RANGE_ZERO, VK_TRUE);
}
7 changes: 7 additions & 0 deletions code/renderer_vulkan/RB_DrawTris.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef RB_DRAWTRIS_H_
#define RB_DRAWTRIS_H_
struct shaderCommands_s;

void RB_DrawTris (struct shaderCommands_s *input);

#endif
Loading