2008-07-20 20:08:08 +02:00
|
|
|
/*
|
2009-08-31 01:32:53 +02:00
|
|
|
NODEINVOCATION.hpp - Organise the invocation state within a single pull() call
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-20 20:08:08 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-20 20:08:08 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2008-07-20 20:08:08 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-20 20:08:08 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-07-20 20:08:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @file nodeinvocation.hpp
|
2008-10-13 04:33:10 +02:00
|
|
|
** Organise the state related to the invocation of s single ProcNode::pull() call
|
2008-07-20 20:08:08 +02:00
|
|
|
** This header defines part of the "glue" which holds together the render node network
|
2008-08-04 05:42:55 +02:00
|
|
|
** and enables to pull result frames from the nodes. Doing so requires some invocation
|
|
|
|
|
** local state to be maintained, especially a table of buffers used to carry out the
|
2008-07-20 20:08:08 +02:00
|
|
|
** calculations. Further, getting the input buffers filled requires to issue recursive
|
|
|
|
|
** \c pull() calls, which on the whole creates a stack-like assembly of local invocation
|
|
|
|
|
** state.
|
2008-10-13 04:33:10 +02:00
|
|
|
** The actual steps to be carried out for a \c pull() call are dependent on the configuration
|
2024-05-06 23:51:48 +02:00
|
|
|
** of the node to pull. Each node has been preconfigured by the builder with a Connectivity
|
|
|
|
|
** descriptor and a concrete type of a StateAdapter. The actual sequence of steps is defined
|
|
|
|
|
** in the header nodeoperation.hpp out of a set of basic operation steps. These steps all use
|
|
|
|
|
** the passed in Invocation object (a sub-interface of StateAdapter) to access the various
|
|
|
|
|
** aspects of the invocation state.
|
2008-07-20 20:08:08 +02:00
|
|
|
**
|
2021-01-23 16:45:04 +01:00
|
|
|
** # composition of the Invocation State
|
2016-11-09 19:13:52 +01:00
|
|
|
**
|
2008-07-20 20:08:08 +02:00
|
|
|
** For each individual ProcNode#pull() call, the WiringAdapter#callDown() builds an StateAdapter
|
2008-08-04 05:42:55 +02:00
|
|
|
** instance directly on the stack, managing the actual buffer pointers and state references. Using this
|
2008-07-20 20:08:08 +02:00
|
|
|
** StateAdapter, the predecessor nodes are pulled. The way these operations are carried out is encoded
|
|
|
|
|
** in the actual StateAdapter type known to the NodeWiring (WiringAdapter) instance. All of these actual
|
2024-05-06 23:51:48 +02:00
|
|
|
** StateAdapter types are built as implementing the engine::StateClosure interface.
|
2016-11-09 19:13:52 +01:00
|
|
|
**
|
|
|
|
|
** @todo relies still on an [obsoleted implementation draft](\ref bufftable-obsolete.hpp)
|
2008-07-20 20:08:08 +02:00
|
|
|
** @see engine::ProcNode
|
|
|
|
|
** @see engine::StateProxy
|
2024-05-11 17:06:12 +02:00
|
|
|
** @see engine::FeedManifold
|
2008-07-20 20:08:08 +02:00
|
|
|
** @see nodewiring.hpp interface for building/wiring the nodes
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef ENGINE_NODEINVOCATION_H
|
|
|
|
|
#define ENGINE_NODEINVOCATION_H
|
|
|
|
|
|
|
|
|
|
|
2024-06-24 23:49:55 +02:00
|
|
|
//#include "steam/engine/proc-node.hpp" ///////////////////////////////TODO clarify if required further on
|
|
|
|
|
#include "steam/engine/connectivity-obsolete.hpp"
|
2024-06-21 16:14:24 +02:00
|
|
|
#include "steam/engine/state-closure-obsolete.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
#include "steam/engine/channel-descriptor.hpp"
|
2024-06-24 23:49:55 +02:00
|
|
|
#include "steam/engine/feed-manifold-obsolete.hpp"
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
namespace steam {
|
2008-07-20 20:08:08 +02:00
|
|
|
namespace engine {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adapter to shield the ProcNode from the actual buffer management,
|
|
|
|
|
* allowing the processing function within ProcNode to use logical
|
|
|
|
|
* buffer IDs. StateAdapter is created on the stack for each pull()
|
|
|
|
|
* call, using setup/wiring data preconfigured by the builder.
|
|
|
|
|
* Its job is to provide the actual implementation of the Cache
|
|
|
|
|
* push / fetch and recursive downcall to render the source frames.
|
|
|
|
|
*/
|
|
|
|
|
class StateAdapter
|
2024-06-21 16:14:24 +02:00
|
|
|
: public StateClosure_OBSOLETE
|
2008-07-20 20:08:08 +02:00
|
|
|
{
|
|
|
|
|
protected:
|
2024-06-21 16:14:24 +02:00
|
|
|
StateClosure_OBSOLETE& parent_;
|
|
|
|
|
StateClosure_OBSOLETE& current_;
|
2008-07-20 20:08:08 +02:00
|
|
|
|
2024-06-21 16:14:24 +02:00
|
|
|
StateAdapter (StateClosure_OBSOLETE& callingProcess)
|
2008-07-20 20:08:08 +02:00
|
|
|
: parent_ (callingProcess),
|
|
|
|
|
current_(callingProcess.getCurrentImplementation())
|
|
|
|
|
{ }
|
|
|
|
|
|
2024-06-21 16:14:24 +02:00
|
|
|
virtual StateClosure_OBSOLETE& getCurrentImplementation () { return current_; }
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-06 23:51:48 +02:00
|
|
|
public: /* === proxying the StateClosure interface === */
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
virtual void releaseBuffer (BuffHandle& bh) { current_.releaseBuffer (bh); }
|
|
|
|
|
|
|
|
|
|
virtual void is_calculated (BuffHandle const& bh) { current_.is_calculated (bh); }
|
|
|
|
|
|
|
|
|
|
virtual BuffHandle fetch (FrameID const& fID) { return current_.fetch (fID); }
|
|
|
|
|
|
2024-05-06 23:51:48 +02:00
|
|
|
virtual BuffTableStorage& getBuffTableStorage() { return current_.getBuffTableStorage(); }
|
2009-09-05 18:15:58 +02:00
|
|
|
|
2009-06-26 18:50:30 +02:00
|
|
|
// note: allocateBuffer() is chosen specifically based on the actual node wiring
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Invocation context state.
|
|
|
|
|
* A ref to this type is carried through the chain of NEXT::step() functions
|
|
|
|
|
* which form the actual invocation sequence. The various operations in this sequence
|
|
|
|
|
* access the context via the references in this struct, while also using the inherited
|
|
|
|
|
* public State interface. The object instance actually used as Invocation is created
|
2009-06-26 18:50:30 +02:00
|
|
|
* on the stack and parametrised according to the necessities of the invocation sequence
|
2024-05-11 17:06:12 +02:00
|
|
|
* actually configured. Initially, this real instance is configured without FeedManifold,
|
2008-07-20 20:08:08 +02:00
|
|
|
* because the invocation may be short-circuited due to Cache hit. Otherwise, when
|
|
|
|
|
* the invocation sequence actually prepares to call the process function of this
|
|
|
|
|
* ProcNode, a buffer table chunk is allocated by the StateProxy and wired in.
|
|
|
|
|
*/
|
|
|
|
|
struct Invocation
|
|
|
|
|
: StateAdapter
|
|
|
|
|
{
|
2024-05-06 23:51:48 +02:00
|
|
|
Connectivity const& wiring;
|
2008-07-20 20:08:08 +02:00
|
|
|
const uint outNr;
|
|
|
|
|
|
2024-05-11 17:06:12 +02:00
|
|
|
FeedManifold* feedManifold;
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
protected:
|
2024-05-11 17:06:12 +02:00
|
|
|
/** creates a new invocation context state, without FeedManifold */
|
2024-06-21 16:14:24 +02:00
|
|
|
Invocation (StateClosure_OBSOLETE& callingProcess, Connectivity const& w, uint o)
|
2008-07-20 20:08:08 +02:00
|
|
|
: StateAdapter(callingProcess),
|
|
|
|
|
wiring(w), outNr(o),
|
2024-05-11 17:06:12 +02:00
|
|
|
feedManifold(0)
|
2008-07-20 20:08:08 +02:00
|
|
|
{ }
|
|
|
|
|
|
2009-09-05 18:15:58 +02:00
|
|
|
public:
|
|
|
|
|
uint nrO() const { return wiring.nrO; }
|
|
|
|
|
uint nrI() const { return wiring.nrI; }
|
|
|
|
|
uint buffTabSize() const { return nrO()+nrI(); }
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
/** setup the link to an externally allocated buffer table */
|
2024-05-11 17:06:12 +02:00
|
|
|
void setBuffTab (FeedManifold* b) { this->feedManifold = b; }
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
buffTab_isConsistent ()
|
|
|
|
|
{
|
2024-05-11 17:06:12 +02:00
|
|
|
return (feedManifold)
|
2008-07-20 20:08:08 +02:00
|
|
|
&& (0 < buffTabSize())
|
|
|
|
|
&& (nrO()+nrI() <= buffTabSize())
|
2024-05-11 17:06:12 +02:00
|
|
|
&& (feedManifold->inBuff == &feedManifold->outBuff[nrO()] )
|
|
|
|
|
&& (feedManifold->inHandle == &feedManifold->outHandle[nrO()])
|
2008-07-20 20:08:08 +02:00
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-10-14 05:33:48 +02:00
|
|
|
public:
|
|
|
|
|
/** specialised version filling in the additional information, i.e
|
|
|
|
|
* the concrete node id and the channel number in question */
|
|
|
|
|
virtual FrameID const&
|
|
|
|
|
genFrameID ()
|
|
|
|
|
{
|
|
|
|
|
return current_.genFrameID(wiring.nodeID, outNr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual FrameID const&
|
|
|
|
|
genFrameID (NodeID const& nID, uint chanNo)
|
|
|
|
|
{
|
|
|
|
|
return current_.genFrameID (nID,chanNo);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-20 20:08:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-09-04 01:54:36 +02:00
|
|
|
////////////TICKET #249 this strategy should better be hidden within the BuffHandle ctor (and type-erased after creation)
|
2024-05-06 23:51:48 +02:00
|
|
|
struct AllocBufferFromParent ///< using the parent StateAdapter for buffer allocations
|
|
|
|
|
: Invocation
|
|
|
|
|
{
|
2024-06-21 16:14:24 +02:00
|
|
|
AllocBufferFromParent (StateClosure_OBSOLETE& sta, Connectivity const& w, const uint outCh)
|
2024-05-06 23:51:48 +02:00
|
|
|
: Invocation(sta, w, outCh) {}
|
|
|
|
|
|
|
|
|
|
virtual BuffHandle
|
|
|
|
|
allocateBuffer (const lumiera::StreamType* ty) { return parent_.allocateBuffer(ty); } ////////////TODO: actually implement the "allocate from parent" logic!
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct AllocBufferFromCache ///< using the global current StateClosure, which will delegate to Cache
|
|
|
|
|
: Invocation
|
|
|
|
|
{
|
2024-06-21 16:14:24 +02:00
|
|
|
AllocBufferFromCache (StateClosure_OBSOLETE& sta, Connectivity const& w, const uint outCh)
|
2024-05-06 23:51:48 +02:00
|
|
|
: Invocation(sta, w, outCh) {}
|
|
|
|
|
|
|
|
|
|
virtual BuffHandle
|
|
|
|
|
allocateBuffer (const lumiera::StreamType* ty) { return current_.allocateBuffer(ty); }
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-20 20:08:08 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The real invocation context state implementation. It is created
|
2024-05-06 23:51:48 +02:00
|
|
|
* by the NodeWiring (Connectivity) of the processing node which
|
2008-07-20 20:08:08 +02:00
|
|
|
* is pulled by this invocation, hereby using the internal configuration
|
2024-05-06 23:51:48 +02:00
|
|
|
* information to guide the selection of the real call sequence
|
2008-07-20 20:08:08 +02:00
|
|
|
*
|
|
|
|
|
* \par assembling the call sequence implementation
|
|
|
|
|
* Each ProcNode#pull() call creates such a StateAdapter subclass on the stack,
|
2024-05-06 23:51:48 +02:00
|
|
|
* with a concrete type according to the Connectivity of the node to pull.
|
2008-07-20 20:08:08 +02:00
|
|
|
* This concrete type encodes a calculation Strategy, which is assembled
|
|
|
|
|
* as a chain of policy templates on top of OperationBase. For each of the
|
2008-10-13 04:33:10 +02:00
|
|
|
* possible configurations we define such a chain (see bottom of nodeoperation.hpp).
|
2008-07-20 20:08:08 +02:00
|
|
|
* The WiringFactory defined in nodewiring.cpp actually drives the instantiation
|
|
|
|
|
* of all those possible combinations.
|
|
|
|
|
*/
|
|
|
|
|
template<class Strategy, class BufferProvider>
|
|
|
|
|
class ActualInvocationProcess
|
|
|
|
|
: public BufferProvider
|
2009-09-05 18:15:58 +02:00
|
|
|
, private Strategy
|
2008-07-20 20:08:08 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2024-06-21 16:14:24 +02:00
|
|
|
ActualInvocationProcess (StateClosure_OBSOLETE& callingProcess, Connectivity const& w, const uint outCh)
|
2008-08-04 05:42:55 +02:00
|
|
|
: BufferProvider(callingProcess, w, outCh)
|
2008-07-20 20:08:08 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
/** contains the details of Cache query and recursive calls
|
2024-05-06 23:51:48 +02:00
|
|
|
* to the predecessor node(s), eventually followed by the
|
2008-07-20 20:08:08 +02:00
|
|
|
* ProcNode::process() callback
|
|
|
|
|
*/
|
|
|
|
|
BuffHandle retrieve ()
|
|
|
|
|
{
|
|
|
|
|
return Strategy::step (*this);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
}} // namespace steam::engine
|
2008-07-20 20:08:08 +02:00
|
|
|
#endif
|