Austin Eng | e9fabf5 | 2019-08-08 17:21:39 +0000 | [diff] [blame] | 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 | |
Austin Eng | e9fabf5 | 2019-08-08 17:21:39 +0000 | [diff] [blame] | 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 BufferBase; |
| 27 | class TextureBase; |
| 28 | |
| 29 | // Helper class to encapsulate the logic of tracking per-resource usage during the |
| 30 | // validation of command buffer passes. It is used both to know if there are validation |
| 31 | // errors, and to get a list of resources used per pass for backends that need the |
| 32 | // information. |
| 33 | class PassResourceUsageTracker { |
| 34 | public: |
Jiawei Shao | 64fcf39 | 2020-04-22 00:55:43 +0000 | [diff] [blame] | 35 | PassResourceUsageTracker(PassType passType); |
Corentin Wallez | 1f6c8c4 | 2019-10-23 11:57:41 +0000 | [diff] [blame] | 36 | void BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage); |
Yunchao He | 23428ea | 2020-05-04 17:10:49 +0000 | [diff] [blame] | 37 | void TextureViewUsedAs(TextureViewBase* texture, wgpu::TextureUsage usage); |
| 38 | void AddTextureUsage(TextureBase* texture, const PassTextureUsage& textureUsage); |
Austin Eng | e9fabf5 | 2019-08-08 17:21:39 +0000 | [diff] [blame] | 39 | |
Austin Eng | e9fabf5 | 2019-08-08 17:21:39 +0000 | [diff] [blame] | 40 | // Returns the per-pass usage for use by backends for APIs with explicit barriers. |
| 41 | PassResourceUsage AcquireResourceUsage(); |
| 42 | |
| 43 | private: |
Jiawei Shao | 64fcf39 | 2020-04-22 00:55:43 +0000 | [diff] [blame] | 44 | PassType mPassType; |
Corentin Wallez | 1f6c8c4 | 2019-10-23 11:57:41 +0000 | [diff] [blame] | 45 | std::map<BufferBase*, wgpu::BufferUsage> mBufferUsages; |
Yunchao He | 23428ea | 2020-05-04 17:10:49 +0000 | [diff] [blame] | 46 | std::map<TextureBase*, PassTextureUsage> mTextureUsages; |
Austin Eng | e9fabf5 | 2019-08-08 17:21:39 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // namespace dawn_native |
| 50 | |
| 51 | #endif // DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_ |