Framegraph improvements

- added a way to compare two handle's underlaying resource
  (i.e. do they refer to the same resource)

- minor refactoring and comment fixes
This commit is contained in:
Mathias Agopian
2020-01-09 17:40:57 -08:00
committed by Mathias Agopian
parent fbad683810
commit b351e709c1
7 changed files with 95 additions and 32 deletions

View File

@@ -48,6 +48,7 @@ set(SRCS
src/fg/FrameGraph.cpp
src/fg/FrameGraphHandle.cpp
src/fg/fg/RenderTarget.cpp
src/fg/fg/RenderTargetResource.cpp
src/fg/fg/ResourceEntry.cpp
src/fg/ResourceAllocator.cpp
src/Box.cpp

View File

@@ -199,6 +199,21 @@ bool FrameGraph::isValid(FrameGraphHandle handle) const noexcept {
return node.version == node.resource->version;
}
bool FrameGraph::equal(FrameGraphHandle lhs, FrameGraphHandle rhs) const noexcept {
if (lhs == rhs) {
return true;
}
if (lhs.isValid() != rhs.isValid()) {
return false;
}
auto const& registry = mResourceNodes;
assert(lhs.index < registry.size());
assert(rhs.index < registry.size());
assert(registry[lhs.index].resource);
assert(registry[rhs.index].resource);
return registry[lhs.index].resource == registry[rhs.index].resource;
}
FrameGraphHandle FrameGraph::createResourceNode(fg::ResourceEntryBase* resource) noexcept {
auto& resourceNodes = mResourceNodes;
size_t index = resourceNodes.size();
@@ -288,7 +303,7 @@ bool FrameGraph::equals(FrameGraphRenderTarget::Descriptor const& cacheEntry,
FrameGraphRenderTarget::Descriptor const& rt) const noexcept {
const Vector<ResourceNode>& resourceNodes = mResourceNodes;
// if the rendertarget we're looking up doesn't has the sample field set to 0, it means the
// if the rendertarget we're looking up doesn't have the sample field set to 0, it means the
// user didn't specify it, and it's okay to match it to any sample count.
// Otherwise, sample count must match, with the caveat that 0 or 1 are treated the same.
const bool samplesMatch = (!rt.samples) ||

View File

@@ -148,8 +148,11 @@ public:
FrameGraph& operator = (FrameGraph const&) = delete;
~FrameGraph();
// returns the default Blackboard
Blackboard& getBlackboard() noexcept { return mBlackboard; }
Blackboard const& getDefaultBlackboard() const noexcept { return mBlackboard; }
// returns the default Blackboard
Blackboard const& getBlackboard() const noexcept { return mBlackboard; }
struct Empty{};
@@ -195,6 +198,8 @@ public:
// it's used to declare a resource write (see Builder::write()).
bool isValid(FrameGraphHandle r) const noexcept;
bool equal(FrameGraphHandle lhs, FrameGraphHandle rhs) const noexcept;
// Return the Descriptor associated to this resource handle. The handle must be valid.
template<typename T>
typename T::Descriptor& getDescriptor(FrameGraphId<T> r) {

View File

@@ -49,6 +49,8 @@ void FrameGraphTexture::create(FrameGraph& fg, const char* name,
texture = fg.getResourceAllocator().createTexture(name, desc.type, desc.levels,
desc.format, samples, desc.width, desc.height, desc.depth, desc.usage);
assert(texture);
}
void FrameGraphTexture::destroy(FrameGraph& fg) noexcept {

View File

@@ -83,6 +83,8 @@ class FrameGraphHandle {
public:
bool isValid() const noexcept { return index != UNINITIALIZED; }
void clear() noexcept { index = UNINITIALIZED; }
bool operator < (const FrameGraphHandle& rhs) const noexcept {
return index < rhs.index;
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* 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 "RenderTargetResource.h"
namespace filament {
using namespace backend;
namespace fg {
void RenderTargetResource::create(FrameGraph& fg) noexcept {
if (!imported) {
if (any(attachments)) {
// devirtualize our texture handles. By this point these handles have been
// remapped to their alias if any.
backend::TargetBufferInfo infos[FrameGraphRenderTarget::Attachments::COUNT];
for (size_t i = 0, c = desc.attachments.textures.size(); i < c; i++) {
static constexpr TargetBufferFlags flags[] = {
TargetBufferFlags::COLOR,
TargetBufferFlags::DEPTH,
TargetBufferFlags::STENCIL };
auto const& attachmentInfo = desc.attachments.textures[i];
assert(bool(attachments & flags[i]) == attachmentInfo.isValid());
if (attachmentInfo.isValid()) {
fg::ResourceEntry<FrameGraphTexture> const& entry =
fg.getResourceEntryUnchecked(attachmentInfo.getHandle());
infos[i].handle = entry.getResource().texture;
infos[i].level = attachmentInfo.getLevel();
assert(infos[i].handle);
}
}
targetInfo.target = fg.getResourceAllocator().createRenderTarget(name,
attachments, width, height, desc.samples,
infos[0], infos[1], {});
}
}
}
void RenderTargetResource::destroy(FrameGraph& fg) noexcept {
if (!imported) {
if (targetInfo.target) {
fg.getResourceAllocator().destroyRenderTarget(targetInfo.target);
targetInfo.target.clear();
}
}
}
} // namespace fg
} // namespace filament

View File

@@ -68,37 +68,9 @@ struct RenderTargetResource final : public VirtualResource { // 104
// updated during execute with the current pass' discard flags
FrameGraphPassResources::RenderTargetInfo targetInfo;
void create(FrameGraph& fg) noexcept override {
if (!imported) {
if (any(attachments)) {
// devirtualize our texture handles. By this point these handles have been
// remapped to their alias if any.
backend::TargetBufferInfo infos[FrameGraphRenderTarget::Attachments::COUNT];
for (size_t i = 0, c = desc.attachments.textures.size(); i < c; i++) {
auto const& attachmentInfo = desc.attachments.textures[i];
if (attachmentInfo.isValid()) {
fg::ResourceEntry<FrameGraphTexture> const& entry =
fg.getResourceEntryUnchecked(attachmentInfo.getHandle());
infos[i].handle = entry.getResource().texture;
infos[i].level = attachmentInfo.getLevel();
}
}
void create(FrameGraph& fg) noexcept override;
// create the concrete rendertarget
targetInfo.target = fg.getResourceAllocator().createRenderTarget(name,
attachments, width, height, desc.samples, infos[0], infos[1], {});
}
}
}
void destroy(FrameGraph& fg) noexcept override {
if (!imported) {
if (targetInfo.target) {
fg.getResourceAllocator().destroyRenderTarget(targetInfo.target);
targetInfo.target.clear();
}
}
}
void destroy(FrameGraph& fg) noexcept override;
};
} // namespace fg