summaryrefslogtreecommitdiff
path: root/tools/gfx/vulkan/vk-helper-functions.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/vulkan/vk-helper-functions.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/vulkan/vk-helper-functions.cpp')
-rw-r--r--tools/gfx/vulkan/vk-helper-functions.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/gfx/vulkan/vk-helper-functions.cpp b/tools/gfx/vulkan/vk-helper-functions.cpp
index aa6c42ec5..da2b55fd2 100644
--- a/tools/gfx/vulkan/vk-helper-functions.cpp
+++ b/tools/gfx/vulkan/vk-helper-functions.cpp
@@ -2,6 +2,7 @@
#include "vk-helper-functions.h"
#include "vk-device.h"
+#include "vk-util.h"
namespace gfx
{
@@ -451,6 +452,44 @@ VkImageAspectFlags getAspectMaskFromFormat(VkFormat format)
} // namespace vk
+Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters)
+{
+ VulkanModule module;
+ SLANG_RETURN_ON_FAIL(module.init(false));
+ VulkanApi api;
+ SLANG_RETURN_ON_FAIL(api.initGlobalProcs(module));
+
+ VkInstanceCreateInfo instanceCreateInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
+ VkInstance instance;
+ SLANG_VK_RETURN_ON_FAIL(api.vkCreateInstance(&instanceCreateInfo, nullptr, &instance));
+
+ // This will fail due to not loading any extensions.
+ api.initInstanceProcs(instance);
+ // Make sure required functions for enumerating physical devices were loaded.
+ if (!api.vkEnumeratePhysicalDevices || !api.vkGetPhysicalDeviceProperties)
+ return SLANG_FAIL;
+
+ uint32_t numPhysicalDevices = 0;
+ SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, nullptr));
+
+ List<VkPhysicalDevice> physicalDevices;
+ physicalDevices.setCount(numPhysicalDevices);
+ SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, physicalDevices.getBuffer()));
+
+ for (const auto& physicalDevice : physicalDevices)
+ {
+ VkPhysicalDeviceProperties props;
+ api.vkGetPhysicalDeviceProperties(physicalDevice, &props);
+ AdapterInfo info = {};
+ memcpy(info.name, props.deviceName, Math::Min(strlen(props.deviceName), sizeof(AdapterInfo::name) - 1));
+ info.vendorID = props.vendorID;
+ info.deviceID = props.deviceID;
+ outAdapters.add(info);
+ }
+
+ return SLANG_OK;
+}
+
Result SLANG_MCALL createVKDevice(const IDevice::Desc* desc, IDevice** outRenderer)
{
RefPtr<vk::DeviceImpl> result = new vk::DeviceImpl();