Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/gpu/vulkan/SDL_gpu_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -11252,13 +11252,14 @@ static Uint8 VULKAN_INTERNAL_IsDeviceSuitable(
VkPhysicalDevice physicalDevice,
VulkanExtensions *physicalDeviceExtensions,
Uint32 *queueFamilyIndex,
Uint8 *deviceRank)
Uint16 *deviceRank)
{
Uint32 queueFamilyCount, queueFamilyRank, queueFamilyBest;
VkQueueFamilyProperties *queueProps;
bool supportsPresent;
VkPhysicalDeviceProperties deviceProperties;
VkPhysicalDeviceFeatures deviceFeatures;
VkPhysicalDeviceMemoryProperties deviceMemory;
Uint32 i;

const Uint8 *devicePriority = renderer->preferLowPower ? DEVICE_PRIORITY_LOWPOWER : DEVICE_PRIORITY_HIGHPERFORMANCE;
Expand All @@ -11285,6 +11286,24 @@ static Uint8 VULKAN_INTERNAL_IsDeviceSuitable(
return 0;
}

/* If we prefer high performance, sum up all device local memory (rounded to megabytes)
* to deviceRank. In the niche case of someone having multiple dedicated GPUs in the same
* system, this theoretically picks the most powerful one (or at least the one with the
* most memory!)
*/

renderer->vkGetPhysicalDeviceMemoryProperties(physicalDevice, &deviceMemory);
Uint64 videoMemory = 0;
for (i = 0; i < deviceMemory.memoryHeapCount; i++) {
VkMemoryHeap heap = deviceMemory.memoryHeaps[i];
if (heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) {
videoMemory += heap.size;
}
}
// Round it to megabytes (as per the vulkan spec videoMemory is in bytes)
Uint64 videoMemoryRounded = videoMemory / 1024 / 1024;
*deviceRank += videoMemoryRounded;

renderer->vkGetPhysicalDeviceFeatures(
physicalDevice,
&deviceFeatures);
Expand Down Expand Up @@ -11392,7 +11411,7 @@ static Uint8 VULKAN_INTERNAL_DeterminePhysicalDevice(VulkanRenderer *renderer)
Uint32 i, physicalDeviceCount;
Sint32 suitableIndex;
Uint32 queueFamilyIndex, suitableQueueFamilyIndex;
Uint8 deviceRank, highestRank;
Uint16 deviceRank, highestRank;

vulkanResult = renderer->vkEnumeratePhysicalDevices(
renderer->instance,
Expand Down
Loading