Hash :
4f87f4e9
Author :
Date :
2023-03-03T13:19:09
Vulkan: Add useResetCommandBufferBitForSecondaryPools feature. Currently ANGLE does not use "vkResetCommandBuffer()" on Vulkan Secondary Command Buffers. Instead it uses "vkFreeCommandBuffers()" and "vkAllocateCommandBuffers". According to spec, "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT" is required only for command buffer reset operations. However, some ARM drivers may not free memory in "vkFreeCommandBuffers()" without this flag. Bug: angleproject:8059 Change-Id: Ibfe45bca345dc48484b625c450369d30805cec77 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4306722 Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Igor Nazarov <i.nazarov@samsung.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// VulkanSecondaryCommandBuffer:
// Implementation of VulkanSecondaryCommandBuffer.
//
#include "libANGLE/renderer/vulkan/VulkanSecondaryCommandBuffer.h"
#include "common/debug.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
namespace rx
{
namespace vk
{
angle::Result VulkanSecondaryCommandBuffer::InitializeCommandPool(Context *context,
CommandPool *pool,
uint32_t queueFamilyIndex,
ProtectionType protectionType)
{
VkCommandPoolCreateInfo poolInfo = {};
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
poolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
poolInfo.queueFamilyIndex = queueFamilyIndex;
if (context->getRenderer()->getFeatures().useResetCommandBufferBitForSecondaryPools.enabled)
{
poolInfo.flags |= VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
}
ASSERT(protectionType == ProtectionType::Unprotected ||
protectionType == ProtectionType::Protected);
if (protectionType == ProtectionType::Protected)
{
poolInfo.flags |= VK_COMMAND_POOL_CREATE_PROTECTED_BIT;
}
ANGLE_VK_TRY(context, pool->init(context->getDevice(), poolInfo));
return angle::Result::Continue;
}
angle::Result VulkanSecondaryCommandBuffer::InitializeRenderPassInheritanceInfo(
ContextVk *contextVk,
const Framebuffer &framebuffer,
const RenderPassDesc &renderPassDesc,
VkCommandBufferInheritanceInfo *inheritanceInfoOut)
{
const vk::RenderPass *compatibleRenderPass = nullptr;
ANGLE_TRY(contextVk->getCompatibleRenderPass(renderPassDesc, &compatibleRenderPass));
inheritanceInfoOut->sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
inheritanceInfoOut->renderPass = compatibleRenderPass->getHandle();
inheritanceInfoOut->subpass = 0;
inheritanceInfoOut->framebuffer = framebuffer.getHandle();
return angle::Result::Continue;
}
angle::Result VulkanSecondaryCommandBuffer::initialize(Context *context,
vk::CommandPool *pool,
bool isRenderPassCommandBuffer,
SecondaryCommandMemoryAllocator *allocator)
{
VkDevice device = context->getDevice();
mCommandPool = pool;
mCommandTracker.reset();
mAnyCommand = false;
VkCommandBufferAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
allocInfo.commandBufferCount = 1;
allocInfo.commandPool = pool->getHandle();
ANGLE_VK_TRY(context, init(device, allocInfo));
// Outside-RP command buffers are begun automatically here. RP command buffers are begun when
// the render pass itself starts, as they require inheritance info.
if (!isRenderPassCommandBuffer)
{
VkCommandBufferInheritanceInfo inheritanceInfo = {};
inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
ANGLE_TRY(begin(context, inheritanceInfo));
}
return angle::Result::Continue;
}
void VulkanSecondaryCommandBuffer::free(VkDevice device)
{
if (mHandle != VK_NULL_HANDLE)
{
mCommandPool->freeCommandBuffers(device, 1, &mHandle);
mHandle = VK_NULL_HANDLE;
}
}
angle::Result VulkanSecondaryCommandBuffer::begin(
Context *context,
const VkCommandBufferInheritanceInfo &inheritanceInfo)
{
ASSERT(!mAnyCommand);
VkCommandBufferBeginInfo beginInfo = {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
beginInfo.pInheritanceInfo = &inheritanceInfo;
if (inheritanceInfo.renderPass != VK_NULL_HANDLE)
{
beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
}
ANGLE_VK_TRY(context, CommandBuffer::begin(beginInfo));
return angle::Result::Continue;
}
angle::Result VulkanSecondaryCommandBuffer::end(Context *context)
{
ANGLE_VK_TRY(context, CommandBuffer::end());
return angle::Result::Continue;
}
VkResult VulkanSecondaryCommandBuffer::reset()
{
mCommandTracker.reset();
mAnyCommand = false;
return CommandBuffer::reset();
}
} // namespace vk
} // namespace rx