dawn-cmake/src/dawn_native/PassResourceUsageTracker.h
Jiawei Shao 64fcf3909a Allow one texture as write-only storage and sampled in one compute pass
This patch enables one texture to be used as both write-only storage
texture and sampled texture in one compute pass.

Note that while we don't need to check the usage scope of a texture in
the whole compute pass scope, we still need to verify one texture cannot
be bound to multiple bindings that are used in one dispatch at the same
time. This check will be added in the following patches.

This patch also adds tests to ensure a texture can be used as the
following binding types in one compute pass:
- read-only storage + sampled
- write-only storage + sampled
- read-only storage + write-only storage

BUG=dawn:267
TEST=dawn_unittests

Change-Id: Ibff2b005a5269a0bfa254e0417de4920758add39
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/20120
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
2020-04-22 00:55:43 +00:00

51 lines
1.8 KiB
C++

// Copyright 2019 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_
#define DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_
#include "dawn_native/PassResourceUsage.h"
#include "dawn_native/dawn_platform.h"
#include <map>
namespace dawn_native {
class BufferBase;
class TextureBase;
// Helper class to encapsulate the logic of tracking per-resource usage during the
// validation of command buffer passes. It is used both to know if there are validation
// errors, and to get a list of resources used per pass for backends that need the
// information.
class PassResourceUsageTracker {
public:
PassResourceUsageTracker(PassType passType);
void BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage);
void TextureUsedAs(TextureBase* texture, wgpu::TextureUsage usage);
// Returns the per-pass usage for use by backends for APIs with explicit barriers.
PassResourceUsage AcquireResourceUsage();
private:
PassType mPassType;
std::map<BufferBase*, wgpu::BufferUsage> mBufferUsages;
std::map<TextureBase*, wgpu::TextureUsage> mTextureUsages;
};
} // namespace dawn_native
#endif // DAWNNATIVE_PASSRESOURCEUSAGETRACKER_H_