CuteLogger
Fast and simple logging solution for Qt based applications
gpuinfo.h
1/*
2 * Copyright (c) 2026 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef GPUINFO_H
19#define GPUINFO_H
20
21#include <QList>
22#include <QString>
23#include <QStringList>
24
25// PCI vendor ids of the common GPU vendors.
26enum GpuVendorId {
27 kGpuVendorNvidia = 0x10DE,
28 kGpuVendorAmd = 0x1002,
29 kGpuVendorIntel = 0x8086,
30};
31
32struct GpuAdapterInfo
33{
34 int index = -1; // current DXGI adapter index; matches QT_D3D_ADAPTER_INDEX
35 QString name; // human-readable description, e.g. "NVIDIA GeForce RTX 3090"
36 uint vendorId = 0; // PCI vendor id (see GpuVendorId)
37 uint deviceId = 0; // PCI device id; together with vendorId identifies the GPU
38};
39
40// Enumerate the physical GPU adapters usable by the renderer.
41// On Windows this uses DXGI (the same enumeration order Qt's D3D RHI backend uses).
42// Returns an empty list on platforms/backends where index-based selection is not
43// supported, in which case the caller should hide the selection UI.
44QList<GpuAdapterInfo> enumerateGpuAdapters();
45
46// Resolve the CURRENT DXGI adapter index (as QT_D3D_ADAPTER_INDEX expects) of the GPU
47// identified by vendorId+deviceId, or -1 if not found. Some drivers enumerate adapters
48// in an unstable order across runs, so the index must be resolved live at startup from
49// the GPU's stable identity rather than persisted from a previous session.
50int gpuAdapterIndexFor(uint vendorId, uint deviceId);
51
52// Choose the hardware video encoder for a given software codec, preferring the encoder
53// family matching the selected GPU vendor (NVIDIA->*_nvenc, AMD->*_amf, Intel->*_qsv)
54// and otherwise falling back to the first type-compatible encoder in hardwareCodecs.
55// When is10bit is true, H.264 hardware encoders are skipped because they do not support
56// 10-bit. Returns an empty string when no compatible hardware encoder is available.
57// This is a pure, platform-independent function so it can be unit tested.
58QString preferredHardwareVcodec(const QStringList &hardwareCodecs,
59 const QString &softwareVcodec,
60 uint vendorId,
61 bool is10bit);
62
63#endif // GPUINFO_H