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/render.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tools/gfx/render.cpp') diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp index b19824671..84f537705 100644 --- a/tools/gfx/render.cpp +++ b/tools/gfx/render.cpp @@ -1,6 +1,7 @@ // render.cpp #include "renderer-shared.h" #include "../../source/core/slang-math.h" +#include "../../source/core/slang-blob.h" #include "open-gl/render-gl.h" #include "debug-layer/debug-device.h" @@ -15,6 +16,11 @@ Result SLANG_MCALL createVKDevice(const IDevice::Desc* desc, IDevice** outDevice Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice); Result SLANG_MCALL createCPUDevice(const IDevice::Desc* desc, IDevice** outDevice); +Result SLANG_MCALL getD3D11Adapters(List& outAdapters); +Result SLANG_MCALL getD3D12Adapters(List& outAdapters); +Result SLANG_MCALL getVKAdapters(List& outAdapters); +Result SLANG_MCALL getCUDAAdapters(List& outAdapters); + static bool debugLayerEnabled = false; bool isGfxDebugLayerEnabled() { return debugLayerEnabled; } @@ -233,6 +239,48 @@ extern "C" return SLANG_OK; } + SLANG_GFX_API SlangResult SLANG_MCALL gfxGetAdapters(DeviceType type, ISlangBlob** outAdaptersBlob) + { + List adapters; + + switch (type) + { +#if SLANG_WINDOWS_FAMILY + case DeviceType::DirectX11: + SLANG_RETURN_ON_FAIL(getD3D11Adapters(adapters)); + break; + case DeviceType::DirectX12: + SLANG_RETURN_ON_FAIL(getD3D12Adapters(adapters)); + break; + case DeviceType::OpenGl: + return SLANG_E_NOT_IMPLEMENTED; + case DeviceType::Vulkan: + SLANG_RETURN_ON_FAIL(getVKAdapters(adapters)); + break; + case DeviceType::CUDA: + SLANG_RETURN_ON_FAIL(getCUDAAdapters(adapters)); + break; +#elif SLANG_LINUX_FAMILY && !defined(__CYGWIN__) + case DeviceType::Vulkan: + SLANG_RETURN_ON_FAIL(getVKAdapters(adapters)); + break; + case DeviceType::CUDA: + SLANG_RETURN_ON_FAIL(getCUDAAdapters(adapters)); + break; +#endif + case DeviceType::CPU: + return SLANG_E_NOT_IMPLEMENTED; + default: + return SLANG_E_INVALID_ARG; + } + + auto adaptersBlob = RawBlob::create(adapters.getBuffer(), adapters.getCount() * sizeof(AdapterInfo)); + if (outAdaptersBlob) + returnComPtr(outAdaptersBlob, adaptersBlob); + + return SLANG_OK; + } + SlangResult _createDevice(const IDevice::Desc* desc, IDevice** outDevice) { switch (desc->deviceType) -- cgit v1.2.3