| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/info/common/gpuinfovulkan.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "gpuinfovulkan.h"cxx . . $ `<file>/src/core/info/common/gpuinfovulkan.h`/ |
| 5 | |
| 6 | #include "../infoproviderregistry.h"cxx . . $ `<file>/src/core/info/infoproviderregistry.h`/ |
| 7 | #include <QProcess> |
| 8 | #include <QStringList> |
| 9 | #include <format> |
| 10 | #include <spdlog/spdlog.h> |
| 11 | #include <utility> |
| 12 | |
| 13 | class GPUInfoVulkanDataSourcecxx . . $ GPUInfoVulkanDataSource# : public IDataSourcecxx . . $ IDataSource#<stdcxx . . $ std/::stringcxx . . $ std/string#> |
| 14 | { |
| 15 | public: |
| 16 | stdcxx . . $ std/::stringcxx . . $ std/string# sourcecxx . . $ GPUInfoVulkanDataSource#source(219584694fe2b248).() const override |
| 17 | { |
| 18 | return "vulkaninfo"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 19 | } |
| 20 | |
| 21 | bool readcxx . . $ GPUInfoVulkanDataSource#read(f38201682fc79d0a).(stdcxx . . $ std/::stringcxx . . $ std/string# &data) override |
| 22 | { |
| 23 | auto env = QProcessEnvironmentcxx . . $ QProcessEnvironment#::systemEnvironmentcxx . . $ QProcessEnvironment#systemEnvironment(f0e8295e01d32d01).(); |
| 24 | env.insertcxx . . $ QProcessEnvironment#insert(c1427772cd1877b0).("LC_ALL"cxx . . $ QString#QString(85c52e162fed56f9)., "C"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 25 | |
| 26 | QProcesscxx . . $ QProcess# cmdcxx . . $ QProcess#QProcess(749de1b6ae65bddd).; |
| 27 | cmd.setProcessChannelModecxx . . $ QProcess#setProcessChannelMode(325e95cd0c77e646).(QProcesscxx . . $ QProcess#::MergedChannelscxx . . $ QProcess#MergedChannels.); |
| 28 | cmd.setProcessEnvironmentcxx . . $ QProcess#setProcessEnvironment(6d5c9e1d6435e06a).(env); |
| 29 | cmd.startcxx . . $ QProcess#start(df994297e51edc6b).(sourcecxx . . $ QString#QString(85c52e162fed56f9).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), QStringListcxx . . $ QList#QList(ced63f7c635d850d).()); |
| 30 | |
| 31 | if (cmd.waitForFinishedcxx . . $ QProcess#waitForFinished(83c267b20bac841a).()) { |
| 32 | data =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). cmd.readAllStandardOutputcxx . . $ QProcess#readAllStandardOutput(b3c286cec66e09f4).().toStdStringcxx . . $ QByteArray#toStdString(219584694fe2b248).(); |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("vulkaninfo command failed"); |
| 37 | return false; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | GPUInfoVulkancxx . . $ GPUInfoVulkan#::GPUInfoVulkancxx . . $ GPUInfoVulkan#GPUInfoVulkan(d9a0eba8acfc8272).( |
| 42 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IDataSourcecxx . . $ IDataSource#<stdcxx . . $ std/::stringcxx . . $ std/string#>> &&dataSource) noexcept |
| 43 | : dataSource_cxx . . $ GPUInfoVulkan#dataSource_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(dataSource)) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> |
| 48 | GPUInfoVulkancxx . . $ GPUInfoVulkan#::provideInfocxx . . $ GPUInfoVulkan#provideInfo(5b65f7e996e13d80).(Vendorcxx . . $ Vendor#, int gpuIndex, IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# const &, |
| 49 | IHWIDTranslatorcxx . . $ IHWIDTranslator# const &) const |
| 50 | { |
| 51 | 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).; |
| 52 | |
| 53 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# devicePropStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).("VkPhysicalDeviceProperties"); |
| 54 | |
| 55 | stdcxx . . $ std/::stringcxx . . $ std/string# datacxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 56 | if (dataSource_cxx . . $ GPUInfoVulkan#dataSource_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).readcxx . . $ IDataSource#read(ad81cd1bcc32f58b).(data)) { |
| 57 | int currentGPUIndex = 0; |
| 58 | auto devicePropStrPos = data.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(devicePropStr); |
| 59 | while (devicePropStrPos != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) { |
| 60 | |
| 61 | if (currentGPUIndex == gpuIndex) { |
| 62 | auto apiVersion = parseApiVersioncxx . . $ GPUInfoVulkan#parseApiVersion(5110f5943e06e162).(data, devicePropStrPos); |
| 63 | if (!apiVersion.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 64 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(GPUInfoVulkancxx . . $ GPUInfoVulkan#::Keyscxx . . $ GPUInfoVulkan#Keys#::apiVersioncxx . . $ GPUInfoVulkan#Keys#apiVersion., |
| 65 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(apiVersion)); |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | devicePropStrPos = data.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(devicePropStr, |
| 70 | devicePropStrPos + devicePropStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).()); |
| 71 | currentGPUIndex++; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return infocxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 76 | } |
| 77 | |
| 78 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> |
| 79 | GPUInfoVulkancxx . . $ GPUInfoVulkan#::provideCapabilitiescxx . . $ GPUInfoVulkan#provideCapabilities(da28437f5803dad2).(Vendorcxx . . $ Vendor#, int, IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# const &) const |
| 80 | { |
| 81 | return {cxx . . $ std/vector#vector(49f6e7a06ebc5aa8).}; |
| 82 | } |
| 83 | |
| 84 | stdcxx . . $ std/::stringcxx . . $ std/string# GPUInfoVulkancxx . . $ GPUInfoVulkan#::parseApiVersioncxx . . $ GPUInfoVulkan#parseApiVersion(5110f5943e06e162).(stdcxx . . $ std/::stringcxx . . $ std/string# const &src, |
| 85 | size_tcxx . . $ size_t# pos) const |
| 86 | { |
| 87 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# apiVerStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).("apiVersion"); |
| 88 | |
| 89 | auto apiVerPos = src.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(apiVerStr, pos); |
| 90 | if (apiVerPos != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) { |
| 91 | |
| 92 | auto startPos = src.find_first_not_ofcxx . . $ std/__cxx11/basic_string#find_first_not_of(5ed402c22c298042).("= ", apiVerPos + apiVerStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).()); |
| 93 | |
| 94 | // version inside parentheses is preferred |
| 95 | auto openParenPos = src.findcxx . . $ std/__cxx11/basic_string#find(5ed402c22c298042).("(", startPos); |
| 96 | if (openParenPos != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) { |
| 97 | auto endPos = src.findcxx . . $ std/__cxx11/basic_string#find(5ed402c22c298042).(")", openParenPos); |
| 98 | auto version = src.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(openParenPos + 1, endPos - openParenPos - 1); |
| 99 | |
| 100 | return versioncxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 101 | } |
| 102 | |
| 103 | // fallback version |
| 104 | auto endPos = src.findcxx . . $ std/__cxx11/basic_string#find(5ed402c22c298042).("\n", startPos); |
| 105 | auto version = src.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(startPos, endPos - startPos); |
| 106 | |
| 107 | return versioncxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 108 | } |
| 109 | else |
| 110 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot find '{}' in vulkaninfo output", apiVerStr.data()); |
| 111 | |
| 112 | return stdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).::stringcxx . . $ std/string#{}; |
| 113 | } |
| 114 | |
| 115 | bool GPUInfoVulkancxx . . $ GPUInfoVulkan#::registered_cxx . . $ GPUInfoVulkan#registered_. = InfoProviderRegistrycxx . . $ InfoProviderRegistry#::addcxx . . $ InfoProviderRegistry#add(2c04d579dc484cde).( |
| 116 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUInfoVulkancxx . . $ GPUInfoVulkan#>(stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUInfoVulkanDataSourcecxx . . $ GPUInfoVulkanDataSource#>())); |