summaryrefslogtreecommitdiffstats
path: root/tools/gfx/render.cpp
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2022-11-03 16:58:49 +0100
committerGitHub <noreply@github.com>2022-11-03 11:58:49 -0400
commit8f9d58416934cbf850f0f01e5fefbdfe1b02d4d6 (patch)
tree3d376e772dcaeb7d0ef55d091fe49e33a6f57fb1 /tools/gfx/render.cpp
parent203b5d7a5014d7f140345567e065cbf57b57b819 (diff)
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 <jsmall@nvidia.com>
Diffstat (limited to 'tools/gfx/render.cpp')
-rw-r--r--tools/gfx/render.cpp48
1 files changed, 48 insertions, 0 deletions
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<AdapterInfo>& outAdapters);
+Result SLANG_MCALL getD3D12Adapters(List<AdapterInfo>& outAdapters);
+Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters);
+Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& 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<AdapterInfo> 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)