| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/info/common/gpuinfoopengl.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "gpuinfoopengl.h"cxx . . $ `<file>/src/core/info/common/gpuinfoopengl.h`/ |
| 5 | |
| 6 | #include "../infoproviderregistry.h"cxx . . $ `<file>/src/core/info/infoproviderregistry.h`/ |
| 7 | #include <QProcess> |
| 8 | #include <QString> |
| 9 | #include <QStringList> |
| 10 | #include <spdlog/spdlog.h> |
| 11 | #include <utility> |
| 12 | |
| 13 | class GPUInfoOpenGLDataSourcecxx . . $ GPUInfoOpenGLDataSource# : public IDataSourcecxx . . $ IDataSource#<stdcxx . . $ std/::stringcxx . . $ std/string#, int const> |
| 14 | { |
| 15 | public: |
| 16 | stdcxx . . $ std/::stringcxx . . $ std/string# sourcecxx . . $ GPUInfoOpenGLDataSource#source(219584694fe2b248).() const override |
| 17 | { |
| 18 | return "glxinfo"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 19 | } |
| 20 | |
| 21 | bool readcxx . . $ GPUInfoOpenGLDataSource#read(5e9573b50e400c4e).(stdcxx . . $ std/::stringcxx . . $ std/string# &data, int const &gpuIndex) override |
| 22 | { |
| 23 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# libGLErrorStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).( |
| 24 | "libGL error: failed to load driver"); |
| 25 | |
| 26 | auto env = QProcessEnvironmentcxx . . $ QProcessEnvironment#::systemEnvironmentcxx . . $ QProcessEnvironment#systemEnvironment(f0e8295e01d32d01).(); |
| 27 | env.insertcxx . . $ QProcessEnvironment#insert(c1427772cd1877b0).("LC_ALL"cxx . . $ QString#QString(85c52e162fed56f9)., "C"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 28 | env.insertcxx . . $ QProcessEnvironment#insert(c1427772cd1877b0).("DRI_PRIME"cxx . . $ QString#QString(85c52e162fed56f9)., QStringcxx . . $ QString#::numbercxx . . $ QString#number(f4fd9db251ca774b).(gpuIndex)); |
| 29 | |
| 30 | QProcesscxx . . $ QProcess# cmdcxx . . $ QProcess#QProcess(749de1b6ae65bddd).; |
| 31 | cmd.setProcessChannelModecxx . . $ QProcess#setProcessChannelMode(325e95cd0c77e646).(QProcesscxx . . $ QProcess#::MergedChannelscxx . . $ QProcess#MergedChannels.); |
| 32 | cmd.setProcessEnvironmentcxx . . $ QProcess#setProcessEnvironment(6d5c9e1d6435e06a).(env); |
| 33 | cmd.startcxx . . $ QProcess#start(df994297e51edc6b).(sourcecxx . . $ QString#QString(85c52e162fed56f9).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), QStringListcxx . . $ QStringList#("-B")); |
| 34 | |
| 35 | if (cmd.waitForFinishedcxx . . $ QProcess#waitForFinished(83c267b20bac841a).()) { |
| 36 | auto output = cmd.readAllStandardOutputcxx . . $ QProcess#readAllStandardOutput(b3c286cec66e09f4).().toStdStringcxx . . $ QByteArray#toStdString(219584694fe2b248).(); |
| 37 | |
| 38 | auto libGLErrorPos = output.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(libGLErrorStr); |
| 39 | if (libGLErrorPos == stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) { |
| 40 | data =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). output; |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | // extract libGL error |
| 45 | auto endLinePos = output.findcxx . . $ std/__cxx11/basic_string#find(5ed402c22c298042).("\n", libGLErrorPos); |
| 46 | auto libGLError = output.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).( |
| 47 | libGLErrorPos + libGLErrorStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).(), |
| 48 | endLinePos - libGLErrorPos - libGLErrorStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).()); |
| 49 | |
| 50 | SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("glxinfo command failed for GPU{} with error '{}{}'", |
| 51 | gpuIndex, libGLErrorStr.data(), libGLError); |
| 52 | } |
| 53 | |
| 54 | SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("glxinfo command failed"); |
| 55 | return false; |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#::GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#GPUInfoOpenGL(24580567c8001d89).( |
| 60 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IDataSourcecxx . . $ IDataSource#<stdcxx . . $ std/::stringcxx . . $ std/string#, int const>> &&dataSource) noexcept |
| 61 | : dataSource_cxx . . $ GPUInfoOpenGL#dataSource_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(dataSource)) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> |
| 66 | GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#::provideInfocxx . . $ GPUInfoOpenGL#provideInfo(5b65f7e996e13d80).(Vendorcxx . . $ Vendor#, int gpuIndex, IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# const &, |
| 67 | IHWIDTranslatorcxx . . $ IHWIDTranslator# const &) const |
| 68 | { |
| 69 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> infocxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 70 | |
| 71 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# queryRendererStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).("GLX_MESA_query_renderer"); |
| 72 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# coreVerStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).("Max core profile version: "); |
| 73 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# compatVerStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).( |
| 74 | "Max compat profile version: "); |
| 75 | |
| 76 | stdcxx . . $ std/::stringcxx . . $ std/string# datacxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 77 | if (dataSource_cxx . . $ GPUInfoOpenGL#dataSource_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).readcxx . . $ IDataSource#read(ad81cd1bcc32f58b).(data, gpuIndex)) { |
| 78 | auto queryRendererPos = data.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(queryRendererStr); |
| 79 | if (queryRendererPos != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) { |
| 80 | |
| 81 | auto coreVer = findItemcxx . . $ GPUInfoOpenGL#findItem(48b69d099a50eb46).(data, coreVerStrcxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02)., queryRendererPos); |
| 82 | if (!coreVer.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 83 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#::Keyscxx . . $ GPUInfoOpenGL#Keys#::coreVersioncxx . . $ GPUInfoOpenGL#Keys#coreVersion., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(coreVer)); |
| 84 | else |
| 85 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot find '{}' in glxinfo output", coreVerStr.data()); |
| 86 | |
| 87 | auto compatVer = findItemcxx . . $ GPUInfoOpenGL#findItem(48b69d099a50eb46).(data, compatVerStrcxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02)., queryRendererPos); |
| 88 | if (!compatVer.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 89 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#::Keyscxx . . $ GPUInfoOpenGL#Keys#::compatVersioncxx . . $ GPUInfoOpenGL#Keys#compatVersion., |
| 90 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(compatVer)); |
| 91 | else |
| 92 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot find '{}' in glxinfo output", compatVerStr.data()); |
| 93 | } |
| 94 | else |
| 95 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot find '{}' in glxinfo output", queryRendererStr.data()); |
| 96 | } |
| 97 | |
| 98 | return infocxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 99 | } |
| 100 | |
| 101 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> |
| 102 | GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#::provideCapabilitiescxx . . $ GPUInfoOpenGL#provideCapabilities(da28437f5803dad2).(Vendorcxx . . $ Vendor#, int, IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# const &) const |
| 103 | { |
| 104 | return {cxx . . $ std/vector#vector(49f6e7a06ebc5aa8).}; |
| 105 | } |
| 106 | |
| 107 | stdcxx . . $ std/::stringcxx . . $ std/string# GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#::findItemcxx . . $ GPUInfoOpenGL#findItem(48b69d099a50eb46).(stdcxx . . $ std/::stringcxx . . $ std/string# const &src, |
| 108 | stdcxx . . $ std/::string_viewcxx . . $ std/string_view# itemStr, size_t pos) const |
| 109 | { |
| 110 | auto itemPos = src.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(itemStr, pos); |
| 111 | if (itemPos != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) { |
| 112 | |
| 113 | auto endLinePos = src.findcxx . . $ std/__cxx11/basic_string#find(5ed402c22c298042).("\n", itemPos); |
| 114 | auto item = src.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(itemPos + itemStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).(), |
| 115 | endLinePos - itemPos - itemStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).()); |
| 116 | return itemcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 117 | } |
| 118 | |
| 119 | return stdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).::stringcxx . . $ std/string#{}; |
| 120 | } |
| 121 | |
| 122 | bool GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#::registered_cxx . . $ GPUInfoOpenGL#registered_. = InfoProviderRegistrycxx . . $ InfoProviderRegistry#::addcxx . . $ InfoProviderRegistry#add(2c04d579dc484cde).( |
| 123 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUInfoOpenGLcxx . . $ GPUInfoOpenGL#>(stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUInfoOpenGLDataSourcecxx . . $ GPUInfoOpenGLDataSource#>())); |