diff options
Diffstat (limited to 'drivers/vulkan')
| -rw-r--r-- | drivers/vulkan/rendering_device_vulkan.cpp | 22 | ||||
| -rw-r--r-- | drivers/vulkan/rendering_device_vulkan.h | 1 | ||||
| -rw-r--r-- | drivers/vulkan/vulkan_context.cpp | 12 |
3 files changed, 27 insertions, 8 deletions
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index ba623eb298..1d6d9d56e8 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -43,6 +43,8 @@ //#define FORCE_FULL_BARRIER +static const uint32_t SMALL_ALLOCATION_MAX_SIZE = 4096; + // Get the Vulkan object information and possible stage access types (bitwise OR'd with incoming values) RenderingDeviceVulkan::Buffer *RenderingDeviceVulkan::_get_buffer_from_owner(RID p_buffer, VkPipelineStageFlags &r_stage_mask, VkAccessFlags &r_access_mask, uint32_t p_post_barrier) { Buffer *buffer = nullptr; @@ -1333,7 +1335,7 @@ Error RenderingDeviceVulkan::_buffer_allocate(Buffer *p_buffer, uint32_t p_size, allocInfo.requiredFlags = 0; allocInfo.preferredFlags = 0; allocInfo.memoryTypeBits = 0; - allocInfo.pool = nullptr; + allocInfo.pool = p_size <= SMALL_ALLOCATION_MAX_SIZE ? small_allocs_pool : nullptr; allocInfo.pUserData = nullptr; VkResult err = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &p_buffer->buffer, &p_buffer->allocation, nullptr); @@ -1836,13 +1838,16 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T //allocate memory + uint32_t width, height; + uint32_t image_size = get_image_format_required_size(p_format.format, p_format.width, p_format.height, p_format.depth, p_format.mipmaps, &width, &height); + VmaAllocationCreateInfo allocInfo; allocInfo.flags = 0; + allocInfo.pool = image_size <= SMALL_ALLOCATION_MAX_SIZE ? small_allocs_pool : nullptr; allocInfo.usage = p_format.usage_bits & TEXTURE_USAGE_CPU_READ_BIT ? VMA_MEMORY_USAGE_CPU_ONLY : VMA_MEMORY_USAGE_GPU_ONLY; allocInfo.requiredFlags = 0; allocInfo.preferredFlags = 0; allocInfo.memoryTypeBits = 0; - allocInfo.pool = nullptr; allocInfo.pUserData = nullptr; Texture texture; @@ -8808,6 +8813,18 @@ void RenderingDeviceVulkan::initialize(VulkanContext *p_context, bool p_local_de vmaCreateAllocator(&allocatorInfo, &allocator); } + { //create pool for small objects + VmaPoolCreateInfo pci; + pci.flags = VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT; + pci.blockSize = 0; + pci.minBlockCount = 0; + pci.maxBlockCount = SIZE_MAX; + pci.priority = 0.5f; + pci.minAllocationAlignment = 0; + pci.pMemoryAllocateNext = nullptr; + vmaCreatePool(allocator, &pci, &small_allocs_pool); + } + frames = memnew_arr(Frame, frame_count); frame = 0; //create setup and frame buffers @@ -9276,6 +9293,7 @@ void RenderingDeviceVulkan::finalize() { for (int i = 0; i < staging_buffer_blocks.size(); i++) { vmaDestroyBuffer(allocator, staging_buffer_blocks[i].buffer, staging_buffer_blocks[i].allocation); } + vmaDestroyPool(allocator, small_allocs_pool); vmaDestroyAllocator(allocator); while (vertex_formats.size()) { diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index f42929ffa4..6510893196 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -1016,6 +1016,7 @@ class RenderingDeviceVulkan : public RenderingDevice { void _free_pending_resources(int p_frame); VmaAllocator allocator = nullptr; + VmaPool small_allocs_pool = nullptr; VulkanContext *context = nullptr; diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index e5d577a79f..1aa1bfddc8 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -273,9 +273,9 @@ Error VulkanContext::_obtain_vulkan_version() { uint32_t api_version; VkResult res = func(&api_version); if (res == VK_SUCCESS) { - vulkan_major = VK_VERSION_MAJOR(api_version); - vulkan_minor = VK_VERSION_MINOR(api_version); - vulkan_patch = VK_VERSION_PATCH(api_version); + vulkan_major = VK_API_VERSION_MAJOR(api_version); + vulkan_minor = VK_API_VERSION_MINOR(api_version); + vulkan_patch = VK_API_VERSION_PATCH(api_version); } else { // according to the documentation this shouldn't fail with anything except a memory allocation error // in which case we're in deep trouble anyway @@ -538,7 +538,7 @@ Error VulkanContext::_check_capabilities() { VkPhysicalDeviceShaderFloat16Int8FeaturesKHR shader_features; shader_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR; - shader_features.pNext = NULL; + shader_features.pNext = nullptr; device_features.pNext = &shader_features; @@ -547,7 +547,7 @@ Error VulkanContext::_check_capabilities() { VkPhysicalDevice16BitStorageFeaturesKHR storage_feature; storage_feature.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR; - storage_feature.pNext = NULL; + storage_feature.pNext = nullptr; device_features.pNext = &storage_feature; @@ -860,7 +860,7 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) { free(device_queue_props); print_verbose(" #" + itos(i) + ": " + vendor + " " + name + " - " + (present_supported ? "Supported" : "Unsupported") + ", " + dev_type); - if (present_supported) { // Select first supported device of preffered type: Discrete > Integrated > Virtual > CPU > Other. + if (present_supported) { // Select first supported device of preferred type: Discrete > Integrated > Virtual > CPU > Other. switch (props.deviceType) { case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: { if (type_selected < 4) { |