FrontendCommon: Add GPU enumeration methods to D3D11/Vulkan host displays
This commit is contained in:
parent
85edbce3ca
commit
7fce9b102e
|
@ -2,6 +2,7 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/d3d11/shader_compiler.h"
|
||||
#include "common/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "display_ps.hlsl.h"
|
||||
#include "display_vs.hlsl.h"
|
||||
#include <array>
|
||||
|
@ -477,4 +478,58 @@ void D3D11HostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 he
|
|||
m_context->Draw(3, 0);
|
||||
}
|
||||
|
||||
std::vector<std::string> D3D11HostDisplay::EnumerateAdapterNames()
|
||||
{
|
||||
ComPtr<IDXGIFactory> dxgi_factory;
|
||||
HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(dxgi_factory.GetAddressOf()));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
std::vector<std::string> adapter_names;
|
||||
ComPtr<IDXGIAdapter> current_adapter;
|
||||
while (SUCCEEDED(
|
||||
dxgi_factory->EnumAdapters(static_cast<UINT>(adapter_names.size()), current_adapter.ReleaseAndGetAddressOf())))
|
||||
{
|
||||
DXGI_ADAPTER_DESC adapter_desc;
|
||||
std::string adapter_name;
|
||||
if (SUCCEEDED(current_adapter->GetDesc(&adapter_desc)))
|
||||
{
|
||||
char adapter_name_buffer[128];
|
||||
const int name_length = WideCharToMultiByte(CP_UTF8, 0, adapter_desc.Description,
|
||||
static_cast<int>(std::wcslen(adapter_desc.Description)),
|
||||
adapter_name_buffer, countof(adapter_name_buffer), 0, nullptr);
|
||||
if (name_length >= 0)
|
||||
adapter_name.assign(adapter_name_buffer, static_cast<size_t>(name_length));
|
||||
else
|
||||
adapter_name.assign("(Unknown)");
|
||||
}
|
||||
else
|
||||
{
|
||||
adapter_name.assign("(Unknown)");
|
||||
}
|
||||
|
||||
// handle duplicate adapter names
|
||||
if (std::any_of(adapter_names.begin(), adapter_names.end(),
|
||||
[&adapter_name](const std::string& other) { return (adapter_name == other); }))
|
||||
{
|
||||
std::string original_adapter_name = std::move(adapter_name);
|
||||
|
||||
u32 current_extra = 2;
|
||||
do
|
||||
{
|
||||
adapter_name = StringUtil::StdStringFromFormat("%s (%u)", original_adapter_name.c_str(), current_extra);
|
||||
current_extra++;
|
||||
} while (std::any_of(adapter_names.begin(), adapter_names.end(),
|
||||
[&adapter_name](const std::string& other) { return (adapter_name == other); }));
|
||||
}
|
||||
|
||||
adapter_names.push_back(std::move(adapter_name));
|
||||
}
|
||||
|
||||
if (!adapter_names.empty())
|
||||
return adapter_names;
|
||||
}
|
||||
|
||||
return {"(Default)"};
|
||||
}
|
||||
|
||||
} // namespace FrontendCommon
|
|
@ -9,6 +9,8 @@
|
|||
#include <dxgi.h>
|
||||
#include <memory>
|
||||
#include <wrl/client.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace FrontendCommon {
|
||||
|
||||
|
@ -60,6 +62,8 @@ public:
|
|||
void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, HostDisplayTexture* texture_handle);
|
||||
void EndRenderAndPresent();
|
||||
|
||||
static std::vector<std::string> EnumerateAdapterNames();
|
||||
|
||||
private:
|
||||
static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "vulkan_host_display.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/log.h"
|
||||
#include "common/scope_guard.h"
|
||||
#include "common/vulkan/builders.h"
|
||||
#include "common/vulkan/context.h"
|
||||
#include "common/vulkan/shader_cache.h"
|
||||
|
@ -489,4 +490,27 @@ void VulkanHostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 h
|
|||
vkCmdDraw(cmdbuffer, 3, 1, 0, 0);
|
||||
}
|
||||
|
||||
std::vector<std::string> VulkanHostDisplay::EnumerateAdapterNames()
|
||||
{
|
||||
if (Vulkan::LoadVulkanLibrary())
|
||||
{
|
||||
Common::ScopeGuard lib_guard([]() { Vulkan::UnloadVulkanLibrary(); });
|
||||
|
||||
VkInstance instance = Vulkan::Context::CreateVulkanInstance(false, false, false);
|
||||
if (instance != VK_NULL_HANDLE)
|
||||
{
|
||||
Common::ScopeGuard instance_guard([&instance]() { vkDestroyInstance(instance, nullptr); });
|
||||
|
||||
if (Vulkan::LoadVulkanInstanceFunctions(instance))
|
||||
{
|
||||
Vulkan::Context::GPUNameList gpus = Vulkan::Context::EnumerateGPUNames(instance);
|
||||
if (!gpus.empty())
|
||||
return gpus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {"(Default)"};
|
||||
}
|
||||
|
||||
} // namespace FrontendCommon
|
|
@ -62,6 +62,8 @@ public:
|
|||
void ResizeSwapChain(u32 new_width, u32 new_height);
|
||||
void DestroySwapChain();
|
||||
|
||||
static std::vector<std::string> EnumerateAdapterNames();
|
||||
|
||||
private:
|
||||
struct PushConstants
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue