1 // Copyright 2018 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_PASSRESOURCEUSAGE_H 16 #define DAWNNATIVE_PASSRESOURCEUSAGE_H 17 18 #include "dawn_native/SubresourceStorage.h" 19 #include "dawn_native/dawn_platform.h" 20 21 #include <set> 22 #include <vector> 23 24 namespace dawn_native { 25 26 // This file declares various "ResourceUsage" structures. They are produced by the frontend 27 // while recording commands to be used for later validation and also some operations in the 28 // backends. The are produced by the "Encoder" objects that finalize them on "EndPass" or 29 // "Finish". Internally the "Encoder" may use the "StateTracker" to create them. 30 31 class BufferBase; 32 class QuerySetBase; 33 class TextureBase; 34 35 // The texture usage inside passes must be tracked per-subresource. 36 using TextureSubresourceUsage = SubresourceStorage<wgpu::TextureUsage>; 37 38 // Which resources are used by a synchronization scope and how they are used. The command 39 // buffer validation pre-computes this information so that backends with explicit barriers 40 // don't have to re-compute it. 41 struct SyncScopeResourceUsage { 42 std::vector<BufferBase*> buffers; 43 std::vector<wgpu::BufferUsage> bufferUsages; 44 45 std::vector<TextureBase*> textures; 46 std::vector<TextureSubresourceUsage> textureUsages; 47 48 std::vector<ExternalTextureBase*> externalTextures; 49 }; 50 51 // Contains all the resource usage data for a compute pass. 52 // 53 // Essentially a list of SyncScopeResourceUsage, one per Dispatch as required by the WebGPU 54 // specification. ComputePassResourceUsage also stores nline the set of all buffers and 55 // textures used, because some unused BindGroups may not be used at all in synchronization 56 // scope but their resources still need to be validated on Queue::Submit. 57 struct ComputePassResourceUsage { 58 // Somehow without this defaulted constructor, MSVC or its STDlib have an issue where they 59 // use the copy constructor (that's deleted) when doing operations on a 60 // vector<ComputePassResourceUsage> 61 ComputePassResourceUsage(ComputePassResourceUsage&&) = default; 62 ComputePassResourceUsage() = default; 63 64 std::vector<SyncScopeResourceUsage> dispatchUsages; 65 66 // All the resources referenced by this compute pass for validation in Queue::Submit. 67 std::set<BufferBase*> referencedBuffers; 68 std::set<TextureBase*> referencedTextures; 69 std::set<ExternalTextureBase*> referencedExternalTextures; 70 }; 71 72 // Contains all the resource usage data for a render pass. 73 // 74 // In the WebGPU specification render passes are synchronization scopes but we also need to 75 // track additional data. It is stored for render passes used by a CommandBuffer, but also in 76 // RenderBundle so they can be merged into the render passes' usage on ExecuteBundles(). 77 struct RenderPassResourceUsage : public SyncScopeResourceUsage { 78 // Storage to track the occlusion queries used during the pass. 79 std::vector<QuerySetBase*> querySets; 80 std::vector<std::vector<bool>> queryAvailabilities; 81 }; 82 83 using RenderPassUsages = std::vector<RenderPassResourceUsage>; 84 using ComputePassUsages = std::vector<ComputePassResourceUsage>; 85 86 // Contains a hierarchy of "ResourceUsage" that mirrors the hierarchy of the CommandBuffer and 87 // is used for validation and to produce barriers and lazy clears in the backends. 88 struct CommandBufferResourceUsage { 89 RenderPassUsages renderPasses; 90 ComputePassUsages computePasses; 91 92 // Resources used in commands that aren't in a pass. 93 std::set<BufferBase*> topLevelBuffers; 94 std::set<TextureBase*> topLevelTextures; 95 std::set<QuerySetBase*> usedQuerySets; 96 }; 97 98 } // namespace dawn_native 99 100 #endif // DAWNNATIVE_PASSRESOURCEUSAGE_H 101