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_WorkItem.h"
15 #include "PDG_WorkItemTypes.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  /// Returns the output file cache state of this work item
138  PDG_WorkItemCacheState outputCacheState() const override;
139 
140 protected:
141  /// Returns true if the entire batch is cached, else false
142  PDG_WorkItemState checkCached(bool add_results) override;
143 
144  /// Notifies the batch item than a given subitem index has finished cooking
145  void notifyCook(PDGE_Resolutions& resolutions,
147  int batch_index,
148  fpreal duration,
149  bool notify_all,
150  bool static_cook,
151  bool unresolve) override;
152 
153  /// Syncs the cache for all subitems
154  void syncCacheId() override;
155 
156  /// Sets the frame of the batch item and all sub items, using the step
157  /// size.
158  bool setFrame(fpreal frame,
159  fpreal frame_step,
160  bool check_dirty) override;
161 
162  /// Called when one of the dependencies owned by this work item
163  /// is resolved.
165  PDGE_Resolutions& resolutions,
166  const PDGE_Evaluator& evaluator,
167  PDGE_Dependency* dependency) override;
168 
169 private:
170  PDG_WorkItemArray myBatchItems;
171  PDGE_Dependency myNotCachedDep;
172 
173  int myOffset;
174  int myStartIndex;
175  int myCacheCheck;
176  int myActivationCount;
177  mutable int myActiveBatchIndex;
178 
179  PDG_BatchActivation myActivationMode;
180  bool myIsPartialCook;
181  bool myIsDynamicBatch;
182 };
183 
184 #endif /* __PDG_BATCHWORKITEM_H__ */
exint PDG_WorkItemID
Type defs for unique work item IDs.
virtual PDG_WorkItemState checkCached(bool add_outputs)
PDG_BatchActivation
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
virtual void syncCacheId()
Syncs a work item's cache with its dependents.
PDG_WorkItemState
Enum of possible work item states.
PDGE_Dependency * notCachedDep()
Returns the can cook dependency object for this work item.
friend class PDG_BatchWorkItem
virtual PDG_WorkItemCacheState outputCacheState() const
Returns the output file cache state of this work item.
PDGE_Dependency::State evalResolve(PDGE_Resolutions &resolutions, const PDGE_Evaluator &evaluator, PDGE_Dependency *dependency) override
UT_StringHolder batchName() const
Returns the batch name; the prefix given to all sub items.
GLenum mode
Definition: glcorearb.h:99
PDG_WorkItemCacheState
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
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.