feat: updated engine version to 4.4-rc1

This commit is contained in:
Sara 2025-02-23 14:38:14 +01:00
parent ee00efde1f
commit 21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *
Import("env")

View file

@ -0,0 +1,42 @@
/**************************************************************************/
/* godot_vulkan.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_VULKAN_H
#define GODOT_VULKAN_H
#ifdef USE_VOLK
#include <volk.h>
#else
#include <stdint.h>
#define VK_NO_STDINT_H
#include <vulkan/vulkan.h>
#endif
#endif // GODOT_VULKAN_H

View file

@ -40,21 +40,355 @@
#include "rendering_device_driver_vulkan.h"
#include "vulkan_hooks.h"
#if defined(VK_TRACK_DRIVER_MEMORY)
/*************************************************/
// Driver memory tracking
/*************************************************/
// Total driver memory and allocation amount.
SafeNumeric<size_t> driver_memory_total_memory;
SafeNumeric<size_t> driver_memory_total_alloc_count;
// Amount of driver memory for every object type.
SafeNumeric<size_t> driver_memory_tracker[RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_COUNT][RenderingContextDriverVulkan::VK_TRACKED_SYSTEM_ALLOCATION_SCOPE_COUNT];
// Amount of allocations for every object type.
SafeNumeric<uint32_t> driver_memory_allocation_count[RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_COUNT][RenderingContextDriverVulkan::VK_TRACKED_SYSTEM_ALLOCATION_SCOPE_COUNT];
#endif
#if defined(VK_TRACK_DEVICE_MEMORY)
/*************************************************/
// Device memory report
/*************************************************/
// Total device memory and allocation amount.
HashMap<uint64_t, size_t> memory_report_table;
// Total memory and allocation amount.
SafeNumeric<uint64_t> memory_report_total_memory;
SafeNumeric<uint64_t> memory_report_total_alloc_count;
// Amount of device memory for every object type.
SafeNumeric<size_t> memory_report_mem_usage[RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_COUNT];
// Amount of device memory allocations for every object type.
SafeNumeric<size_t> memory_report_allocation_count[RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_COUNT];
#endif
const char *RenderingContextDriverVulkan::get_tracked_object_name(uint32_t p_type_index) const {
#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
static constexpr const char *vkTrackedObjectTypeNames[] = { "UNKNOWN",
"INSTANCE",
"PHYSICAL_DEVICE",
"DEVICE",
"QUEUE",
"SEMAPHORE",
"COMMAND_BUFFER",
"FENCE",
"DEVICE_MEMORY",
"BUFFER",
"IMAGE",
"EVENT",
"QUERY_POOL",
"BUFFER_VIEW",
"IMAGE_VIEW",
"SHADER_MODULE",
"PIPELINE_CACHE",
"PIPELINE_LAYOUT",
"RENDER_PASS",
"PIPELINE",
"DESCRIPTOR_SET_LAYOUT",
"SAMPLER",
"DESCRIPTOR_POOL",
"DESCRIPTOR_SET",
"FRAMEBUFFER",
"COMMAND_POOL",
"DESCRIPTOR_UPDATE_TEMPLATE_KHR",
"SURFACE_KHR",
"SWAPCHAIN_KHR",
"DEBUG_UTILS_MESSENGER_EXT",
"DEBUG_REPORT_CALLBACK_EXT",
"ACCELERATION_STRUCTURE",
"VMA_BUFFER_OR_IMAGE" };
return vkTrackedObjectTypeNames[p_type_index];
#else
return "VK_TRACK_*_MEMORY disabled at build time";
#endif
}
#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
uint64_t RenderingContextDriverVulkan::get_tracked_object_type_count() const {
return VK_TRACKED_OBJECT_TYPE_COUNT;
}
#endif
#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
RenderingContextDriverVulkan::VkTrackedObjectType vk_object_to_tracked_object(VkObjectType p_type) {
if (p_type > VK_OBJECT_TYPE_COMMAND_POOL && p_type != (VkObjectType)RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_VMA) {
switch (p_type) {
case VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE:
return RenderingContextDriverVulkan::VK_TRACKED_OBJECT_DESCRIPTOR_UPDATE_TEMPLATE_KHR;
case VK_OBJECT_TYPE_SURFACE_KHR:
return RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_SURFACE;
case VK_OBJECT_TYPE_SWAPCHAIN_KHR:
return RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_SWAPCHAIN;
case VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT:
return RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT;
case VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT:
return RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT;
case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR:
case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV:
return RenderingContextDriverVulkan::VK_TRACKED_OBJECT_TYPE_ACCELERATION_STRUCTURE;
default:
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Unknown VkObjectType enum value " + itos((uint32_t)p_type) + ".Please add it to VkTrackedObjectType, switch statement in "
"vk_object_to_tracked_object and get_tracked_object_name.",
(int)p_type);
return (RenderingContextDriverVulkan::VkTrackedObjectType)VK_OBJECT_TYPE_UNKNOWN;
}
}
return (RenderingContextDriverVulkan::VkTrackedObjectType)p_type;
}
#endif
#if defined(VK_TRACK_DEVICE_MEMORY)
uint64_t RenderingContextDriverVulkan::get_device_total_memory() const {
return memory_report_total_memory.get();
}
uint64_t RenderingContextDriverVulkan::get_device_allocation_count() const {
return memory_report_total_alloc_count.get();
}
uint64_t RenderingContextDriverVulkan::get_device_memory_by_object_type(uint32_t p_type) const {
return memory_report_mem_usage[p_type].get();
}
uint64_t RenderingContextDriverVulkan::get_device_allocs_by_object_type(uint32_t p_type) const {
return memory_report_allocation_count[p_type].get();
}
#endif
#if defined(VK_TRACK_DRIVER_MEMORY)
uint64_t RenderingContextDriverVulkan::get_driver_total_memory() const {
return driver_memory_total_memory.get();
}
uint64_t RenderingContextDriverVulkan::get_driver_allocation_count() const {
return driver_memory_total_alloc_count.get();
}
uint64_t RenderingContextDriverVulkan::get_driver_memory_by_object_type(uint32_t p_type) const {
uint64_t ret = 0;
for (uint32_t i = 0; i < VK_TRACKED_SYSTEM_ALLOCATION_SCOPE_COUNT; i++) {
ret += driver_memory_tracker[p_type][i].get();
}
return ret;
}
uint64_t RenderingContextDriverVulkan::get_driver_allocs_by_object_type(uint32_t p_type) const {
uint64_t ret = 0;
for (uint32_t i = 0; i < VK_TRACKED_SYSTEM_ALLOCATION_SCOPE_COUNT; i++) {
ret += driver_memory_allocation_count[p_type][i].get();
}
return ret;
}
#endif
#if defined(VK_TRACK_DEVICE_MEMORY)
void RenderingContextDriverVulkan::memory_report_callback(const VkDeviceMemoryReportCallbackDataEXT *p_callback_data, void *p_user_data) {
if (!p_callback_data) {
return;
}
const RenderingContextDriverVulkan::VkTrackedObjectType obj_type = vk_object_to_tracked_object(p_callback_data->objectType);
uint64_t obj_id = p_callback_data->memoryObjectId;
if (p_callback_data->type == VK_DEVICE_MEMORY_REPORT_EVENT_TYPE_ALLOCATE_EXT) {
// Realloc, update size
if (memory_report_table.has(obj_id)) {
memory_report_total_memory.sub(memory_report_table[obj_id]);
memory_report_mem_usage[obj_type].sub(memory_report_table[obj_id]);
memory_report_total_memory.add(p_callback_data->size);
memory_report_mem_usage[obj_type].add(p_callback_data->size);
memory_report_table[p_callback_data->memoryObjectId] = p_callback_data->size;
} else {
memory_report_table[obj_id] = p_callback_data->size;
memory_report_total_alloc_count.increment();
memory_report_allocation_count[obj_type].increment();
memory_report_mem_usage[obj_type].add(p_callback_data->size);
memory_report_total_memory.add(p_callback_data->size);
}
} else if (p_callback_data->type == VK_DEVICE_MEMORY_REPORT_EVENT_TYPE_FREE_EXT) {
if (memory_report_table.has(obj_id)) {
memory_report_total_alloc_count.decrement();
memory_report_allocation_count[obj_type].decrement();
memory_report_mem_usage[obj_type].sub(p_callback_data->size);
memory_report_total_memory.sub(p_callback_data->size);
memory_report_table.remove(memory_report_table.find(obj_id));
}
}
}
#endif
VkAllocationCallbacks *RenderingContextDriverVulkan::get_allocation_callbacks(VkObjectType p_type) {
#if !defined(VK_TRACK_DRIVER_MEMORY)
return nullptr;
#else
if (!Engine::get_singleton()->is_extra_gpu_memory_tracking_enabled()) {
return nullptr;
}
#ifdef _MSC_VER
#define LAMBDA_VK_CALL_CONV
#else
#define LAMBDA_VK_CALL_CONV VKAPI_PTR
#endif
struct TrackedMemHeader {
size_t size;
VkSystemAllocationScope allocation_scope;
VkTrackedObjectType type;
};
VkAllocationCallbacks tracking_callbacks = {
// Allocation function
nullptr,
[](
void *p_user_data,
size_t size,
size_t alignment,
VkSystemAllocationScope allocation_scope) LAMBDA_VK_CALL_CONV -> void * {
static constexpr size_t tracking_data_size = 32;
VkTrackedObjectType type = static_cast<VkTrackedObjectType>(*reinterpret_cast<VkTrackedObjectType *>(p_user_data));
driver_memory_total_memory.add(size);
driver_memory_total_alloc_count.increment();
driver_memory_tracker[type][allocation_scope].add(size);
driver_memory_allocation_count[type][allocation_scope].increment();
alignment = MAX(alignment, tracking_data_size);
uint8_t *ret = reinterpret_cast<uint8_t *>(Memory::alloc_aligned_static(size + alignment, alignment));
if (ret == nullptr) {
return nullptr;
}
// Track allocation
TrackedMemHeader *header = reinterpret_cast<TrackedMemHeader *>(ret);
header->size = size;
header->allocation_scope = allocation_scope;
header->type = type;
*reinterpret_cast<size_t *>(ret + alignment - sizeof(size_t)) = alignment;
// Return first available chunk of memory
return ret + alignment;
},
// Reallocation function
[](
void *p_user_data,
void *p_original,
size_t size,
size_t alignment,
VkSystemAllocationScope allocation_scope) LAMBDA_VK_CALL_CONV -> void * {
if (p_original == nullptr) {
VkObjectType type = static_cast<VkObjectType>(*reinterpret_cast<uint32_t *>(p_user_data));
return get_allocation_callbacks(type)->pfnAllocation(p_user_data, size, alignment, allocation_scope);
}
uint8_t *mem = reinterpret_cast<uint8_t *>(p_original);
// Retrieve alignment
alignment = *reinterpret_cast<size_t *>(mem - sizeof(size_t));
// Retrieve allocation data
TrackedMemHeader *header = reinterpret_cast<TrackedMemHeader *>(mem - alignment);
// Update allocation size
driver_memory_total_memory.sub(header->size);
driver_memory_total_memory.add(size);
driver_memory_tracker[header->type][header->allocation_scope].sub(header->size);
driver_memory_tracker[header->type][header->allocation_scope].add(size);
uint8_t *ret = reinterpret_cast<uint8_t *>(Memory::realloc_aligned_static(header, size + alignment, header->size + alignment, alignment));
if (ret == nullptr) {
return nullptr;
}
// Update tracker
header = reinterpret_cast<TrackedMemHeader *>(ret);
header->size = size;
return ret + alignment;
},
// Free function
[](
void *p_user_data,
void *p_memory) LAMBDA_VK_CALL_CONV {
if (!p_memory) {
return;
}
uint8_t *mem = reinterpret_cast<uint8_t *>(p_memory);
size_t alignment = *reinterpret_cast<size_t *>(mem - sizeof(size_t));
TrackedMemHeader *header = reinterpret_cast<TrackedMemHeader *>(mem - alignment);
driver_memory_total_alloc_count.decrement();
driver_memory_total_memory.sub(header->size);
driver_memory_tracker[header->type][header->allocation_scope].sub(header->size);
driver_memory_allocation_count[header->type][header->allocation_scope].decrement();
Memory::free_aligned_static(header);
},
// Internal allocation / deallocation. We don't track them as they cannot really be controlled or optimized by the programmer.
[](
void *p_user_data,
size_t size,
VkInternalAllocationType allocation_type,
VkSystemAllocationScope allocation_scope) LAMBDA_VK_CALL_CONV {
},
[](
void *p_user_data,
size_t size,
VkInternalAllocationType allocation_type,
VkSystemAllocationScope allocation_scope) LAMBDA_VK_CALL_CONV {
},
};
// Create a callback per object type
static VkAllocationCallbacks object_callbacks[VK_TRACKED_OBJECT_TYPE_COUNT] = {};
static uint32_t object_user_data[VK_TRACKED_OBJECT_TYPE_COUNT] = {};
// Only build the first time
if (!object_callbacks[0].pfnAllocation) {
for (uint32_t c = 0; c < VK_TRACKED_OBJECT_TYPE_COUNT; ++c) {
object_callbacks[c] = tracking_callbacks;
object_user_data[c] = c;
object_callbacks[c].pUserData = &object_user_data[c];
for (uint32_t i = 0; i < VK_TRACKED_SYSTEM_ALLOCATION_SCOPE_COUNT; i++) {
driver_memory_tracker[c][i].set(0);
driver_memory_allocation_count[c][i].set(0);
}
}
}
uint32_t type_index = vk_object_to_tracked_object(p_type);
return &object_callbacks[type_index];
#endif
}
RenderingContextDriverVulkan::RenderingContextDriverVulkan() {
// Empty constructor.
}
RenderingContextDriverVulkan::~RenderingContextDriverVulkan() {
if (debug_messenger != VK_NULL_HANDLE && functions.DestroyDebugUtilsMessengerEXT != nullptr) {
functions.DestroyDebugUtilsMessengerEXT(instance, debug_messenger, nullptr);
functions.DestroyDebugUtilsMessengerEXT(instance, debug_messenger, get_allocation_callbacks(VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT));
}
if (debug_report != VK_NULL_HANDLE && functions.DestroyDebugReportCallbackEXT != nullptr) {
functions.DestroyDebugReportCallbackEXT(instance, debug_report, nullptr);
functions.DestroyDebugReportCallbackEXT(instance, debug_report, get_allocation_callbacks(VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT));
}
if (instance != VK_NULL_HANDLE) {
vkDestroyInstance(instance, nullptr);
vkDestroyInstance(instance, get_allocation_callbacks(VK_OBJECT_TYPE_INSTANCE));
}
}
@ -441,7 +775,7 @@ Error RenderingContextDriverVulkan::_initialize_instance() {
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "GetProcAddr: Failed to init VK_EXT_debug_utils\nGetProcAddr: Failure");
}
VkResult res = functions.CreateDebugUtilsMessengerEXT(instance, &debug_messenger_create_info, nullptr, &debug_messenger);
VkResult res = functions.CreateDebugUtilsMessengerEXT(instance, &debug_messenger_create_info, get_allocation_callbacks(VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT), &debug_messenger);
switch (res) {
case VK_SUCCESS:
break;
@ -461,7 +795,7 @@ Error RenderingContextDriverVulkan::_initialize_instance() {
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "GetProcAddr: Failed to init VK_EXT_debug_report\nGetProcAddr: Failure");
}
VkResult res = functions.CreateDebugReportCallbackEXT(instance, &debug_report_callback_create_info, nullptr, &debug_report);
VkResult res = functions.CreateDebugReportCallbackEXT(instance, &debug_report_callback_create_info, get_allocation_callbacks(VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT), &debug_report);
switch (res) {
case VK_SUCCESS:
break;
@ -509,7 +843,7 @@ Error RenderingContextDriverVulkan::_initialize_devices() {
Device &driver_device = driver_devices[i];
driver_device.name = String::utf8(props.deviceName);
driver_device.vendor = Vendor(props.vendorID);
driver_device.vendor = props.vendorID;
driver_device.type = DeviceType(props.deviceType);
driver_device.workarounds = Workarounds();
@ -546,7 +880,7 @@ void RenderingContextDriverVulkan::_check_driver_workarounds(const VkPhysicalDev
// This bug was fixed in driver version 512.503.0, so we only enabled it on devices older than this.
//
r_device.workarounds.avoid_compute_after_draw =
r_device.vendor == VENDOR_QUALCOMM &&
r_device.vendor == Vendor::VENDOR_QUALCOMM &&
p_device_properties.deviceID >= 0x6000000 && // Adreno 6xx
p_device_properties.driverVersion < VK_MAKE_VERSION(512, 503, 0) &&
r_device.name.find("Turnip") < 0;
@ -560,7 +894,7 @@ Error RenderingContextDriverVulkan::_create_vulkan_instance(const VkInstanceCrea
if (VulkanHooks::get_singleton() != nullptr) {
return VulkanHooks::get_singleton()->create_vulkan_instance(p_create_info, r_instance) ? OK : ERR_CANT_CREATE;
} else {
VkResult err = vkCreateInstance(p_create_info, nullptr, r_instance);
VkResult err = vkCreateInstance(p_create_info, get_allocation_callbacks(VK_OBJECT_TYPE_INSTANCE), r_instance);
ERR_FAIL_COND_V_MSG(err == VK_ERROR_INCOMPATIBLE_DRIVER, ERR_CANT_CREATE,
"Cannot find a compatible Vulkan installable client driver (ICD).\n\n"
"vkCreateInstance Failure");
@ -679,7 +1013,7 @@ bool RenderingContextDriverVulkan::surface_get_needs_resize(SurfaceID p_surface)
void RenderingContextDriverVulkan::surface_destroy(SurfaceID p_surface) {
Surface *surface = (Surface *)(p_surface);
vkDestroySurfaceKHR(instance, surface->vk_surface, nullptr);
vkDestroySurfaceKHR(instance, surface->vk_surface, get_allocation_callbacks(VK_OBJECT_TYPE_SURFACE_KHR));
memdelete(surface);
}

View file

@ -35,12 +35,13 @@
#include "servers/rendering/rendering_context_driver.h"
#ifdef USE_VOLK
#include <volk.h>
#else
#include <vulkan/vulkan.h>
#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
#define VK_TRACK_DRIVER_MEMORY
#define VK_TRACK_DEVICE_MEMORY
#endif
#include "drivers/vulkan/godot_vulkan.h"
class RenderingContextDriverVulkan : public RenderingContextDriver {
public:
struct Functions {
@ -77,6 +78,12 @@ public:
PFN_vkDebugReportMessageEXT DebugReportMessageEXT = nullptr;
PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT = nullptr;
// Debug marker extensions.
PFN_vkCmdDebugMarkerBeginEXT CmdDebugMarkerBeginEXT = nullptr;
PFN_vkCmdDebugMarkerEndEXT CmdDebugMarkerEndEXT = nullptr;
PFN_vkCmdDebugMarkerInsertEXT CmdDebugMarkerInsertEXT = nullptr;
PFN_vkDebugMarkerSetObjectNameEXT DebugMarkerSetObjectNameEXT = nullptr;
bool debug_report_functions_available() const {
return CreateDebugReportCallbackEXT != nullptr &&
DebugReportMessageEXT != nullptr &&
@ -110,6 +117,8 @@ private:
// Static callbacks.
static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_messenger_callback(VkDebugUtilsMessageSeverityFlagBitsEXT p_message_severity, VkDebugUtilsMessageTypeFlagsEXT p_message_type, const VkDebugUtilsMessengerCallbackDataEXT *p_callback_data, void *p_user_data);
static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_report_callback(VkDebugReportFlagsEXT p_flags, VkDebugReportObjectTypeEXT p_object_type, uint64_t p_object, size_t p_location, int32_t p_message_code, const char *p_layer_prefix, const char *p_message, void *p_user_data);
// Debug marker extensions.
VkDebugReportObjectTypeEXT _convert_to_debug_report_objectType(VkObjectType p_object_type);
protected:
Error _find_validation_layers(TightLocalVector<const char *> &r_layer_names) const;
@ -153,6 +162,45 @@ public:
bool queue_family_supports_present(VkPhysicalDevice p_physical_device, uint32_t p_queue_family_index, SurfaceID p_surface) const;
const Functions &functions_get() const;
static VkAllocationCallbacks *get_allocation_callbacks(VkObjectType p_type);
#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
enum VkTrackedObjectType {
VK_TRACKED_OBJECT_DESCRIPTOR_UPDATE_TEMPLATE_KHR = VK_OBJECT_TYPE_COMMAND_POOL + 1,
VK_TRACKED_OBJECT_TYPE_SURFACE,
VK_TRACKED_OBJECT_TYPE_SWAPCHAIN,
VK_TRACKED_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT,
VK_TRACKED_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT,
VK_TRACKED_OBJECT_TYPE_ACCELERATION_STRUCTURE,
VK_TRACKED_OBJECT_TYPE_VMA,
VK_TRACKED_OBJECT_TYPE_COUNT
};
enum VkTrackedSystemAllocationScope {
VK_TRACKED_SYSTEM_ALLOCATION_SCOPE_COUNT = VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE + 1
};
#endif
const char *get_tracked_object_name(uint32_t p_type_index) const override;
#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
uint64_t get_tracked_object_type_count() const override;
#endif
#if defined(VK_TRACK_DRIVER_MEMORY)
uint64_t get_driver_total_memory() const override;
uint64_t get_driver_allocation_count() const override;
uint64_t get_driver_memory_by_object_type(uint32_t p_type) const override;
uint64_t get_driver_allocs_by_object_type(uint32_t p_type) const override;
#endif
#if defined(VK_TRACK_DEVICE_MEMORY)
uint64_t get_device_total_memory() const override;
uint64_t get_device_allocation_count() const override;
uint64_t get_device_memory_by_object_type(uint32_t p_type) const override;
uint64_t get_device_allocs_by_object_type(uint32_t p_type) const override;
static VKAPI_ATTR void VKAPI_CALL memory_report_callback(const VkDeviceMemoryReportCallbackDataEXT *p_callback_data, void *p_user_data);
#endif
RenderingContextDriverVulkan();
virtual ~RenderingContextDriverVulkan() override;
};

File diff suppressed because it is too large Load diff

View file

@ -43,11 +43,7 @@
#endif
#include "thirdparty/vulkan/vk_mem_alloc.h"
#ifdef USE_VOLK
#include <volk.h>
#else
#include <vulkan/vulkan.h>
#endif
#include "drivers/vulkan/godot_vulkan.h"
// Design principles:
// - Vulkan structs are zero-initialized and fields not requiring a non-zero value are omitted (except in cases where expresivity reasons apply).
@ -111,7 +107,18 @@ class RenderingDeviceDriverVulkan : public RenderingDeviceDriver {
PFN_vkAcquireNextImageKHR AcquireNextImageKHR = nullptr;
PFN_vkQueuePresentKHR QueuePresentKHR = nullptr;
PFN_vkCreateRenderPass2KHR CreateRenderPass2KHR = nullptr;
// Debug marker extensions.
PFN_vkCmdDebugMarkerBeginEXT CmdDebugMarkerBeginEXT = nullptr;
PFN_vkCmdDebugMarkerEndEXT CmdDebugMarkerEndEXT = nullptr;
PFN_vkCmdDebugMarkerInsertEXT CmdDebugMarkerInsertEXT = nullptr;
PFN_vkDebugMarkerSetObjectNameEXT DebugMarkerSetObjectNameEXT = nullptr;
// Debug device fault.
PFN_vkGetDeviceFaultInfoEXT GetDeviceFaultInfoEXT = nullptr;
};
// Debug marker extensions.
VkDebugReportObjectTypeEXT _convert_to_debug_report_objectType(VkObjectType p_object_type);
VkDevice vk_device = VK_NULL_HANDLE;
RenderingContextDriverVulkan *context_driver = nullptr;
@ -131,7 +138,17 @@ class RenderingDeviceDriverVulkan : public RenderingDeviceDriver {
VRSCapabilities vrs_capabilities;
ShaderCapabilities shader_capabilities;
StorageBufferCapabilities storage_buffer_capabilities;
bool buffer_device_address_support = false;
bool pipeline_cache_control_support = false;
bool device_fault_support = false;
#if defined(VK_TRACK_DEVICE_MEMORY)
bool device_memory_report_support = false;
#endif
#if defined(SWAPPY_FRAME_PACING_ENABLED)
// Swappy frame pacer for Android.
bool swappy_frame_pacer_enable = false;
uint8_t swappy_mode = 2; // See default value for display/window/frame_pacing/android/swappy_mode.
#endif
DeviceFunctions device_functions;
void _register_requested_device_extension(const CharString &p_extension_name, bool p_required);
@ -160,10 +177,18 @@ private:
VmaPool _find_or_create_small_allocs_pool(uint32_t p_mem_type_index);
private:
#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
// It's a circular buffer.
BufferID breadcrumb_buffer;
uint32_t breadcrumb_offset = 0u;
uint32_t breadcrumb_id = 0u;
#endif
public:
/*****************/
/**** BUFFERS ****/
/*****************/
private:
struct BufferInfo {
VkBuffer vk_buffer = VK_NULL_HANDLE;
struct {
@ -174,19 +199,20 @@ private:
VkBufferView vk_view = VK_NULL_HANDLE; // For texel buffers.
};
public:
virtual BufferID buffer_create(uint64_t p_size, BitField<BufferUsageBits> p_usage, MemoryAllocationType p_allocation_type) override final;
virtual bool buffer_set_texel_format(BufferID p_buffer, DataFormat p_format) override final;
virtual void buffer_free(BufferID p_buffer) override final;
virtual uint64_t buffer_get_allocation_size(BufferID p_buffer) override final;
virtual uint8_t *buffer_map(BufferID p_buffer) override final;
virtual void buffer_unmap(BufferID p_buffer) override final;
virtual uint64_t buffer_get_device_address(BufferID p_buffer) override final;
/*****************/
/**** TEXTURE ****/
/*****************/
struct TextureInfo {
VkImage vk_image = VK_NULL_HANDLE;
VkImageView vk_view = VK_NULL_HANDLE;
DataFormat rd_format = DATA_FORMAT_MAX;
VkImageCreateInfo vk_create_info = {};
@ -195,6 +221,10 @@ public:
VmaAllocation handle = nullptr;
VmaAllocationInfo info = {};
} allocation; // All 0/null if just a view.
#ifdef DEBUG_ENABLED
bool created_from_extension = false;
bool transient = false;
#endif
};
VkSampleCountFlagBits _ensure_supported_sample_count(TextureSamples p_requested_sample_count);
@ -306,6 +336,7 @@ private:
public:
virtual CommandPoolID command_pool_create(CommandQueueFamilyID p_cmd_queue_family, CommandBufferType p_cmd_buffer_type) override final;
virtual bool command_pool_reset(CommandPoolID p_cmd_pool) override final;
virtual void command_pool_free(CommandPoolID p_cmd_pool) override final;
// ----- BUFFER -----
@ -332,7 +363,11 @@ private:
LocalVector<CommandQueue *> command_queues_acquired;
LocalVector<uint32_t> command_queues_acquired_semaphores;
RenderPassID render_pass;
int pre_transform_rotation_degrees = 0;
uint32_t image_index = 0;
#ifdef ANDROID_ENABLED
uint64_t refresh_duration = 0;
#endif
};
void _swap_chain_release(SwapChain *p_swap_chain);
@ -342,13 +377,24 @@ public:
virtual Error swap_chain_resize(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, uint32_t p_desired_framebuffer_count) override final;
virtual FramebufferID swap_chain_acquire_framebuffer(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, bool &r_resize_required) override final;
virtual RenderPassID swap_chain_get_render_pass(SwapChainID p_swap_chain) override final;
virtual int swap_chain_get_pre_rotation_degrees(SwapChainID p_swap_chain) override final;
virtual DataFormat swap_chain_get_format(SwapChainID p_swap_chain) override final;
virtual void swap_chain_set_max_fps(SwapChainID p_swap_chain, int p_max_fps) override final;
virtual void swap_chain_free(SwapChainID p_swap_chain) override final;
/*********************/
/**** FRAMEBUFFER ****/
/*********************/
struct Framebuffer {
VkFramebuffer vk_framebuffer = VK_NULL_HANDLE;
// Only filled in by a framebuffer created by a swap chain. Unused otherwise.
VkImage swap_chain_image = VK_NULL_HANDLE;
VkImageSubresourceRange swap_chain_image_subresource_range = {};
bool swap_chain_acquired = false;
};
virtual FramebufferID framebuffer_create(RenderPassID p_render_pass, VectorView<TextureID> p_attachments, uint32_t p_width, uint32_t p_height) override final;
virtual void framebuffer_free(FramebufferID p_framebuffer) override final;
@ -361,7 +407,8 @@ private:
// Version 2: Added shader name.
// Version 3: Added writable.
// Version 4: 64-bit vertex input mask.
static const uint32_t VERSION = 4;
// Version 5: Add 4 bytes padding to align the Data struct after the change in version 4.
static const uint32_t VERSION = 5;
struct DataBinding {
uint32_t type = 0;
@ -402,9 +449,10 @@ private:
public:
virtual String shader_get_binary_cache_key() override final;
virtual Vector<uint8_t> shader_compile_binary_from_spirv(VectorView<ShaderStageSPIRVData> p_spirv, const String &p_shader_name) override final;
virtual ShaderID shader_create_from_bytecode(const Vector<uint8_t> &p_shader_binary, ShaderDescription &r_shader_desc, String &r_name) override final;
virtual ShaderID shader_create_from_bytecode(const Vector<uint8_t> &p_shader_binary, ShaderDescription &r_shader_desc, String &r_name, const Vector<ImmutableSampler> &p_immutable_samplers) override final;
virtual void shader_free(ShaderID p_shader) override final;
virtual void shader_destroy_modules(ShaderID p_shader) override final;
/*********************/
/**** UNIFORM SET ****/
/*********************/
@ -439,18 +487,27 @@ private:
DescriptorSetPools descriptor_set_pools;
uint32_t max_descriptor_sets_per_pool = 0;
VkDescriptorPool _descriptor_set_pool_find_or_create(const DescriptorSetPoolKey &p_key, DescriptorSetPools::Iterator *r_pool_sets_it);
void _descriptor_set_pool_unreference(DescriptorSetPools::Iterator p_pool_sets_it, VkDescriptorPool p_vk_descriptor_pool);
HashMap<int, DescriptorSetPools> linear_descriptor_set_pools;
bool linear_descriptor_pools_enabled = true;
VkDescriptorPool _descriptor_set_pool_find_or_create(const DescriptorSetPoolKey &p_key, DescriptorSetPools::Iterator *r_pool_sets_it, int p_linear_pool_index);
void _descriptor_set_pool_unreference(DescriptorSetPools::Iterator p_pool_sets_it, VkDescriptorPool p_vk_descriptor_pool, int p_linear_pool_index);
// Global flag to toggle usage of immutable sampler when creating pipeline layouts.
// It cannot change after creating the PSOs, since we need to skipping samplers when creating uniform sets.
bool immutable_samplers_enabled = true;
struct UniformSetInfo {
VkDescriptorSet vk_descriptor_set = VK_NULL_HANDLE;
VkDescriptorPool vk_descriptor_pool = VK_NULL_HANDLE;
DescriptorSetPools::Iterator pool_sets_it = {};
VkDescriptorPool vk_linear_descriptor_pool = VK_NULL_HANDLE;
DescriptorSetPools::Iterator pool_sets_it;
};
public:
virtual UniformSetID uniform_set_create(VectorView<BoundUniform> p_uniforms, ShaderID p_shader, uint32_t p_set_index) override final;
virtual UniformSetID uniform_set_create(VectorView<BoundUniform> p_uniforms, ShaderID p_shader, uint32_t p_set_index, int p_linear_pool_index) override final;
virtual void linear_uniform_set_pools_reset(int p_linear_pool_index) override final;
virtual void uniform_set_free(UniformSetID p_uniform_set) override final;
virtual bool uniform_sets_have_linear_pools() const override final;
// ----- COMMANDS -----
@ -532,6 +589,7 @@ public:
// Binding.
virtual void command_bind_render_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) override final;
virtual void command_bind_render_uniform_set(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) override final;
virtual void command_bind_render_uniform_sets(CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count) override final;
// Drawing.
virtual void command_render_draw(CommandBufferID p_cmd_buffer, uint32_t p_vertex_count, uint32_t p_instance_count, uint32_t p_base_vertex, uint32_t p_first_instance) override final;
@ -574,6 +632,7 @@ public:
// Binding.
virtual void command_bind_compute_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) override final;
virtual void command_bind_compute_uniform_set(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) override final;
virtual void command_bind_compute_uniform_sets(CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count) override final;
// Dispatching.
virtual void command_compute_dispatch(CommandBufferID p_cmd_buffer, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) override final;
@ -606,6 +665,14 @@ public:
virtual void command_begin_label(CommandBufferID p_cmd_buffer, const char *p_label_name, const Color &p_color) override final;
virtual void command_end_label(CommandBufferID p_cmd_buffer) override final;
/****************/
/**** DEBUG *****/
/****************/
virtual void command_insert_breadcrumb(CommandBufferID p_cmd_buffer, uint32_t p_data) override final;
void print_lost_device_info();
void on_device_lost() const;
static String get_vulkan_result(VkResult err);
/********************/
/**** SUBMISSION ****/
/********************/
@ -620,6 +687,7 @@ public:
virtual void set_object_name(ObjectType p_type, ID p_driver_id, const String &p_name) override final;
virtual uint64_t get_resource_native_handle(DriverResource p_type, ID p_driver_id) override final;
virtual uint64_t get_total_memory_used() override final;
virtual uint64_t get_lazily_memory_used() override final;
virtual uint64_t limit_get(Limit p_limit) override final;
virtual uint64_t api_trait_get(ApiTrait p_trait) override final;
virtual bool has_feature(Features p_feature) override final;
@ -642,7 +710,7 @@ private:
VertexFormatInfo,
ShaderInfo,
UniformSetInfo>;
PagedAllocator<VersatileResource> resources_allocator;
PagedAllocator<VersatileResource, true> resources_allocator;
/******************/
@ -651,4 +719,6 @@ public:
virtual ~RenderingDeviceDriverVulkan();
};
using VKC = RenderingContextDriverVulkan;
#endif // RENDERING_DEVICE_DRIVER_VULKAN_H

View file

@ -31,11 +31,7 @@
#ifndef VULKAN_HOOKS_H
#define VULKAN_HOOKS_H
#ifdef USE_VOLK
#include <volk.h>
#else
#include <vulkan/vulkan.h>
#endif
#include "drivers/vulkan/godot_vulkan.h"
class VulkanHooks {
private: