From f0ff8fbdeb0f65b75d25204d4b5aa82e253deb26 Mon Sep 17 00:00:00 2001 From: Clemens Zangl Date: Mon, 16 Dec 2024 08:48:23 +0900 Subject: [PATCH] Restructure the code for better library builds, and improvements to x64 builds --- CMakeLists.txt | 4 +- glide3x/h5/CMakeLists.txt | 63 ++++++------------------- glide3x/h5/cinit/CMakeLists.txt | 9 ++++ glide3x/h5/cinit/h3cinit.c | 3 +- glide3x/h5/glide3/src/fxglide.h | 18 +++++-- glide3x/h5/incsrc/CMakeLists.txt | 7 +++ glide3x/h5/minihwc/CMakeLists.txt | 58 +++++++++++++++++++++++ glide3x/h5/minihwc/gdebug.c | 24 +++------- glide3x/h5/{incsrc => minihwc}/gdebug.h | 0 glide3x/h5/minihwc/lin_mode.c | 3 +- glide3x/h5/minihwc/minihwc.c | 15 +++--- glide3x/h5/minihwc/minihwc.h | 1 + 12 files changed, 124 insertions(+), 81 deletions(-) create mode 100644 glide3x/h5/cinit/CMakeLists.txt create mode 100644 glide3x/h5/incsrc/CMakeLists.txt create mode 100644 glide3x/h5/minihwc/CMakeLists.txt rename glide3x/h5/{incsrc => minihwc}/gdebug.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62de028c..80b5703c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,14 +13,14 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Set the configuration for the assembler if (${BUILD_32BIT}) if(MSVC) - # Nothing to do - MSVC supports building 32bit using a different cmake invokation + # Nothing to do - MSVC supports building 32bit using a different cmake invocation else() # Set this flag for the compiler and linker set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") endif() - + # tell the assembler to generate 32 bit files if (WIN32) set(CMAKE_ASM_NASM_OBJECT_FORMAT win32) diff --git a/glide3x/h5/CMakeLists.txt b/glide3x/h5/CMakeLists.txt index 84e7cacb..545a0671 100644 --- a/glide3x/h5/CMakeLists.txt +++ b/glide3x/h5/CMakeLists.txt @@ -1,8 +1,8 @@ set (GLIDE_H5_DIR ${CMAKE_SOURCE_DIR}/glide3x/h5) -set (CINIT_DIR ${GLIDE_H5_DIR}/cinit) - -set (MINIHWC_DIR ${GLIDE_H5_DIR}/minihwc) +add_subdirectory(incsrc) +add_subdirectory(cinit) +add_subdirectory(minihwc) set(GLIDE_SOURCES ${GLIDE_H5_DIR}/glide3/src/fifo.c @@ -34,7 +34,6 @@ set(GLIDE_SOURCES ) - set(GLIDE_SOURCES ${GLIDE_SOURCES} # We always use the C routines for drawing triangles, never the asm or 3dnow ones ${GLIDE_H5_DIR}/glide3/src/gxdraw.c @@ -47,42 +46,18 @@ if(WIN32) ${GLIDE_H5_DIR}/glide3/src/gsfc.c ${GLIDE_H5_DIR}/glide3/src/winsurf.c ) - - set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES} - ${MINIHWC_DIR}/hwcio.c - ${MINIHWC_DIR}/gdebug.c - ${MINIHWC_DIR}/minihwc.c - ${MINIHWC_DIR}/win_mode.c - ) - if (${BUILD_32BIT}) - # This code is anyway only relevant for Win9x, and can be excluded for x64 builds. - set (GLIDE_ASM_SOURCES ${GLIDE_ASM_SOURCES} - ${MINIHWC_DIR}/win9x.asm - ) - endif() else() # Linux build - set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES} - ${MINIHWC_DIR}/hwcio.c - ${MINIHWC_DIR}/gdebug.c - + set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES} ${FXMISC_DIR}/fxos.c ${FXMISC_DIR}/fximg.c ) - if (${USE_DRI}) set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES} ${FXMISC_DIR}/linhwc.c ${FXMISC_DIR}/linutil.c ) - else() - set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES} - ${MINIHWC_DIR}/minihwc.c - ${MINIHWC_DIR}/lin_mode.c - ${MINIHWC_DIR}/gpio.c - ${CINIT_DIR}/h3cinit.c - ) endif() endif() @@ -93,18 +68,19 @@ add_library(${CMAKE_PROJECT_NAME} SHARED ${GLIDE_SOURCES} ${GLIDE_OUTSIDE_SOURCES} ${GLIDE_ASM_SOURCES} - ) +) target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${GLIDE_H5_DIR}/glide3/src ${GLIDE_H5_DIR}/incsrc ${GLIDE_H5_DIR}/init - ${GLIDE_H5_DIR}/minihwc - ${CINIT_DIR} ) target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC pcilib + cinit + h3 + minihwc ) if (${EMBED_TEXUS2}) @@ -133,12 +109,9 @@ target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC -DUSE_PACKET_FIFO=1 -DGLIDE_CHECK_CONTEXT - # subsystem - -DH3 - -DH4 - -DFX_GLIDE_H5_CSIM=1 - -DFX_GLIDE_NAPALM=1 - + # Do not use the ASM routines, but the C triangle setup routines instead, even when building x86 + -DGLIDE_USE_C_TRISETUP + # other -DGLIDE_PLUG -DGLIDE_SPLASH @@ -156,30 +129,22 @@ if (${BUILD_32BIT}) -DGL_X86 ) else() - target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC - -DGLIDE_BUILD_64BIT - # Do not use the ASM routines, but the C triangle setup routines instead - -DGLIDE_USE_C_TRISETUP - ) - + #target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC + # -DGLIDE_BUILD_64BIT + #) endif() if(WIN32) # Windows-only defines target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC - -D__WIN32__ -DFX_DLL_ENABLE - -DHWC_ACCESS_DDRAW=1 - -DHWC_EXT_INIT=1 -DGLIDE_ALT_TAB=1 -DBETA=1 - -DHWC_MINIVDD_HACK=1 -DWIN40COMPAT=1 -DWINXP_ALT_TAB_FIX=1 -DWINXP_SAFER_ALT_TAB_FIX=1 - -DNEED_MSGFILE_ASSIGN ) # Windows build uses DirectDraw to detect possible screen resolutions and prepare diff --git a/glide3x/h5/cinit/CMakeLists.txt b/glide3x/h5/cinit/CMakeLists.txt new file mode 100644 index 00000000..281005ca --- /dev/null +++ b/glide3x/h5/cinit/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(cinit + h3cinit.c +) +target_include_directories(cinit PUBLIC .) +target_link_libraries(cinit PUBLIC + fxmisc + h3 +) + diff --git a/glide3x/h5/cinit/h3cinit.c b/glide3x/h5/cinit/h3cinit.c index 54123278..9dab9f86 100644 --- a/glide3x/h5/cinit/h3cinit.c +++ b/glide3x/h5/cinit/h3cinit.c @@ -331,7 +331,8 @@ */ #include -#include +#include +#include #include "h3cinitdd.h" diff --git a/glide3x/h5/glide3/src/fxglide.h b/glide3x/h5/glide3/src/fxglide.h index 453cc675..5d4e0ba4 100644 --- a/glide3x/h5/glide3/src/fxglide.h +++ b/glide3x/h5/glide3/src/fxglide.h @@ -2151,7 +2151,7 @@ extern struct _GlideRoot_s GR_CDECL _GlideRoot; extern GrGCFuncs _curGCFuncs; #endif -#if defined( _MSC_VER) +#if defined( _MSC_VER) && !defined(_WIN64) /* Turn off the no return value warning for the function definition. * * NB: The function returns a value so that we can use it in places @@ -2168,6 +2168,8 @@ extern GrGCFuncs _curGCFuncs; } # define P6FENCE _grP6Fence() # pragma warning(default : 4035) +#elif defined( _MSC_VER) && defined(_WIN64) +#define P6FENCE _mm_sfence() #elif defined(macintosh) && defined(__POWERPC__) && defined(__MWERKS__) # define P6FENCE __sync() #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) @@ -2314,6 +2316,10 @@ _trisetup_noclip_valid(const void *va, const void *vb, const void *vc ); #define TRISETUP_ARGB(__cullMode) TRISETUP_NORGB(__cullMode) #if defined(_MSC_VER) +#if defined(_WIN64) +#define TRISETUP \ + (*gc->triSetupProc) +#else /* defined(_WIN64) */ #if defined(GLIDE_DEBUG) || GLIDE_USE_C_TRISETUP /* MSVC6 Debug does funny stuff, so push our parms inline */ #define TRISETUP(_a, _b, _c) \ @@ -2332,6 +2338,7 @@ _trisetup_noclip_valid(const void *va, const void *vb, const void *vc ); __asm { mov edx, gc }; \ ((FxI32 (*)(const void *va, const void *vb, const void *vc, GrGC *gc))*gc->triSetupProc)(_a, _b, _c, gc) #endif +#endif #elif defined(__POWERPC__) #define TRISETUP(_a, _b, _c) \ @@ -2762,7 +2769,12 @@ static __inline unsigned long getThreadValueFast (void) } #else /* __GNUC__ */ - +#ifdef _WIN64 +inline unsigned long +getThreadValueFast() { + return (unsigned long)TlsGetValue(_GlideRoot.tlsIndex); +} +#else // below is for 32 bit systems #pragma warning (4:4035) /* No return value */ __inline unsigned long getThreadValueFast() { @@ -2772,7 +2784,7 @@ getThreadValueFast() { __asm mov eax, DWORD PTR [eax] } } - +#endif /* _WIN64 */ #endif /* __GNUC__ */ #endif diff --git a/glide3x/h5/incsrc/CMakeLists.txt b/glide3x/h5/incsrc/CMakeLists.txt new file mode 100644 index 00000000..4a646c32 --- /dev/null +++ b/glide3x/h5/incsrc/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(h3 INTERFACE) +target_include_directories(h3 INTERFACE .) +target_link_libraries(h3 INTERFACE + fxmisc + pcilib +) + diff --git a/glide3x/h5/minihwc/CMakeLists.txt b/glide3x/h5/minihwc/CMakeLists.txt new file mode 100644 index 00000000..39a424ce --- /dev/null +++ b/glide3x/h5/minihwc/CMakeLists.txt @@ -0,0 +1,58 @@ +if(WIN32) + set(MINIHWC_OS_SPECIFIC_SOURCES + win_mode.c + ) +else () + set(MINIHWC_OS_SPECIFIC_SOURCES + lin_mode.c + linhwc.c + gpio.c + ) +endif() + +if (${BUILD_32BIT}) + # This code is anyway only relevant for Win9x, and can be excluded for x64 builds. + set (MINHWC_ASM_SOURCES ${MINHWC_ASM_SOURCES} + win9x.asm + ) +endif() + +add_library(minihwc + ${MINHWC_ASM_SOURCES} + ${MINIHWC_OS_SPECIFIC_SOURCES} + hwcio.c + gdebug.c + minihwc.c +) + +if (${BUILD_32BIT}) + # 32 bit compilation + target_compile_definitions(minihwc PUBLIC + -DGL_X86 + ) +endif() + +if(WIN32) + # Windows-only defines + target_compile_definitions(minihwc PUBLIC + -D__WIN32__ + -DHWC_ACCESS_DDRAW=1 + -DHWC_EXT_INIT=1 + -DHWC_MINIVDD_HACK=1 + ) +endif() + + +target_compile_definitions(minihwc PUBLIC + # subsystem + -DH3 + -DH4 + -DFX_GLIDE_H5_CSIM=1 + -DFX_GLIDE_NAPALM=1 + +) + + +target_include_directories(minihwc PUBLIC .) + +target_link_libraries(minihwc PUBLIC fxmisc h3 glide_common) diff --git a/glide3x/h5/minihwc/gdebug.c b/glide3x/h5/minihwc/gdebug.c index 07a99257..cd8bfe29 100644 --- a/glide3x/h5/minihwc/gdebug.c +++ b/glide3x/h5/minihwc/gdebug.c @@ -75,23 +75,15 @@ char *hwcGetenv (const char *a); /* - * For linux, we cannot statically initialize gdbg_msgfile - * to stderr. In linux, stderr is not constant. The same - * would be true of stdout for that matter. So, we initialize - * gdbg_msgfile to NULL and then initialize it to stderr - * below. There are two dfns here, one for the static dfn - * and one for the dynamic dfn. For linux they are different. - * For Windows they are the same. + * We cannot statically initialize gdbg_msgfile + * to stderr. In linux, stderr is not constant. The same + * would be true of stdout for that matter. So, we initialize + * gdbg_msgfile to NULL and then initialize it to stderr/stdout + * below. */ #if defined(__linux__) || defined(__FreeBSD__) -#define INITIAL_STATIC_GDBG_MSGFILE NULL #define INITIAL_GDBG_MSGFILE stderr #else -#ifdef NEED_MSGFILE_ASSIGN -#define INITIAL_STATIC_GDBG_MSGFILE NULL -#else -#define INITIAL_STATIC_GDBG_MSGFILE stdout -#endif #define INITIAL_GDBG_MSGFILE stdout #endif @@ -119,11 +111,11 @@ extern int __cdecl klvfprintf(FILE *stream, va_list arg ) ; #endif -static FILE *gdbg_msgfile; // GDBG info/error file +static FILE *gdbg_msgfile = NULL; // GDBG info/error file #else /* #ifdef KERNEL */ -static FILE *gdbg_msgfile = INITIAL_STATIC_GDBG_MSGFILE; // GDBG info/error file +static FILE* gdbg_msgfile = NULL; // GDBG info/error file //---------------------------------------------------------------------- @@ -187,9 +179,7 @@ void gdbg_init_gdbg_msgfile(void) static int done=0; // only execute once if (done)return; done = 1; -#ifdef NEED_MSGFILE_ASSIGN gdbg_msgfile = INITIAL_GDBG_MSGFILE; -#endif } FX_EXPORT void FX_CSTYLE diff --git a/glide3x/h5/incsrc/gdebug.h b/glide3x/h5/minihwc/gdebug.h similarity index 100% rename from glide3x/h5/incsrc/gdebug.h rename to glide3x/h5/minihwc/gdebug.h diff --git a/glide3x/h5/minihwc/lin_mode.c b/glide3x/h5/minihwc/lin_mode.c index 71c0994e..41b21212 100644 --- a/glide3x/h5/minihwc/lin_mode.c +++ b/glide3x/h5/minihwc/lin_mode.c @@ -34,8 +34,7 @@ static XDGAMode *vidModes = 0; #include #include #include "h3cinit.h" -#include "glide.h" -#include "fxglide.h" +#include "glidesys.h" #define CFG_FILE "/etc/conf.3dfx/voodoo3" diff --git a/glide3x/h5/minihwc/minihwc.c b/glide3x/h5/minihwc/minihwc.c index 75f5a719..abec95a0 100644 --- a/glide3x/h5/minihwc/minihwc.c +++ b/glide3x/h5/minihwc/minihwc.c @@ -758,7 +758,6 @@ #include #include <3dfx.h> -#include #ifdef HWC_EXT_INIT #ifdef __WIN32__ @@ -792,7 +791,7 @@ #include #include "qmodes.h" -#ifndef GLIDE_BUILD_64BIT +#ifndef _WIN64 #if 0 /* moved to asm so we don't need w9x ddk headers. */ #define IS_32 #define Not_VxD @@ -804,7 +803,7 @@ extern DWORD __cdecl CM_Get_DevNode_Key(DWORD,PCHAR,PVOID,ULONG,ULONG); #define CM_REGISTRY_HARDWARE 0 #define CM_REGISTRY_SOFTWARE 1 #endif -#endif /* GLIDE_BUILD_64BIT */ +#endif /* _WIN64 */ #endif @@ -1067,8 +1066,10 @@ static void hwc_errncpy(char *dst,const char *src) * This was yoinked from sst1/include/sst1init.h, and should be * merged back into something if we decide that we need it later. */ -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(_WIN64) #define P6FENCE {_asm xchg eax, fenceVar} +#elif defined(_MSC_VER) && defined(_WIN64) +#define P6FENCE _mm_sfence(); #elif defined(__POWERPC__) && defined(__MWERKS__) #define P6FENCE __sync() #elif defined(__DJGPP__) || (defined (__MINGW32__) && !defined(__x86_64__)) @@ -1076,7 +1077,7 @@ static void hwc_errncpy(char *dst,const char *src) #elif defined(__GNUC__) && (defined(__i386__) && !defined(__x86_64__)) #define P6FENCE __asm __volatile ("xchg %%eax, fenceVar":::"%eax") #elif defined(__GNUC__) && defined(__x86_64__) -#define P6FENCE /* TODO Clemens */ +#define P6FENCE asm volatile ("" ::: "memory"); #elif defined(__GNUC__) && defined(__ia64__) # define P6FENCE asm volatile ("mf.a" ::: "memory"); #elif defined(__GNUC__) && defined(__alpha__) @@ -1363,7 +1364,7 @@ getRegPath() } } } else { - #ifndef GLIDE_BUILD_64BIT +#ifndef _WIN64 QDEVNODE QDevNode; QIN Qin; int status = 0; @@ -1390,7 +1391,7 @@ getRegPath() strcat(strval, "\\glide"); retVal = strval; } -#endif +#endif /* _WIN64 */ } return retVal; diff --git a/glide3x/h5/minihwc/minihwc.h b/glide3x/h5/minihwc/minihwc.h index 7715df84..6f596793 100644 --- a/glide3x/h5/minihwc/minihwc.h +++ b/glide3x/h5/minihwc/minihwc.h @@ -240,6 +240,7 @@ #include <3dfx.h> #include +#include #include #include