From eaadad3961819c1b9ba24f6f85d3beca33d695ac Mon Sep 17 00:00:00 2001 From: Andrew Copland Date: Mon, 14 Oct 2024 20:48:35 +0100 Subject: [PATCH 1/2] Pioneer on RaspberryPi Use OpenGL 3.1 on Pi Add PIONEER_TARGET_RASPBERRY_PI define in CmakeLists --- CMakeLists.txt | 8 ++++ CMakePresets.json | 6 +-- scripts/CMakeExperimentalPresets.json | 68 +++++++++++++++++++++++++++ src/graphics/opengl/RendererGL.cpp | 17 ++++++- 4 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 scripts/CMakeExperimentalPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 36974bcc24a..5da3d2e0027 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,14 @@ if (USE_AVX2) endif() endif(USE_AVX2) +# Default to enabling PIONEER_TARGET_RASPBERRY_PI if we're compiling on ARM64 +option(PIONEER_TARGET_RASPBERRY_PI "Compile for Raspberry Pi specifically (degrades to OpenGL 3.1)" ${PIONEER_TARGET_ARM64}) + +if (PIONEER_TARGET_RASPBERRY_PI) + # add_compile_options("-mcpu=cortex-a76" "-ffast-math") + add_compile_options("-ffast-math") +endif(PIONEER_TARGET_RASPBERRY_PI) + option(USE_LLD_LINKER "Use the LLVM lld linker instead of gcc's linker" OFF) if (CMAKE_COMPILER_IS_GNUCXX) add_compile_options( diff --git a/CMakePresets.json b/CMakePresets.json index 228711f3fdd..9fa7a056ba4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -77,8 +77,7 @@ "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": true, "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", - "CMAKE_BUILD_TYPE": "Debug", - "PROFILER_ENABLED": "1" + "CMAKE_BUILD_TYPE": "Debug" }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { @@ -138,8 +137,7 @@ "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", "CMAKE_BUILD_TYPE": "Debug", "CMAKE_C_COMPILER": "/usr/bin/clang", - "CMAKE_CXX_COMPILER": "/usr/bin/clang++", - "PROFILER_ENABLED": "1" + "CMAKE_CXX_COMPILER": "/usr/bin/clang++" }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { diff --git a/scripts/CMakeExperimentalPresets.json b/scripts/CMakeExperimentalPresets.json new file mode 100644 index 00000000000..e2291b23594 --- /dev/null +++ b/scripts/CMakeExperimentalPresets.json @@ -0,0 +1,68 @@ +{ + "version": 2, + "configurePresets": [ + { + "name": "RPi-Linux-Debug", + "displayName": "Linux RPi Debug", + "description": "Use system compiler; Profiler=no", + "binaryDir": "${sourceDir}/build/", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_BUILD_TYPE": "Debug", + "USE_SSE42": false, + "USE_AVX2": false, + "PIONEER_TARGET_RASPBERRY_PI": true + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "hostOS": [ + "Linux" + ] + } + } + }, + { + "name": "RPi-Linux-Profiler", + "displayName": "Linux RPi Profiling", + "description": "Use system compiler; Profiler=yes", + "binaryDir": "${sourceDir}/build/", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "PROFILER_ENABLED": "1", + "USE_SSE42": false, + "USE_AVX2": false, + "PIONEER_TARGET_RASPBERRY_PI": true + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "hostOS": [ + "Linux" + ] + } + } + }, + { + "name": "RPi-linux-release", + "displayName": "Linux RPi Release", + "description": "Use system compiler; Opt=yes; Profiler=no", + "binaryDir": "${sourceDir}/build/", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_BUILD_TYPE": "Release", + "USE_SSE42": false, + "USE_AVX2": false, + "PIONEER_TARGET_RASPBERRY_PI": true + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "hostOS": [ + "Linux" + ] + } + } + } + ] +} diff --git a/src/graphics/opengl/RendererGL.cpp b/src/graphics/opengl/RendererGL.cpp index 5f6a47094a8..64673b0c47b 100644 --- a/src/graphics/opengl/RendererGL.cpp +++ b/src/graphics/opengl/RendererGL.cpp @@ -49,9 +49,16 @@ namespace Graphics { Uint32 winFlags = 0; winFlags |= SDL_WINDOW_OPENGL; - // We'd like a context that implements OpenGL 3.2 to allow creation of multisampled textures + // We'd like a context that implements OpenGL 3.1 to allow creation of multisampled textures SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); +#if defined(PIONEER_TARGET_RASPBERRY_PI) + // on Arm and other platforms we attempt to create an OpenGL 3.1 context as this is what Raspberry Pi 4 & 5 currently support + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); +#else + // x86/x64 we use newer OpenGL SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); +#endif + // Request core profile as we're uninterested in old fixed-function API // also cannot initialise 3.x context on OSX with anything but CORE profile SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); @@ -194,11 +201,19 @@ namespace Graphics { if (vs.enableDebugMessages) GLDebug::Enable(); +#if defined(PIONEER_TARGET_RASPBERRY_PI) + // on Arm and other platforms we attempt to create an OpenGL 3.1 context as this is what Raspberry Pi 4 & 5 currently support + if (!glewIsSupported("GL_VERSION_3_1")) { + Error("Pioneer can not run on your device (Raspberry Pi?) as it does not appear to support OpenGL 3.1"); + } +#else + // x86/x64 we use newer OpenGL if (!glewIsSupported("GL_VERSION_3_2")) { Error( "Pioneer can not run on your graphics card as it does not appear to support OpenGL 3.2\n" "Please check to see if your GPU driver vendor has an updated driver - or that drivers are installed correctly."); } +#endif if (!glewIsSupported("GL_EXT_texture_compression_s3tc")) { if (glewIsSupported("GL_ARB_texture_compression")) { From 776b528d1bb7159f88312113e493db6cf6d3cf80 Mon Sep 17 00:00:00 2001 From: Andrew Copland Date: Mon, 14 Oct 2024 22:23:25 +0100 Subject: [PATCH 2/2] Add definition for PIONEER_TARGET_RASPBERRY_PI so it gets picked up in compilation --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5da3d2e0027..54907209efb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,8 @@ endif(USE_AVX2) option(PIONEER_TARGET_RASPBERRY_PI "Compile for Raspberry Pi specifically (degrades to OpenGL 3.1)" ${PIONEER_TARGET_ARM64}) if (PIONEER_TARGET_RASPBERRY_PI) - # add_compile_options("-mcpu=cortex-a76" "-ffast-math") + add_definitions(-DPIONEER_TARGET_RASPBERRY_PI) + # add_compile_options("-mcpu=cortex-a76") add_compile_options("-ffast-math") endif(PIONEER_TARGET_RASPBERRY_PI)