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) Lumiera.org
5  2012, 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 
23 
35 #ifndef STEAM_ENGINE_JOB_TICKET_H
36 #define STEAM_ENGINE_JOB_TICKET_H
37 
38 #include "steam/common.hpp"
39 #include "vault/gear/job.h"
41 #include "lib/time/timevalue.hpp"
42 #include "lib/linked-elements.hpp"
43 #include "lib/util-foreach.hpp"
44 #include "lib/iter-adapter.hpp"
45 #include "lib/itertools.hpp"
46 #include "lib/util.hpp"
47 
48 #include <utility>
49 #include <stack>
50 
51 
52 namespace steam {
53 namespace engine {
54 
55 using vault::gear::Job;
60 using lib::time::Time;
61 using util::isnil;
62 using lib::HashVal;
63 using lib::LUID;
64 
65 
87  class JobTicket
89  {
91  struct Prerequisite
92  {
93  Prerequisite* next{nullptr}; // for intrusive list
94  JobTicket& prereqTicket;
95 
96  template<class ALO>
97  Prerequisite (ExitNode const& node, ALO& allocateTicket)
98  : prereqTicket{allocateTicket (node, allocateTicket)}
99  { }
100  };
102 
103 
105  struct Provision
106  {
107  JobFunctor& jobFunctor;
108  ExitNode const& exitNode;
109  InvocationInstanceID invocationSeed;
110  Prerequisites prerequisites{};
111 
112  Provision (JobFunctor& func, ExitNode const& node, HashVal seed =0)
113  : jobFunctor{func}
114  , exitNode{node}
115  , invocationSeed(static_cast<JobClosure&>(func).buildInstanceID(seed))
116  { }
117  };
118 
121 
122 
123  JobTicket();
124 
125  template<class ALO>
126  static Provision buildProvisionSpec (ExitNode const&, ALO&);
127 
128 
129 
130  public:
131  template<class ALO>
132  JobTicket (ExitNode const& exitNode, ALO& allocator)
133  : provision_{buildProvisionSpec (exitNode, allocator)}
134  { }
135 
136  static JobTicket NOP;
137 
138 
139  bool
140  empty() const
141  {
142  return isnil (provision_.exitNode);
143  }
144 
145  bool
146  isValid() const
147  {
148  if (empty()) return false;
149 
150  InvocationInstanceID empty;
151  return not lumiera_invokey_eq (&util::unConst(provision_).invocationSeed, &empty)
152  and provision_.exitNode.isValid()
153  and util::and_all (provision_.prerequisites
154  ,[](auto& pq){ return pq.prereqTicket.isValid(); });
155  }
156 
157 
163  auto
165  {
166  return lib::transformIterator (this->empty()? Prerequisites::iterator()
167  : provision_.prerequisites.begin()
168  ,[](Prerequisite& prq) -> JobTicket&
169  {
170  return prq.prereqTicket;
171  });
172  }
173 
177  Job createJobFor (Time nominalTime);
178 
183 
184 
185  protected:
187  bool verifyInstance (JobFunctor&, InvocationInstanceID const&, Time) const;
188 
189  };
190 
191 
192 
193 
194 
211  template<class ALO>
212  inline JobTicket::Provision
213  JobTicket::buildProvisionSpec (ExitNode const& exitNode, ALO& allocTicket)
214  {
215  REQUIRE (not isnil (exitNode)); // has valid functor
216  HashVal invoSeed = exitNode.getPipelineIdentity();
217  JobFunctor& func = exitNode.getInvocationFunctor();
218  Provision provisionSpec{func, exitNode, invoSeed};
219  for (ExitNode const& preNode: exitNode.getPrerequisites())
220  provisionSpec.prerequisites.emplace(preNode, allocTicket);
221  return provisionSpec;
222  }
223 
224 
225 
226 }}// namespace steam::engine
227 #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:140
Intrusive single linked list, possibly taking ownership of node elements.
lumiera_uid * LUID
a Lumiera UID
Definition: hash-value.h:59
Helper template(s) for creating Lumiera Forward Iterators.
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
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:136
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:305
static InvocationInstanceID timeHash(Time, InvocationInstanceID const &)
Tag the precomputed invocation ID with the nominal frame time.
Definition: job-ticket.cpp:118
A top-level point in the render node network where data generation can be driven. ...
Definition: exit-node.hpp:72
Another Lumiera Forward Iterator building block, based on incorporating a state type right into the i...
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:213
Intrusive single linked list with optional ownership.
Definition of a render job.
opaque ID attached to each individual job invocation.
Definition: job.h:111
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
Interface of the closure for frame rendering jobs.
Definition: job.h:242
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:474
Helpers for working with iterators based on the pipeline model.
Individual frame rendering task, forwarding to a closure.
Definition: job.h:275
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:797
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:164
execution plan for pulling a specific exit node.
Definition: job-ticket.hpp:87
Duration getExpectedRuntime()
Core operation: guess expected runtime for rendering.
Definition: job-ticket.cpp:102
Job createJobFor(Time nominalTime)
Core operation: build a concrete render job based on this blueprint.
Definition: job-ticket.cpp:79