From 85581bdace08f7b19e00db6a56e5414912f8f7cf Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 2 Oct 2019 08:42:22 +0200 Subject: [PATCH] [util] Move GetAdapterLUID out of DXGI internals --- src/dxgi/dxgi_adapter.cpp | 26 ++------------------------ src/util/meson.build | 1 + src/util/util_luid.cpp | 34 ++++++++++++++++++++++++++++++++++ src/util/util_luid.h | 15 +++++++++++++++ 4 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 src/util/util_luid.cpp create mode 100644 src/util/util_luid.h diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index a587229b..86bd012f 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -10,32 +10,10 @@ #include "dxgi_options.h" #include "dxgi_output.h" +#include "../util/util_luid.h" + namespace dxvk { - static LUID GetAdapterLUID(UINT Adapter) { - static std::mutex s_mutex; - static std::vector s_luids; - - std::lock_guard lock(s_mutex); - uint32_t newLuidCount = Adapter + 1; - - while (s_luids.size() < newLuidCount) { - LUID luid = { 0, 0 }; - - if (!AllocateLocallyUniqueId(&luid)) - Logger::err("DXGI: Failed to allocate LUID"); - - - Logger::info(str::format("DXGI: Adapter LUID ", s_luids.size(), ": ", - std::hex, luid.HighPart, ":", luid.LowPart, std::dec)); - - s_luids.push_back(luid); - } - - return s_luids[Adapter]; - } - - DxgiVkAdapter::DxgiVkAdapter(DxgiAdapter* pAdapter) : m_adapter(pAdapter) { diff --git a/src/util/meson.build b/src/util/meson.build index 1a18d834..e6081832 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -2,6 +2,7 @@ util_src = files([ 'util_env.cpp', 'util_string.cpp', 'util_gdi.cpp', + 'util_luid.cpp', 'com/com_guid.cpp', 'com/com_private_data.cpp', diff --git a/src/util/util_luid.cpp b/src/util/util_luid.cpp new file mode 100644 index 00000000..1b90bcb2 --- /dev/null +++ b/src/util/util_luid.cpp @@ -0,0 +1,34 @@ +#include "util_luid.h" +#include "util_string.h" + +#include "./log/log.h" + +#include +#include + +namespace dxvk { + + LUID GetAdapterLUID(UINT Adapter) { + static std::mutex s_mutex; + static std::vector s_luids; + + std::lock_guard lock(s_mutex); + uint32_t newLuidCount = Adapter + 1; + + while (s_luids.size() < newLuidCount) { + LUID luid = { 0, 0 }; + + if (!::AllocateLocallyUniqueId(&luid)) + Logger::err("Failed to allocate LUID"); + + + Logger::info(str::format("Adapter LUID ", s_luids.size(), ": ", + std::hex, luid.HighPart, ":", luid.LowPart, std::dec)); + + s_luids.push_back(luid); + } + + return s_luids[Adapter]; + } + +} diff --git a/src/util/util_luid.h b/src/util/util_luid.h new file mode 100644 index 00000000..718040e3 --- /dev/null +++ b/src/util/util_luid.h @@ -0,0 +1,15 @@ +#include "./com/com_include.h" + +namespace dxvk { + + /** + * \brief Retrieves an adapter LUID + * + * Note that this only works reliably within the + * module that this function was compiled into. + * \param [in] Adapter The adapter index + * \returns LUID An LUID for that adapter + */ + LUID GetAdapterLUID(UINT Adapter); + +}