From 449b5c8f504bea1387aa9511c1317ef4b3680835 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 8 Nov 2023 03:40:05 +0100 Subject: [PATCH] Engine: draft a messaging interface for `EngineObserver` (see #1347) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For now, the `EngineObserver` is defined as an empty shell, outfitted with a low-level binary message dispatch API. Messages are keyed by a Symbol, which allows evolution of private message types. Routing and Addressing is governed by an opaque size_t hash. The `EngineEvent` data base class provides »4 Slots« of inline binary storage; concrete subclasses shall define the mapping of actual data into this space and provide a convenience constructor for events. For use by the Scheduler, a `WorkTiming`-Event is defined based on this scheme; this allows to implement the λ-work and λ-done of the Scheduler-`ExecutionCtx`. These hooks will be invoked at begin and end of any render calculations. --- src/vault/gear/activity-lang.cpp | 7 ++ src/vault/gear/engine-observer.hpp | 68 ++++++++++- src/vault/gear/scheduler.hpp | 35 +++++- wiki/thinkPad.ichthyo.mm | 176 +++++++++++++++++++++++++++-- 4 files changed, 268 insertions(+), 18 deletions(-) diff --git a/src/vault/gear/activity-lang.cpp b/src/vault/gear/activity-lang.cpp index aa5dc5b24..6924ee4e8 100644 --- a/src/vault/gear/activity-lang.cpp +++ b/src/vault/gear/activity-lang.cpp @@ -32,11 +32,14 @@ #include "vault/gear/activity-lang.hpp" #include "lib/format-obj.hpp" +#include "lib/symbol.hpp" +#include "vault/gear/scheduler.hpp"//////////////////////////////////////////////////////////////TODO extract -> scheduler.cpp #include #include ////////////////////////////////////////////////////////////TODO should be in a scheduler translation-unit / extract scheduler-API using std::string; +using lib::Symbol; using lib::time::Time; using lib::time::TimeValue; @@ -52,6 +55,10 @@ namespace gear { { return boost::hash_value (uint32_t{id}); } + + Symbol WorkTiming::WORKSTART{"WorkStart"}; + Symbol WorkTiming::WORKSTOP {"WorkStop"}; + ///////////////////////////////////////////////////////////////////////////////////////////////TODO extract scheduler-API diff --git a/src/vault/gear/engine-observer.hpp b/src/vault/gear/engine-observer.hpp index 339a4a65d..1c7ac8159 100644 --- a/src/vault/gear/engine-observer.hpp +++ b/src/vault/gear/engine-observer.hpp @@ -32,6 +32,7 @@ ** @see Activity::Verb::WORKSTART ** ** @todo WIP-WIP-WIP 10/2023 »Playback Vertical Slice« created as a stub + ** @todo design and implement the EngineObserver as publisher-subscriber... ////////////////////////////////TICKET #1347 : design EngineObserver ** */ @@ -44,23 +45,78 @@ #include "vault/gear/block-flow.hpp" #include "vault/gear/scheduler-commutator.hpp" #include "vault/gear/scheduler-invocation.hpp" -//#include "lib/symbol.hpp" +#include "lib/symbol.hpp" #include "lib/nocopy.hpp" //#include "lib/util.hpp" //#include +#include +#include namespace vault{ namespace gear { - + + using lib::Symbol; // using util::isnil; // using std::string; + using std::move; + + /** + * Low-level Render Engine event — abstracted storage base. + */ + class EngineEvent + { + protected: + static size_t constexpr RAW_SIZ = 3; + using Storage = std::array; + + template + union Payload + { + static_assert (sizeof(DAT) <= RAW_SIZ * sizeof(int64_t)); + + Storage raw; + DAT data; + + Payload() : raw{0} { } + Payload (DAT const& d) : data{d} { } + Payload (DAT && dr) : data{move(dr)} { } + + // default copy and assignment acceptable + + DAT const& operator= (DAT const& d) { data = d; return data; } + DAT const& operator= (DAT && dr) { data = move(dr); return data; } + + operator Storage&() { return raw; } + operator Storage&&() { return move(raw); } + }; + + /** base init for derived classes to implant custom payload */ + EngineEvent (Symbol msgID, Storage&& payload) + : message{msgID} + , storage_{move (payload)} + { } + + public: + EngineEvent() + : message{Symbol::BOTTOM} + , storage_{0} + { } + + // default copy and assignment acceptable + + Symbol message; + + private: + Storage storage_; + }; + /** * Collector and aggregator for performance data. - * @todo WIP-WIP 10/2023 - stub as placeholder for later development + * @todo WIP-WIP 10/2023 - stub as placeholder for later development ////////////////////////////////////TICKET #1347 : design EngineObserver * @see Scheduler */ class EngineObserver @@ -71,6 +127,12 @@ namespace gear { explicit EngineObserver() { } + + void + dispatchEvent (size_t /*address*/, EngineEvent /*event*/) + { + /* TICKET #1347 actually move this event into a dispatcher queue */ + } }; diff --git a/src/vault/gear/scheduler.hpp b/src/vault/gear/scheduler.hpp index d56d9f955..26b196ab7 100644 --- a/src/vault/gear/scheduler.hpp +++ b/src/vault/gear/scheduler.hpp @@ -94,7 +94,7 @@ ** @see SchedulerCommutator Layer-2 ** @see activity.hpp description of »Render Activities« ** - ** @todo WIP-WIP 10/2023 »Playback Vertical Slice« + ** @todo WIP 11/2023 »Playback Vertical Slice« ** */ @@ -196,7 +196,7 @@ namespace gear { /******************************************************//** * »Scheduler-Service« : coordinate render activities. - * @todo WIP-WIP 10/2023 + * @todo WIP 11/2023 * @see BlockFlow * @see SchedulerUsage_test */ @@ -387,6 +387,21 @@ namespace gear { + /** work-timing event for performance observation */ + class WorkTiming + : public EngineEvent + { + using Payload = EngineEvent::Payload