summaryrefslogtreecommitdiff
path: root/drivers/vulkan/vulkan_context.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vulkan/vulkan_context.h')
-rw-r--r--drivers/vulkan/vulkan_context.h180
1 files changed, 128 insertions, 52 deletions
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index 9ebea42ecb..ae7c697be8 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,44 +31,83 @@
#ifndef VULKAN_CONTEXT_H
#define VULKAN_CONTEXT_H
-#include "core/error_list.h"
-#include "core/map.h"
+#include "core/error/error_list.h"
#include "core/os/mutex.h"
-#include "core/rid_owner.h"
-#include "core/ustring.h"
+#include "core/string/ustring.h"
+#include "core/templates/map.h"
+#include "core/templates/rid_owner.h"
#include "servers/display_server.h"
+
+#ifdef USE_VOLK
+#include <volk.h>
+#else
#include <vulkan/vulkan.h>
+#endif
class VulkanContext {
+public:
+ struct SubgroupCapabilities {
+ uint32_t size;
+ VkShaderStageFlags supportedStages;
+ VkSubgroupFeatureFlags supportedOperations;
+ VkBool32 quadOperationsInAllStages;
+
+ uint32_t supported_stages_flags_rd() const;
+ String supported_stages_desc() const;
+ uint32_t supported_operations_flags_rd() const;
+ String supported_operations_desc() const;
+ };
+
+ struct MultiviewCapabilities {
+ bool is_supported;
+ bool geometry_shader_is_supported;
+ bool tessellation_shader_is_supported;
+ uint32_t max_view_count;
+ uint32_t max_instance_count;
+ };
+
+private:
enum {
MAX_EXTENSIONS = 128,
MAX_LAYERS = 64,
FRAME_LAG = 2
};
- VkInstance inst;
- VkSurfaceKHR surface;
- VkPhysicalDevice gpu;
+ VkInstance inst = VK_NULL_HANDLE;
+ VkPhysicalDevice gpu = VK_NULL_HANDLE;
VkPhysicalDeviceProperties gpu_props;
- uint32_t queue_family_count;
- VkQueueFamilyProperties *queue_props;
- VkDevice device;
+ uint32_t queue_family_count = 0;
+ VkQueueFamilyProperties *queue_props = nullptr;
+ VkDevice device = VK_NULL_HANDLE;
bool device_initialized = false;
bool inst_initialized = false;
- //present
- bool queues_initialized;
- uint32_t graphics_queue_family_index;
- uint32_t present_queue_family_index;
- bool separate_present_queue;
- VkQueue graphics_queue;
- VkQueue present_queue;
+ // Vulkan 1.0 doesn't return version info so we assume this by default until we know otherwise
+ uint32_t vulkan_major = 1;
+ uint32_t vulkan_minor = 0;
+ uint32_t vulkan_patch = 0;
+ SubgroupCapabilities subgroup_capabilities;
+ MultiviewCapabilities multiview_capabilities;
+
+ String device_vendor;
+ String device_name;
+ String pipeline_cache_id;
+ uint32_t device_api_version = 0;
+
+ bool buffers_prepared = false;
+
+ // Present queue.
+ bool queues_initialized = false;
+ uint32_t graphics_queue_family_index = 0;
+ uint32_t present_queue_family_index = 0;
+ bool separate_present_queue = false;
+ VkQueue graphics_queue = VK_NULL_HANDLE;
+ VkQueue present_queue = VK_NULL_HANDLE;
VkColorSpaceKHR color_space;
VkFormat format;
- VkSemaphore image_acquired_semaphores[FRAME_LAG];
VkSemaphore draw_complete_semaphores[FRAME_LAG];
VkSemaphore image_ownership_semaphores[FRAME_LAG];
- int frame_index;
+ int frame_index = 0;
VkFence fences[FRAME_LAG];
VkPhysicalDeviceMemoryProperties memory_properties;
VkPhysicalDeviceFeatures physical_device_features;
@@ -78,7 +117,6 @@ class VulkanContext {
VkCommandBuffer graphics_to_present_cmd;
VkImageView view;
VkFramebuffer framebuffer;
-
} SwapchainImageResources;
struct Window {
@@ -86,36 +124,47 @@ class VulkanContext {
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
SwapchainImageResources *swapchain_image_resources = VK_NULL_HANDLE;
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
+ VkSemaphore image_acquired_semaphores[FRAME_LAG];
+ bool semaphore_acquired = false;
uint32_t current_buffer = 0;
int width = 0;
int height = 0;
- VkCommandPool present_cmd_pool; //for separate present queue
+ DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;
+ VkCommandPool present_cmd_pool = VK_NULL_HANDLE; // For separate present queue.
VkRenderPass render_pass = VK_NULL_HANDLE;
};
struct LocalDevice {
bool waiting = false;
- VkDevice device;
- VkQueue queue;
+ VkDevice device = VK_NULL_HANDLE;
+ VkQueue queue = VK_NULL_HANDLE;
};
RID_Owner<LocalDevice, true> local_device_owner;
Map<DisplayServer::WindowID, Window> windows;
- uint32_t swapchainImageCount;
+ uint32_t swapchainImageCount = 0;
+
+ // Commands.
- //commands
+ bool prepared = false;
+
+ Vector<VkCommandBuffer> command_buffer_queue;
+ int command_buffer_count = 1;
- bool prepared;
+ // Extensions.
- //extensions
- bool VK_KHR_incremental_present_enabled;
- bool VK_GOOGLE_display_timing_enabled;
- const char **instance_validation_layers;
- uint32_t enabled_extension_count;
- uint32_t enabled_layer_count;
+ bool VK_KHR_incremental_present_enabled = true;
+ bool VK_GOOGLE_display_timing_enabled = true;
+ uint32_t enabled_extension_count = 0;
const char *extension_names[MAX_EXTENSIONS];
- const char *enabled_layers[MAX_LAYERS];
+ bool enabled_debug_utils = false;
+
+ /**
+ * True if VK_EXT_debug_report extension is used. VK_EXT_debug_report is deprecated but it is
+ * still used if VK_EXT_debug_utils is not available.
+ */
+ bool enabled_debug_report = false;
PFN_vkCreateDebugUtilsMessengerEXT CreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugUtilsMessengerEXT DestroyDebugUtilsMessengerEXT;
@@ -124,6 +173,9 @@ class VulkanContext {
PFN_vkCmdEndDebugUtilsLabelEXT CmdEndDebugUtilsLabelEXT;
PFN_vkCmdInsertDebugUtilsLabelEXT CmdInsertDebugUtilsLabelEXT;
PFN_vkSetDebugUtilsObjectNameEXT SetDebugUtilsObjectNameEXT;
+ PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT;
+ PFN_vkDebugReportMessageEXT DebugReportMessageEXT;
+ PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT;
PFN_vkGetPhysicalDeviceSurfaceSupportKHR fpGetPhysicalDeviceSurfaceSupportKHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fpGetPhysicalDeviceSurfaceCapabilitiesKHR;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR fpGetPhysicalDeviceSurfaceFormatsKHR;
@@ -136,20 +188,33 @@ class VulkanContext {
PFN_vkGetRefreshCycleDurationGOOGLE fpGetRefreshCycleDurationGOOGLE;
PFN_vkGetPastPresentationTimingGOOGLE fpGetPastPresentationTimingGOOGLE;
- VkDebugUtilsMessengerEXT dbg_messenger;
+ VkDebugUtilsMessengerEXT dbg_messenger = VK_NULL_HANDLE;
+ VkDebugReportCallbackEXT dbg_debug_report = VK_NULL_HANDLE;
- Error _create_validation_layers();
+ Error _obtain_vulkan_version();
Error _initialize_extensions();
+ Error _check_capabilities();
- VkBool32 _check_layers(uint32_t check_count, const char **check_names, uint32_t layer_count, VkLayerProperties *layers);
- static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_messenger_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
+ VkBool32 _check_layers(uint32_t check_count, const char *const *check_names, uint32_t layer_count, VkLayerProperties *layers);
+ static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_messenger_callback(
+ VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData);
+ static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_report_callback(
+ VkDebugReportFlagsEXT flags,
+ VkDebugReportObjectTypeEXT objectType,
+ uint64_t object,
+ size_t location,
+ int32_t messageCode,
+ const char *pLayerPrefix,
+ const char *pMessage,
+ void *pUserData);
+
Error _create_physical_device();
- Error _initialize_queues(VkSurfaceKHR surface);
+ Error _initialize_queues(VkSurfaceKHR p_surface);
Error _create_device();
@@ -160,28 +225,27 @@ class VulkanContext {
Error _create_swap_chain();
Error _create_semaphores();
- Vector<VkCommandBuffer> command_buffer_queue;
- int command_buffer_count;
-
protected:
virtual const char *_get_platform_surface_extension() const = 0;
- // virtual VkResult _create_surface(VkSurfaceKHR *surface, VkInstance p_instance) = 0;
- virtual Error _window_create(DisplayServer::WindowID p_window_id, VkSurfaceKHR p_surface, int p_width, int p_height);
+ virtual Error _window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, VkSurfaceKHR p_surface, int p_width, int p_height);
- VkInstance _get_instance() {
- return inst;
- }
+ virtual bool _use_validation_layers();
- bool buffers_prepared;
-
- bool use_validation_layers;
+ Error _get_preferred_validation_layers(uint32_t *count, const char *const **names);
public:
+ uint32_t get_vulkan_major() const { return vulkan_major; };
+ uint32_t get_vulkan_minor() const { return vulkan_minor; };
+ SubgroupCapabilities get_subgroup_capabilities() const { return subgroup_capabilities; };
+ MultiviewCapabilities get_multiview_capabilities() const { return multiview_capabilities; };
+
VkDevice get_device();
VkPhysicalDevice get_physical_device();
+ VkInstance get_instance() { return inst; }
int get_swapchain_image_count() const;
- uint32_t get_graphics_queue() const;
+ VkQueue get_graphics_queue() const;
+ uint32_t get_graphics_queue_family_index() const;
void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
int window_get_width(DisplayServer::WindowID p_window = 0);
@@ -207,6 +271,18 @@ public:
Error swap_buffers();
Error initialize();
+ void command_begin_label(VkCommandBuffer p_command_buffer, String p_label_name, const Color p_color);
+ void command_insert_label(VkCommandBuffer p_command_buffer, String p_label_name, const Color p_color);
+ void command_end_label(VkCommandBuffer p_command_buffer);
+ void set_object_name(VkObjectType p_object_type, uint64_t p_object_handle, String p_object_name);
+
+ String get_device_vendor_name() const;
+ String get_device_name() const;
+ String get_device_pipeline_cache_uuid() const;
+
+ void set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_mode);
+ DisplayServer::VSyncMode get_vsync_mode(DisplayServer::WindowID p_window = 0) const;
+
VulkanContext();
virtual ~VulkanContext();
};