• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2017 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 // Resource:
7 //    Resource lifetime tracking in the Vulkan back-end.
8 //
9 
10 #include "libANGLE/renderer/vulkan/ResourceVk.h"
11 
12 #include "libANGLE/renderer/vulkan/ContextVk.h"
13 
14 namespace rx
15 {
16 namespace vk
17 {
18 // Resource implementation.
waitForIdle(ContextVk * contextVk,const char * debugMessage,RenderPassClosureReason reason)19 angle::Result Resource::waitForIdle(ContextVk *contextVk,
20                                     const char *debugMessage,
21                                     RenderPassClosureReason reason)
22 {
23     // If there are pending commands for the resource, flush them.
24     if (contextVk->hasUnsubmittedUse(mUse))
25     {
26         ANGLE_TRY(contextVk->flushImpl(nullptr, nullptr, reason));
27     }
28 
29     RendererVk *renderer = contextVk->getRenderer();
30     // Make sure the driver is done with the resource.
31     if (!renderer->hasResourceUseFinished(mUse))
32     {
33         if (debugMessage)
34         {
35             ANGLE_VK_PERF_WARNING(contextVk, GL_DEBUG_SEVERITY_HIGH, "%s", debugMessage);
36         }
37         ANGLE_TRY(renderer->finishResourceUse(contextVk, mUse));
38     }
39 
40     ASSERT(renderer->hasResourceUseFinished(mUse));
41 
42     return angle::Result::Continue;
43 }
44 
operator <<(std::ostream & os,const ResourceUse & use)45 std::ostream &operator<<(std::ostream &os, const ResourceUse &use)
46 {
47     const Serials &serials = use.getSerials();
48     os << '{';
49     for (size_t i = 0; i < serials.size(); i++)
50     {
51         os << serials[i].getValue();
52         if (i < serials.size() - 1)
53         {
54             os << ",";
55         }
56     }
57     os << '}';
58     return os;
59 }
60 
61 // SharedGarbage implementation.
62 SharedGarbage::SharedGarbage() = default;
63 
SharedGarbage(SharedGarbage && other)64 SharedGarbage::SharedGarbage(SharedGarbage &&other)
65 {
66     *this = std::move(other);
67 }
68 
SharedGarbage(const ResourceUse & use,GarbageList && garbage)69 SharedGarbage::SharedGarbage(const ResourceUse &use, GarbageList &&garbage)
70     : mLifetime(use), mGarbage(std::move(garbage))
71 {}
72 
73 SharedGarbage::~SharedGarbage() = default;
74 
operator =(SharedGarbage && rhs)75 SharedGarbage &SharedGarbage::operator=(SharedGarbage &&rhs)
76 {
77     std::swap(mLifetime, rhs.mLifetime);
78     std::swap(mGarbage, rhs.mGarbage);
79     return *this;
80 }
81 
destroyIfComplete(RendererVk * renderer)82 bool SharedGarbage::destroyIfComplete(RendererVk *renderer)
83 {
84     if (renderer->hasResourceUseFinished(mLifetime))
85     {
86         for (GarbageObject &object : mGarbage)
87         {
88             object.destroy(renderer);
89         }
90         return true;
91     }
92     return false;
93 }
94 
hasResourceUseSubmitted(RendererVk * renderer) const95 bool SharedGarbage::hasResourceUseSubmitted(RendererVk *renderer) const
96 {
97     return renderer->hasResourceUseSubmitted(mLifetime);
98 }
99 
100 // ReleasableResource implementation.
101 template <class T>
release(RendererVk * renderer)102 void ReleasableResource<T>::release(RendererVk *renderer)
103 {
104     renderer->collectGarbage(mUse, &mObject);
105 }
106 
107 template class ReleasableResource<Semaphore>;
108 }  // namespace vk
109 }  // namespace rx
110