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/cuda/cuda-helper-functions.cpp | 23 +++++++++++++++++++++++ tools/gfx/cuda/cuda-helper-functions.h | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'tools/gfx/cuda') diff --git a/tools/gfx/cuda/cuda-helper-functions.cpp b/tools/gfx/cuda/cuda-helper-functions.cpp index 6325d9fc6..702caf253 100644 --- a/tools/gfx/cuda/cuda-helper-functions.cpp +++ b/tools/gfx/cuda/cuda-helper-functions.cpp @@ -72,6 +72,22 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message, # endif } // namespace cuda +Result SLANG_MCALL getCUDAAdapters(List& outAdapters) +{ + int count; + cudaGetDeviceCount(&count); + for (int i = 0; i < count; i++) + { + cudaDeviceProp prop; + cudaGetDeviceProperties(&prop, i); + AdapterInfo info = {}; + memcpy(info.name, prop.name, Math::Min(strlen(prop.name), sizeof(AdapterInfo::name) - 1)); + outAdapters.add(info); + } + + return SLANG_OK; +} + Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { RefPtr result = new cuda::DeviceImpl(); @@ -80,6 +96,13 @@ returnComPtr(outDevice, result); return SLANG_OK; } #else + +Result SLANG_MCALL getCUDAAdapters(List& outAdapters) +{ + SLANG_UNUSED(outAdapters); + return SLANG_FAIL; +} + Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) { SLANG_UNUSED(desc); diff --git a/tools/gfx/cuda/cuda-helper-functions.h b/tools/gfx/cuda/cuda-helper-functions.h index 001e3946a..92ac4f4ed 100644 --- a/tools/gfx/cuda/cuda-helper-functions.h +++ b/tools/gfx/cuda/cuda-helper-functions.h @@ -3,12 +3,13 @@ #include "slang-gfx.h" #include "cuda-base.h" +#include "../../../source/core/slang-list.h" namespace gfx { -#ifdef GFX_ENABLE_CUDA using namespace Slang; +#ifdef GFX_ENABLE_CUDA namespace cuda { SLANG_FORCE_INLINE bool _isError(CUresult result) { return result != 0; } @@ -101,6 +102,8 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message, } // namespace cuda #endif +Result SLANG_MCALL getCUDAAdapters(List& outAdapters); + Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice); } // namespace gfx -- cgit v1.2.3