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/dawn_platform.h" 19 20 #include <set> 21 #include <vector> 22 23 namespace dawn_native { 24 25 class BufferBase; 26 class QuerySetBase; 27 class TextureBase; 28 29 enum class PassType { Render, Compute }; 30 31 // Describe the usage of the whole texture and its subresources. 32 // - subresourceUsages vector is used to track every subresource's usage within a texture. 33 // 34 // - usage variable is used the track the whole texture even though it can be deduced from 35 // subresources' usages. This is designed deliberately to track texture usage in a fast path 36 // at frontend. 37 // 38 // - sameUsagesAcrossSubresources is used for optimization at backend. If the texture view 39 // we are using covers all subresources, then the texture's usages of all subresources are 40 // the same. Otherwise the texture's usages of all subresources are thought as different, 41 // although we can deliberately design some particular cases in which we have a few texture 42 // views and all of them have the same usages and they cover all subresources of the texture 43 // altogether. 44 45 // TODO(yunchao.he@intel.com): if sameUsagesAcrossSubresources is true, we don't need 46 // the vector to record every single subresource's Usages. The texture usage is enough. And we 47 // can decompress texture usage to a vector if necessary. 48 struct PassTextureUsage { 49 wgpu::TextureUsage usage = wgpu::TextureUsage::None; 50 bool sameUsagesAcrossSubresources = true; 51 std::vector<wgpu::TextureUsage> subresourceUsages; 52 }; 53 54 // Which resources are used by pass and how they are used. The command buffer validation 55 // pre-computes this information so that backends with explicit barriers don't have to 56 // re-compute it. 57 struct PassResourceUsage { 58 PassType passType; 59 std::vector<BufferBase*> buffers; 60 std::vector<wgpu::BufferUsage> bufferUsages; 61 62 std::vector<TextureBase*> textures; 63 std::vector<PassTextureUsage> textureUsages; 64 }; 65 66 using PerPassUsages = std::vector<PassResourceUsage>; 67 68 struct CommandBufferResourceUsage { 69 PerPassUsages perPass; 70 std::set<BufferBase*> topLevelBuffers; 71 std::set<TextureBase*> topLevelTextures; 72 std::set<QuerySetBase*> usedQuerySets; 73 }; 74 75 } // namespace dawn_native 76 77 #endif // DAWNNATIVE_PASSRESOURCEUSAGE_H 78