Lumiera  0.pre.03
»edit your freedom«
nodeoperation.hpp
Go to the documentation of this file.
1 /*
2  NODEOPERATION.hpp - Specify how the nodes call each other and how processing is organized
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
56 #ifndef ENGINE_NODEOPERATION_H
57 #define ENGINE_NODEOPERATION_H
58 
59 
60 #include "steam/state.hpp"
65 
66 #include "lib/meta/util.hpp"
67 #include "lib/meta/configflags.hpp"
68 #include "lib/frameid.hpp"
69 
70 
71 
72 
73 namespace steam {
74 namespace engine {
75 namespace config {
76 
77 
85  {
86  typedef lib::meta::Yes_t is_defined;
87 
89  getSource (Invocation& ivo, uint chanNo)
90  {
91  UNIMPLEMENTED ("retrieve source data provided by the vault/scheduler");
92  }
93 
95  pullPredecessor (Invocation& ivo, uint chanNo)
96  {
97  UNIMPLEMENTED ("invoke pull() on the denoted predecessor node");
98  }
99 
100  void
101  releaseBuffers(BuffHandle* table, uint slotCnt, uint slot_to_retain)
102  {
103  UNIMPLEMENTED ("release all buffers with the exception of the desired output");
104  }
105 
106  bool
107  validateBuffers (Invocation& ivo)
108  {
109  UNIMPLEMENTED ("Do a final, specifically tailored validation step on the buffers prior to invoking the process function");
110  }
111  };
112 
113 
114  template<class NEXT>
115  struct QueryCache : NEXT
116  {
117  BuffHandle
118  step (Invocation& ivo)
119  {
120  BuffHandle fetched = ivo.fetch (ivo.genFrameID());
121  if (fetched)
122  return fetched;
123  else
124  return NEXT::step (ivo);
125  }
126  };
127 
128 
129  template<class NEXT>
130  struct AllocBufferTable : NEXT
131  {
132  BuffHandle
133  step (Invocation& ivo)
134  {
135  BuffTableChunk buffTab (ivo.wiring, ivo.getBuffTableStorage());
136  ivo.setBuffTab(&buffTab);
137  ASSERT (ivo.buffTab);
138  ASSERT (ivo.buffTab_isConsistent());
139 
140  return NEXT::step (ivo);
141  }
142  };
143 
144 
145  template<class NEXT>
146  struct PullInput : NEXT
147  {
148  BuffHandle
149  step (Invocation& ivo)
150  {
151  BuffHandle * inH = ivo.buffTab->inHandle;
152  BuffHandle::PBuff *inBuff = ivo.buffTab->inBuff;
153 
154  for (uint i = 0; i < ivo.nrI(); ++i )
155  {
156  inBuff[i] =
157  &*(inH[i] = this->pullPredecessor(ivo,i)); // invoke predecessor
158  // now Input #i is ready...
159  }
160  return NEXT::step (ivo);
161  }
162  };
163 
164 
165  template<class NEXT>
166  struct ReadSource : NEXT
167  {
168  BuffHandle
169  step (Invocation& ivo)
170  {
171  BuffHandle *inH = ivo.buffTab->inHandle;
172  BuffHandle *outH = ivo.buffTab->outHandle;
173  BuffHandle::PBuff *inBuff = ivo.buffTab->inBuff;
174  BuffHandle::PBuff *outBuff = ivo.buffTab->outBuff;
175 
176  ASSERT (ivo.nrO() == ivo.nrI() );
177 
178  for (uint i = 0; i < ivo.nrI(); ++i )
179  {
180  inBuff[i] = outBuff[i] =
181  &*(inH[i] = outH[i] = this->getSource(ivo,i));
182  // now Input #i is ready...
183  }
184  return NEXT::step (ivo);
185  }
186  };
187 
188 
189  template<class NEXT>
190  struct AllocOutput : NEXT
191  {
192  BuffHandle
193  step (Invocation& ivo)
194  {
195  ASSERT (ivo.buffTab);
196  ASSERT (ivo.nrO() < ivo.buffTabSize());
197  BuffHandle *outH = ivo.buffTab->outHandle;
198  BuffHandle::PBuff *outBuff = ivo.buffTab->outBuff;
199 
200  for (uint i = 0; i < ivo.nrO(); ++i )
201  {
202  outBuff[i] =
203  &*(outH[i] = ivo.allocateBuffer (ivo.wiring.out[i].bufferType));
204  // now Output buffer for channel #i is available...
205  }
206  return NEXT::step (ivo);
207  }
208  };
209 
210 
211  template<class NEXT>
212  struct ProcessData : NEXT
213  {
214  BuffHandle
215  step (Invocation& ivo)
216  {
217  ASSERT (ivo.buffTab);
218  ASSERT (ivo.buffTab_isConsistent());
219  ASSERT (this->validateBuffers(ivo));
220 
221  // Invoke our own process() function,
222  // providing the array of outBuffer+inBuffer ptrs
223  (*ivo.wiring.procFunction) (*ivo.buffTab->outBuff);
224 
225  return NEXT::step (ivo);
226  }
227  };
228 
229 
230  template<class NEXT>
231  struct FeedCache : NEXT
232  {
233  BuffHandle
234  step (Invocation& ivo)
235  {
236  for (uint i = 0; i < ivo.nrO(); ++i )
237  {
238  // declare all Outputs as finished
239  ivo.is_calculated(ivo.buffTab->outHandle[i]);
240  }
241 
242  return NEXT::step (ivo);
243  }
244  };
245 
246 
247  template<class NEXT>
248  struct ReleaseBuffers : NEXT
249  {
250  BuffHandle
251  step (Invocation& ivo)
252  {
253  // all buffers besides the required Output no longer needed
254  this->releaseBuffers(ivo.buffTab->outHandle,
255  ivo.buffTabSize(),
256  ivo.outNr);
257 
258  return ivo.buffTab->outHandle[ivo.outNr];
259  }
260  };
261 
262 
263 
264 
265 
266  /* =============================================================== */
267  /* === declare the possible Assembly of these elementary steps === */
268 
269  enum Cases
270  {
271  CACHING = 1,
272  PROCESS,
273  INPLACE,
274 
275  NOT_SET = 0,
276  NUM_Cases = INPLACE
277  };
278 
279 
280  using lib::meta::Config;
283  template<class CONF>
285  template<uint STEAM_ign, uint INPLA_ign>
286  struct SelectBuffProvider< Config<CACHING, STEAM_ign, INPLA_ign>> { typedef AllocBufferFromCache Type; };
287 
288 
289  template<class Config>
290  struct Strategy ;
291 
292 
293  template<uint INPLACE_ign>
294  struct Strategy< Config<CACHING,PROCESS,INPLACE_ign>>
295  : QueryCache<
296  AllocBufferTable<
297  PullInput<
298  AllocOutput<
299  ProcessData<
300  FeedCache<
301  ReleaseBuffers<
302  OperationBase > > > > > > >
303  { };
304 
305  template<uint INPLACE_ign>
306  struct Strategy< Config<PROCESS,INPLACE_ign>>
308  PullInput<
309  AllocOutput<
310  ProcessData<
311  ReleaseBuffers<
312  OperationBase > > > > >
313  { };
314 
315  template<>
316  struct Strategy< Config<> >
318  ReadSource<
319  ReleaseBuffers<
320  OperationBase > > >
321  { };
322 
323  template<>
324  struct Strategy< Config<INPLACE> > : Strategy< Config<> > { };
325 
326  template<>
327  struct Strategy< Config<CACHING> >
329  ReadSource<
330  AllocOutput<
331  ProcessData< // wiring_.processFunction is supposed to do just buffer copying here
332  ReleaseBuffers<
333  OperationBase > > > > >
334  { };
335 
336 
337 
338 
339 }}} // namespace steam::engine::config
340 #endif
Base class of all concrete invocation sequences.
Interface to the processing nodes and the render nodes network.
Obsolete, to be rewritten /////TICKET #826 to be allocated on the stack while evaluating a ProcNode::...
Access point to an ongoing render&#39;s processing state.
Under some circumstances it is necessary to assemble functionality out of elementary building blocks...
Marker tuple to identify a specific frame.
Simple and lightweight helpers for metaprogramming and type detection.
virtual BuffHandle allocateBuffer(const lumiera::StreamType *)=0
allocate a new writable buffer with type and size according to the BufferDescriptor.
Steam-Layer implementation namespace root.
virtual BuffHandle fetch(FrameID const &fID)
try to fetch an existing buffer containing the denoted frame from a cache or similar backing system (...
Organise the state related to the invocation of s single ProcNode::pull() call This header defines pa...
void setBuffTab(BuffTable *b)
setup the link to an externally allocated buffer table
Invocation context state.
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition: meta/util.hpp:104
< using the parent StateAdapter for buffer allocations
< using the global current State, which will delegate to Cache
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:115
virtual FrameID const & genFrameID()
specialised version filling in the additional information, i.e the concrete node id and the channel n...
virtual BuffTableStorage & getBuffTableStorage()
necessary for creating a local BuffTableChunk
Representation of the Media type of a data channel used within the engine.
placeholder type for the contents of a data buffer.
Definition: streamtype.hpp:121
< distinct type representing a configuration
Definition: configflags.hpp:90
virtual void is_calculated(BuffHandle const &bh)
declare the data contained in the Buffer to be ready.