2023-05-07 22:12:39 +00:00
|
|
|
/**
|
|
|
|
* @file tools/dxgi.cpp
|
2023-05-24 03:57:23 +00:00
|
|
|
* @brief Displays information about connected displays and GPUs
|
2023-05-07 22:12:39 +00:00
|
|
|
*/
|
2023-05-24 03:57:23 +00:00
|
|
|
#define WINVER 0x0A00
|
2020-01-23 22:43:39 +00:00
|
|
|
#include <d3dcommon.h>
|
2021-05-17 19:21:57 +00:00
|
|
|
#include <dxgi.h>
|
2020-01-23 22:43:39 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2022-08-08 03:37:57 +00:00
|
|
|
#include "src/utility.h"
|
2020-01-23 22:43:39 +00:00
|
|
|
|
|
|
|
using namespace std::literals;
|
|
|
|
namespace dxgi {
|
2023-03-28 01:45:29 +00:00
|
|
|
template <class T>
|
|
|
|
void
|
|
|
|
Release(T *dxgi) {
|
|
|
|
dxgi->Release();
|
|
|
|
}
|
2020-01-23 22:43:39 +00:00
|
|
|
|
2023-03-28 01:45:29 +00:00
|
|
|
using factory1_t = util::safe_ptr<IDXGIFactory1, Release<IDXGIFactory1>>;
|
|
|
|
using adapter_t = util::safe_ptr<IDXGIAdapter1, Release<IDXGIAdapter1>>;
|
|
|
|
using output_t = util::safe_ptr<IDXGIOutput, Release<IDXGIOutput>>;
|
2020-01-23 22:43:39 +00:00
|
|
|
|
2023-03-28 01:45:29 +00:00
|
|
|
} // namespace dxgi
|
2020-01-23 22:43:39 +00:00
|
|
|
|
2023-03-28 01:45:29 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
2020-01-23 22:43:39 +00:00
|
|
|
HRESULT status;
|
2023-05-24 03:57:23 +00:00
|
|
|
|
|
|
|
// Set ourselves as per-monitor DPI aware for accurate resolution values on High DPI systems
|
|
|
|
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
2020-01-23 22:43:39 +00:00
|
|
|
|
|
|
|
dxgi::factory1_t::pointer factory_p {};
|
2023-03-28 01:45:29 +00:00
|
|
|
status = CreateDXGIFactory1(IID_IDXGIFactory1, (void **) &factory_p);
|
2020-01-23 22:43:39 +00:00
|
|
|
dxgi::factory1_t factory { factory_p };
|
2023-03-28 01:45:29 +00:00
|
|
|
if (FAILED(status)) {
|
2020-01-23 22:43:39 +00:00
|
|
|
std::cout << "Failed to create DXGIFactory1 [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dxgi::adapter_t::pointer adapter_p {};
|
2023-03-28 01:45:29 +00:00
|
|
|
for (int x = 0; factory->EnumAdapters1(x, &adapter_p) != DXGI_ERROR_NOT_FOUND; ++x) {
|
2020-01-23 22:43:39 +00:00
|
|
|
dxgi::adapter_t adapter { adapter_p };
|
|
|
|
|
|
|
|
DXGI_ADAPTER_DESC1 adapter_desc;
|
|
|
|
adapter->GetDesc1(&adapter_desc);
|
|
|
|
|
|
|
|
std::cout
|
|
|
|
<< "====== ADAPTER ====="sv << std::endl;
|
|
|
|
std::wcout
|
|
|
|
<< L"Device Name : "sv << adapter_desc.Description << std::endl;
|
|
|
|
std::cout
|
|
|
|
<< "Device Vendor ID : 0x"sv << util::hex(adapter_desc.VendorId).to_string_view() << std::endl
|
|
|
|
<< "Device Device ID : 0x"sv << util::hex(adapter_desc.DeviceId).to_string_view() << std::endl
|
|
|
|
<< "Device Video Mem : "sv << adapter_desc.DedicatedVideoMemory / 1048576 << " MiB"sv << std::endl
|
|
|
|
<< "Device Sys Mem : "sv << adapter_desc.DedicatedSystemMemory / 1048576 << " MiB"sv << std::endl
|
2021-05-17 19:21:57 +00:00
|
|
|
<< "Share Sys Mem : "sv << adapter_desc.SharedSystemMemory / 1048576 << " MiB"sv << std::endl
|
|
|
|
<< std::endl
|
2020-01-23 22:43:39 +00:00
|
|
|
<< " ====== OUTPUT ======"sv << std::endl;
|
|
|
|
|
|
|
|
dxgi::output_t::pointer output_p {};
|
2023-03-28 01:45:29 +00:00
|
|
|
for (int y = 0; adapter->EnumOutputs(y, &output_p) != DXGI_ERROR_NOT_FOUND; ++y) {
|
2021-05-17 19:21:57 +00:00
|
|
|
dxgi::output_t output { output_p };
|
2020-01-23 22:43:39 +00:00
|
|
|
|
|
|
|
DXGI_OUTPUT_DESC desc;
|
|
|
|
output->GetDesc(&desc);
|
|
|
|
|
2023-03-28 01:45:29 +00:00
|
|
|
auto width = desc.DesktopCoordinates.right - desc.DesktopCoordinates.left;
|
2020-01-23 22:43:39 +00:00
|
|
|
auto height = desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top;
|
|
|
|
|
|
|
|
std::wcout
|
|
|
|
<< L" Output Name : "sv << desc.DeviceName << std::endl;
|
|
|
|
std::cout
|
|
|
|
<< " AttachedToDesktop : "sv << (desc.AttachedToDesktop ? "yes"sv : "no"sv) << std::endl
|
2021-05-17 19:21:57 +00:00
|
|
|
<< " Resolution : "sv << width << 'x' << height << std::endl
|
|
|
|
<< std::endl;
|
2020-01-23 22:43:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|