1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_RENDERER_BACKEND_VULKAN_DEVICESELECTION
#define INCLUDED_RENDERER_BACKEND_VULKAN_DEVICESELECTION
#include <cstddef>
#include <cstdint>
#include <glad/vulkan.h>
#include <js/TypeDecls.h>
#include <limits>
#include <string>
#include <vector>
class ScriptRequest;
namespace Renderer
{
namespace Backend
{
namespace Vulkan
{
/**
* Structure to store all information that might be useful on device selection.
*/
struct SAvailablePhysicalDevice
{
uint32_t index = std::numeric_limits<uint32_t>::max();
VkPhysicalDevice device = VK_NULL_HANDLE;
VkPhysicalDeviceProperties properties{};
VkPhysicalDeviceDescriptorIndexingPropertiesEXT descriptorIndexingProperties{};
VkPhysicalDeviceMemoryProperties memoryProperties{};
VkPhysicalDeviceFeatures features{};
VkPhysicalDeviceDescriptorIndexingFeaturesEXT descriptorIndexingFeatures{};
std::vector<VkQueueFamilyProperties> queueFamilies;
bool hasRequiredExtensions = false;
bool hasOutputToSurfaceSupport = false;
size_t graphicsQueueFamilyIndex = 0;
size_t presentQueueFamilyIndex = 0;
VkDeviceSize deviceTotalMemory = 0;
VkDeviceSize hostTotalMemory = 0;
std::vector<std::string> extensions;
VkSurfaceCapabilitiesKHR surfaceCapabilities;
std::vector<VkSurfaceFormatKHR> surfaceFormats;
std::vector<VkPresentModeKHR> presentModes;
};
/**
* @return all available physical devices for the Vulkan instance with
* additional flags of surface and required extensions support.
* We could have a single function that returns a selected device. But we use
* multiple functions to be able to save some information about available
* devices before filtering and give a choice to a user.
*/
std::vector<SAvailablePhysicalDevice> GetAvailablePhysicalDevices(
VkInstance instance, VkSurfaceKHR surface,
const std::vector<const char*>& requiredDeviceExtensions);
/**
* @return true if we can't use the device for our needs. For example, it
* doesn't graphics or present queues. Because we can't render the game without
* them.
*/
bool IsPhysicalDeviceUnsupported(const SAvailablePhysicalDevice& device);
/**
* @return true if the first device is better for our needs than the second
* one. Useful in functions like std::sort. The first and the second devices
* should be supported (in other words IsPhysicalDeviceSupported should
* return true for both of them).
*/
bool ComparePhysicalDevices(
const SAvailablePhysicalDevice& device1,
const SAvailablePhysicalDevice& device2);
bool IsSurfaceFormatSupported(
const VkSurfaceFormatKHR& surfaceFormat);
/**
* Report all desired information about the available physical device.
*/
void ReportAvailablePhysicalDevice(const SAvailablePhysicalDevice& device,
const ScriptRequest& rq, JS::HandleValue settings);
} // namespace Vulkan
} // namespace Backend
} // namespace Renderer
#endif // INCLUDED_RENDERER_BACKEND_VULKAN_DEVICESELECTION
|