diff options
Diffstat (limited to 'tools/gfx/vulkan/vk-helper-functions.cpp')
| -rw-r--r-- | tools/gfx/vulkan/vk-helper-functions.cpp | 39 |
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(); |
