Lumiera  0.pre.03
»edit your freedom«
job-ticket.hpp
Go to the documentation of this file.
1 /*
2  JOB-TICKET.hpp - execution plan for render jobs
3 
4  Copyright (C)
5  2012, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
26 #ifndef STEAM_ENGINE_JOB_TICKET_H
27 #define STEAM_ENGINE_JOB_TICKET_H
28 
29 #include "steam/common.hpp"
30 #include "vault/gear/job.h"
32 #include "lib/time/timevalue.hpp"
33 #include "lib/linked-elements.hpp"
34 #include "lib/util-foreach.hpp"
35 #include "lib/iter-adapter.hpp"
36 #include "lib/itertools.hpp"
37 #include "lib/util.hpp"
38 
39 #include <utility>
40 #include <stack>
41 
42 
43 namespace steam {
44 namespace engine {
45 
46 using vault::gear::Job;
51 using lib::time::Time;
52 using util::isnil;
53 using lib::HashVal;
54 using lib::LUID;
55 
56 
78  class JobTicket
80  {
82  struct Prerequisite
83  {
84  Prerequisite* next{nullptr}; // for intrusive list
85  JobTicket& prereqTicket;
86 
87  template<class ALO>
88  Prerequisite (ExitNode const& node, ALO& allocateTicket)
89  : prereqTicket{allocateTicket (node, allocateTicket)}
90  { }
91  };
93 
94 
96  struct Provision
97  {
98  JobFunctor& jobFunctor;
99  ExitNode const& exitNode;
100  InvocationInstanceID invocationSeed;
101  Prerequisites prerequisites{};
102 
103  Provision (JobFunctor& func, ExitNode const& node, HashVal seed =0)
104  : jobFunctor{func}
105  , exitNode{node}
106  , invocationSeed(static_cast<JobClosure&>(func).buildInstanceID(seed))
107  { }
108  };
109 
112 
113 
114  JobTicket();
115 
116  template<class ALO>
117  static Provision buildProvisionSpec (ExitNode const&, ALO&);
118 
119 
120 
121  public:
122  template<class ALO>
123  JobTicket (ExitNode const& exitNode, ALO& allocator)
124  : provision_{buildProvisionSpec (exitNode, allocator)}
125  { }
126 
127  static JobTicket NOP;
128 
129 
130  bool
131  empty() const
132  {
133  return isnil (provision_.exitNode);
134  }
135 
136  bool
137  isValid() const
138  {
139  if (empty()) return false;
140 
141  InvocationInstanceID empty;
142  return not lumiera_invokey_eq (&util::unConst(provision_).invocationSeed, &empty)
143  and provision_.exitNode.isValid()
144  and util::and_all (provision_.prerequisites
145  ,[](auto& pq){ return pq.prereqTicket.isValid(); });
146  }
147 
148 
154  auto
156  {
157  return lib::transformIterator (this->empty()? Prerequisites::iterator()
158  : provision_.prerequisites.begin()
159  ,[](Prerequisite& prq) -> JobTicket&
160  {
161  return prq.prereqTicket;
162  });
163  }
164 
168  Job createJobFor (Time nominalTime);
169 
174 
175 
176  protected:
178  bool verifyInstance (JobFunctor&, InvocationInstanceID const&, Time) const;
179 
180  };
181 
182 
183 
184 
185 
202  template<class ALO>
203  inline JobTicket::Provision
204  JobTicket::buildProvisionSpec (ExitNode const& exitNode, ALO& allocTicket)
205  {
206  REQUIRE (not isnil (exitNode)); // has valid functor
207  HashVal invoSeed = exitNode.getPipelineIdentity();
208  JobFunctor& func = exitNode.getInvocationFunctor();
209  Provision provisionSpec{func, exitNode, invoSeed};
210  for (ExitNode const& preNode: exitNode.getPrerequisites())
211  provisionSpec.prerequisites.emplace(preNode, allocTicket);
212  return provisionSpec;
213  }
214 
215 
216 
217 }}// namespace steam::engine
218 #endif /*STEAM_ENGINE_JOB_TICKET_H*/
Basic set of definitions and includes commonly used together.
bool verifyInstance(JobFunctor &, InvocationInstanceID const &, Time) const
Helper for tests: verify the given invocation parameters match this JobTicket.
Definition: job-ticket.cpp:132
Intrusive single linked list, possibly taking ownership of node elements.
lumiera_uid * LUID
a Lumiera UID
Definition: hash-value.h:55
Helper template(s) for creating Lumiera Forward Iterators.
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
Effective top-level exit point to pull rendered data from the nodes network.
Steam-Layer implementation namespace root.
static JobTicket NOP
special »do nothing« JobTicket marker
Definition: job-ticket.hpp:127
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
static InvocationInstanceID timeHash(Time, InvocationInstanceID const &)
Tag the precomputed invocation ID with the nominal frame time.
Definition: job-ticket.cpp:110
A top-level point in the render node network where data generation can be driven. ...
Definition: exit-node.hpp:63
Another Lumiera Forward Iterator building block, based on incorporating a state type as »*State Core*...
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
static Provision buildProvisionSpec(ExitNode const &, ALO &)
Definition: job-ticket.hpp:204
Intrusive single linked list with optional ownership.
Definition of a render job.
opaque ID attached to each individual job invocation.
Definition: job.h:103
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:52
Interface of the closure for frame rendering jobs.
Definition: job.h:235
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
Helpers for working with iterators based on the pipeline model.
Individual frame rendering task, forwarding to a closure.
Definition: job.h:268
a family of time value like entities and their relationships.
auto transformIterator(IT const &src, FUN processingFunc)
Build a TransformIter: convenience free function shortcut, picking up the involved types automaticall...
Definition: itertools.hpp:788
Perform operations "for each element" of a collection.
auto getPrerequisites()
Core operation: iterate over the prerequisites, required to carry out a render operation based on thi...
Definition: job-ticket.hpp:155
execution plan for pulling a specific exit node.
Definition: job-ticket.hpp:78
Duration getExpectedRuntime()
Core operation: guess expected runtime for rendering.
Definition: job-ticket.cpp:94
Job createJobFor(Time nominalTime)
Core operation: build a concrete render job based on this blueprint.
Definition: job-ticket.cpp:71