载入中...
搜索中...
未找到
GpuInfoProvider.cpp
浏览该文件的文档.
1// Publishes the Vulkan physical-device description as the IGpuInfo capability,
2// so the system module can report it without including graphics.
3
4#include "common/Capability.h"
5#include "common/GpuInfo.h"
6#include "common/Module.h"
7#include "graphics/Graphics.h"
9
10#include <cstdio>
11#include <string>
12
13namespace eve::graphics::vulkan {
14namespace {
15
16std::string vendorNameFromId(uint32_t vendorID) {
17 switch (vendorID) {
18 case 0x1002: return "AMD";
19 case 0x10DE: return "NVIDIA";
20 case 0x8086: return "Intel";
21 case 0x13B5: return "ARM";
22 case 0x5143: return "Qualcomm";
23 case 0x1010: return "ImgTec";
24 case 0x106B: return "Apple";
25 default: {
26 char buf[32];
27 std::snprintf(buf, sizeof(buf), "0x%04X", vendorID);
28 return buf;
29 }
30 }
31}
32
33const char *deviceTypeName(vk::PhysicalDeviceType t) {
34 switch (t) {
35 case vk::PhysicalDeviceType::eDiscreteGpu: return "discrete";
36 case vk::PhysicalDeviceType::eIntegratedGpu: return "integrated";
37 case vk::PhysicalDeviceType::eVirtualGpu: return "virtual";
38 case vk::PhysicalDeviceType::eCpu: return "cpu";
39 default: return "other";
40 }
41}
42
43class VulkanGpuInfo : public eve::caps::IGpuInfo {
44public:
45 bool gpuReady() const override { return device() != nullptr; }
46
47 std::string gpuName() const override {
48 auto *gfx = device();
49 if (!gfx) return {};
50 return gfx->getDevice().physical_device.properties.deviceName.data();
51 }
52
53 std::string gpuVendor() const override {
54 auto *gfx = device();
55 if (!gfx) return {};
56 return vendorNameFromId(gfx->getDevice().physical_device.properties.vendorID);
57 }
58
59 std::string gpuDeviceType() const override {
60 auto *gfx = device();
61 if (!gfx) return {};
62 return deviceTypeName(gfx->getDevice().physical_device.properties.deviceType);
63 }
64
65 int gpuMemoryTotalMB() const override {
66 auto *gfx = device();
67 if (!gfx) return 0;
68 const auto &mem = gfx->getDevice().physical_device.memory_properties;
69 uint64_t bytes = 0;
70 for (uint32_t i = 0; i < mem.memoryHeapCount; ++i) {
71 if (mem.memoryHeaps[i].flags & vk::MemoryHeapFlagBits::eDeviceLocal)
72 bytes += mem.memoryHeaps[i].size;
73 }
74 return static_cast<int>(bytes / (1024ull * 1024ull));
75 }
76
77private:
79 static Graphics *device() {
80 auto *base = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
81 auto *gfx = dynamic_cast<Graphics *>(base);
82 if (!gfx) return nullptr;
83 vk::PhysicalDevice pd = gfx->getDevice().physical_device;
84 if (static_cast<VkPhysicalDevice>(pd) == VK_NULL_HANDLE) return nullptr;
85 return gfx;
86 }
87};
88
89// Registered at static-init so the capability is available before any module
90// is constructed; the provider itself resolves Graphics lazily on each call.
91struct Register {
92 Register() {
93 static VulkanGpuInfo info;
95 }
96} g_register;
97
98} // namespace
99} // namespace eve::graphics::vulkan
vkb::Device & device
I * query()
Definition Capability.h:77