Debian Codegraph @

src/core/info/igpuinfo.h

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #pragma once
5
6 #include "vendor.h"
7 #include <filesystem>
8 #include <memory>
9 #include <string>
10 #include <string_view>
11 #include <utility>
12 #include <vector>
13
14 class IHWIDTranslator;
15
16 class IGPUInfo
17 {
18 public:
19 struct Keys
20 {
21 static constexpr std::string_view vendorID{"vendorid"};
22 static constexpr std::string_view deviceID{"deviceid"};
23 static constexpr std::string_view subvendorID{"svendorid"};
24 static constexpr std::string_view subdeviceID{"sdeviceid"};
25 static constexpr std::string_view vendorName{"vendor"};
26 static constexpr std::string_view deviceName{"device"};
27 static constexpr std::string_view subdeviceName{"sdevice"};
28 static constexpr std::string_view pciSlot{"pcislot"};
29 static constexpr std::string_view driver{"driver"};
30 static constexpr std::string_view revision{"revision"};
31 static constexpr std::string_view memory{"memory"};
32 static constexpr std::string_view uniqueID{"uniqueid"};
33 };
34
35 struct Path
36 {
37 Path(std::filesystem::path sys, std::filesystem::path dev) noexcept
38 : sys(std::move(sys))
39 , dev(std::move(dev))
40 {
41 }
42 std::filesystem::path const sys;
43 std::filesystem::path const dev;
44 };
45
46 class IProvider
47 {
48 public:
49 virtual std::vector<std::pair<std::string, std::string>>
50 provideInfo(Vendor vendor, int gpuIndex, IGPUInfo::Path const &path,
51 IHWIDTranslator const &hwIDTranslator) const = 0;
52
53 virtual std::vector<std::string>
54 provideCapabilities(Vendor vendor, int gpuIndex,
55 IGPUInfo::Path const &path) const = 0;
56
57 virtual ~IProvider() = default;
58 };
59
60 class IProviderRegistry
61 {
62 public:
63 virtual std::vector<std::unique_ptr<IGPUInfo::IProvider>> const &
64 gpuInfoProviders() const = 0;
65
66 virtual ~IProviderRegistry() = default;
67 };
68
69 /// @returns gpu vendor id
70 virtual Vendor vendor() const = 0;
71
72 /// @returns gpu index
73 virtual int index() const = 0;
74
75 /// @returns gpu Path
76 virtual IGPUInfo::Path const &path() const = 0;
77
78 /// @returns collection of keys for the stored gpu information
79 virtual std::vector<std::string> keys() const = 0;
80
81 /// @returns string with gpu info or empty string when no info
82 /// is mapped to the key
83 virtual std::string info(std::string_view key) const = 0;
84
85 /// @returns true when the capability is present
86 virtual bool hasCapability(std::string_view name) const = 0;
87
88 /// Initialize gpu info
89 /// @param infoProviders information providers
90 /// @param hwidTranslator hwid code translator
91 virtual void initialize(
92 std::vector<std::unique_ptr<IGPUInfo::IProvider>> const &infoProviders,
93 IHWIDTranslator const &hwidTranslator) = 0;
94
95 virtual ~IGPUInfo() = default;
96 };