Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize Mesa library #3414

Merged
merged 16 commits into from Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .appveyor.yml
Expand Up @@ -43,6 +43,8 @@ environment:

before_build:
- ps: if($env:qtbin.contains('_64')) { $env:BITS=64 } else { $env:BITS=32 }
- ps: if($env:qtbin.contains('_64')) { $env:PKGARCH="x64" } else { $env:PKGARCH="x86" }
- ps: if($env:qtbin.contains('_64')) { $env:cmake_args:="-A x64" }
- ps: if($env:qtver.contains('6.')) { $env:SSL="OpenSSL-" } else { $env:SSL="OpenSSL-1-" }
- set PUBLISH_BINARY=false
- set USE_EXT_LIBGLES=false
Expand Down Expand Up @@ -80,6 +82,7 @@ after_test:
- if [%PUBLISH_BINARY%]==[true] cmake --build c:\stellarium\build-%qtver%-%qtbin%\ --config %configuration% --target install
- if [%USE_EXT_LIBGLES%]==[true] appveyor DownloadFile https://github.com/Stellarium/stellarium-data/releases/download/qt-5.6/libGLES-Win%BITS%.zip -FileName c:\stellarium\build-%qtver%-%qtbin%\libGLES.zip
- if [%USE_EXT_LIBGLES%]==[true] 7z e c:\stellarium\build-%qtver%-%qtbin%\libGLES.zip -aoa -oc:\stellarium-%qtver%-%qtbin%\qtstuff
- if [%PUBLISH_BINARY%]==[true] appveyor DownloadFile https://github.com/Stellarium/stellarium-data/releases/download/mesa-win-20.1.8/opengl32sw-%PKGARCH%.dll -FileName c:\stellarium-%qtver%-%qtbin%\qtstuff\opengl32sw.dll
- if [%PUBLISH_BINARY%]==[true] cmake --build c:\stellarium\build-%qtver%-%qtbin%\ --config %configuration% --target stellarium-installer
- if [%USE_EXTRA_EXE%]==[true] cmake --build c:\stellarium\build-%qtver%-%qtbin%\ --config %configuration% --target stellarium-patch-installer
- if [%PUBLISH_BINARY%]==[true] cd c:\stellarium\installers
Expand Down
37 changes: 34 additions & 3 deletions guide/ch_advanced_use.tex
Expand Up @@ -453,6 +453,38 @@ \subsubsection{NMEA Device}
hardware and other settings, e.g. real GPS sensor or network and WiFi
detection.\footnote{\url{https://support.microsoft.com/en-us/windows/windows-location-service-and-privacy-3a8eee0a-5b0b-dc07-eede-2a5ca1c49088}}


\subsection{Modernized MESA3D libraries (Software OpenGL on Windows)}
\label{sec:ExtraData:Mesa}

Stellarium uses hardware-accelerated OpenGL for rendering. On very old Windows systems without dedicated graphics hardware,
or in special circumstances like virtual machines, hardware accelerated graphics may not be available,
and the \program{Mesa3D} software implementation of OpenGL is used. This can also be forced by the command-line option \command{-\/-mesa-mode}.
Rendering the graphics without hardware acceleration is of course much slower than accelerated graphics, but it's surely better than nothing.

Qt's default Mesa library (Mesa 11) provides support for OpenGL~3.0 only. This prevents users of all versions from applying dithering in Mesa mode.
Also the \program{ShowMySky} skylight model (see section~\ref{sec:skylight:ShowMySky}) is then not available.

We have replaced\newFeature{23.4} this by a version of Mesa~20 compiled by Federico Dossena\footnote{\url{https://fdossena.com/?p=mesa/index.frag}} which appears to be even a bit faster.

The \program{Mesa3D} project \footnote{\url{https://www.mesa3d.org/}} meanwhile (2023) provides at least OpenGL~4.5.
If you wish to use more ``up to date'' precompiled binaries and have Administrator privileges on your Windows system,
you can replace this library using the following steps to install inofficial builds\footnote{\url{https://github.com/pal1000/mesa-dist-win/}}.
Note however that after this upgrade, the program runs with considerably ($\approx$35\%?) lower framerate.
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't you say this improves frame rate rather than degrades?

Copy link
Member Author

@gzotti gzotti Sep 16, 2023

Choose a reason for hiding this comment

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

This branch should

  1. replace Qt's Mesa 11 by fdossena's Mesa 20. Unconditionally.
  2. For "purists" who don't like taking Mesa DLLs from other sources than github, describe a path to move to a "more official" Mesa build, which however runs considerably slower. Just like giving instructions to run nouveau drivers for OS purists.

(2) is done. The next steps will hopefully bring the Mesa20 DLL to where it belongs.

Copy link
Contributor

@10110111 10110111 Sep 16, 2023

Choose a reason for hiding this comment

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

(2) makes zero sense, because pal1000's builds are not more official than fdossena's ones. Both provide instructions to reproduce the builds, so you can make your own binaries if you want. And GitHub is not an authority for Mesa in any way, since Mesa has long moved to GitLab@FreeDekstop.

You must decide whether this is really beneficial in your situation. The libraries don't provide any additional graphics features that Stellarium makes use of.

\begin{itemize}
\item Download the latest ``release-msvc'' package as you need from \url{https://github.com/pal1000/mesa-dist-win/releases} and unpack it somewhere.
Copy link
Contributor

Choose a reason for hiding this comment

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

The instructions seem out of date, referring to the previous source of packages.

\item Copy \file{(x86|x64)/{libglapi.dll,libgallium\_wgl.dll,opengl32.dll}} to where the executable \file{stellarium.exe} is.
\item Delete the existing \file{opengl32sw.dll}
\item Rename the just-copied \file{opengl32.dll} to \file{opengl32sw.dll}.
\end{itemize}

\noindent Now running Stellarium in Mesa mode (with link from program menu or command line) should report to provide OpenGL~4.5.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Command Line Options}
%\label{command-line-options}
\label{sec:CommandLineOptions}
Expand All @@ -474,7 +506,7 @@ \chapter{Command Line Options}

For example, using the option \texttt{-c\ my\_config.ini} would resolve to the file
\file{\textless{}user\ directory\textgreater{}/my\_config.ini} whereas
\file{-c\ ./my\_config.ini} can be used to explicitly say the file
\file{-c\ ./my\_config.ini} can be used to explicitly point to the file
\file{my\_config.ini} in the current working directory.\\
-\/-log-file or -l & log file name & Specify the log file name. The default value is \file{log.txt}.

Expand All @@ -484,7 +516,7 @@ \chapter{Command Line Options}
Note: The old configuration file will be overwritten. \\\midrule
-\/-user-dir & path & Specify the user data directory. \\
-\/-screenshot-dir & path & Specify the directory to which screenshots will be saved. \\\midrule
-\/-full-screen & yes or no & Over-rides the full screen setting in the config file. \\\midrule
-\/-full-screen & yes or no & Overrides the full screen setting in the config file. \\\midrule
-\/-home-planet & planet & Specify observer planet (English name). \\
-\/-longitude & longitude & Specify latitude, e.g. +53d58'16.65" \\
-\/-latitude & latitude & Specify longitude, e.g. -1d4'27.48" \\
Expand All @@ -509,7 +541,6 @@ \chapter{Command Line Options}
-\/-angle-d3d11 & {[}none{]} & Force use Direct3D 11 for ANGLE OpenGL ES2 rendering engine.\footnotemark[1]\footnotemark[3]\\
-\/-angle-warp & {[}none{]} & Force use the Direct3D 11 software rasterizer for ANGLE OpenGL ES2 rendering engine.\footnotemark[1]\footnotemark[3]\\
-\/-mesa-mode or -m & {[}none{]} & Use MESA as software OpenGL rendering engine.\footnotemark[1]\\
-\/-safe-mode or -s & {[}none{]} & Synonymous to -\/-mesa-mode.\footnotemark[1]\\
-\/-single-buffer & {[}none{]} & Use single-buffering. This reportedly avoids screen blanking problems with some Intel GPUs. \\
-\/-opengl-compat or -C & {[}none{]} & Request OpenGL 3.3 Compatibility Profile. Might fix graphics problems in some driver configurations.\\
\bottomrule
Expand Down
17 changes: 10 additions & 7 deletions src/CLIProcessor.cpp
Expand Up @@ -36,12 +36,7 @@
void CLIProcessor::parseCLIArgsPreQApp(const QStringList argList)
{
#ifdef Q_OS_WIN
if (argsGetOption(argList, "-s", "--safe-mode"))
{
qDebug() << "DEPRECATION NOTE: --safe-mode given on command line. Use --mesa-mode instead!";
qputenv("QT_OPENGL", "software");
}

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
if (argsGetOption(argList, "-a", "--angle-mode"))
qputenv("QT_OPENGL", "angle");

Expand All @@ -60,8 +55,15 @@ void CLIProcessor::parseCLIArgsPreQApp(const QStringList argList)
qputenv("QT_OPENGL", "angle");
qputenv("QT_ANGLE_PLATFORM", "warp");
}
#endif
if (argsGetOption(argList, "-m", "--mesa-mode"))
{
qputenv("QT_OPENGL", "software");
qputenv("MESA_GL_VERSION_OVERRIDE", "3.3"); // The Mesa 20.1.8 library reports providing 3.1 only. This does the trick for us.
// These prepare using current Mesa3D libraries, should the user install them. Else the vars are harmless.
qputenv("QT_OPENGL_DLL", "opengl32sw.dll");
qputenv("GALLIUM_DRIVER", "llvmpipe");
}
#endif
// Override user dir. This must be made via environment variable, else an empty user dir is created before resetting (GH:#3079)
try
Expand Down Expand Up @@ -131,12 +133,13 @@ void CLIProcessor::parseCLIArgsPreConfig(const QStringList& argList)
<< "--multires-image : With filename / URL argument, specify a\n"
<< " multi-resolution image to load\n"
#ifdef Q_OS_WIN
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
<< "--angle-mode (or -a) : Use ANGLE as OpenGL ES2 rendering engine (autodetect driver)\n"
<< "--angle-d3d9 (or -9) : Force use Direct3D 9 for ANGLE OpenGL ES2 rendering engine\n"
<< "--angle-d3d11 : Force use Direct3D 11 for ANGLE OpenGL ES2 rendering engine\n"
<< "--angle-warp : Force use the Direct3D 11 software rasterizer for ANGLE OpenGL ES2 rendering engine\n"
#endif
<< "--mesa-mode (or -m) : Use MESA as software OpenGL rendering engine\n"
<< "--safe-mode (or -s) : DEPRECATED! Synonymous to --mesa-mode \n"
#ifdef ENABLE_SPOUT
<< "--spout (or -S) <sky|all> : Act as SPOUT sender (Sky only/including GUI)\n"
<< "--spout-name <name> : Set particular name for SPOUT sender.\n"
Expand Down
22 changes: 20 additions & 2 deletions src/core/StelTexture.cpp
Expand Up @@ -134,9 +134,27 @@ StelTexture::GLData StelTexture::loadFromPath(const QString &path, const int dec
{
try
{
return imageToGLData(QImage(path), decimateBy);
QImageReader imgReader(path);
QImage img = imgReader.read();
if (img.isNull())
{
QImageReader::ImageReaderError error=imgReader.error();
qCritical() << "Error reading image file " << path << ":" << imgReader.errorString();

if (error==QImageReader::InvalidDataError)
qCritical() << "This may also indicate an out-of-memory error.";
}
return imageToGLData(img, decimateBy);
}
catch(std::bad_alloc& ex) //this catches out-of-memory errors from file conversion
{
qCritical()<<"Failed loading texture from"<<path<<"error:"<<ex.what();
qCritical() << "Try higher value for config.ini:[astro]/nebula_texture_decimation";
GLData ret;
ret.loaderError = ex.what();
return ret;
}
catch(std::exception& ex) //this catches out-of-memory errors from file conversion
catch(std::exception& ex) //this catches other errors from file conversion
{
qCritical()<<"Failed loading texture from"<<path<<"error:"<<ex.what();
GLData ret;
Expand Down
6 changes: 6 additions & 0 deletions src/core/modules/Landscape.cpp
Expand Up @@ -550,6 +550,8 @@ void LandscapeOldStyle::load(const QSettings& landscapeIni, const QString& lands
// if that query is not going to be prevented by the polygon that already has been loaded at that point...
if ( (!horizonPolygon) && calibrated ) { // for uncalibrated landscapes the texture is currently never queried, so no need to store.
QImage *image = new QImage(texturePath);
if (image->isNull())
qWarning() << "Null image (out of memory!) in Landscape!";
sidesImages.append(image); // indices identical to those in sideTexs
memorySize+=(image->sizeInBytes());
}
Expand Down Expand Up @@ -1567,6 +1569,8 @@ void LandscapeFisheye::create(const QString _name, float _texturefov, const QStr
{
mapImage = new QImage(_maptex);
memorySize+=(mapImage->sizeInBytes());
if (mapImage->isNull())
qWarning() << "Null image in Landscape" << _name << "- cannot load" << _maptex;
}
mapTex = texMan.createTexture(_maptex, StelTexture::StelTextureParams(true));
memorySize+=mapTex->getGlSize();
Expand Down Expand Up @@ -1852,6 +1856,8 @@ void LandscapeSpherical::create(const QString _name, const QString& _maptex, con
{
mapImage = new QImage(_maptex);
memorySize+=(mapImage->sizeInBytes());
if (mapImage->isNull())
qWarning() << "Null image in Landscape" << _name << "- cannot load" << _maptex;
}

auto& gl = *QOpenGLContext::currentContext()->functions();
Expand Down