HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_BatchWorkItem.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_BATCHWORKITEM_H__
10 #define __PDG_BATCHWORKITEM_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_Types.h"
15 #include "PDG_WorkItem.h"
16 
17 #include <UT/UT_StringHolder.h>
18 
20 {
21 public:
23  PDG_GraphContext* context,
24  bool is_static = true,
25  PDG_WorkItemID item_id = theInvalidId,
26  int batch_size = 0);
27 
28  ~PDG_BatchWorkItem() override;
29 
30  /// Returns the memory usage of this batch. Does not count sub items in the
31  /// batch as they're technically owned by the node.
32  void memoryInfo(PDG_MemoryInfo& memory_info,
33  bool inclusive) const override;
34 
35  /// Returns the starting index for the batch, if it supports partial
36  /// cooking.
37  int batchStart() const;
38 
39  /// Returns the size of the batch
40  int batchSize() const;
41 
42  /// Returns the list of sub items in the batch
44  { return myBatchItems; }
45 
46  /// Returns the batch name; the prefix given to all sub items
48  { return name(); }
49 
50  /// Resets the work item's dependency objects
51  void resetOwner() override;
52 
53  /// Returns a sub item for a given index, or nullptr if the index is out
54  /// of the valid range.
55  PDG_WorkItem* subitem(int index) const;
56 
57  /// Inserts a subitem at a specific index. Used for deserialization
58  void insertSubitem(int index, PDG_WorkItem* item);
59 
60  /// Initializes the batch item with a given sub item count and starting
61  /// state
62  void initBatchItems(
63  PDG_WorkItemArray& items,
64  int count);
65 
66  /// Reinitializes the batch item properties from the ones on this work
67  /// item. Assumes the same batch size.
68  void initBatchItems();
69 
70  /// Sets the pending dirty flag on all sub items
71  void setPendingDirty(PendingDirty pending) override;
72 
73  /// Sets the partial batch flag
74  void setIsPartialCook(bool is_partial);
75 
76  /// sets the is dynamic batch flag
77  void setIsDynamicBatch(bool is_dynamic);
78 
79  /// Returns the partial batch flag
80  bool isPartialCook() const
81  { return myIsPartialCook; }
82 
83  /// Returns true if the batch is allowed to dynamically add work items
84  /// while it c ooks
85  bool isDynamicBatch() const
86  { return myIsDynamicBatch; }
87 
88  /// Sets the batch offset
89  void setOffset(int offset);
90 
91  /// Returns the batch offset, e.g. the start of the first item in the real
92  /// index space
93  int offset() const
94  { return myOffset; }
95 
96  /// Sets the activation mode of the batch
97  void setActivationMode(
99 
100  /// Sets the activation count, used when the activation mode is set to
101  /// ActivateFixed.
102  void setActivationCount(
103  int activation_count);
104 
105  /// Gets the activation mode of the batch
106  PDG_BatchActivation activationMode() const;
107 
108  /// Gets the activation count
109  int activationCount() const;
110 
111  /// Sets the start index of the batch
112  void setStartIndex(int index);
113 
114  /// Sets a stat on the batch item, and the subitems if requested
116  bool batched) override;
117 
118  /// Returns the can cook dependency object for this work item
120  { return &myNotCachedDep; }
121 
122  /// Tries marking the not cached dep as resolved
123  void tryNotCached(
124  PDGE_Resolutions& resolutions,
125  PDG_WorkItem* work_item);
126 
127  /// Returns the active batch sub item, if any
128  const PDG_WorkItem* activeBatchItem() const;
129 
130  /// Sets the active batch sub item index, and returns that sub item if
131  /// the index is valid
132  const PDG_WorkItem* setActiveBatchIndex(int index) const;
133 
134  /// Dynamically adds a new work item to the batch
135  PDG_WorkItem* appendSubItem(UT_WorkBuffer& errors);
136 
137 protected:
138  /// Returns true if the entire batch is cached, else false
139  PDG_WorkItemState checkCached(bool add_results) override;
140 
141  /// Notifies the batch item than a given subitem index has finished cooking
142  void notifyCook(PDGE_Resolutions& resolutions,
144  int batch_index,
145  fpreal duration,
146  bool notify_all,
147  bool static_cook,
148  bool unresolve) override;
149 
150  /// Syncs the cache for all subitems
151  void syncCacheId() override;
152 
153  /// Sets the frame of the batch item and all sub items, using the step
154  /// size.
155  bool setFrame(fpreal frame,
156  fpreal frame_step,
157  bool check_dirty) override;
158 
159  /// Called when one of the dependencies owned by this work item
160  /// is resolved.
162  PDGE_Resolutions& resolutions,
163  const PDGE_Evaluator& evaluator,
164  PDGE_Dependency* dependency) override;
165 
166 private:
167  PDG_WorkItemArray myBatchItems;
168  PDGE_Dependency myNotCachedDep;
169 
170  int myOffset;
171  int myStartIndex;
172  int myCacheCheck;
173  int myActivationCount;
174  mutable int myActiveBatchIndex;
175 
176  PDG_BatchActivation myActivationMode;
177  bool myIsPartialCook;
178  bool myIsDynamicBatch;
179 };
180 
181 #endif /* __PDG_BATCHWORKITEM_H__ */
virtual PDG_WorkItemState checkCached(bool add_outputs)
const PDG_WorkItemArray & batchItems() const
Returns the list of sub items in the batch.
bool isPartialCook() const
Returns the partial batch flag.
void resetOwner() override
Resets the work item's dependency objects.
#define PDG_API
Definition: PDG_API.h:23
**But if you need a result
Definition: thread.h:613
GLintptr offset
Definition: glcorearb.h:665
PDG_BatchActivation
Definition: PDG_Types.h:106
virtual void syncCacheId()
Syncs a work item's cache with its dependents.
PDGE_Dependency * notCachedDep()
Returns the can cook dependency object for this work item.
friend class PDG_BatchWorkItem
Definition: PDG_WorkItem.h:967
PDGE_Dependency::State evalResolve(PDGE_Resolutions &resolutions, const PDGE_Evaluator &evaluator, PDGE_Dependency *dependency) override
PDG_WorkItemState
Enum of possible work item states.
Definition: PDG_Types.h:413
UT_StringHolder batchName() const
Returns the batch name; the prefix given to all sub items.
GLenum mode
Definition: glcorearb.h:99
bool isDynamicBatch() const
bool setFrame(fpreal frame)
virtual void setPendingDirty(PendingDirty pending)
Sets the pending dirty flag on the work item, used for regeneration.
StatType
Enumeration of stats stored in this object.
virtual void memoryInfo(PDG_MemoryInfo &memory_info, bool inclusive) const
Returns a break down of the memory used by the work item.
virtual fpreal setTimeStat(PDG_WorkItemStats::StatType stat, bool batched)
Sets a stat to the current time.
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
exint PDG_WorkItemID
Type defs for unique work item IDs.
Definition: PDG_Types.h:48
virtual void notifyCook(PDGE_Resolutions &resolutions, PDG_WorkItemState result, int batch_index, fpreal duration, bool notify_all, bool static_cook, bool unresolve)
Notifies this work item that is has cooked.
GLint GLsizei count
Definition: glcorearb.h:405
UT_StringHolder name() const
Returns the name of the work item, guaranteed to be unique.