2008-06-24 05:19:11 +02:00
|
|
|
/*
|
|
|
|
|
NODEOPERATION.hpp - Specify how the nodes call each other and how processing is organized
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
/** @file nodeoperation.hpp
|
|
|
|
|
** Chunks of operation for invoking the rendernodes.
|
|
|
|
|
** This header defines the "glue" which holds together the render node network
|
|
|
|
|
** and enables to pull a result frames from the nodes. Especially, the aspect of
|
|
|
|
|
** buffer management is covered here. Each node has been preconfigured by the builder
|
|
|
|
|
** with a WiringDescriptor and a concrete type of a StateAdapter. These concrete
|
|
|
|
|
** StateAdapter objects are assembled out of the building blocks defined in this header,
|
|
|
|
|
** depending on the desired mode of operation. Any node can be built to
|
|
|
|
|
** - participate in the Caching or ignore the cache
|
|
|
|
|
** - actually process a result or just pull frames from a source
|
|
|
|
|
** - employ in-Place calculations or use separate in/out buffers
|
|
|
|
|
** Additionally, each node may have a given number of input/output pins, expecting to
|
|
|
|
|
** be provided with buffers holding a specific kind of data.
|
|
|
|
|
**
|
|
|
|
|
** \par composition of the StateAdapter
|
|
|
|
|
** For each individual ProcNode#pull() call, the WiringAdapter#callDown() builds an StateAdapter
|
|
|
|
|
** instance directly on the stack, holding the actual buffer pointers and state references. Using this
|
|
|
|
|
** 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
|
|
|
|
|
** StateAdapter types are built as implementing the engine::State interface, on top of the InvocationStateBase
|
|
|
|
|
** and inheriting from a chain of strategy classes (single inheritance, mostly \em no virtual functions).
|
|
|
|
|
**
|
|
|
|
|
** @see engine::ProcNode
|
|
|
|
|
** @see engine::StateProxy
|
|
|
|
|
** @see nodewiring.hpp interface for building/wiring the nodes
|
|
|
|
|
**
|
|
|
|
|
*/
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
#ifndef ENGINE_NODEOPERATION_H
|
|
|
|
|
#define ENGINE_NODEOPERATION_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "proc/engine/procnode.hpp"
|
2008-07-05 18:50:54 +02:00
|
|
|
#include "proc/engine/nodewiringconfig.hpp"
|
|
|
|
|
#include "lib/appconfig.hpp"
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace engine {
|
|
|
|
|
|
|
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (abstract) base class of all concrete StateAdapter types.
|
|
|
|
|
* Defines the skeleton for the node operation/calculation
|
|
|
|
|
*/
|
|
|
|
|
class InvocationStateBase
|
|
|
|
|
: public State
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
};
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
: public State
|
|
|
|
|
{
|
|
|
|
|
State& parent_;
|
|
|
|
|
State& current_;
|
2008-06-29 15:32:19 +02:00
|
|
|
WiringDescriptor const& wiring_;
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
StateAdapter (State& callingProcess, WiringDescriptor const&)
|
|
|
|
|
: parent_ (callingProcess),
|
|
|
|
|
current_(callingProcess.getCurrentImplementation())
|
|
|
|
|
{ }
|
|
|
|
|
|
2008-06-29 15:32:19 +02:00
|
|
|
friend class NodeWiring<StateAdapter>; // both are sharing implementation details...
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual State& getCurrentImplementation () { return current_; }
|
|
|
|
|
|
|
|
|
|
/** contains the details of Cache query and recursive calls
|
|
|
|
|
* to the predecessor node(s), eventually followed by the
|
|
|
|
|
* ProcNode::process() callback
|
|
|
|
|
*/
|
2008-06-29 15:32:19 +02:00
|
|
|
BuffHandle retrieve (uint requiredOutputNr)
|
|
|
|
|
{
|
|
|
|
|
return retrieveResult (requiredOutputNr);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
template<class NEXT>
|
|
|
|
|
struct QueryCache : NEXT
|
2008-06-29 15:32:19 +02:00
|
|
|
{
|
2008-07-01 04:53:23 +02:00
|
|
|
BuffHandle step () // brauche: current state
|
2008-06-29 15:32:19 +02:00
|
|
|
{
|
|
|
|
|
BuffHandle fetched = current_.fetch (genFrameID (requiredOutputNr));
|
|
|
|
|
if (fetched)
|
|
|
|
|
return fetched;
|
2008-07-01 04:53:23 +02:00
|
|
|
else
|
|
|
|
|
return NEXT::step();
|
2008-06-29 15:32:19 +02:00
|
|
|
}
|
|
|
|
|
};
|
2008-07-01 04:53:23 +02:00
|
|
|
|
2008-06-29 15:32:19 +02:00
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
template<class NEXT>
|
|
|
|
|
struct PullInput : NEXT
|
2008-06-29 15:32:19 +02:00
|
|
|
{
|
2008-07-01 04:53:23 +02:00
|
|
|
BuffHandle step ()
|
2008-06-29 15:32:19 +02:00
|
|
|
{
|
2008-07-01 04:53:23 +02:00
|
|
|
this->createBuffTable();
|
|
|
|
|
|
|
|
|
|
ASSERT (this->buffTab);
|
|
|
|
|
ASSERT (0 < this->buffTabSize());
|
|
|
|
|
ASSERT (this->nrO+this->nrI <= this->buffTabSize());
|
|
|
|
|
ASSERT (this->buffTab->inHandles = &this->buffTab->handles[this->nrO]);
|
|
|
|
|
BuffHandle *inH = this->buffTab->inHandles;
|
|
|
|
|
BuffHandle::PBuff *inBuff = this->buffTab->inBuffs;
|
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < this->nrI; ++i )
|
|
|
|
|
{
|
|
|
|
|
inBuff[i] =
|
|
|
|
|
*(inH[i] = this->pullPredecessor(i)); // invoke predecessor
|
|
|
|
|
// now Input #i is ready...
|
|
|
|
|
}
|
|
|
|
|
return NEXT::step();
|
2008-06-29 15:32:19 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
template<class NEXT>
|
|
|
|
|
struct AllocOutputFromCache
|
2008-06-29 15:32:19 +02:00
|
|
|
{
|
2008-07-01 04:53:23 +02:00
|
|
|
BuffHandle step ()
|
2008-06-29 15:32:19 +02:00
|
|
|
{
|
2008-07-01 04:53:23 +02:00
|
|
|
ASSERT (this->buffTab);
|
|
|
|
|
ASSERT (this->nrO < this->buffTabSize());
|
|
|
|
|
BuffHandle *outH = this->buffTab->handles;
|
|
|
|
|
BuffHandle::PBuff *outBuff = this->buffTab->buffers;
|
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < this->nrO; ++i )
|
2008-06-29 15:32:19 +02:00
|
|
|
{
|
2008-07-01 04:53:23 +02:00
|
|
|
outBuff[i] =
|
|
|
|
|
*(outH[i] = this->allocateBuffer(i));
|
2008-06-29 15:32:19 +02:00
|
|
|
// now Output buffer for channel #i is available...
|
|
|
|
|
}
|
2008-07-01 04:53:23 +02:00
|
|
|
return NEXT::step();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class NEXT>
|
|
|
|
|
struct ProcessData
|
|
|
|
|
{
|
|
|
|
|
BuffHandle step ()
|
|
|
|
|
{
|
|
|
|
|
ASSERT (this->buffTab);
|
|
|
|
|
ASSERT (this->nrO+this->nrI <= this->buffTabSize());
|
|
|
|
|
ASSERT (this->validateBuffers());
|
2008-06-29 15:32:19 +02:00
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
// Invoke our own process() function, providing the buffer array
|
|
|
|
|
this->wiring_.processFunction (this->buffTab->buffers);
|
2008-06-29 15:32:19 +02:00
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
return NEXT::step();
|
2008-06-29 15:32:19 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
template<class NEXT>
|
|
|
|
|
struct FeedCache
|
|
|
|
|
{
|
|
|
|
|
BuffHandle step ()
|
|
|
|
|
{
|
|
|
|
|
// declare all Outputs as finished
|
|
|
|
|
this->current_.isCalculated(this->buffTab->handles,
|
|
|
|
|
this->nrO);
|
|
|
|
|
|
|
|
|
|
return NEXT::step();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class NEXT>
|
|
|
|
|
struct ReleaseBuffers
|
|
|
|
|
{
|
|
|
|
|
BuffHandle step ()
|
|
|
|
|
{
|
|
|
|
|
// all buffers besides the required Output no longer needed
|
|
|
|
|
this->current_.releaseBuffers(this->buffTab->handles,
|
|
|
|
|
this->buffTabSize(),
|
|
|
|
|
this->requiredOutputNr);
|
|
|
|
|
|
|
|
|
|
return this->buffTab->outH[this->requiredOutputNr];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class NEXT>
|
2008-06-29 15:32:19 +02:00
|
|
|
struct NoProcess
|
|
|
|
|
{
|
|
|
|
|
BuffHandle calculateResult(BuffHandle* calculated)
|
|
|
|
|
{
|
|
|
|
|
uint nrO = this->getNrO();
|
|
|
|
|
for (uint i = 0; i<nrO; ++i )
|
|
|
|
|
{
|
|
|
|
|
calculated[i] = this->retrieveInput(i); ///TODO: Null pointer when no caching!!!!!
|
|
|
|
|
this->outBuff[i] = current_.getBuffer(calculated[i]);
|
|
|
|
|
// now Buffer containing Output channel #i is available...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->feedCache();
|
|
|
|
|
for (uint i=0; i < nrO; ++i)
|
|
|
|
|
if (i!=requiredOutputNr)
|
|
|
|
|
current_.releaseBuffer(i);
|
|
|
|
|
|
|
|
|
|
return calculated[requiredOutputNr];
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-24 05:19:11 +02:00
|
|
|
};
|
|
|
|
|
|
2008-07-01 04:53:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* === declare the possible Assembly of these elementary steps === */
|
|
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
|
struct Strategy
|
|
|
|
|
{
|
|
|
|
|
BuffHandle step () { NOTREACHED; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
2008-07-07 05:40:53 +02:00
|
|
|
struct Strategy< Config<CACHING,PROCESS,INPLACE> >
|
2008-07-01 04:53:23 +02:00
|
|
|
: QueryCache <
|
|
|
|
|
PullInput<
|
|
|
|
|
AllocOutputFromCache<
|
|
|
|
|
ProcessData<
|
|
|
|
|
FeedCache<
|
|
|
|
|
ReleaseBuffers<
|
|
|
|
|
InvocationStateBase > > > > > >
|
|
|
|
|
{ };
|
|
|
|
|
|
|
|
|
|
template<>
|
2008-07-07 05:40:53 +02:00
|
|
|
struct Strategy< Config<PROCESS> >
|
2008-07-01 04:53:23 +02:00
|
|
|
: PullInput<
|
|
|
|
|
AllocOutputFromParent<
|
|
|
|
|
ProcessData<
|
|
|
|
|
ReleaseBuffers<
|
|
|
|
|
InvocationStateBase > > > >
|
|
|
|
|
{ };
|
2008-06-24 05:19:11 +02:00
|
|
|
|
|
|
|
|
|
2008-07-05 18:50:54 +02:00
|
|
|
// At Application startup: build table of all possible operation configs
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
determine_if_case_is_possible (Bits& caseFlags)
|
|
|
|
|
{
|
|
|
|
|
////////////////////////////////////////////////TODO: Henne oder Ei?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
build_table_of_possible_configs ()
|
|
|
|
|
{
|
|
|
|
|
registerPossibleCases (&determine_if_case_is_possible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace lumiera;
|
|
|
|
|
LifecycleHook schedule_ (ON_BASIC_INIT, &build_table_of_possible_configs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-06-24 05:19:11 +02:00
|
|
|
} // namespace engine
|
|
|
|
|
#endif
|