From 8f9d58416934cbf850f0f01e5fefbdfe1b02d4d6 Mon Sep 17 00:00:00 2001 From: skallweitNV <64953474+skallweitNV@users.noreply.github.com> Date: Thu, 3 Nov 2022 16:58:49 +0100 Subject: Add gfxGetAdapters function (currently implemented for D3D12/Vulkan) (#2486) * Add gfxGetAdapters function (currently implemented for D3D12/Vulkan) * Extend to handle DirectX11 and CUDA * Use blob to return adapter list and add AdapterList helper * Replace strncpy with memcpy Co-authored-by: jsmall-nvidia --- tools/gfx/d3d12/d3d12-helper-functions.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tools/gfx/d3d12/d3d12-helper-functions.cpp') diff --git a/tools/gfx/d3d12/d3d12-helper-functions.cpp b/tools/gfx/d3d12/d3d12-helper-functions.cpp index 5f9102d0c..34efa8401 100644 --- a/tools/gfx/d3d12/d3d12-helper-functions.cpp +++ b/tools/gfx/d3d12/d3d12-helper-functions.cpp @@ -613,6 +613,27 @@ void translatePostBuildInfoDescs( } // namespace d3d12 +Result SLANG_MCALL getD3D12Adapters(List& outAdapters) +{ + List> dxgiAdapters; + DeviceCheckFlags flags = DeviceCheckFlag::UseHardwareDevice; + SLANG_RETURN_ON_FAIL(D3DUtil::findAdapters(flags, UnownedStringSlice(), dxgiAdapters)); + + outAdapters.clear(); + for (const auto& dxgiAdapter : dxgiAdapters) + { + DXGI_ADAPTER_DESC desc; + dxgiAdapter->GetDesc(&desc); + AdapterInfo info = {}; + auto name = String::fromWString(desc.Description); + memcpy(info.name, name.getBuffer(), Math::Min(name.getLength(), (Index)sizeof(AdapterInfo::name) - 1)); + info.vendorID = desc.VendorId; + info.deviceID = desc.DeviceId; + outAdapters.add(info); + } + return SLANG_OK; +} + Result SLANG_MCALL createD3D12Device(const IDevice::Desc* desc, IDevice** outDevice) { RefPtr result = new d3d12::DeviceImpl(); -- cgit v1.2.3