From fbad6838109c862a2dceea88bb679dc10b760f02 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Thu, 9 Jan 2020 16:46:18 -0800 Subject: [PATCH] Implement a "black board" for the framegraph FrameGraph always keeps a default Blackboard, but additional ones can be created if needed. A blackboard is just a registry of FrameGraphHandles, queryable by name. --- filament/CMakeLists.txt | 2 ++ filament/src/fg/Blackboard.cpp | 35 +++++++++++++++++++ filament/src/fg/Blackboard.h | 55 ++++++++++++++++++++++++++++++ filament/src/fg/FrameGraph.h | 5 +++ filament/src/fg/FrameGraphHandle.h | 2 ++ 5 files changed, 99 insertions(+) create mode 100644 filament/src/fg/Blackboard.cpp create mode 100644 filament/src/fg/Blackboard.h diff --git a/filament/CMakeLists.txt b/filament/CMakeLists.txt index 2de45bd7fc..3de27a70a2 100644 --- a/filament/CMakeLists.txt +++ b/filament/CMakeLists.txt @@ -44,6 +44,7 @@ set(SRCS src/components/LightManager.cpp src/components/RenderableManager.cpp src/components/TransformManager.cpp + src/fg/Blackboard.cpp src/fg/FrameGraph.cpp src/fg/FrameGraphHandle.cpp src/fg/fg/RenderTarget.cpp @@ -90,6 +91,7 @@ set(PRIVATE_HDRS src/components/LightManager.h src/components/RenderableManager.h src/components/TransformManager.h + src/fg/Blackboard.h src/fg/FrameGraph.h src/fg/FrameGraphPass.h src/fg/FrameGraphPassResources.h diff --git a/filament/src/fg/Blackboard.cpp b/filament/src/fg/Blackboard.cpp new file mode 100644 index 0000000000..191af16f27 --- /dev/null +++ b/filament/src/fg/Blackboard.cpp @@ -0,0 +1,35 @@ +/* + * 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 "Blackboard.h" + +using namespace utils; + +namespace filament { + +FrameGraphHandle Blackboard::getHandle(utils::StaticString const& name) const noexcept { + auto it = mMap.find(name); + if (it != mMap.end()) { + return it.value(); + } + return {}; +} + +void Blackboard::remove(utils::StaticString const& name) noexcept { + mMap.erase(name); +} + +} // namespace filament diff --git a/filament/src/fg/Blackboard.h b/filament/src/fg/Blackboard.h new file mode 100644 index 0000000000..3f3156c2cd --- /dev/null +++ b/filament/src/fg/Blackboard.h @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#ifndef TNT_FILAMENT_FG_BLACKBOARD_H +#define TNT_FILAMENT_FG_BLACKBOARD_H + +#include "FrameGraphHandle.h" + +#include + +#include + +namespace filament { + +class Blackboard { + using Container = tsl::robin_map; + +public: + auto& operator [](utils::StaticString const& name) noexcept { + return mMap.insert_or_assign(name, FrameGraphHandle{}).first.value(); + } + + template + void put(utils::StaticString const& name, FrameGraphId handle) noexcept { + mMap.insert_or_assign(name, handle); + } + + template + FrameGraphId get(utils::StaticString&& name) const noexcept { + return static_cast>(getHandle(std::forward(name))); + } + + void remove(utils::StaticString const& name) noexcept; + +private: + FrameGraphHandle getHandle(utils::StaticString const& name) const noexcept; + Container mMap; +}; + +} // namespace filament + +#endif //TNT_FILAMENT_FG_BLACKBOARD_H diff --git a/filament/src/fg/FrameGraph.h b/filament/src/fg/FrameGraph.h index a8733643f0..09bbf1f424 100644 --- a/filament/src/fg/FrameGraph.h +++ b/filament/src/fg/FrameGraph.h @@ -18,6 +18,7 @@ #define TNT_FILAMENT_FRAMEGRAPH_H +#include "Blackboard.h" #include "FrameGraphPass.h" #include "FrameGraphHandle.h" #include "FrameGraphPassResources.h" @@ -147,6 +148,9 @@ public: FrameGraph& operator = (FrameGraph const&) = delete; ~FrameGraph(); + Blackboard& getBlackboard() noexcept { return mBlackboard; } + Blackboard const& getDefaultBlackboard() const noexcept { return mBlackboard; } + struct Empty{}; /* @@ -322,6 +326,7 @@ private: FrameGraphHandle moveResource(FrameGraphHandle from, FrameGraphHandle to); + Blackboard mBlackboard; fg::ResourceAllocatorInterface& mResourceAllocator; details::LinearAllocatorArena mArena; Vector mPassNodes; // list of frame graph passes diff --git a/filament/src/fg/FrameGraphHandle.h b/filament/src/fg/FrameGraphHandle.h index 821846f5f8..f6db4458c5 100644 --- a/filament/src/fg/FrameGraphHandle.h +++ b/filament/src/fg/FrameGraphHandle.h @@ -34,6 +34,7 @@ struct RenderTarget; struct RenderTargetResource; } // namespace fg +class Blackboard; class FrameGraph; class FrameGraphPassResources; @@ -64,6 +65,7 @@ class FrameGraphId; class FrameGraphHandle { template friend class FrameGraphId; + friend class Blackboard; friend class FrameGraph; friend class FrameGraphPassResources; friend struct fg::PassNode;