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