From 5d7e98c4be398b1a36a883efcffc6c15d53bdf56 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 21 Feb 2022 16:32:05 -0500 Subject: [PATCH] Enumerate devices on DX12 --- engine/gfx/dx12/CMakeLists.txt | 2 +- engine/gfx/dx12/include/gfx_dx12.hpp | 12 ++++++++++++ engine/gfx/dx12/src/gfx_dx12.cpp | 25 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/engine/gfx/dx12/CMakeLists.txt b/engine/gfx/dx12/CMakeLists.txt index d2f0fe5..d11cd05 100755 --- a/engine/gfx/dx12/CMakeLists.txt +++ b/engine/gfx/dx12/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(GFXDX12 STATIC src/gfx_dx12.cpp) target_include_directories(GFXDX12 PUBLIC include) -target_link_libraries(GFXDX12 PUBLIC GFX) \ No newline at end of file +target_link_libraries(GFXDX12 PUBLIC GFX d3d12.lib dxgi.lib) \ No newline at end of file diff --git a/engine/gfx/dx12/include/gfx_dx12.hpp b/engine/gfx/dx12/include/gfx_dx12.hpp index 64f7e89..26b7ff2 100755 --- a/engine/gfx/dx12/include/gfx_dx12.hpp +++ b/engine/gfx/dx12/include/gfx_dx12.hpp @@ -1,7 +1,14 @@ #pragma once +#include +#include +#include +#include + #include "gfx.hpp" +using namespace Microsoft::WRL; + class gfx_dx12 : public GFX { public: bool is_supported() override { return true; } @@ -10,4 +17,9 @@ public: bool initialize(const GFXCreateInfo& info) override; const char* get_name() override; + +private: + void get_device(); + + ComPtr device; }; diff --git a/engine/gfx/dx12/src/gfx_dx12.cpp b/engine/gfx/dx12/src/gfx_dx12.cpp index 5b57a8f..5b54f8e 100755 --- a/engine/gfx/dx12/src/gfx_dx12.cpp +++ b/engine/gfx/dx12/src/gfx_dx12.cpp @@ -6,14 +6,35 @@ #include -using namespace Microsoft::WRL; +// from https://stackoverflow.com/a/18374698 +std::string ws2s(const std::wstring& wstr) { + using convert_typeX = std::codecvt_utf8; + std::wstring_convert converterX; -ComPtr g_Device; + return converterX.to_bytes(wstr); +} bool gfx_dx12::initialize(const GFXCreateInfo& info) { + get_device(); + return true; } +void gfx_dx12::get_device() { + ComPtr dxgiFactory; + UINT createFactoryFlags = DXGI_CREATE_FACTORY_DEBUG; + + CreateDXGIFactory2(createFactoryFlags, IID_PPV_ARGS(&dxgiFactory)); + + ComPtr adapter; + for (UINT i = 0; dxgiFactory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++) { + DXGI_ADAPTER_DESC1 dxgiAdapterDesc1; + adapter->GetDesc1(&dxgiAdapterDesc1); + + prism::log("GPU: {}", ws2s(dxgiAdapterDesc1.Description)); + } +} + const char* gfx_dx12::get_name() { return "DX12"; }