1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // VulkanSecondaryCommandBuffer:
7 // Implementation of VulkanSecondaryCommandBuffer.
8 //
9
10 #include "libANGLE/renderer/vulkan/VulkanSecondaryCommandBuffer.h"
11
12 #include "common/debug.h"
13 #include "libANGLE/renderer/vulkan/ContextVk.h"
14 #include "libANGLE/renderer/vulkan/vk_utils.h"
15
16 namespace rx
17 {
18 namespace vk
19 {
InitializeCommandPool(Context * context,SecondaryCommandPool * pool,uint32_t queueFamilyIndex,ProtectionType protectionType)20 angle::Result VulkanSecondaryCommandBuffer::InitializeCommandPool(Context *context,
21 SecondaryCommandPool *pool,
22 uint32_t queueFamilyIndex,
23 ProtectionType protectionType)
24 {
25 ANGLE_TRY(pool->init(context, queueFamilyIndex, protectionType));
26 return angle::Result::Continue;
27 }
28
InitializeRenderPassInheritanceInfo(ContextVk * contextVk,const Framebuffer & framebuffer,const RenderPassDesc & renderPassDesc,VkCommandBufferInheritanceInfo * inheritanceInfoOut)29 angle::Result VulkanSecondaryCommandBuffer::InitializeRenderPassInheritanceInfo(
30 ContextVk *contextVk,
31 const Framebuffer &framebuffer,
32 const RenderPassDesc &renderPassDesc,
33 VkCommandBufferInheritanceInfo *inheritanceInfoOut)
34 {
35 const RenderPass *compatibleRenderPass = nullptr;
36 ANGLE_TRY(contextVk->getCompatibleRenderPass(renderPassDesc, &compatibleRenderPass));
37
38 inheritanceInfoOut->sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
39 inheritanceInfoOut->renderPass = compatibleRenderPass->getHandle();
40 inheritanceInfoOut->subpass = 0;
41 inheritanceInfoOut->framebuffer = framebuffer.getHandle();
42
43 return angle::Result::Continue;
44 }
45
initialize(Context * context,SecondaryCommandPool * pool,bool isRenderPassCommandBuffer,SecondaryCommandMemoryAllocator * allocator)46 angle::Result VulkanSecondaryCommandBuffer::initialize(Context *context,
47 SecondaryCommandPool *pool,
48 bool isRenderPassCommandBuffer,
49 SecondaryCommandMemoryAllocator *allocator)
50 {
51 mCommandPool = pool;
52 mCommandTracker.reset();
53 mAnyCommand = false;
54
55 ANGLE_TRY(pool->allocate(context, this));
56
57 // Outside-RP command buffers are begun automatically here. RP command buffers are begun when
58 // the render pass itself starts, as they require inheritance info.
59 if (!isRenderPassCommandBuffer)
60 {
61 VkCommandBufferInheritanceInfo inheritanceInfo = {};
62 inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
63 ANGLE_TRY(begin(context, inheritanceInfo));
64 }
65
66 return angle::Result::Continue;
67 }
68
destroy()69 void VulkanSecondaryCommandBuffer::destroy()
70 {
71 if (valid())
72 {
73 ASSERT(mCommandPool != nullptr);
74 mCommandPool->collect(this);
75 }
76 }
77
begin(Context * context,const VkCommandBufferInheritanceInfo & inheritanceInfo)78 angle::Result VulkanSecondaryCommandBuffer::begin(
79 Context *context,
80 const VkCommandBufferInheritanceInfo &inheritanceInfo)
81 {
82 ASSERT(!mAnyCommand);
83
84 VkCommandBufferBeginInfo beginInfo = {};
85 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
86 beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
87 beginInfo.pInheritanceInfo = &inheritanceInfo;
88 if (inheritanceInfo.renderPass != VK_NULL_HANDLE)
89 {
90 beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
91 }
92
93 ANGLE_VK_TRY(context, CommandBuffer::begin(beginInfo));
94 return angle::Result::Continue;
95 }
96
end(Context * context)97 angle::Result VulkanSecondaryCommandBuffer::end(Context *context)
98 {
99 ANGLE_VK_TRY(context, CommandBuffer::end());
100 return angle::Result::Continue;
101 }
102
reset()103 VkResult VulkanSecondaryCommandBuffer::reset()
104 {
105 mCommandTracker.reset();
106 mAnyCommand = false;
107 return CommandBuffer::reset();
108 }
109 } // namespace vk
110 } // namespace rx
111