mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-16 04:11:25 +00:00
Using this container is a small performance regression in the simple cases where all subresources are the same, or when the texture has few subrsources. However it give better performance in the hard subresource tracking cases of textures with many subresources. Using SubresourceStorage also makes it easier to work with compressed storage since the compression is mostly transparent. It reduces code duplication and prevent bugs from appearing when a developer would forget to handle compression. This fixes a state tracking issue in ValidatePassResourceUsage where the function didn't correctly handle the case where the PassResourceUsage was compressed. Also removes the unused vulkan::Texture::TransitionFullUsage. Also makes SubresourceStorage<T> only require operator== on T and not operator !=. Also fixes the texture format's aspect being used to create pipeline barriers instead of the range's aspects. Bug: dawn:441 Change-Id: I234b8191f39a09b541c1c63a60cccd6cee970550 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37706 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org> Auto-Submit: Corentin Wallez <cwallez@chromium.org>
90 lines
3.5 KiB
C++
90 lines
3.5 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.
|
|
|
|
#include "dawn_native/PassResourceUsageTracker.h"
|
|
|
|
#include "dawn_native/Buffer.h"
|
|
#include "dawn_native/EnumMaskIterator.h"
|
|
#include "dawn_native/Format.h"
|
|
#include "dawn_native/Texture.h"
|
|
|
|
namespace dawn_native {
|
|
PassResourceUsageTracker::PassResourceUsageTracker(PassType passType) : mPassType(passType) {
|
|
}
|
|
|
|
void PassResourceUsageTracker::BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage) {
|
|
// std::map's operator[] will create the key and return 0 if the key didn't exist
|
|
// before.
|
|
mBufferUsages[buffer] |= usage;
|
|
}
|
|
|
|
void PassResourceUsageTracker::TextureViewUsedAs(TextureViewBase* view,
|
|
wgpu::TextureUsage usage) {
|
|
TextureBase* texture = view->GetTexture();
|
|
const SubresourceRange& range = view->GetSubresourceRange();
|
|
|
|
// Get or create a new PassTextureUsage for that texture (initially filled with
|
|
// wgpu::TextureUsage::None)
|
|
auto it = mTextureUsages.emplace(texture, texture);
|
|
PassTextureUsage& textureUsage = it.first->second;
|
|
|
|
textureUsage.usage |= usage;
|
|
textureUsage.subresourceUsages.Update(
|
|
range, [usage](const SubresourceRange&, wgpu::TextureUsage* storedUsage) {
|
|
*storedUsage |= usage;
|
|
});
|
|
}
|
|
|
|
void PassResourceUsageTracker::AddTextureUsage(TextureBase* texture,
|
|
const PassTextureUsage& textureUsage) {
|
|
// Get or create a new PassTextureUsage for that texture (initially filled with
|
|
// wgpu::TextureUsage::None)
|
|
auto it = mTextureUsages.emplace(texture, texture);
|
|
PassTextureUsage* passTextureUsage = &it.first->second;
|
|
|
|
passTextureUsage->usage |= textureUsage.usage;
|
|
|
|
passTextureUsage->subresourceUsages.Merge(
|
|
textureUsage.subresourceUsages,
|
|
[](const SubresourceRange&, wgpu::TextureUsage* storedUsage,
|
|
const wgpu::TextureUsage& addedUsage) { *storedUsage |= addedUsage; });
|
|
}
|
|
|
|
// Returns the per-pass usage for use by backends for APIs with explicit barriers.
|
|
PassResourceUsage PassResourceUsageTracker::AcquireResourceUsage() {
|
|
PassResourceUsage result;
|
|
result.passType = mPassType;
|
|
result.buffers.reserve(mBufferUsages.size());
|
|
result.bufferUsages.reserve(mBufferUsages.size());
|
|
result.textures.reserve(mTextureUsages.size());
|
|
result.textureUsages.reserve(mTextureUsages.size());
|
|
|
|
for (auto& it : mBufferUsages) {
|
|
result.buffers.push_back(it.first);
|
|
result.bufferUsages.push_back(it.second);
|
|
}
|
|
|
|
for (auto& it : mTextureUsages) {
|
|
result.textures.push_back(it.first);
|
|
result.textureUsages.push_back(std::move(it.second));
|
|
}
|
|
|
|
mBufferUsages.clear();
|
|
mTextureUsages.clear();
|
|
|
|
return result;
|
|
}
|
|
|
|
} // namespace dawn_native
|