Path: blob/master/drivers/vulkan/rendering_device_driver_vulkan.h
9903 views
/**************************************************************************/1/* rendering_device_driver_vulkan.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/templates/hash_map.h"33#include "core/templates/paged_allocator.h"34#include "drivers/vulkan/rendering_context_driver_vulkan.h"35#include "drivers/vulkan/rendering_shader_container_vulkan.h"36#include "servers/rendering/rendering_device_driver.h"3738#ifdef DEBUG_ENABLED39#ifndef _MSC_VER40#define _DEBUG41#endif42#endif43#include "thirdparty/vulkan/vk_mem_alloc.h"4445#include "drivers/vulkan/godot_vulkan.h"4647// Design principles:48// - Vulkan structs are zero-initialized and fields not requiring a non-zero value are omitted (except in cases where expresivity reasons apply).49class RenderingDeviceDriverVulkan : public RenderingDeviceDriver {50/*****************/51/**** GENERIC ****/52/*****************/5354struct CommandQueue;55struct SwapChain;56struct CommandBufferInfo;57struct RenderPassInfo;58struct Framebuffer;5960struct Queue {61VkQueue queue = VK_NULL_HANDLE;62uint32_t virtual_count = 0;63BinaryMutex submit_mutex;64};6566struct SubgroupCapabilities {67uint32_t size = 0;68uint32_t min_size = 0;69uint32_t max_size = 0;70VkShaderStageFlags supported_stages = 0;71VkSubgroupFeatureFlags supported_operations = 0;72VkBool32 quad_operations_in_all_stages = false;73bool size_control_is_supported = false;7475uint32_t supported_stages_flags_rd() const;76String supported_stages_desc() const;77uint32_t supported_operations_flags_rd() const;78String supported_operations_desc() const;79};8081struct ShaderCapabilities {82bool shader_float16_is_supported = false;83bool shader_int8_is_supported = false;84};8586struct StorageBufferCapabilities {87bool storage_buffer_16_bit_access_is_supported = false;88bool uniform_and_storage_buffer_16_bit_access_is_supported = false;89bool storage_push_constant_16_is_supported = false;90bool storage_input_output_16 = false;91};9293struct DeviceFunctions {94PFN_vkCreateSwapchainKHR CreateSwapchainKHR = nullptr;95PFN_vkDestroySwapchainKHR DestroySwapchainKHR = nullptr;96PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR = nullptr;97PFN_vkAcquireNextImageKHR AcquireNextImageKHR = nullptr;98PFN_vkQueuePresentKHR QueuePresentKHR = nullptr;99PFN_vkCreateRenderPass2KHR CreateRenderPass2KHR = nullptr;100PFN_vkCmdEndRenderPass2KHR EndRenderPass2KHR = nullptr;101102// Debug marker extensions.103PFN_vkCmdDebugMarkerBeginEXT CmdDebugMarkerBeginEXT = nullptr;104PFN_vkCmdDebugMarkerEndEXT CmdDebugMarkerEndEXT = nullptr;105PFN_vkCmdDebugMarkerInsertEXT CmdDebugMarkerInsertEXT = nullptr;106PFN_vkDebugMarkerSetObjectNameEXT DebugMarkerSetObjectNameEXT = nullptr;107108// Debug device fault.109PFN_vkGetDeviceFaultInfoEXT GetDeviceFaultInfoEXT = nullptr;110};111// Debug marker extensions.112VkDebugReportObjectTypeEXT _convert_to_debug_report_objectType(VkObjectType p_object_type);113114VkDevice vk_device = VK_NULL_HANDLE;115RenderingContextDriverVulkan *context_driver = nullptr;116RenderingContextDriver::Device context_device = {};117uint32_t frame_count = 1;118VkPhysicalDevice physical_device = VK_NULL_HANDLE;119VkPhysicalDeviceProperties physical_device_properties = {};120VkPhysicalDeviceFeatures physical_device_features = {};121VkPhysicalDeviceFeatures requested_device_features = {};122HashMap<CharString, bool> requested_device_extensions;123HashSet<CharString> enabled_device_extension_names;124TightLocalVector<TightLocalVector<Queue>> queue_families;125TightLocalVector<VkQueueFamilyProperties> queue_family_properties;126RDD::Capabilities device_capabilities;127SubgroupCapabilities subgroup_capabilities;128MultiviewCapabilities multiview_capabilities;129FragmentShadingRateCapabilities fsr_capabilities;130FragmentDensityMapCapabilities fdm_capabilities;131ShaderCapabilities shader_capabilities;132StorageBufferCapabilities storage_buffer_capabilities;133RenderingShaderContainerFormatVulkan shader_container_format;134bool buffer_device_address_support = false;135bool vulkan_memory_model_support = false;136bool vulkan_memory_model_device_scope_support = false;137bool pipeline_cache_control_support = false;138bool device_fault_support = false;139#if defined(VK_TRACK_DEVICE_MEMORY)140bool device_memory_report_support = false;141#endif142#if defined(SWAPPY_FRAME_PACING_ENABLED)143// Swappy frame pacer for Android.144bool swappy_frame_pacer_enable = false;145uint8_t swappy_mode = 2; // See default value for display/window/frame_pacing/android/swappy_mode.146#endif147DeviceFunctions device_functions;148149void _register_requested_device_extension(const CharString &p_extension_name, bool p_required);150Error _initialize_device_extensions();151Error _check_device_features();152Error _check_device_capabilities();153void _choose_vrs_capabilities();154Error _add_queue_create_info(LocalVector<VkDeviceQueueCreateInfo> &r_queue_create_info);155Error _initialize_device(const LocalVector<VkDeviceQueueCreateInfo> &p_queue_create_info);156Error _initialize_allocator();157Error _initialize_pipeline_cache();158VkResult _create_render_pass(VkDevice p_device, const VkRenderPassCreateInfo2 *p_create_info, const VkAllocationCallbacks *p_allocator, VkRenderPass *p_render_pass);159bool _release_image_semaphore(CommandQueue *p_command_queue, uint32_t p_semaphore_index, bool p_release_on_swap_chain);160bool _recreate_image_semaphore(CommandQueue *p_command_queue, uint32_t p_semaphore_index, bool p_release_on_swap_chain);161void _set_object_name(VkObjectType p_object_type, uint64_t p_object_handle, String p_object_name);162163public:164Error initialize(uint32_t p_device_index, uint32_t p_frame_count) override final;165166private:167/****************/168/**** MEMORY ****/169/****************/170171VmaAllocator allocator = nullptr;172HashMap<uint32_t, VmaPool> small_allocs_pools;173174VmaPool _find_or_create_small_allocs_pool(uint32_t p_mem_type_index);175176private:177#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)178// It's a circular buffer.179BufferID breadcrumb_buffer;180uint32_t breadcrumb_offset = 0u;181uint32_t breadcrumb_id = 0u;182#endif183184public:185/*****************/186/**** BUFFERS ****/187/*****************/188struct BufferInfo {189VkBuffer vk_buffer = VK_NULL_HANDLE;190struct {191VmaAllocation handle = nullptr;192uint64_t size = UINT64_MAX;193} allocation;194uint64_t size = 0;195VkBufferView vk_view = VK_NULL_HANDLE; // For texel buffers.196};197198virtual BufferID buffer_create(uint64_t p_size, BitField<BufferUsageBits> p_usage, MemoryAllocationType p_allocation_type) override final;199virtual bool buffer_set_texel_format(BufferID p_buffer, DataFormat p_format) override final;200virtual void buffer_free(BufferID p_buffer) override final;201virtual uint64_t buffer_get_allocation_size(BufferID p_buffer) override final;202virtual uint8_t *buffer_map(BufferID p_buffer) override final;203virtual void buffer_unmap(BufferID p_buffer) override final;204virtual uint64_t buffer_get_device_address(BufferID p_buffer) override final;205206/*****************/207/**** TEXTURE ****/208/*****************/209210struct TextureInfo {211VkImage vk_image = VK_NULL_HANDLE;212VkImageView vk_view = VK_NULL_HANDLE;213DataFormat rd_format = DATA_FORMAT_MAX;214VkImageCreateInfo vk_create_info = {};215VkImageViewCreateInfo vk_view_create_info = {};216struct {217VmaAllocation handle = nullptr;218VmaAllocationInfo info = {};219} allocation; // All 0/null if just a view.220#ifdef DEBUG_ENABLED221bool created_from_extension = false;222bool transient = false;223#endif224};225226VkSampleCountFlagBits _ensure_supported_sample_count(TextureSamples p_requested_sample_count);227228public:229virtual TextureID texture_create(const TextureFormat &p_format, const TextureView &p_view) override final;230virtual TextureID texture_create_from_extension(uint64_t p_native_texture, TextureType p_type, DataFormat p_format, uint32_t p_array_layers, bool p_depth_stencil, uint32_t p_mipmaps) override final;231virtual TextureID texture_create_shared(TextureID p_original_texture, const TextureView &p_view) override final;232virtual TextureID texture_create_shared_from_slice(TextureID p_original_texture, const TextureView &p_view, TextureSliceType p_slice_type, uint32_t p_layer, uint32_t p_layers, uint32_t p_mipmap, uint32_t p_mipmaps) override final;233virtual void texture_free(TextureID p_texture) override final;234virtual uint64_t texture_get_allocation_size(TextureID p_texture) override final;235virtual void texture_get_copyable_layout(TextureID p_texture, const TextureSubresource &p_subresource, TextureCopyableLayout *r_layout) override final;236virtual uint8_t *texture_map(TextureID p_texture, const TextureSubresource &p_subresource) override final;237virtual void texture_unmap(TextureID p_texture) override final;238virtual BitField<TextureUsageBits> texture_get_usages_supported_by_format(DataFormat p_format, bool p_cpu_readable) override final;239virtual bool texture_can_make_shared_with_format(TextureID p_texture, DataFormat p_format, bool &r_raw_reinterpretation) override final;240241/*****************/242/**** SAMPLER ****/243/*****************/244public:245virtual SamplerID sampler_create(const SamplerState &p_state) final override;246virtual void sampler_free(SamplerID p_sampler) final override;247virtual bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_filter) override final;248249/**********************/250/**** VERTEX ARRAY ****/251/**********************/252private:253struct VertexFormatInfo {254TightLocalVector<VkVertexInputBindingDescription> vk_bindings;255TightLocalVector<VkVertexInputAttributeDescription> vk_attributes;256VkPipelineVertexInputStateCreateInfo vk_create_info = {};257};258259public:260virtual VertexFormatID vertex_format_create(VectorView<VertexAttribute> p_vertex_attribs) override final;261virtual void vertex_format_free(VertexFormatID p_vertex_format) override final;262263/******************/264/**** BARRIERS ****/265/******************/266267virtual void command_pipeline_barrier(268CommandBufferID p_cmd_buffer,269BitField<PipelineStageBits> p_src_stages,270BitField<PipelineStageBits> p_dst_stages,271VectorView<MemoryBarrier> p_memory_barriers,272VectorView<BufferBarrier> p_buffer_barriers,273VectorView<TextureBarrier> p_texture_barriers) override final;274275/****************/276/**** FENCES ****/277/****************/278279private:280struct Fence {281VkFence vk_fence = VK_NULL_HANDLE;282CommandQueue *queue_signaled_from = nullptr;283};284285public:286virtual FenceID fence_create() override final;287virtual Error fence_wait(FenceID p_fence) override final;288virtual void fence_free(FenceID p_fence) override final;289290/********************/291/**** SEMAPHORES ****/292/********************/293294virtual SemaphoreID semaphore_create() override final;295virtual void semaphore_free(SemaphoreID p_semaphore) override final;296297/******************/298/**** COMMANDS ****/299/******************/300301// ----- QUEUE FAMILY -----302303virtual CommandQueueFamilyID command_queue_family_get(BitField<CommandQueueFamilyBits> p_cmd_queue_family_bits, RenderingContextDriver::SurfaceID p_surface = 0) override final;304305// ----- QUEUE -----306private:307struct CommandQueue {308LocalVector<VkSemaphore> image_semaphores;309LocalVector<SwapChain *> image_semaphores_swap_chains;310LocalVector<uint32_t> pending_semaphores_for_execute;311LocalVector<uint32_t> pending_semaphores_for_fence;312LocalVector<uint32_t> free_image_semaphores;313LocalVector<Pair<Fence *, uint32_t>> image_semaphores_for_fences;314uint32_t queue_family = 0;315uint32_t queue_index = 0;316};317318public:319virtual CommandQueueID command_queue_create(CommandQueueFamilyID p_cmd_queue_family, bool p_identify_as_main_queue = false) override final;320virtual Error command_queue_execute_and_present(CommandQueueID p_cmd_queue, VectorView<SemaphoreID> p_wait_semaphores, VectorView<CommandBufferID> p_cmd_buffers, VectorView<SemaphoreID> p_cmd_semaphores, FenceID p_cmd_fence, VectorView<SwapChainID> p_swap_chains) override final;321virtual void command_queue_free(CommandQueueID p_cmd_queue) override final;322323private:324// ----- POOL -----325326struct CommandPool {327VkCommandPool vk_command_pool = VK_NULL_HANDLE;328CommandBufferType buffer_type = COMMAND_BUFFER_TYPE_PRIMARY;329LocalVector<CommandBufferInfo *> command_buffers_created;330};331332public:333virtual CommandPoolID command_pool_create(CommandQueueFamilyID p_cmd_queue_family, CommandBufferType p_cmd_buffer_type) override final;334virtual bool command_pool_reset(CommandPoolID p_cmd_pool) override final;335virtual void command_pool_free(CommandPoolID p_cmd_pool) override final;336337private:338// ----- BUFFER -----339340struct CommandBufferInfo {341VkCommandBuffer vk_command_buffer = VK_NULL_HANDLE;342Framebuffer *active_framebuffer = nullptr;343RenderPassInfo *active_render_pass = nullptr;344};345346public:347virtual CommandBufferID command_buffer_create(CommandPoolID p_cmd_pool) override final;348virtual bool command_buffer_begin(CommandBufferID p_cmd_buffer) override final;349virtual bool command_buffer_begin_secondary(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, uint32_t p_subpass, FramebufferID p_framebuffer) override final;350virtual void command_buffer_end(CommandBufferID p_cmd_buffer) override final;351virtual void command_buffer_execute_secondary(CommandBufferID p_cmd_buffer, VectorView<CommandBufferID> p_secondary_cmd_buffers) override final;352353/********************/354/**** SWAP CHAIN ****/355/********************/356357private:358struct SwapChain {359VkSwapchainKHR vk_swapchain = VK_NULL_HANDLE;360RenderingContextDriver::SurfaceID surface = RenderingContextDriver::SurfaceID();361VkFormat format = VK_FORMAT_UNDEFINED;362VkColorSpaceKHR color_space = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;363TightLocalVector<VkImage> images;364TightLocalVector<VkImageView> image_views;365TightLocalVector<VkSemaphore> present_semaphores;366TightLocalVector<FramebufferID> framebuffers;367LocalVector<CommandQueue *> command_queues_acquired;368LocalVector<uint32_t> command_queues_acquired_semaphores;369RenderPassID render_pass;370int pre_transform_rotation_degrees = 0;371uint32_t image_index = 0;372#ifdef ANDROID_ENABLED373uint64_t refresh_duration = 0;374#endif375};376377void _swap_chain_release(SwapChain *p_swap_chain);378379public:380virtual SwapChainID swap_chain_create(RenderingContextDriver::SurfaceID p_surface) override final;381virtual Error swap_chain_resize(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, uint32_t p_desired_framebuffer_count) override final;382virtual FramebufferID swap_chain_acquire_framebuffer(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, bool &r_resize_required) override final;383virtual RenderPassID swap_chain_get_render_pass(SwapChainID p_swap_chain) override final;384virtual int swap_chain_get_pre_rotation_degrees(SwapChainID p_swap_chain) override final;385virtual DataFormat swap_chain_get_format(SwapChainID p_swap_chain) override final;386virtual void swap_chain_set_max_fps(SwapChainID p_swap_chain, int p_max_fps) override final;387virtual void swap_chain_free(SwapChainID p_swap_chain) override final;388389private:390/*********************/391/**** FRAMEBUFFER ****/392/*********************/393394struct Framebuffer {395VkFramebuffer vk_framebuffer = VK_NULL_HANDLE;396397// Only filled in if the framebuffer uses a fragment density map with offsets. Unused otherwise.398uint32_t fragment_density_map_offsets_layers = 0;399400// Only filled in by a framebuffer created by a swap chain. Unused otherwise.401VkImage swap_chain_image = VK_NULL_HANDLE;402VkImageSubresourceRange swap_chain_image_subresource_range = {};403bool swap_chain_acquired = false;404};405406public:407virtual FramebufferID framebuffer_create(RenderPassID p_render_pass, VectorView<TextureID> p_attachments, uint32_t p_width, uint32_t p_height) override final;408virtual void framebuffer_free(FramebufferID p_framebuffer) override final;409410/****************/411/**** SHADER ****/412/****************/413private:414struct ShaderInfo {415VkShaderStageFlags vk_push_constant_stages = 0;416TightLocalVector<VkPipelineShaderStageCreateInfo> vk_stages_create_info;417TightLocalVector<VkDescriptorSetLayout> vk_descriptor_set_layouts;418VkPipelineLayout vk_pipeline_layout = VK_NULL_HANDLE;419};420421public:422virtual ShaderID shader_create_from_container(const Ref<RenderingShaderContainer> &p_shader_container, const Vector<ImmutableSampler> &p_immutable_samplers) override final;423virtual void shader_free(ShaderID p_shader) override final;424425virtual void shader_destroy_modules(ShaderID p_shader) override final;426/*********************/427/**** UNIFORM SET ****/428/*********************/429430// Descriptor sets require allocation from a pool.431// The documentation on how to use pools properly432// is scarce, and the documentation is strange.433//434// Basically, you can mix and match pools as you435// like, but you'll run into fragmentation issues.436// Because of this, the recommended approach is to437// create a pool for every descriptor set type, as438// this prevents fragmentation.439//440// This is implemented here as a having a list of441// pools (each can contain up to 64 sets) for each442// set layout. The amount of sets for each type443// is used as the key.444445private:446static const uint32_t MAX_UNIFORM_POOL_ELEMENT = 65535;447448struct DescriptorSetPoolKey {449uint16_t uniform_type[UNIFORM_TYPE_MAX] = {};450451bool operator<(const DescriptorSetPoolKey &p_other) const {452return memcmp(uniform_type, p_other.uniform_type, sizeof(uniform_type)) < 0;453}454};455456using DescriptorSetPools = RBMap<DescriptorSetPoolKey, HashMap<VkDescriptorPool, uint32_t>>;457DescriptorSetPools descriptor_set_pools;458uint32_t max_descriptor_sets_per_pool = 0;459460HashMap<int, DescriptorSetPools> linear_descriptor_set_pools;461bool linear_descriptor_pools_enabled = true;462VkDescriptorPool _descriptor_set_pool_find_or_create(const DescriptorSetPoolKey &p_key, DescriptorSetPools::Iterator *r_pool_sets_it, int p_linear_pool_index);463void _descriptor_set_pool_unreference(DescriptorSetPools::Iterator p_pool_sets_it, VkDescriptorPool p_vk_descriptor_pool, int p_linear_pool_index);464465// Global flag to toggle usage of immutable sampler when creating pipeline layouts.466// It cannot change after creating the PSOs, since we need to skipping samplers when creating uniform sets.467bool immutable_samplers_enabled = true;468469struct UniformSetInfo {470VkDescriptorSet vk_descriptor_set = VK_NULL_HANDLE;471VkDescriptorPool vk_descriptor_pool = VK_NULL_HANDLE;472VkDescriptorPool vk_linear_descriptor_pool = VK_NULL_HANDLE;473DescriptorSetPools::Iterator pool_sets_it;474};475476public:477virtual UniformSetID uniform_set_create(VectorView<BoundUniform> p_uniforms, ShaderID p_shader, uint32_t p_set_index, int p_linear_pool_index) override final;478virtual void linear_uniform_set_pools_reset(int p_linear_pool_index) override final;479virtual void uniform_set_free(UniformSetID p_uniform_set) override final;480virtual bool uniform_sets_have_linear_pools() const override final;481482// ----- COMMANDS -----483484virtual void command_uniform_set_prepare_for_use(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) override final;485486/******************/487/**** TRANSFER ****/488/******************/489490virtual void command_clear_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, uint64_t p_offset, uint64_t p_size) override final;491virtual void command_copy_buffer(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, BufferID p_dst_buffer, VectorView<BufferCopyRegion> p_regions) override final;492493virtual void command_copy_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<TextureCopyRegion> p_regions) override final;494virtual void command_resolve_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, uint32_t p_src_layer, uint32_t p_src_mipmap, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, uint32_t p_dst_layer, uint32_t p_dst_mipmap) override final;495virtual void command_clear_color_texture(CommandBufferID p_cmd_buffer, TextureID p_texture, TextureLayout p_texture_layout, const Color &p_color, const TextureSubresourceRange &p_subresources) override final;496497virtual void command_copy_buffer_to_texture(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<BufferTextureCopyRegion> p_regions) override final;498virtual void command_copy_texture_to_buffer(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, BufferID p_dst_buffer, VectorView<BufferTextureCopyRegion> p_regions) override final;499500/******************/501/**** PIPELINE ****/502/******************/503private:504struct PipelineCacheHeader {505uint32_t magic = 0;506uint32_t data_size = 0;507uint64_t data_hash = 0;508uint32_t vendor_id = 0;509uint32_t device_id = 0;510uint32_t driver_version = 0;511uint8_t uuid[VK_UUID_SIZE] = {};512uint8_t driver_abi = 0;513};514515struct PipelineCache {516String file_path;517size_t current_size = 0;518Vector<uint8_t> buffer; // Header then data.519VkPipelineCache vk_cache = VK_NULL_HANDLE;520};521522static int caching_instance_count;523PipelineCache pipelines_cache;524String pipeline_cache_id;525HashMap<uint64_t, bool> has_comp_alpha;526527public:528virtual void pipeline_free(PipelineID p_pipeline) override final;529530// ----- BINDING -----531532virtual void command_bind_push_constants(CommandBufferID p_cmd_buffer, ShaderID p_shader, uint32_t p_first_index, VectorView<uint32_t> p_data) override final;533534// ----- CACHE -----535536virtual bool pipeline_cache_create(const Vector<uint8_t> &p_data) override final;537virtual void pipeline_cache_free() override final;538virtual size_t pipeline_cache_query_size() override final;539virtual Vector<uint8_t> pipeline_cache_serialize() override final;540541/*******************/542/**** RENDERING ****/543/*******************/544545private:546// ----- SUBPASS -----547548struct RenderPassInfo {549VkRenderPass vk_render_pass = VK_NULL_HANDLE;550bool uses_fragment_density_map_offsets = false;551};552553public:554virtual RenderPassID render_pass_create(VectorView<Attachment> p_attachments, VectorView<Subpass> p_subpasses, VectorView<SubpassDependency> p_subpass_dependencies, uint32_t p_view_count, AttachmentReference p_fragment_density_map_attachment) override final;555virtual void render_pass_free(RenderPassID p_render_pass) override final;556557// ----- COMMANDS -----558559virtual void command_begin_render_pass(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, FramebufferID p_framebuffer, CommandBufferType p_cmd_buffer_type, const Rect2i &p_rect, VectorView<RenderPassClearValue> p_clear_values) override final;560virtual void command_end_render_pass(CommandBufferID p_cmd_buffer) override final;561virtual void command_next_render_subpass(CommandBufferID p_cmd_buffer, CommandBufferType p_cmd_buffer_type) override final;562virtual void command_render_set_viewport(CommandBufferID p_cmd_buffer, VectorView<Rect2i> p_viewports) override final;563virtual void command_render_set_scissor(CommandBufferID p_cmd_buffer, VectorView<Rect2i> p_scissors) override final;564virtual void command_render_clear_attachments(CommandBufferID p_cmd_buffer, VectorView<AttachmentClear> p_attachment_clears, VectorView<Rect2i> p_rects) override final;565566// Binding.567virtual void command_bind_render_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) override final;568virtual void command_bind_render_uniform_set(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) override final;569virtual 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;570571// Drawing.572virtual 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;573virtual void command_render_draw_indexed(CommandBufferID p_cmd_buffer, uint32_t p_index_count, uint32_t p_instance_count, uint32_t p_first_index, int32_t p_vertex_offset, uint32_t p_first_instance) override final;574virtual void command_render_draw_indexed_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, uint32_t p_draw_count, uint32_t p_stride) override final;575virtual void command_render_draw_indexed_indirect_count(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, BufferID p_count_buffer, uint64_t p_count_buffer_offset, uint32_t p_max_draw_count, uint32_t p_stride) override final;576virtual void command_render_draw_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, uint32_t p_draw_count, uint32_t p_stride) override final;577virtual void command_render_draw_indirect_count(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, BufferID p_count_buffer, uint64_t p_count_buffer_offset, uint32_t p_max_draw_count, uint32_t p_stride) override final;578579// Buffer binding.580virtual void command_render_bind_vertex_buffers(CommandBufferID p_cmd_buffer, uint32_t p_binding_count, const BufferID *p_buffers, const uint64_t *p_offsets) override final;581virtual void command_render_bind_index_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, IndexBufferFormat p_format, uint64_t p_offset) override final;582583// Dynamic state.584virtual void command_render_set_blend_constants(CommandBufferID p_cmd_buffer, const Color &p_constants) override final;585virtual void command_render_set_line_width(CommandBufferID p_cmd_buffer, float p_width) override final;586587// ----- PIPELINE -----588589virtual PipelineID render_pipeline_create(590ShaderID p_shader,591VertexFormatID p_vertex_format,592RenderPrimitive p_render_primitive,593PipelineRasterizationState p_rasterization_state,594PipelineMultisampleState p_multisample_state,595PipelineDepthStencilState p_depth_stencil_state,596PipelineColorBlendState p_blend_state,597VectorView<int32_t> p_color_attachments,598BitField<PipelineDynamicStateFlags> p_dynamic_state,599RenderPassID p_render_pass,600uint32_t p_render_subpass,601VectorView<PipelineSpecializationConstant> p_specialization_constants) override final;602603/*****************/604/**** COMPUTE ****/605/*****************/606607// ----- COMMANDS -----608609// Binding.610virtual void command_bind_compute_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) override final;611virtual void command_bind_compute_uniform_set(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) override final;612virtual 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;613614// Dispatching.615virtual 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;616virtual void command_compute_dispatch_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset) override final;617618// ----- PIPELINE -----619620virtual PipelineID compute_pipeline_create(ShaderID p_shader, VectorView<PipelineSpecializationConstant> p_specialization_constants) override final;621622/*****************/623/**** QUERIES ****/624/*****************/625626// ----- TIMESTAMP -----627628// Basic.629virtual QueryPoolID timestamp_query_pool_create(uint32_t p_query_count) override final;630virtual void timestamp_query_pool_free(QueryPoolID p_pool_id) override final;631virtual void timestamp_query_pool_get_results(QueryPoolID p_pool_id, uint32_t p_query_count, uint64_t *r_results) override final;632virtual uint64_t timestamp_query_result_to_time(uint64_t p_result) override final;633634// Commands.635virtual void command_timestamp_query_pool_reset(CommandBufferID p_cmd_buffer, QueryPoolID p_pool_id, uint32_t p_query_count) override final;636virtual void command_timestamp_write(CommandBufferID p_cmd_buffer, QueryPoolID p_pool_id, uint32_t p_index) override final;637638/****************/639/**** LABELS ****/640/****************/641642virtual void command_begin_label(CommandBufferID p_cmd_buffer, const char *p_label_name, const Color &p_color) override final;643virtual void command_end_label(CommandBufferID p_cmd_buffer) override final;644645/****************/646/**** DEBUG *****/647/****************/648virtual void command_insert_breadcrumb(CommandBufferID p_cmd_buffer, uint32_t p_data) override final;649void print_lost_device_info();650void on_device_lost() const;651static String get_vulkan_result(VkResult err);652653/********************/654/**** SUBMISSION ****/655/********************/656657virtual void begin_segment(uint32_t p_frame_index, uint32_t p_frames_drawn) override final;658virtual void end_segment() override final;659660/**************/661/**** MISC ****/662/**************/663664virtual void set_object_name(ObjectType p_type, ID p_driver_id, const String &p_name) override final;665virtual uint64_t get_resource_native_handle(DriverResource p_type, ID p_driver_id) override final;666virtual uint64_t get_total_memory_used() override final;667virtual uint64_t get_lazily_memory_used() override final;668virtual uint64_t limit_get(Limit p_limit) override final;669virtual uint64_t api_trait_get(ApiTrait p_trait) override final;670virtual bool has_feature(Features p_feature) override final;671virtual const MultiviewCapabilities &get_multiview_capabilities() override final;672virtual const FragmentShadingRateCapabilities &get_fragment_shading_rate_capabilities() override final;673virtual const FragmentDensityMapCapabilities &get_fragment_density_map_capabilities() override final;674virtual String get_api_name() const override final;675virtual String get_api_version() const override final;676virtual String get_pipeline_cache_uuid() const override final;677virtual const Capabilities &get_capabilities() const override final;678virtual const RenderingShaderContainerFormat &get_shader_container_format() const override final;679680virtual bool is_composite_alpha_supported(CommandQueueID p_queue) const override final;681682private:683/*********************/684/**** BOOKKEEPING ****/685/*********************/686687using VersatileResource = VersatileResourceTemplate<688BufferInfo,689TextureInfo,690VertexFormatInfo,691ShaderInfo,692UniformSetInfo,693RenderPassInfo,694CommandBufferInfo>;695PagedAllocator<VersatileResource, true> resources_allocator;696697/******************/698699public:700RenderingDeviceDriverVulkan(RenderingContextDriverVulkan *p_context_driver);701virtual ~RenderingDeviceDriverVulkan();702};703704using VKC = RenderingContextDriverVulkan;705706707