summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-08-25 01:50:33 +0000
committerazhirnov <zh1dron@gmail.com>2020-08-25 01:50:33 +0000
commit0e68bbb65f21e1d58ba3e74d1b8efb5912bd7a01 (patch)
tree41a085279b1c31803c22ce0bd25d00bb8aaf1549 /Graphics/GraphicsEngineVulkan
parentadded namespace to macros (diff)
downloadDiligentCore-0e68bbb65f21e1d58ba3e74d1b8efb5912bd7a01.tar.gz
DiligentCore-0e68bbb65f21e1d58ba3e74d1b8efb5912bd7a01.zip
added AdapterId to Vulkan backend
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanInstance.hpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp45
3 files changed, 30 insertions, 19 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanInstance.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanInstance.hpp
index 0ca092c6..f5b921a6 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanInstance.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanInstance.hpp
@@ -65,7 +65,7 @@ public:
bool IsExtensionAvailable(const char* ExtensionName)const;
bool IsExtensionEnabled (const char* ExtensionName)const;
- VkPhysicalDevice SelectPhysicalDevice()const;
+ VkPhysicalDevice SelectPhysicalDevice(uint32_t AdapterId)const;
VkAllocationCallbacks* GetVkAllocator()const{return m_pVkAllocator;}
VkInstance GetVkInstance() const{return m_VkInstance; }
diff --git a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
index 8c2b7e10..89895ad0 100644
--- a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
@@ -143,7 +143,7 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& _E
EngineCI.ppGlobalExtensionNames,
reinterpret_cast<VkAllocationCallbacks*>(EngineCI.pVkAllocator));
- auto vkDevice = Instance->SelectPhysicalDevice();
+ auto vkDevice = Instance->SelectPhysicalDevice(EngineCI.AdapterId);
auto PhysicalDevice = VulkanUtilities::VulkanPhysicalDevice::Create(vkDevice, Instance);
const auto& PhysicalDeviceFeatures = PhysicalDevice->GetFeatures();
diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp
index 603da02a..99620e7d 100644
--- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp
@@ -279,17 +279,9 @@ VulkanInstance::~VulkanInstance()
#endif
}
-VkPhysicalDevice VulkanInstance::SelectPhysicalDevice() const
+VkPhysicalDevice VulkanInstance::SelectPhysicalDevice(uint32_t AdapterId) const
{
- VkPhysicalDevice SelectedPhysicalDevice = VK_NULL_HANDLE;
-
- // Select a device that exposes a queue family that suppors both compute and graphics operations
- // Prefer discrete GPU
- for (auto Device : m_PhysicalDevices)
- {
- VkPhysicalDeviceProperties DeviceProps;
- vkGetPhysicalDeviceProperties(Device, &DeviceProps);
-
+ const auto IsGraphicsAndComputeQueueSupported = [](VkPhysicalDevice Device) {
uint32_t QueueFamilyCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(Device, &QueueFamilyCount, nullptr);
VERIFY_EXPR(QueueFamilyCount > 0);
@@ -300,21 +292,40 @@ VkPhysicalDevice VulkanInstance::SelectPhysicalDevice() const
// If an implementation exposes any queue family that supports graphics operations,
// at least one queue family of at least one physical device exposed by the implementation
// must support both graphics and compute operations.
- bool GraphicsAndComputeQueueSupported = false;
for (const auto& QueueFamilyProps : QueueFamilyProperties)
{
if ((QueueFamilyProps.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0 &&
(QueueFamilyProps.queueFlags & VK_QUEUE_COMPUTE_BIT) != 0)
{
- GraphicsAndComputeQueueSupported = true;
- break;
+ return true;
}
}
- if (GraphicsAndComputeQueueSupported)
+ return false;
+ };
+
+ VkPhysicalDevice SelectedPhysicalDevice = VK_NULL_HANDLE;
+
+ if (AdapterId < m_PhysicalDevices.size() &&
+ IsGraphicsAndComputeQueueSupported(m_PhysicalDevices[AdapterId]))
+ {
+ SelectedPhysicalDevice = m_PhysicalDevices[AdapterId];
+ }
+
+ // Select a device that exposes a queue family that suppors both compute and graphics operations.
+ // Prefer discrete GPU.
+ if (SelectedPhysicalDevice == VK_NULL_HANDLE)
+ {
+ for (auto Device : m_PhysicalDevices)
{
- SelectedPhysicalDevice = Device;
- if (DeviceProps.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
- break;
+ VkPhysicalDeviceProperties DeviceProps;
+ vkGetPhysicalDeviceProperties(Device, &DeviceProps);
+
+ if (IsGraphicsAndComputeQueueSupported(Device))
+ {
+ SelectedPhysicalDevice = Device;
+ if (DeviceProps.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
+ break;
+ }
}
}