Skip to content

Commit 6c7ab7f

Browse files
null77Commit Bot
authored andcommitted
Vulkan: Reorganize helper classes.
This renames ResourceVk to vk::CommandGraphResource, which should help clarify its usage. This also moves LineLoopHandler, ImageHelper, and the DynamicBuffer and DynamicCommandPool classes into a new vk_helpers module. This file contains helper classes that manage other resources. Also this makes DynamicBuffer and DynamicDescriptorPool no longer inherit from CommandGraphResource. In the future, only Impl objects will be allowed to be graph resources. Bug: angleproject:2318 Change-Id: I0fa23da2ac853d90f3c822547a4a314f247cc757 Reviewed-on: https://chromium-review.googlesource.com/985200 Commit-Queue: Jamie Madill <[email protected]> Reviewed-by: Frank Henigman <[email protected]>
1 parent 5ae64c9 commit 6c7ab7f

26 files changed

+1160
-1167
lines changed

src/libANGLE/renderer/vulkan/BufferVk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
#include "libANGLE/Observer.h"
1414
#include "libANGLE/renderer/BufferImpl.h"
15-
#include "libANGLE/renderer/vulkan/vk_utils.h"
15+
#include "libANGLE/renderer/vulkan/vk_helpers.h"
1616

1717
namespace rx
1818
{
1919
class RendererVk;
2020

21-
class BufferVk : public BufferImpl, public ResourceVk
21+
class BufferVk : public BufferImpl, public vk::CommandGraphResource
2222
{
2323
public:
2424
BufferVk(const gl::BufferState &state);

src/libANGLE/renderer/vulkan/CommandGraph.cpp

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,98 @@ Error InitAndBeginCommandBuffer(VkDevice device,
5151

5252
} // anonymous namespace
5353

54+
// CommandGraphResource implementation.
55+
CommandGraphResource::CommandGraphResource() : mCurrentWritingNode(nullptr)
56+
{
57+
}
58+
59+
CommandGraphResource::~CommandGraphResource()
60+
{
61+
}
62+
63+
void CommandGraphResource::updateQueueSerial(Serial queueSerial)
64+
{
65+
ASSERT(queueSerial >= mStoredQueueSerial);
66+
67+
if (queueSerial > mStoredQueueSerial)
68+
{
69+
mCurrentWritingNode = nullptr;
70+
mCurrentReadingNodes.clear();
71+
mStoredQueueSerial = queueSerial;
72+
}
73+
}
74+
75+
Serial CommandGraphResource::getQueueSerial() const
76+
{
77+
return mStoredQueueSerial;
78+
}
79+
80+
bool CommandGraphResource::hasCurrentWritingNode(Serial currentSerial) const
81+
{
82+
return (mStoredQueueSerial == currentSerial && mCurrentWritingNode != nullptr &&
83+
!mCurrentWritingNode->hasChildren());
84+
}
85+
86+
CommandGraphNode *CommandGraphResource::getCurrentWritingNode(Serial currentSerial)
87+
{
88+
ASSERT(currentSerial == mStoredQueueSerial);
89+
return mCurrentWritingNode;
90+
}
91+
92+
CommandGraphNode *CommandGraphResource::getNewWritingNode(RendererVk *renderer)
93+
{
94+
CommandGraphNode *newCommands = renderer->allocateCommandNode();
95+
onWriteResource(newCommands, renderer->getCurrentQueueSerial());
96+
return newCommands;
97+
}
98+
99+
Error CommandGraphResource::beginWriteResource(RendererVk *renderer,
100+
CommandBuffer **commandBufferOut)
101+
{
102+
CommandGraphNode *commands = getNewWritingNode(renderer);
103+
104+
VkDevice device = renderer->getDevice();
105+
ANGLE_TRY(commands->beginOutsideRenderPassRecording(device, renderer->getCommandPool(),
106+
commandBufferOut));
107+
return NoError();
108+
}
109+
110+
void CommandGraphResource::onWriteResource(CommandGraphNode *writingNode, Serial serial)
111+
{
112+
updateQueueSerial(serial);
113+
114+
// Make sure any open reads and writes finish before we execute 'newCommands'.
115+
if (!mCurrentReadingNodes.empty())
116+
{
117+
CommandGraphNode::SetHappensBeforeDependencies(mCurrentReadingNodes, writingNode);
118+
mCurrentReadingNodes.clear();
119+
}
120+
121+
if (mCurrentWritingNode && mCurrentWritingNode != writingNode)
122+
{
123+
CommandGraphNode::SetHappensBeforeDependency(mCurrentWritingNode, writingNode);
124+
}
125+
126+
mCurrentWritingNode = writingNode;
127+
}
128+
129+
void CommandGraphResource::onReadResource(CommandGraphNode *readingNode, Serial serial)
130+
{
131+
if (hasCurrentWritingNode(serial))
132+
{
133+
// Ensure 'readOperation' happens after the current write commands.
134+
CommandGraphNode::SetHappensBeforeDependency(getCurrentWritingNode(serial), readingNode);
135+
ASSERT(mStoredQueueSerial == serial);
136+
}
137+
else
138+
{
139+
updateQueueSerial(serial);
140+
}
141+
142+
// Add the read operation to the list of nodes currently reading this resource.
143+
mCurrentReadingNodes.push_back(readingNode);
144+
}
145+
54146
// CommandGraphNode implementation.
55147

56148
CommandGraphNode::CommandGraphNode() : mHasChildren(false), mVisitedState(VisitedState::Unvisited)
@@ -354,7 +446,7 @@ Error CommandGraph::submitCommands(VkDevice device,
354446
ANGLE_TRY(primaryCommandBufferOut->end());
355447

356448
// TODO(jmadill): Use pool allocation so we don't need to deallocate command graph.
357-
for (vk::CommandGraphNode *node : mNodes)
449+
for (CommandGraphNode *node : mNodes)
358450
{
359451
delete node;
360452
}

src/libANGLE/renderer/vulkan/CommandGraph.h

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,46 @@ namespace rx
1818
namespace vk
1919
{
2020

21+
// This is a helper class for back-end objects used in Vk command buffers. It records a serial
22+
// at command recording times indicating an order in the queue. We use Fences to detect when
23+
// commands finish, and then release any unreferenced and deleted resources based on the stored
24+
// queue serial in a special 'garbage' queue. Resources also track current read and write
25+
// dependencies. Only one command buffer node can be writing to the Resource at a time, but many
26+
// can be reading from it. Together the dependencies will form a command graph at submission time.
27+
class CommandGraphResource
28+
{
29+
public:
30+
CommandGraphResource();
31+
virtual ~CommandGraphResource();
32+
33+
void updateQueueSerial(Serial queueSerial);
34+
Serial getQueueSerial() const;
35+
36+
// Returns true if any tracked read or write nodes match 'currentSerial'.
37+
bool hasCurrentWritingNode(Serial currentSerial) const;
38+
39+
// Returns the active write node, and asserts 'currentSerial' matches the stored serial.
40+
CommandGraphNode *getCurrentWritingNode(Serial currentSerial);
41+
42+
// Allocates a new write node and calls onWriteResource internally.
43+
CommandGraphNode *getNewWritingNode(RendererVk *renderer);
44+
45+
// Allocates a write node via getNewWriteNode and returns a started command buffer.
46+
// The started command buffer will render outside of a RenderPass.
47+
Error beginWriteResource(RendererVk *renderer, CommandBuffer **commandBufferOut);
48+
49+
// Sets up dependency relations. 'writingNode' will modify 'this' ResourceVk.
50+
void onWriteResource(CommandGraphNode *writingNode, Serial serial);
51+
52+
// Sets up dependency relations. 'readingNode' will read from 'this' ResourceVk.
53+
void onReadResource(CommandGraphNode *readingNode, Serial serial);
54+
55+
private:
56+
Serial mStoredQueueSerial;
57+
std::vector<CommandGraphNode *> mCurrentReadingNodes;
58+
CommandGraphNode *mCurrentWritingNode;
59+
};
60+
2161
enum class VisitedState
2262
{
2363
Unvisited,
@@ -39,7 +79,7 @@ enum class VisitedState
3979
// for a directed acyclic CommandGraph. When we need to submit the CommandGraph, say during a
4080
// SwapBuffers or ReadPixels call, we begin a primary Vulkan CommandBuffer, and walk the
4181
// CommandGraph, starting at the most senior nodes, recording secondary CommandBuffers inside
42-
// and outside vk::RenderPasses as necessary, filled with the right load/store operations. Once
82+
// and outside RenderPasses as necessary, filled with the right load/store operations. Once
4383
// the primary CommandBuffer has recorded all of the secondary CommandBuffers from all the open
4484
// CommandGraphNodes, we submit the primary CommandBuffer to the VkQueue on the device.
4585

src/libANGLE/renderer/vulkan/ContextVk.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "libANGLE/renderer/vulkan/CompilerVk.h"
2020
#include "libANGLE/renderer/vulkan/ContextVk.h"
2121
#include "libANGLE/renderer/vulkan/DeviceVk.h"
22-
#include "libANGLE/renderer/vulkan/DynamicDescriptorPool.h"
2322
#include "libANGLE/renderer/vulkan/FenceNVVk.h"
2423
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
2524
#include "libANGLE/renderer/vulkan/ImageVk.h"
@@ -732,7 +731,7 @@ gl::Error ContextVk::memoryBarrierByRegion(const gl::Context *context, GLbitfiel
732731
return gl::InternalError();
733732
}
734733

735-
DynamicDescriptorPool *ContextVk::getDynamicDescriptorPool()
734+
vk::DynamicDescriptorPool *ContextVk::getDynamicDescriptorPool()
736735
{
737736
return &mDynamicDescriptorPool;
738737
}

src/libANGLE/renderer/vulkan/ContextVk.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#include <vulkan/vulkan.h>
1414

1515
#include "libANGLE/renderer/ContextImpl.h"
16-
#include "libANGLE/renderer/vulkan/DynamicBuffer.h"
17-
#include "libANGLE/renderer/vulkan/DynamicDescriptorPool.h"
18-
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
16+
#include "libANGLE/renderer/vulkan/vk_helpers.h"
1917

2018
namespace rx
2119
{
@@ -156,7 +154,7 @@ class ContextVk : public ContextImpl
156154

157155
void invalidateCurrentPipeline();
158156

159-
DynamicDescriptorPool *getDynamicDescriptorPool();
157+
vk::DynamicDescriptorPool *getDynamicDescriptorPool();
160158

161159
const VkClearValue &getClearColorValue() const;
162160
const VkClearValue &getClearDepthStencilValue() const;
@@ -179,7 +177,7 @@ class ContextVk : public ContextImpl
179177

180178
// The dynamic descriptor pool is externally sychronized, so cannot be accessed from different
181179
// threads simultaneously. Hence, we keep it in the ContextVk instead of the RendererVk.
182-
DynamicDescriptorPool mDynamicDescriptorPool;
180+
vk::DynamicDescriptorPool mDynamicDescriptorPool;
183181

184182
// Triggers adding dependencies to the command graph.
185183
bool mTexturesDirty;
@@ -189,7 +187,6 @@ class ContextVk : public ContextImpl
189187
VkClearValue mClearColorValue;
190188
VkClearValue mClearDepthStencilValue;
191189
};
192-
193190
} // namespace rx
194191

195192
#endif // LIBANGLE_RENDERER_VULKAN_CONTEXTVK_H_

src/libANGLE/renderer/vulkan/DynamicBuffer.cpp

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)