HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_Processor.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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_PROCESSOR_H__
10 #define __PDG_PROCESSOR_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_EvaluationContext.h"
15 #include "PDG_Node.h"
16 
17 #include <UT/UT_Lock.h>
18 #include <UT/UT_TBBSpinLock.h>
19 #include <UT/UT_UniquePtr.h>
20 
21 class PDG_WorkItemHolder;
22 
23 /**
24  * Concrete node type that creates new work items from upstream items. This
25  * node can either create items each item an upstream item is cooked, or when
26  * all upstream items are generated or cooked. Work items can also be injected
27  * into the node.
28  */
30 {
31 public:
32  /// Prioritization schemes that node can use when generating work items.
34  {
35  /// Inheirt the priority from the upstream work items, or 0 if there
36  /// are no upstream items
38 
39  /// Set the priority based on an expression
41 
42  /// Set the priority using logic in the node. Only used by
43  /// ROP Fetch
44  ePriorityNode
45  };
46 
47  /// Labeling scheme that node can use when generating work item.
48  enum LabelType
49  {
50  /// Use the default label field on the root graph, or no label
51  /// if there is no default
53 
54  /// Inherit the label from the parent item
56 
57  /// Set the label based on an expression
59 
60  /// Set the label baed on custom node logic
61  eLabelNode
62  };
63 
64  /// The caching mode, used to control whether or not the node should
65  /// attempt to read existing files from disk prior to cooking
66  enum CacheMode
67  {
68  /// Automatic - checks if the file exists and uses it if it does
70 
71  /// Always Read - always tries to read, and fails if the file does not
72  /// exist
74 
75  /// Always Write - always writes, always spawns a job to do the cook
76  /// and possibly overrwrites existing files
78 
79  /// Same automatic, but the node will not invalidate work items due to
80  /// upstream cache changes
82  };
83 
84  /// Enumeration of generation conditions
86  {
87  /// Generate work items each time an input work item cooks
89 
90  /// Generate work items when all inputs work items are generated
92 
93  /// Automatic generation mode
95 
96  /// Generate work items when all inputs work items are cooked
98  };
99 
100 public:
101  /// Constructs an new processor from graph context, name, callback type
102  /// and custom id. Most of the initialization for this class is handled
103  /// in the PDG_Node base.
105  PDG_GraphContext* context,
106  const UT_StringHolder& name,
107  const PDG_NodeCallbackType* type_object,
108  int custom_id = -1);
109 
110  ~PDG_Processor() override {}
111 
112  /// Returns the total memory usage of the node, including any work items
113  /// owned by it.
114  void memoryInfo(PDG_MemoryInfo& memory_info,
115  bool inclusive) const override;
116 
117  /// Returns the priority scheme used by this node. The default is to
118  /// inherit from the upstream work item, if any.
119  inline PriorityType prioritizeBy() const
120  { return myPriorityType; }
121 
122  /// Returns the cook type for work items created by this node.
124  { return myCookType; }
125 
126  /// Returns true if the processor has been configured to use services
127  /// for the current cook.
128  inline bool useServices() const
129  {
130  return (myServiceStatus ==
131  eServiceStatusStarted);
132  }
133 
134  /// Returns the condition when this node resets service clients
136  { return myServiceResetWhen; }
137 
138  /// Returns the reset type for service clients used by this node
140  { return myServiceResetType; }
141 
142  /// Constructs a new work item holder for this node, for work item
143  /// injection. The caller takes ownership of the object.
145  workItemHolder();
146 
147  /// Injects work items using a holder, which should be constructed with the
148  /// this->workItemHolder() method. If compact_items is true, the node's
149  /// work item array is compacted, prioritized and sorted after injecting
150  /// items.
151  void injectStaticItems(
152  PDG_WorkItemHolder& holder,
153  bool compact_items,
154  bool sort_items);
155 
156 
157  /// Resets this dependency owner
158  void resetOwner() override;
159 
160  /// Returns the priority for the specified work item
161  int itemPriority(const PDG_WorkItem* work_item,
162  PriorityType priority_type) const;
163 
164  /// Deserialized the specified work item into this node. Most of the
165  /// work is handled by the parent class, but processor nodes need to
166  /// update the myParentMap.
167  bool deserializeWorkItem(
168  PDG_WorkItem* work_item) override;
169 
170  /// Called after deserializing a work item and adding its dependencies
171  void commitWorkItem(PDG_WorkItem* work_item) override;
172 
173  /// Syncs data for the work item, using node-specific logic
174  void syncWorkItem(
175  PDG_WorkItem* work_item,
176  const PDG_WorkItem* clone_target) override;
177 
178  /// Checks if a work item is cached based on its expected outputs and the
179  /// current output cache state
181  PDG_WorkItem* work_item) const override;
182 
183 protected:
184  /// Runs node-specific pre cook logic. Called before anything in the graph
185  /// evaluates.
186  bool preCook(bool is_dirty,
187  bool has_filter) override;
188 
189  /// Runs node-specific post cook logic. Called after all work items have
190  /// finished cooking.
191  void postCook() override;
192 
193 
194  /// Called when this node should clear all work items. Management of the
195  /// main work item array is handled by the parent class, but processors
196  /// need to clear their myParentMap contents.
197  void clearAllWorkItems() override;
198 
199  /// Called when this node should clear a specific work item. Processor
200  /// nodes need to update the myParentMap accordingly.
201  void clearWorkItem(PDG_WorkItem* work_item) override;
202 
203  /// Called when this node should add a work item. Processor nodes need to
204  /// update the myParentMap accordingly.
205  void addWorkItem(PDG_WorkItem* work_item) override;
206 
207  /// Called when a dependency owned by this node is resolved. This method
208  /// will generate work items when the generation mode is set to either
209  /// AllInputsCooked or AllInputsGenerated.
211  PDGE_Resolutions& resolutions,
212  const PDGE_Evaluator& evaluator,
213  PDGE_Dependency* dependency) override;
214 
215  /// Called when a dependency owned by thhis node receives a partial
216  /// resolution. This method will generate work items when the generation
217  /// mode is set to EachInputCooked.
219  PDGE_Resolutions& resolutions,
220  const PDGE_Evaluator& evaluator,
221  PDGE_Dependency* dependency,
222  const PDGE_DependencyOwner::Array& owners)
223  override;
224 
225  /// Caches any built in parm state for the current cook
226  bool cacheBuiltinParms(PDG_NodeSet& dirty,
227  bool dynamic_inputs) override;
228 
229  /// Adds dependencies on input nodes based on the current generation
230  /// settings
231  void addInputDeps(PDG_Node* input_node) override;
232 
233  /// Returns true if the work item should be scheduled, or false if it
234  /// should be immediately marked as cooked.
235  bool shouldSchedule(
236  const PDG_WorkItem* work_item) const override;
237 
238 private:
239  /// Enumeration of service status
240  enum ServiceStatus
241  {
242  /// Services have not yet been checked/started
243  eServiceStatusUnstarted,
244 
245  /// Services have been successfully started
246  eServiceStatusStarted,
247 
248  /// Services failed to start
249  eServiceStatusFailed,
250 
251  /// Services are not used/disabled
252  eServiceStatusUnused,
253  };
254 
255  /// Queries for existing work items generate in this node for the
256  /// specified upstream item.
257  bool workItemsForParent(
258  PDG_WorkItemArray& work_items,
259  PDG_BatchWorkItemSet& batches,
260  PDG_WorkItem* upstream_item);
261 
262  /// Generates work items from an upstream work item
263  bool generateFromUpstream(
264  PDGE_Resolutions& resolutions,
265  PDG_WorkItem* upstream_item);
266 
267  /// Adds internal dependencies between the specified work items, i.e.
268  /// dependencies between sibling work items.
269  void addInternalDependencies(
270  const PDG_WorkItemArray& work_items);
271 
272  /// Adds the specified work items to this node.
273  void addWorkItems(
274  const PDG_WorkItemArray& all_items,
275  const PDG_WorkItemArray& work_items,
276  const PDG_WorkItemPairArray& pairs,
278  bool compact_items,
279  bool sort_items);
280 
281  /// Sets the label for a specific work item
282  void setWorkItemLabel(
283  PDG_WorkItem* work_item,
284  int thread) const;
285 
286  /// Sets the label and command for the specified work items
287  void configureWorkItems(
288  const PDG_WorkItemArray& work_items,
289  PDG_EvaluationContext::State state) const;
290 
291  /// Configures services for this node
292  void configureServices();
293 
294  /// Checks if any of the expected output files in the node have
295  /// duplicate paths, and emits a warning if they do
296  void checkDuplicateOutputs() const;
297 
298 private:
299  PDG_WorkItemConstMap myParentMap;
300  PDG_WorkItemArray myPendingInjections;
301 
302  PriorityType myPriorityType;
303  LabelType myLabelType;
304  GenerateWhen myGenerateWhen;
305  CacheMode myCacheMode;
306  PDG_WorkItemCookType myCookType;
307 
308  ServiceStatus myServiceStatus;
309  PDG_ServiceResetWhen myServiceResetWhen;
310  PDG_ServiceResetType myServiceResetType;
311 
312  mutable UT_Lock myServiceStatusLock;
313  mutable UT_TBBSpinLock myPendingLock;
314  bool myHadInjection;
315  bool myUseScheduleCondition;
316 };
317 
318 #endif /* __PDG_PROCESSOR_H__ */
PDG_ServiceResetType serviceResetType() const
Returns the reset type for service clients used by this node.
Automatic - checks if the file exists and uses it if it does.
Definition: PDG_Processor.h:69
LabelType
Labeling scheme that node can use when generating work item.
Definition: PDG_Processor.h:48
virtual PDGE_Dependency::State evalPartial(PDGE_Resolutions &, const PDGE_Evaluator &, PDGE_Dependency *, const Array &)
#define PDG_API
Definition: PDG_API.h:23
virtual bool deserializeWorkItem(PDG_WorkItem *work_item)
State
Evaluation context state.
PriorityType
Prioritization schemes that node can use when generating work items.
Definition: PDG_Processor.h:33
virtual void clearAllWorkItems()
friend class PDG_Processor
Definition: PDG_Node.h:575
PDG_WorkItemCookType
Enumeration of work item cook types.
Definition: PDG_Types.h:486
PDG_WorkItemCookType cookType() const
Returns the cook type for work items created by this node.
GenerateWhen
Enumeration of generation conditions.
Definition: PDG_Processor.h:85
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
virtual void postCook()
Generate work items when all inputs work items are generated.
Definition: PDG_Processor.h:91
Inherit the label from the parent item.
Definition: PDG_Processor.h:55
Generate work items when all inputs work items are cooked.
Definition: PDG_Processor.h:97
GLuint const GLchar * name
Definition: glcorearb.h:786
PDG_ServiceResetType
Definition: PDG_Types.h:175
PDG_WorkItemState
Enum of possible work item states.
Definition: PDG_Types.h:413
Set the priority based on an expression.
Definition: PDG_Processor.h:40
virtual void syncWorkItem(PDG_WorkItem *work_item, const PDG_WorkItem *clone_target)
Syncs data for the work item, using node-specific logic.
Definition: PDG_Node.h:353
virtual void addInputDeps(PDG_Node *input_node)
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
PriorityType prioritizeBy() const
Set the label based on an expression.
Definition: PDG_Processor.h:58
bool preCook(PDG_NodeSet &dirty, PDG_NodeSet &visited, bool &save_scene, bool has_filter)
Runs precook logic for this node and recurses into input nodes.
virtual void commitWorkItem(PDG_WorkItem *work_item)
Called after a work item is completely deserialized.
~PDG_Processor() override
virtual bool shouldSchedule(const PDG_WorkItem *work_item) const
Definition: PDG_Node.h:616
Generate work items each time an input work item cooks.
Definition: PDG_Processor.h:88
PDG_ServiceResetWhen
When service clients should be reset.
Definition: PDG_Types.h:158
virtual PDGE_Dependency::State evalResolve(PDGE_Resolutions &, const PDGE_Evaluator &, PDGE_Dependency *)
Called when a dependency owned by this object is resolved.
PDG_ServiceResetWhen serviceResetWhen() const
Returns the condition when this node resets service clients.
virtual bool cacheBuiltinParms(PDG_NodeSet &dirty, bool dynamic_inputs)
void resetOwner() override
Resets the owner.
void addWorkItems(const PDG_WorkItemArray &work_items, PDG_EvaluationContext::State state, bool sort_items, bool add_batches)
virtual void clearWorkItem(PDG_WorkItem *work_item)
virtual void addWorkItem(PDG_WorkItem *work_item)
Automatic generation mode.
Definition: PDG_Processor.h:94
bool useServices() const
virtual void memoryInfo(PDG_MemoryInfo &memory_info, bool inclusive) const
Returns the memory usage as a PDG_MemoryInfo struct.
virtual PDG_WorkItemState isOutputCached(PDG_WorkItem *work_item) const
Definition: PDG_Node.h:359