HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SOP_Compiled.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SOP_Compiled.h ( SOP Library, C++)
7  *
8  * COMMENTS:
9  * Compiles chains of nodes into a single object
10  * that can be evaluated.
11  */
12 
13 #ifndef __SOP_Compiled_h__
14 #define __SOP_Compiled_h__
15 
16 #include "SOP_API.h"
17 #include "SOP_Node.h"
18 #include "SOP_NodeVerb.h"
19 #include <DEP/DEP_TimedMicroNode.h>
20 #include <CE/CE_Error.h>
21 
23 {
24 public:
25  SOP_Compiled();
26  virtual ~SOP_Compiled();
27 
29  {
33  };
34 
35  class TaskState
36  {
37  public:
39  {
40  myDirty = true;
41  myCooking = false;
42  myUseCount = 0;
43  myLocked = false;
44  myCECache = false;
45  myTimeDependent = false;
46  myNodeCache = 0;
47  myNodeParms = 0;
48  myNodeParmsOrig = 0;
49  myParmsDirty = true;
50  myDependsOnExprInputs = true;
51  }
53  {
54  delete myNodeCache;
55  delete myNodeParms;
56  delete myNodeParmsOrig;
57  }
58 
60  bool myDirty;
61  bool myCECache;
63  bool myCooking; // recursion flag.
65  bool myLocked;
66  bool myParmsDirty; // Whether node parms current
67  bool myDependsOnExprInputs; // If expr inputs used.
70  SOP_NodeParms *myNodeParmsOrig; // Pre-vexpression cache
71  };
72 
74 
76  {
77  bool executeInputs(TaskStateArray &state, const OP_Context &context, UT_ErrorManager &errors, DEP_MicroNode *depnode);
78 
79  public:
80  ExecuteParms(TaskStateArray &state, UnloadMode unloadmode,
81  const OP_Context &context,
82  UT_ErrorManager &errors, DEP_MicroNode *depnode,
83  SOP_NodeVerb::ForbiddenNodeMap &forbiddennodes,
84  UT_Array<GU_DetailHandle> *recyclingbin)
85  : myState(state)
86  , myUnloadMode(unloadmode)
87  , myContext(context)
88  , myErrors(errors)
89  , myDepNode(depnode)
90  , myForbiddenNodes(forbiddennodes)
91  , myRecyclingBin(recyclingbin)
92  { }
93 
95  {}
96 
97  TaskStateArray &state() const { return myState; }
98  UnloadMode unloadMode() const { return myUnloadMode; }
99  const OP_Context &context() const { return myContext; }
100  UT_ErrorManager &errors() const { return myErrors; }
101  DEP_MicroNode *depnode() const { return myDepNode; }
102 
103  SOP_NodeVerb::ForbiddenNodeMap &forbiddenNodes() const { return myForbiddenNodes; }
104 
105  bool hasRecycleableGdp() const
106  {
107  if (!myRecyclingBin)
108  return false;
109  return myRecyclingBin->entries() > 0;
110  }
111  GU_DetailHandle allocGdp(bool clear = true) const
112  {
113  GU_DetailHandle result;
114  if (!hasRecycleableGdp())
115  {
117  }
118  else
119  {
120  result = myRecyclingBin->last();
121  myRecyclingBin->removeLast();
122  if (clear)
123  result.gdpNC()->stashAll();
124  myRecycledGdpId.append(result.gdp()->getUniqueId());
125  myRecycledGdpShareCount.append(result.getRefCount());
126  }
127  return result;
128  }
129 
130  bool isGdpIdRecycled(const GU_DetailHandle &gdh) const
131  {
132  UT_ASSERT(gdh.isValid());
133  exint idx = myRecycledGdpId.find(gdh.gdp()->getUniqueId());
134  if (idx < 0)
135  return false;
136  // Verify we haven't had any extra copies made of us during
137  // task execution. We compare against our stashed use
138  // count when first built.
139  if (gdh.getRefCount() != myRecycledGdpShareCount(idx))
140  {
141  return false;
142  }
143  return true;
144  }
145 
146  protected:
156  };
157 
158  class Task
159  {
160  public:
161  Task(SOP_Node *node, int stateid);
162  virtual ~Task();
163 
164  void setInput(int inputidx, Task *input);
165  void setExprInput(int inputidx, Task *input);
166  void appendOutput(Task *output);
167 
168  // Verify we are still wired up the way we used to be. Only the
169  // node id is valid at this point.
170  virtual bool validate();
171  virtual void addNodes(SOP_NodeVerb::ForbiddenNodeMap &nodeset);
172 
173  // Unloads any cached gdps, but not necessarily things like
174  // VEX bindings.
175  virtual void forceUnload(TaskStateArray &state);
176 
177  // Resets the time dependencies of its own node's parm lists,
178  // and any child states node's parm lists.
179  virtual void clearNodeTimeDependencies();
180 
181  SOP_Node *getNode() const { return myNode; }
182  int getNodeId() const { return myNodeId; }
183  GU_DetailHandle getDetailHandle(const TaskStateArray &state) { return state(myStateId).myGdh; }
184  bool hasCECache(const TaskStateArray &state) const { return state(myStateId).myCECache; }
185  bool getTimeDependent(const TaskStateArray &state) const { return state(myStateId).myTimeDependent; }
186  void setTimeDependent(TaskStateArray &state, bool timedep) { state(myStateId).myTimeDependent = timedep; }
187  GU_DetailHandle unloadDetailHandle(TaskStateArray &state, bool flushce, UnloadMode unloadmode, UT_ErrorManager &errors);
188 
189  void setDetailHandle(TaskStateArray &state, GU_DetailHandle gdh, bool cecache)
190  {
191  markClean(state);
192  state(myStateId).myUseCount = 0;
193  state(myStateId).myGdh = gdh;
194  state(myStateId).myCECache = cecache;
195  }
196 
197  void lock(TaskStateArray &state)
198  {
199  state(myStateId).myLocked = true;
200  }
201  bool isLocked(TaskStateArray &state) const
202  {
203  return state(myStateId).myLocked;
204  }
205 
206  bool isDirty(const TaskStateArray &state) const { return state(myStateId).myDirty; }
207  void dirty(TaskStateArray &state) { state(myStateId).myDirty = true; }
208  void markClean(TaskStateArray &state) { state(myStateId).myDirty = false; }
209 
210  bool isParmsDirty(const TaskStateArray &state) const { return state(myStateId).myParmsDirty; }
211  void dirtyParms(TaskStateArray &state) { state(myStateId).myParmsDirty = true; }
212  void markParmsClean(TaskStateArray &state) { state(myStateId).myParmsDirty = false; }
213  bool dependsOnExprInputs(const TaskStateArray &state) const { return state(myStateId).myDependsOnExprInputs; }
214  void clearDependsOnExprInputs(TaskStateArray &state) { state(myStateId).myDependsOnExprInputs = false; }
215  void setDependsOnExprInputs(TaskStateArray &state) { state(myStateId).myDependsOnExprInputs = true; }
216 
217  /// Dirties ourself and all children until we hit something
218  /// already dirty.
219  void dirtyChildren(TaskStateArray &state);
220 
221  /// Computes myself, and chains to any inputs, provided not
222  /// dirty.
223  bool execute(const ExecuteParms &parms);
224 
225  virtual bool doExecute(const ExecuteParms &parms) = 0;
226 
227  bool executeInputs(const ExecuteParms &parms);
228  bool executeExprInputs(const ExecuteParms &parms);
229 
230  void dump(std::ostream &os) const;
231  UT_StringHolder buildName() const;
232 
233  protected:
234  virtual void dumpSubclass(std::ostream &os) const {}
236  int myNodeId;
245  };
246 
247  /// Determine if the compiled task list still matches what
248  /// the SOP network has.
249  bool isTopologyDirty(const OP_Context &context);
250 
251  bool isTopologyTimeDependent() const;
252 
253  void dump(std::ostream &os) const;
254 
255  /// Compile a node block, only rebuilding if Topo dependency is
256  /// invalid
257  bool compile(SOP_Node *root, const OP_Context &context, UT_ErrorManager &errors);
258 
259  /// Determines what node is at the root of the compile block
260  SOP_Node *getRoot() const;
261 
262  /// Is the task list compiled & valid?
263  bool isCompiled() const;
264 
265  /// Donate the provided detail to be recycled if needed.
266  /// The passed in handle will be cleared.
267  void donateForRecycling(GU_DetailHandle &gdh);
268 
269  /// Execute our cached block
270  /// The inputgdhs will be cleared as they are used, allowing
271  /// them to be stolen & written to if they are unique.
272  GU_DetailHandle execute(TaskStateArray &states,
273  UnloadMode unload,
274  const OP_Context &context,
275  UT_ErrorManager &errors,
276  DEP_MicroNode *depnode,
277  const UT_StringArray &inputnames,
278  UT_Array<GU_DetailHandle> &inputgdhs);
279 
280  void clear();
281 
282  exint taskCount() const { return myTasks.size(); }
283  exint taskInputCount() const { return myTaskInputs.size(); }
284  exint nodeCount() const { return myNodeSet ? myNodeSet->size() : 0; }
285 
286  /// Determines somewhat conservatively if the node is eligbile for
287  /// compilation. Verbs always are, but things like subnets are only
288  /// if their SOP contents are as well.
289  static bool canBeCompiled(SOP_Node *node);
290 
291 
292 protected:
299 };
300 
301 #endif
302 
void stashAll()
Definition: GA_Detail.h:133
exint taskCount() const
Definition: SOP_Compiled.h:282
exint nodeCount() const
Definition: SOP_Compiled.h:284
UT_Array< Task * > myTaskInputs
Definition: SOP_Compiled.h:296
void lock(TaskStateArray &state)
Definition: SOP_Compiled.h:197
Unsorted map container.
Definition: UT_Map.h:83
bool isValid() const
Determine if this is a valid handle (!isNull())
DEP_MicroNode * depnode() const
Definition: SOP_Compiled.h:101
DEP_MicroNode * myDepNode
Definition: SOP_Compiled.h:151
bool isGdpIdRecycled(const GU_DetailHandle &gdh) const
Definition: SOP_Compiled.h:130
UT_Array< Task * > myOutputs
Definition: SOP_Compiled.h:244
UT_IntArray myNodeInputIds
Definition: SOP_Compiled.h:240
UT_Array< TaskState > TaskStateArray
Definition: SOP_Compiled.h:73
const GU_Detail * gdp() const
GU_DetailHandle allocGdp(bool clear=true) const
Definition: SOP_Compiled.h:111
UT_ExintArray myRecycledGdpShareCount
Definition: SOP_Compiled.h:155
UT_Array< GU_DetailHandle > * myRecyclingBin
Definition: SOP_Compiled.h:153
bool isDirty(const TaskStateArray &state) const
Definition: SOP_Compiled.h:206
bool hasCECache(const TaskStateArray &state) const
Definition: SOP_Compiled.h:184
SOP_Node * getNode() const
Definition: SOP_Compiled.h:181
const OP_Context & context() const
Definition: SOP_Compiled.h:99
void allocateAndSet(GU_Detail *gdp, bool own=true)
TaskStateArray & myState
Definition: SOP_Compiled.h:147
UT_Array< GU_DetailHandle > myRecyclingBin
Definition: SOP_Compiled.h:298
bool hasRecycleableGdp() const
Definition: SOP_Compiled.h:105
UnloadMode unloadMode() const
Definition: SOP_Compiled.h:98
int getRefCount() const
Returns the number of references made to the base handle.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
int64 exint
Definition: SYS_Types.h:115
SOP_NodeCache * myNodeCache
Definition: SOP_Compiled.h:68
UT_ErrorManager & myErrors
Definition: SOP_Compiled.h:150
void dirtyParms(TaskStateArray &state)
Definition: SOP_Compiled.h:211
GU_DetailHandle getDetailHandle(const TaskStateArray &state)
Definition: SOP_Compiled.h:183
SOP_NodeParms * myNodeParms
Definition: SOP_Compiled.h:69
SOP_NodeVerb::ForbiddenNodeMap * myNodeSet
Definition: SOP_Compiled.h:297
void clearDependsOnExprInputs(TaskStateArray &state)
Definition: SOP_Compiled.h:214
void setTimeDependent(TaskStateArray &state, bool timedep)
Definition: SOP_Compiled.h:186
void setDetailHandle(TaskStateArray &state, GU_DetailHandle gdh, bool cecache)
Definition: SOP_Compiled.h:189
virtual void dumpSubclass(std::ostream &os) const
Definition: SOP_Compiled.h:234
UT_Array< Task * > myInputs
Definition: SOP_Compiled.h:242
TaskStateArray & state() const
Definition: SOP_Compiled.h:97
SOP_NodeParms * myNodeParmsOrig
Definition: SOP_Compiled.h:70
int getNodeId() const
Definition: SOP_Compiled.h:182
GU_Detail * gdpNC()
void dirty(TaskStateArray &state)
Definition: SOP_Compiled.h:207
exint getUniqueId() const
Definition: GA_Detail.h:117
UT_Array< Task * > myTasks
Definition: SOP_Compiled.h:295
void markClean(TaskStateArray &state)
Definition: SOP_Compiled.h:208
UT_ErrorManager & errors() const
Definition: SOP_Compiled.h:100
DEP_TimedMicroNode myTopoMicroNode
Definition: SOP_Compiled.h:293
static GU_Detail * prepNewDetail(GU_Detail *gdp)
SOP_NodeVerb::ForbiddenNodeMap & forbiddenNodes() const
Definition: SOP_Compiled.h:103
bool isLocked(TaskStateArray &state) const
Definition: SOP_Compiled.h:201
void setDependsOnExprInputs(TaskStateArray &state)
Definition: SOP_Compiled.h:215
UT_ExintArray myRecycledGdpId
Definition: SOP_Compiled.h:154
exint taskInputCount() const
Definition: SOP_Compiled.h:283
ExecuteParms(TaskStateArray &state, UnloadMode unloadmode, const OP_Context &context, UT_ErrorManager &errors, DEP_MicroNode *depnode, SOP_NodeVerb::ForbiddenNodeMap &forbiddennodes, UT_Array< GU_DetailHandle > *recyclingbin)
Definition: SOP_Compiled.h:80
void markParmsClean(TaskStateArray &state)
Definition: SOP_Compiled.h:212
A global error manager scope.
#define SOP_API
Definition: SOP_API.h:10
const OP_Context & myContext
Definition: SOP_Compiled.h:149
SOP_NodeVerb::ForbiddenNodeMap & myForbiddenNodes
Definition: SOP_Compiled.h:152
bool isParmsDirty(const TaskStateArray &state) const
Definition: SOP_Compiled.h:210
bool dependsOnExprInputs(const TaskStateArray &state) const
Definition: SOP_Compiled.h:213
UT_Array< Task * > myExprInputs
Definition: SOP_Compiled.h:243
bool getTimeDependent(const TaskStateArray &state) const
Definition: SOP_Compiled.h:185
GU_DetailHandle myGdh
Definition: SOP_Compiled.h:59