Lumiera  0.pre.03
»edit your freedom«
weaving-pattern.hpp
Go to the documentation of this file.
1 /*
2  WEAVING-PATTERN.hpp - Base patterns to organise data connections and render processing invocation
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6  2024, Hermann Vosseler <Ichthyostega@web.de>
7 
8   **Lumiera** is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by the
10   Free Software Foundation; either version 2 of the License, or (at your
11   option) any later version. See the file COPYING for further details.
12 
13 */
14 
15 
50 #ifndef STEAM_ENGINE_WEAVING_PATTERN_H
51 #define STEAM_ENGINE_WEAVING_PATTERN_H
52 
53 #include "steam/common.hpp"
58 //#include "vault/gear/job.h"
59 //#include "steam/engine/exit-node.hpp"
60 //#include "lib/time/timevalue.hpp"
61 //#include "lib/linked-elements.hpp"
62 #include "lib/several.hpp"
63 //#include "lib/util-foreach.hpp"
64 //#include "lib/iter-adapter.hpp"
65 #include "lib/meta/function.hpp"
66 //#include "lib/itertools.hpp"
67 //#include "lib/util.hpp" ////////OOO wegen manifoldSiz<FUN>()
68 
69 #include <utility>
70 #include <array>
71 //#include <stack>
72 
73 
74 namespace steam {
75 namespace engine {
76 
77  using std::forward;
78  using lib::Several;
79 
81 #if false
82 
90  class StateAdapter
91  : public StateClosure
92  {
93  protected:
94  StateClosure& parent_;
95  StateClosure& current_;
96 
97  StateAdapter (StateClosure& callingProcess)
98  : parent_ (callingProcess),
99  current_(callingProcess.getCurrentImplementation())
100  { }
101 
102  virtual StateClosure& getCurrentImplementation () { return current_; }
103 
104 
105 
106  public: /* === proxying the StateClosure interface === */
107 
108  virtual void releaseBuffer (BuffHandle& bh) { current_.releaseBuffer (bh); }
109 
110  virtual void is_calculated (BuffHandle const& bh) { current_.is_calculated (bh); }
111 
112  virtual BuffHandle fetch (FrameID const& fID) { return current_.fetch (fID); }
113 
114  virtual BuffTableStorage& getBuffTableStorage() { return current_.getBuffTableStorage(); }
115 
116  // note: allocateBuffer() is chosen specifically based on the actual node wiring
117 
118  };
119 
120 
121 
122 
123 
136  struct Invocation
137  : StateAdapter
138  {
139  Connectivity const& wiring;
140  const uint outNr;
141 
142  FeedManifold* feedManifold;
143 
144  protected:
146  Invocation (StateClosure& callingProcess, Connectivity const& w, uint o)
147  : StateAdapter(callingProcess),
148  wiring(w), outNr(o),
149  feedManifold(0)
150  { }
151 
152  public:
153  uint nrO() const { return wiring.nrO; }
154  uint nrI() const { return wiring.nrI; }
155  uint buffTabSize() const { return nrO()+nrI(); }
156 
158  void setBuffTab (FeedManifold* b) { this->feedManifold = b; }
159 
160  bool
161  buffTab_isConsistent ()
162  {
163  return (feedManifold)
164  && (0 < buffTabSize())
165  && (nrO()+nrI() <= buffTabSize())
166  && (feedManifold->inBuff == &feedManifold->outBuff[nrO()] )
167  && (feedManifold->inHandle == &feedManifold->outHandle[nrO()])
168  ;
169  }
170 
171 
172  public:
175  virtual FrameID const&
176  genFrameID ()
177  {
178  return current_.genFrameID(wiring.nodeID, outNr);
179  }
180 
181  virtual FrameID const&
182  genFrameID (NodeID const& nID, uint chanNo)
183  {
184  return current_.genFrameID (nID,chanNo);
185  }
186 
187  };
188 
189 
191  struct AllocBufferFromParent
192  : Invocation
193  {
194  AllocBufferFromParent (StateClosure& sta, Connectivity const& w, const uint outCh)
195  : Invocation(sta, w, outCh) {}
196 
197  virtual BuffHandle
198  allocateBuffer (const lumiera::StreamType* ty) { return parent_.allocateBuffer(ty); }
199  };
200 
201  struct AllocBufferFromCache
202  : Invocation
203  {
204  AllocBufferFromCache (StateClosure& sta, Connectivity const& w, const uint outCh)
205  : Invocation(sta, w, outCh) {}
206 
207  virtual BuffHandle
208  allocateBuffer (const lumiera::StreamType* ty) { return current_.allocateBuffer(ty); }
209  };
210 
211 
227  template<class Strategy, class BufferProvider>
228  class ActualInvocationProcess
229  : public BufferProvider
230  , private Strategy
231  {
232  public:
233  ActualInvocationProcess (StateClosure& callingProcess, Connectivity const& w, const uint outCh)
234  : BufferProvider(callingProcess, w, outCh)
235  { }
236 
241  BuffHandle retrieve ()
242  {
243  return Strategy::step (*this);
244  }
245  };
246 #endif
247 
249 
261  template<class INVO>
262  struct SimpleWeavingPattern
263  : INVO
264  {
265  using Feed = typename INVO::Feed;
266 
267  static_assert (_verify_usable_as_InvocationAdapter<Feed>());
268 
269  Several<PortRef> leadPort;
270  Several<BuffDescr> outTypes;
271 
272  uint resultSlot{0};
273 
275  template<typename...ARGS>
277  ,Several<BuffDescr>&& dr
278  ,uint resultIdx
279  ,ARGS&& ...args)
280  : INVO{forward<ARGS>(args)...}
281  , leadPort{move(pr)}
282  , outTypes{move(dr)}
283  , resultSlot{resultIdx}
284  { }
285 
286 
287  Feed
288  mount()
289  {
290  return INVO::buildFeed();
291  }
292 
293  void
294  pull (Feed& feed, TurnoutSystem& turnoutSys)
295  {
296  for (uint i=0; i<leadPort.size(); ++i)
297  {
298  BuffHandle inputData = leadPort[i].get().weave (turnoutSys);
299  feed.inBuff.createAt(i, move(inputData));
300  }
301  }
302 
303  void
304  shed (Feed& feed, OptionalBuff outBuff)
305  {
306  for (uint i=0; i<outTypes.size(); ++i)
307  {
308  BuffHandle resultData =
309  i == resultSlot and outBuff? *outBuff
310  : outTypes[i].lockBuffer();
311  feed.outBuff.createAt(i, move(resultData));
312  }
313  feed.connect (leadPort.size(),outTypes.size());
314  }
315 
316  void
317  weft (Feed& feed)
318  {
319  feed.invoke(); // process data
320  }
321 
322  BuffHandle
323  fix (Feed& feed)
324  {
325  for (uint i=0; i<leadPort.size(); ++i)
326  {
327  feed.inBuff[i].release();
328  }
329  for (uint i=0; i<outTypes.size(); ++i)
330  {
331  feed.outBuff[i].emit(); // state transition: data ready
332  if (i != resultSlot)
333  feed.outBuff[i].release();
334  }
335  ENSURE (resultSlot < INVO::MAX_SIZ, "invalid result buffer configured.");
336  return feed.outBuff[resultSlot];
337  }
338 
339  };
340 
341 
349  template<class PAT>
350  class Turnout
351  : public Port
352  , public PAT
353 // , util::MoveOnly
354  {
355  using Feed = typename PAT::Feed;
356 
357  public:
358  template<typename...INIT>
359  Turnout (ProcID& id, INIT&& ...init)
360  : Port{id}
361  , PAT{forward<INIT> (init)...}
362  { }
363 
369  BuffHandle
370  weave (TurnoutSystem& turnoutSys, OptionalBuff outBuff =std::nullopt) override
371  {
372  Feed feed = PAT::mount();
373  PAT::pull(feed, turnoutSys);
374  PAT::shed(feed, outBuff);
375  PAT::weft(feed);
376  return PAT::fix (feed);
377  }
378  };
379 
380 
381 
382 
383 }}// namespace steam::engine
384 #endif /*STEAM_ENGINE_WEAVING_PATTERN_H*/
Basic set of definitions and includes commonly used together.
Processing structure to activate a Render Node and produce result data.
Definition: turnout.hpp:202
Invocation(StateClosure_OBSOLETE &callingProcess, Connectivity const &w, uint o)
creates a new invocation context state, without FeedManifold
SimpleWeavingPattern(Several< PortRef > &&pr, Several< BuffDescr > &&dr, uint resultIdx, ARGS &&...args)
forwarding-ctor to provide the detailed input/output connections
auto retrieve(void *streamType)
Entrance point for defining data flows and processing steps.
Communication hub to coordinate and activate the »Render Node Network« performance.
Steam-Layer implementation namespace root.
Abstraction interface: array-like random access by subscript.
virtual BuffHandle allocateBuffer(const lumiera::StreamType *)=0
allocate a new writable buffer with type and size according to the BuffDescr.
void setBuffTab(FeedManifold *b)
setup the link to an externally allocated buffer table
Metaprogramming tools for transforming functor types.
Abstraction: Fixed array of elements.
Definition: several.hpp:156
Interface to the processing nodes and the render nodes network.
BuffHandle weave(TurnoutSystem &turnoutSys, OptionalBuff outBuff=std::nullopt) override
Entrance point to the next recursive step of media processing.
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:111
virtual FrameID const & genFrameID()
specialised version filling in the additional information, i.e the concrete node id and the channel n...
THe actual state of a frame rendering evaluation parametrised for a single job.