Skip to content

Commit

Permalink
CMake (GPU): change ENABLE_NVIDIA_GPU to `ENABLE_PROPRIETARY_GPU_DR…
Browse files Browse the repository at this point in the history
…IVER_API`
  • Loading branch information
CarterLi committed Jan 2, 2024
1 parent 0a1de91 commit 21353b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ cmake_dependent_option(ENABLE_PCI_MEMORY "Enable detecting GPU memory size with

option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
option(ENABLE_PROPRIETARY_GPU_DRIVER_API "Enable proprietary GPU driver API (NVML, IGCL and AGS)" ON)
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
option(ENABLE_NVIDIA_GPU "Enable Nvidia NVML" ON)

####################
# Compiler options #
Expand Down Expand Up @@ -629,8 +629,6 @@ elseif(WIN32)
src/detection/displayserver/displayserver_windows.c
src/detection/font/font_windows.c
src/detection/gpu/gpu_windows.c
src/detection/gpu/gpu_intel.c
src/detection/gpu/gpu_amd.c
src/detection/host/host_windows.c
src/detection/icons/icons_windows.c
src/detection/libc/libc_windows.cpp
Expand Down Expand Up @@ -674,9 +672,15 @@ if(ENABLE_DIRECTX_HEADERS)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_wsl.cpp)
endif()

if(ENABLE_NVIDIA_GPU AND (LINUX OR BSD OR WIN32))
message(STATUS "Enabling Nvidia NVML")
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_nvidia.c)
if(ENABLE_PROPRIETARY_GPU_DRIVER_API AND (LINUX OR BSD OR WIN32))
message(STATUS "Enabling proprietary GPU driver API")
if(LINUX OR BSD OR WIN32)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_nvidia.c)
endif()
if(WIN32)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_intel.c)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_amd.c)
endif()
endif()

include(CheckFunctionExists)
Expand All @@ -702,8 +706,8 @@ add_library(libfastfetch OBJECT
${LIBFASTFETCH_SRC}
)

if(ENABLE_NVIDIA_GPU AND (LINUX OR BSD OR WIN32))
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_NVIDIA_GPU=1)
if(ENABLE_PROPRIETARY_GPU_DRIVER_API AND (LINUX OR BSD OR WIN32))
target_compile_definitions(libfastfetch PRIVATE FF_USE_PROPRIETARY_GPU_DRIVER_API)
endif()

if(yyjson_FOUND)
Expand Down
9 changes: 9 additions & 0 deletions src/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ void ffListFeatures(void)
#ifdef FF_HAVE_DIRECTX_HEADERS
"Directx Headers\n"
#endif
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
"Proprietary GPU driver API\n"
#endif
#ifdef FF_USE_SYSTEM_YYJSON
"System yyjson\n"
#endif
#ifdef FF_USE_PCI_MEMORY
"PCI memory\n"
#endif
""
, stdout);
}
9 changes: 6 additions & 3 deletions src/detection/gpu/gpu_linux.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "detection/gpu/gpu.h"
#include "detection/gpu/gpu_driver_specific.h"
#include "detection/vulkan/vulkan.h"

#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
#include "detection/gpu/gpu_driver_specific.h"
#endif

#ifdef FF_HAVE_LIBPCI
#include "common/io/io.h"
#include "common/library.h"
Expand Down Expand Up @@ -245,7 +248,7 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;

#ifdef FF_HAVE_NVIDIA_GPU
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->driverSpecific))
{
ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) {
Expand All @@ -267,7 +270,7 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET)
gpu->type = gpu->dedicated.total > (uint64_t)1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
}
#endif
#endif // FF_USE_PROPRIETARY_GPU_DRIVER_API

#ifdef __linux__
if(options->temp && gpu->temperature != gpu->temperature)
Expand Down
9 changes: 8 additions & 1 deletion src/detection/gpu/gpu_windows.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#include "gpu.h"
#include "detection/gpu/gpu_driver_specific.h"
#include "util/windows/unicode.h"
#include "util/windows/registry.h"

#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
#include "detection/gpu/gpu_driver_specific.h"
#endif

#include <inttypes.h>

static int isGpuNameEqual(const FFGPUResult* gpu, const FFstrbuf* name)
{
return ffStrbufEqual(&gpu->name, name);
}

#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
static inline bool getDriverSpecificDetectionFn(const char* vendor, __typeof__(&ffDetectNvidiaGpuInfo)* pDetectFn, const char** pDllName)
{
if (vendor == FF_GPU_VENDOR_NAME_NVIDIA)
Expand Down Expand Up @@ -44,6 +48,7 @@ static inline bool getDriverSpecificDetectionFn(const char* vendor, __typeof__(&

return true;
}
#endif // FF_USE_PROPRIETARY_GPU_DRIVER_API

const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus)
{
Expand Down Expand Up @@ -139,6 +144,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
}
}

#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
__typeof__(&ffDetectNvidiaGpuInfo) detectFn;
const char* dllName;

Expand Down Expand Up @@ -168,6 +174,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
);
}
}
#endif // FF_USE_PROPRIETARY_GPU_DRIVER_API
}

return NULL;
Expand Down

2 comments on commit 21353b8

@ceamac
Copy link
Contributor

@ceamac ceamac commented on 21353b8 Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one more call to ffDetectNvidiaGpuInfo in gpu_wsl.cpp, it should be guarded with #ifdef too. Sorry I didn't notice it yesterday.

@CarterLi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes

Please sign in to comment.