Skip to content

Commit

Permalink
Added adapter UUID and LUID to AdapterInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Oct 22, 2024
1 parent 35c5ec3 commit 9629d2a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/donut/app/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ freely, subject to the following restrictions:

#include <list>
#include <functional>
#include <optional>

namespace donut::app
{
Expand Down Expand Up @@ -169,10 +170,17 @@ namespace donut::app

struct AdapterInfo
{
typedef std::array<uint8_t, 16> UUID;
typedef std::array<uint8_t, 8> LUID;

std::string name;
uint32_t vendorID = 0;
uint32_t deviceID = 0;
uint64_t dedicatedVideoMemory = 0;

std::optional<UUID> uuid;
std::optional<LUID> luid;

#if DONUT_WITH_DX11 || DONUT_WITH_DX12
nvrhi::RefCountPtr<IDXGIAdapter> dxgiAdapter;
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/app/dx11/DeviceManager_DX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ bool DeviceManager_DX11::EnumerateAdapters(std::vector<AdapterInfo>& outAdapters
adapterInfo.deviceID = desc.DeviceId;
adapterInfo.dedicatedVideoMemory = desc.DedicatedVideoMemory;

AdapterInfo::LUID luid;
static_assert(luid.size() == sizeof(desc.AdapterLuid));
memcpy(luid.data(), &desc.AdapterLuid, luid.size());
adapterInfo.luid = luid;

outAdapters.push_back(std::move(adapterInfo));
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/dx12/DeviceManager_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ bool DeviceManager_DX12::EnumerateAdapters(std::vector<AdapterInfo>& outAdapters
adapterInfo.deviceID = desc.DeviceId;
adapterInfo.dedicatedVideoMemory = desc.DedicatedVideoMemory;

AdapterInfo::LUID luid;
static_assert(luid.size() == sizeof(desc.AdapterLuid));
memcpy(luid.data(), &desc.AdapterLuid, luid.size());
adapterInfo.luid = luid;

outAdapters.push_back(std::move(adapterInfo));
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/app/vulkan/DeviceManager_VK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,12 @@ bool DeviceManager_VK::EnumerateAdapters(std::vector<AdapterInfo>& outAdapters)

for (auto physicalDevice : devices)
{
vk::PhysicalDeviceProperties properties = physicalDevice.getProperties();
vk::PhysicalDeviceProperties2 properties2;
vk::PhysicalDeviceIDProperties idProperties;
properties2.pNext = &idProperties;
physicalDevice.getProperties2(&properties2);

auto const& properties = properties2.properties;

AdapterInfo adapterInfo;
adapterInfo.name = properties.deviceName.data();
Expand All @@ -1079,6 +1084,19 @@ bool DeviceManager_VK::EnumerateAdapters(std::vector<AdapterInfo>& outAdapters)
adapterInfo.vkPhysicalDevice = physicalDevice;
adapterInfo.dedicatedVideoMemory = 0;

AdapterInfo::UUID uuid;
static_assert(uuid.size() == idProperties.deviceUUID.size());
memcpy(uuid.data(), idProperties.deviceUUID.data(), uuid.size());
adapterInfo.uuid = uuid;

if (idProperties.deviceLUIDValid)
{
AdapterInfo::LUID luid;
static_assert(luid.size() == idProperties.deviceLUID.size());
memcpy(luid.data(), idProperties.deviceLUID.data(), luid.size());
adapterInfo.luid = luid;
}

// Go through the memory types to figure out the amount of VRAM on this physical device.
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
for (uint32_t heapIndex = 0; heapIndex < memoryProperties.memoryHeapCount; ++heapIndex)
Expand Down

0 comments on commit 9629d2a

Please sign in to comment.