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