• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_
16 #define DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_
17 
18 #include "dawn_native/PassResourceUsage.h"
19 
20 #include "dawn_native/dawn_platform.h"
21 
22 #include <map>
23 
24 namespace dawn_native {
25 
26     class BindGroupBase;
27     class BufferBase;
28     class ExternalTextureBase;
29     class QuerySetBase;
30     class TextureBase;
31 
32     using QueryAvailabilityMap = std::map<QuerySetBase*, std::vector<bool>>;
33 
34     // Helper class to build SyncScopeResourceUsages
35     class SyncScopeUsageTracker {
36       public:
37         void BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage);
38         void TextureViewUsedAs(TextureViewBase* texture, wgpu::TextureUsage usage);
39         void AddRenderBundleTextureUsage(TextureBase* texture,
40                                          const TextureSubresourceUsage& textureUsage);
41 
42         // Walks the bind groups and tracks all its resources.
43         void AddBindGroup(BindGroupBase* group);
44 
45         // Returns the per-pass usage for use by backends for APIs with explicit barriers.
46         SyncScopeResourceUsage AcquireSyncScopeUsage();
47 
48       private:
49         std::map<BufferBase*, wgpu::BufferUsage> mBufferUsages;
50         std::map<TextureBase*, TextureSubresourceUsage> mTextureUsages;
51         std::set<ExternalTextureBase*> mExternalTextureUsages;
52     };
53 
54     // Helper class to build ComputePassResourceUsages
55     class ComputePassResourceUsageTracker {
56       public:
57         void AddDispatch(SyncScopeResourceUsage scope);
58         void AddReferencedBuffer(BufferBase* buffer);
59         void AddResourcesReferencedByBindGroup(BindGroupBase* group);
60 
61         ComputePassResourceUsage AcquireResourceUsage();
62 
63       private:
64         ComputePassResourceUsage mUsage;
65     };
66 
67     // Helper class to build RenderPassResourceUsages
68     class RenderPassResourceUsageTracker : public SyncScopeUsageTracker {
69       public:
70         void TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex);
71         const QueryAvailabilityMap& GetQueryAvailabilityMap() const;
72 
73         RenderPassResourceUsage AcquireResourceUsage();
74 
75       private:
76         // Hide AcquireSyncScopeUsage since users of this class should use AcquireResourceUsage
77         // instead.
78         using SyncScopeUsageTracker::AcquireSyncScopeUsage;
79 
80         // Tracks queries used in the render pass to validate that they aren't written twice.
81         QueryAvailabilityMap mQueryAvailabilities;
82     };
83 
84 }  // namespace dawn_native
85 
86 #endif  // DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_
87