LCOV - code coverage report
Current view: top level - source/renderer/backend/vulkan - DeviceSelection.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 2 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2023 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 "scriptinterface/ScriptForward.h"
      22             : 
      23             : #include <glad/vulkan.h>
      24             : #include <limits>
      25             : #include <vector>
      26             : 
      27             : namespace Renderer
      28             : {
      29             : 
      30             : namespace Backend
      31             : {
      32             : 
      33             : namespace Vulkan
      34             : {
      35             : 
      36             : /**
      37             :  * Structure to store all information that might be useful on device selection.
      38             :  */
      39           0 : struct SAvailablePhysicalDevice
      40             : {
      41           0 :     uint32_t index = std::numeric_limits<uint32_t>::max();
      42             :     VkPhysicalDevice device = VK_NULL_HANDLE;
      43             :     VkPhysicalDeviceProperties properties{};
      44             :     VkPhysicalDeviceDescriptorIndexingPropertiesEXT descriptorIndexingProperties{};
      45             :     VkPhysicalDeviceMemoryProperties memoryProperties{};
      46             :     VkPhysicalDeviceFeatures features{};
      47             :     VkPhysicalDeviceDescriptorIndexingFeaturesEXT descriptorIndexingFeatures{};
      48             :     std::vector<VkQueueFamilyProperties> queueFamilies;
      49             :     bool hasRequiredExtensions = false;
      50             :     bool hasOutputToSurfaceSupport = false;
      51             :     size_t graphicsQueueFamilyIndex = 0;
      52             :     size_t presentQueueFamilyIndex = 0;
      53             :     VkDeviceSize deviceTotalMemory = 0;
      54             :     VkDeviceSize hostTotalMemory = 0;
      55             :     std::vector<std::string> extensions;
      56             :     VkSurfaceCapabilitiesKHR surfaceCapabilities;
      57             :     std::vector<VkSurfaceFormatKHR> surfaceFormats;
      58             :     std::vector<VkPresentModeKHR> presentModes;
      59             : };
      60             : 
      61             : /**
      62             :  * @return all available physical devices for the Vulkan instance with
      63             :  * additional flags of surface and required extensions support.
      64             :  * We could have a single function that returns a selected device. But we use
      65             :  * multiple functions to be able to save some information about available
      66             :  * devices before filtering and give a choice to a user.
      67             :  */
      68             : std::vector<SAvailablePhysicalDevice> GetAvailablePhysicalDevices(
      69             :     VkInstance instance, VkSurfaceKHR surface,
      70             :     const std::vector<const char*>& requiredDeviceExtensions);
      71             : 
      72             : /**
      73             :  * @return true if we can't use the device for our needs. For example, it
      74             :  * doesn't graphics or present queues. Because we can't render the game without
      75             :  * them.
      76             :  */
      77             : bool IsPhysicalDeviceUnsupported(const SAvailablePhysicalDevice& device);
      78             : 
      79             : /**
      80             :  * @return true if the first device is better for our needs than the second
      81             :  * one. Useful in functions like std::sort. The first and the second devices
      82             :  * should be supported (in other words IsPhysicalDeviceSupported should
      83             :  * return true for both of them).
      84             :  */
      85             : bool ComparePhysicalDevices(
      86             :     const SAvailablePhysicalDevice& device1,
      87             :     const SAvailablePhysicalDevice& device2);
      88             : 
      89             : bool IsSurfaceFormatSupported(
      90             :     const VkSurfaceFormatKHR& surfaceFormat);
      91             : 
      92             : /**
      93             :  * Report all desired information about the available physical device.
      94             :  */
      95             : void ReportAvailablePhysicalDevice(const SAvailablePhysicalDevice& device,
      96             :     const ScriptRequest& rq, JS::HandleValue settings);
      97             : 
      98             : } // namespace Vulkan
      99             : 
     100             : } // namespace Backend
     101             : 
     102             : } // namespace Renderer
     103             : 
     104             : #endif // INCLUDED_RENDERER_BACKEND_VULKAN_DEVICESELECTION

Generated by: LCOV version 1.13