blob: cfcaa225e1277a8bcc794332003f4d66fd767cbb [file] [log] [blame]
Austin Enge9fabf52019-08-08 17:21:39 +00001// 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 Enge9fabf52019-08-08 17:21:39 +000018#include "dawn_native/PassResourceUsage.h"
19
20#include "dawn_native/dawn_platform.h"
21
22#include <map>
23
24namespace 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 Shao64fcf392020-04-22 00:55:43 +000035 PassResourceUsageTracker(PassType passType);
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000036 void BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage);
Yunchao He23428ea2020-05-04 17:10:49 +000037 void TextureViewUsedAs(TextureViewBase* texture, wgpu::TextureUsage usage);
38 void AddTextureUsage(TextureBase* texture, const PassTextureUsage& textureUsage);
Austin Enge9fabf52019-08-08 17:21:39 +000039
Austin Enge9fabf52019-08-08 17:21:39 +000040 // Returns the per-pass usage for use by backends for APIs with explicit barriers.
41 PassResourceUsage AcquireResourceUsage();
42
43 private:
Jiawei Shao64fcf392020-04-22 00:55:43 +000044 PassType mPassType;
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000045 std::map<BufferBase*, wgpu::BufferUsage> mBufferUsages;
Yunchao He23428ea2020-05-04 17:10:49 +000046 std::map<TextureBase*, PassTextureUsage> mTextureUsages;
Austin Enge9fabf52019-08-08 17:21:39 +000047 };
48
49} // namespace dawn_native
50
51#endif // DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_