Skip to content

Commit 5b3eb4d

Browse files
committed
Merge branch 'master' into for-0.56.0/sync
2 parents 47e12b8 + 1672200 commit 5b3eb4d

21 files changed

+392
-91
lines changed

CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ macro(AddApplicationInternal Target Executable)
827827
add_dependencies(${Target} runtime_deps)
828828
endif()
829829

830-
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_OPTIONS ${A_Flags})
830+
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_OPTIONS ${A_CompileFlags})
831+
set_property(TARGET ${Target} APPEND PROPERTY LINK_OPTIONS ${A_LinkFlags})
831832
set_property(TARGET ${Target} APPEND PROPERTY INCLUDE_DIRECTORIES ${ENGINE_DIR} ${MOUNT_DIR} ${LIB_DIR})
832833
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_DEFINITIONS ${A_Definitions})
833834
set_target_properties(${Target} PROPERTIES OUTPUT_NAME "${Executable}" PREFIX "" FOLDER "engine")
@@ -846,13 +847,14 @@ endmacro()
846847

847848
function(AddApplication)
848849
set(oneValueArgs Target ExecutableName)
849-
set(multiValueArgs ApplicationMain Definitions Flags CompileFeatures Files Libs Tests)
850+
set(multiValueArgs ApplicationMain Definitions CompileFlags LinkFlags Files Libs Tests)
850851
cmake_parse_arguments(A "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
851852

852853
# Reuse object files between the real application and the test one
853854
add_library(${A_Target}-objects OBJECT EXCLUDE_FROM_ALL ${A_Files} ${PCH_FILE})
854855
target_link_libraries(${A_Target}-objects engine-lib ${A_Libs} ${LIBS_BASE} ${CPP23SupportLibrary})
855-
set_property(TARGET ${A_Target}-objects APPEND PROPERTY COMPILE_OPTIONS ${A_Flags})
856+
set_property(TARGET ${A_Target}-objects APPEND PROPERTY COMPILE_OPTIONS ${A_CompileFlags})
857+
set_property(TARGET ${A_Target}-objects APPEND PROPERTY LINK_OPTIONS ${A_LinkFlags})
856858
set_property(TARGET ${A_Target}-objects APPEND PROPERTY INCLUDE_DIRECTORIES ${ENGINE_DIR} ${MOUNT_DIR} ${LIB_DIR})
857859
set_property(TARGET ${A_Target}-objects APPEND PROPERTY COMPILE_DEFINITIONS ${A_Definitions})
858860

@@ -893,8 +895,8 @@ if (NOT NACL)
893895
ExecutableName dummyapp
894896
Definitions USELESS_DEFINITION_TO_AVOID_PCH_ISSUE
895897
ApplicationMain ${ENGINE_DIR}/null/NullApplication.cpp
896-
Flags ${WARNINGS}
897-
Files ${COMMON_DIR}/Util.h # must be nonempty
898+
CompileFlags ${WARNINGS}
899+
Files ${DUMMYAPPLIST}
898900
Tests ${ENGINETESTLIST}
899901
)
900902
endif()
@@ -920,7 +922,8 @@ if (BUILD_CLIENT)
920922
ExecutableName ${CLIENT_EXECUTABLE_NAME}
921923
ApplicationMain ${ENGINE_DIR}/client/ClientApplication.cpp
922924
Definitions ${Definitions}
923-
Flags ${WARNINGS}
925+
CompileFlags ${WARNINGS};${OPENMP_COMPILE_FLAG}
926+
LinkFlags ${OPENMP_LINK_FLAG}
924927
Files ${WIN_RC} ${BUILDINFOLIST} ${QCOMMONLIST} ${SERVERLIST} ${CLIENTBASELIST} ${CLIENTLIST}
925928
Libs ${LIBS_CLIENT} ${LIBS_CLIENTBASE} ${LIBS_ENGINE}
926929
Tests ${CLIENTTESTLIST}
@@ -938,7 +941,7 @@ if (BUILD_SERVER)
938941
ExecutableName daemonded
939942
ApplicationMain ${ENGINE_DIR}/server/ServerApplication.cpp
940943
Definitions BUILD_ENGINE BUILD_SERVER
941-
Flags ${WARNINGS}
944+
CompileFlags ${WARNINGS}
942945
Files ${WIN_RC} ${BUILDINFOLIST} ${QCOMMONLIST} ${SERVERLIST} ${DEDSERVERLIST}
943946
Libs ${LIBS_ENGINE}
944947
Tests ${ENGINETESTLIST}
@@ -951,7 +954,7 @@ if (BUILD_TTY_CLIENT)
951954
ExecutableName daemon-tty
952955
ApplicationMain ${ENGINE_DIR}/client/ClientApplication.cpp
953956
Definitions BUILD_ENGINE BUILD_TTY_CLIENT
954-
Flags ${WARNINGS}
957+
CompileFlags ${WARNINGS}
955958
Files ${WIN_RC} ${BUILDINFOLIST} ${QCOMMONLIST} ${SERVERLIST} ${CLIENTBASELIST} ${TTYCLIENTLIST}
956959
Libs ${LIBS_CLIENTBASE} ${LIBS_ENGINE}
957960
Tests ${ENGINETESTLIST}

cmake/DaemonFlags.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ if (USE_FLOAT_EXCEPTIONS)
259259
add_definitions(-DDAEMON_USE_FLOAT_EXCEPTIONS)
260260
endif()
261261

262+
if (NOT NACL AND BUILD_CLIENT)
263+
option(USE_OPENMP "Use OpenMP to parallelize some tasks" OFF)
264+
endif()
265+
262266
if (MSVC)
263267
set_c_cxx_flag("/MP")
264268

@@ -267,6 +271,11 @@ if (MSVC)
267271
set_cxx_flag("/std:c++23preview")
268272
endif()
269273

274+
if (NOT NACL AND BUILD_CLIENT AND USE_OPENMP)
275+
# Flag checks doen't work with MSVC so we assume it's there.
276+
set(OPENMP_COMPILE_FLAG "/openmp")
277+
endif()
278+
270279
if (USE_FAST_MATH)
271280
set_c_cxx_flag("/fp:fast")
272281
else()
@@ -362,6 +371,17 @@ else()
362371
endif()
363372
endif()
364373

374+
if (NOT NACL AND BUILD_CLIENT AND USE_OPENMP)
375+
check_CXX_compiler_flag("-fopenmp" FLAG_FOPENMP)
376+
377+
if (FLAG_FOPENMP)
378+
set(OPENMP_COMPILE_FLAG "-fopenmp")
379+
set(OPENMP_LINK_FLAG "-fopenmp")
380+
else()
381+
message(WARNING "Missing OpenMP")
382+
endif()
383+
endif()
384+
365385
if (NACL AND USE_NACL_SAIGO AND SAIGO_ARCH STREQUAL "arm")
366386
# Saigo produces broken arm builds when optimizing them.
367387
# See: https://github.com/Unvanquished/Unvanquished/issues/3297

src.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ set(ENGINELIST
188188
${ENGINE_DIR}/framework/CvarSystem.h
189189
${ENGINE_DIR}/framework/LogSystem.cpp
190190
${ENGINE_DIR}/framework/LogSystem.h
191+
${ENGINE_DIR}/framework/OmpSystem.cpp
192+
${ENGINE_DIR}/framework/OmpSystem.h
191193
${ENGINE_DIR}/framework/Resource.cpp
192194
${ENGINE_DIR}/framework/Resource.h
193195
${ENGINE_DIR}/framework/System.cpp
@@ -207,6 +209,11 @@ set(ENGINELIST
207209
${ENGINE_DIR}/RefAPI.h
208210
)
209211

212+
set(OMPLIST
213+
${ENGINE_DIR}/framework/OmpSystem.cpp
214+
${ENGINE_DIR}/framework/OmpSystem.h
215+
)
216+
210217
if (WIN32)
211218
set(ENGINELIST ${ENGINELIST}
212219
${ENGINE_DIR}/sys/con_passive.cpp
@@ -271,6 +278,7 @@ set(CLIENTBASELIST
271278
)
272279

273280
set(CLIENTLIST
281+
${OMPLIST}
274282
${ENGINE_DIR}/audio/ALObjects.cpp
275283
${ENGINE_DIR}/audio/ALObjects.h
276284
${ENGINE_DIR}/audio/Audio.cpp
@@ -304,16 +312,23 @@ set(CLIENTTESTLIST ${ENGINETESTLIST}
304312
)
305313

306314
set(TTYCLIENTLIST
315+
${OMPLIST}
307316
${ENGINE_DIR}/null/NullAudio.cpp
308317
${ENGINE_DIR}/null/NullKeyboard.cpp
309318
${ENGINE_DIR}/null/null_input.cpp
310319
${ENGINE_DIR}/null/null_renderer.cpp
311320
)
312321

313322
set(DEDSERVERLIST
323+
${OMPLIST}
314324
${ENGINE_DIR}/null/NullKeyboard.cpp
315325
${ENGINE_DIR}/null/null_client.cpp
316326
${ENGINE_DIR}/null/null_input.cpp
317327
)
318328

329+
set(DUMMYAPPLIST
330+
${OMPLIST}
331+
${COMMON_DIR}/Util.h
332+
)
333+
319334
set(WIN_RC ${ENGINE_DIR}/sys/windows-resource/icon.rc)

src/engine/client/cl_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ bool CL_InitRenderer()
21362136
}
21372137
}
21382138

2139-
cls.whiteShader = re.RegisterShader( "white", RSF_NOMIP );
2139+
cls.whiteShader = re.RegisterShader( "white", RSF_NOMIP | RSF_2D );
21402140

21412141
g_console_field_width = cls.windowConfig.vidWidth / SMALLCHAR_WIDTH - 2;
21422142
g_consoleField.SetWidth(g_console_field_width);

src/engine/client/client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ struct clientStatic_t
306306

307307
// rendering info
308308
WindowConfig windowConfig;
309-
qhandle_t whiteShader;
309+
qhandle_t whiteShader; // used for console drawing
310310
fontInfo_t *consoleFont;
311311

312312
// www downloading

src/engine/framework/OmpSystem.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
===========================================================================
3+
Daemon BSD Source Code
4+
Copyright (c) 2025, Daemon Developers
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Daemon developers nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
===========================================================================
29+
*/
30+
31+
#include <algorithm>
32+
33+
#include "CvarSystem.h"
34+
#include "OmpSystem.h"
35+
36+
#if defined(_OPENMP)
37+
#include "omp.h"
38+
#endif
39+
40+
#if defined(_OPENMP)
41+
static Cvar::Range<Cvar::Cvar<int>> common_ompThreads(
42+
"common.ompThreads", "OpenMP threads", Cvar::NONE, 0, 0, 32 );
43+
#endif
44+
45+
namespace Omp {
46+
#if defined(_OPENMP)
47+
static int ompMaxThreads = 1;
48+
#endif
49+
50+
static int ompThreads = 1;
51+
52+
static void ReadMaxThreads()
53+
{
54+
#if defined(_OPENMP)
55+
ompMaxThreads = omp_get_max_threads();
56+
#endif
57+
}
58+
59+
void EnlistThreads()
60+
{
61+
#if defined(_OPENMP)
62+
omp_set_num_threads( ompThreads );
63+
#endif
64+
}
65+
66+
void SetupThreads()
67+
{
68+
#if defined(_OPENMP)
69+
if ( common_ompThreads.Get() )
70+
{
71+
ompThreads = common_ompThreads.Get();
72+
}
73+
else
74+
{
75+
switch( ompMaxThreads )
76+
{
77+
case 1:
78+
ompThreads = 1;
79+
break;
80+
case 2:
81+
case 3:
82+
ompThreads = 2;
83+
break;
84+
default:
85+
/* Using half threads than available is known to work best with:
86+
- 2 threads on Low-end 4-cores (no SMP) Ryzen 3 3200G,
87+
- 16 threads on High-end 16-cores/32-threads Ryzen Threadripper PRO 3955WX
88+
89+
It has not been tested on a system where ompMaxThreads / 2 > 16. */
90+
ompThreads = std::min( ompMaxThreads / 2, 16 );
91+
}
92+
}
93+
#endif
94+
95+
EnlistThreads();
96+
}
97+
98+
void Init()
99+
{
100+
ReadMaxThreads();
101+
SetupThreads();
102+
}
103+
104+
int GetThreads()
105+
{
106+
return ompThreads;
107+
}
108+
}

src/engine/framework/OmpSystem.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
===========================================================================
3+
Daemon BSD Source Code
4+
Copyright (c) 2025, Daemon Developers
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Daemon developers nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
===========================================================================
29+
*/
30+
31+
#ifndef COMMON_OMP_SYSTEM_H_
32+
#define COMMON_OMP_SYSTEM_H_
33+
34+
namespace Omp {
35+
void EnlistThreads();
36+
void SetupThreads();
37+
void Init();
38+
int GetThreads();
39+
};
40+
41+
#endif // COMMON_OMP_SYSTEM_H_

src/engine/framework/System.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
#include "ConsoleHistory.h"
3535
#include "CommandSystem.h"
3636
#include "LogSystem.h"
37+
#include "OmpSystem.h"
3738
#include "System.h"
3839
#include "CrashDump.h"
3940
#include "CvarSystem.h"
@@ -968,6 +969,8 @@ static void Init(int argc, char** argv)
968969
for (auto& cvar: cmdlineArgs.cvars)
969970
Cvar::SetValue(cvar.first, cvar.second);
970971

972+
Omp::Init();
973+
971974
// Load the console history
972975
Console::History::Load();
973976

src/engine/qcommon/common.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Maryland 20850 USA.
4747
#include "framework/CommandSystem.h"
4848
#include "framework/CvarSystem.h"
4949
#include "framework/LogSystem.h"
50+
#include "framework/OmpSystem.h"
5051
#include "framework/System.h"
5152
#include "sys/sys_events.h"
5253
#include <common/FileSystem.h>
@@ -783,6 +784,8 @@ static Cvar::Cvar<bool> showTraceStats("common.showTraceStats", "are physics tra
783784

784785
void Com_Frame()
785786
{
787+
Omp::SetupThreads();
788+
786789
int msec, minMsec;
787790
static int lastTime = 0;
788791
//int key;

src/engine/renderer/DetectGLVendors.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ std::string GetGLHardwareVendorName( glHardwareVendor_t hardwareVendor )
4646
"Broadcom",
4747
"Intel",
4848
"Nvidia",
49+
"Moore Threads",
4950
"OutOfRange",
5051
};
5152

@@ -71,6 +72,7 @@ std::string GetGLDriverVendorName( glDriverVendor_t driverVendor )
7172
"Intel",
7273
"Mesa",
7374
"Nvidia",
75+
"Moore Threads",
7476
"OutOfRange",
7577
};
7678

@@ -117,10 +119,12 @@ void DetectGLVendors(
117119
// Mesa Panfrost, newer Panfrost uses "Mesa" instead.
118120
{ "Panfrost", { glDriverVendor_t::MESA, glHardwareVendor_t::ARM } },
119121
// Mesa Nvidia for supported OpenGL 2+ hardware.
122+
// Mesa Amber also provides "Nouveau", but this is for unsupported pre-OpenGL 2 Nvidia.
120123
{ "nouveau", { glDriverVendor_t::MESA, glHardwareVendor_t::NVIDIA } },
121124
// Proprietary Nvidia drivers on all systems like Linux, Windows, and macOS.
122125
{ "NVIDIA Corporation", { glDriverVendor_t::NVIDIA, glHardwareVendor_t::NVIDIA } },
123-
// Mesa Amber also provides "Nouveau", but this is for unsupported pre-OpenGL 2 Nvidia.
126+
// Moore Threads drivers on Linux and Windows.
127+
{ "Moore Threads", { glDriverVendor_t::MTHREADS, glHardwareVendor_t::MTHREADS } },
124128
};
125129

126130
auto it = vendorDriverHardware.find( vendorString );

0 commit comments

Comments
 (0)