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 =
26  PDG_WorkItemInvalidID,
27  int batch_size = 0);
28 
29  ~PDG_BatchWorkItem() override;
30 
31  /// Returns the memory usage of this batch. Does not count sub items in the
32  /// batch as they're technically owned by the node.
33  void memoryInfo(PDG_MemoryInfo& memory_info,
34  bool inclusive) const override;
35 
36  /// Returns the starting index for the batch, if it supports partial
37  /// cooking.
38  int batchStart() const;
39 
40  /// Returns the size of the batch
41  int batchSize() const;
42 
43  /// Returns the list of sub items in the batch
45  { return myBatchItems; }
46 
47  /// Returns the batch name; the prefix given to all sub items
49  { return name(); }
50 
51  /// Resets the work item's dependency objects
52  void resetOwner() override;
53 
54  /// Returns a sub item for a given index, or nullptr if the index is out
55  /// of the valid range.
56  PDG_WorkItem* subitem(int index) const;
57 
58  /// Inserts a subitem at a specific index. Used for deserialization
59  void insertSubitem(int index, PDG_WorkItem* item);
60 
61  /// Initializes the batch item with a given sub item count and starting
62  /// state
63  void initBatchItems(
64  PDG_WorkItemPtrArray& items,
65  int count);
66 
67  /// Reinitializes the batch item properties from the ones on this work
68  /// item. Assumes the same batch size.
69  void initBatchItems();
70 
71  /// Sets the pending dirty flag on all sub items
72  void setPendingDirty(
73  PDG_WorkItemPendingDirty pending) override;
74 
75  /// Sets the partial batch flag
76  void setIsPartialCook(bool is_partial);
77 
78  /// sets the is dynamic batch flag
79  void setIsDynamicBatch(bool is_dynamic);
80 
81  /// Sets the work item command directly, and updates the cook type of any
82  /// subitems in the batch
83  bool setCommand(
84  const UT_StringHolder& command,
85  bool shell=false) override;
86 
87  /// Sets a per-platform work item command, and updates the cook type of
88  /// any subitems in the batch
90  const UT_StringHolder& linux,
91  const UT_StringHolder& mac,
92  const UT_StringHolder& windows,
93  bool shell=false) override;
94 
95  /// Returns the partial batch flag
96  bool isPartialCook() const
97  { return myIsPartialCook; }
98 
99  /// Returns true if the batch is allowed to dynamically add work items
100  /// while it c ooks
101  bool isDynamicBatch() const
102  { return myIsDynamicBatch; }
103 
104  /// Sets the batch offset
105  void setOffset(int offset);
106 
107  /// Returns the batch offset, e.g. the start of the first item in the real
108  /// index space
109  int offset() const
110  { return myOffset; }
111 
112  /// Sets the activation mode of the batch
113  void setActivationMode(
115 
116  /// Sets the activation count, used when the activation mode is set to
117  /// ActivateFixed.
118  void setActivationCount(
119  int activation_count);
120 
121  /// Gets the activation mode of the batch
122  PDG_BatchActivation activationMode() const;
123 
124  /// Gets the activation count
125  int activationCount() const;
126 
127  /// Sets the start index of the batch
128  void setStartIndex(int index);
129 
130  /// Sets a stat on the batch item, and the subitems if requested
132  bool batched) override;
133 
134  /// Returns the can cook dependency object for this work item
136  { return &myNotCachedDep; }
137 
138  /// Tries marking the not cached dep as resolved
139  void tryNotCached(
140  PDGE_Resolutions& resolutions,
141  PDG_WorkItem* work_item);
142 
143  /// Returns the active batch sub item, if any
144  const PDG_WorkItem* activeBatchItem() const;
145 
146  /// Sets the active batch sub item index, and returns that sub item if
147  /// the index is valid
148  const PDG_WorkItem* setActiveBatchIndex(int index) const;
149 
150  /// Dynamically adds a new work item to the batch
151  PDG_WorkItem* appendSubItem(UT_WorkBuffer& errors);
152 
153  /// Returns the output file cache state of this work item
154  PDG_WorkItemCacheState outputCacheState() const override;
155 
156 protected:
157  /// Returns true if the entire batch is cached, else false
158  PDG_WorkItemState checkCached(bool add_results) override;
159 
160  /// Notifies the batch item than a given subitem index has finished cooking
161  void notifyCook(PDGE_Resolutions& resolutions,
163  int batch_index,
164  fpreal duration,
165  bool notify_all,
166  bool static_cook,
167  bool unresolve) override;
168 
169  /// Syncs the cache for all subitems
170  void syncCacheId() override;
171 
172  /// Sets the frame of the batch item and all sub items, using the step
173  /// size.
174  bool setFrameInternal(
175  fpreal frame,
176  fpreal frame_step,
177  bool check_dirty,
178  bool emit) override;
179 
180  /// Called when one of the dependencies owned by this work item
181  /// is resolved.
183  PDGE_Resolutions& resolutions,
184  const PDGE_Evaluator& evaluator,
185  PDGE_Dependency* dependency) override;
186 
187 private:
188  PDG_WorkItemArray myBatchItems;
189  PDGE_Dependency myNotCachedDep;
190 
191  int myOffset;
192  int myStartIndex;
193  int myCacheCheck;
194  int myActivationCount;
195  mutable int myActiveBatchIndex;
196 
197  PDG_BatchActivation myActivationMode;
198  bool myIsPartialCook;
199  bool myIsDynamicBatch;
200 };
201 
202 #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.
virtual bool setFrameInternal(fpreal frame, fpreal frame_step, bool check_dirty, bool emit)
Internal method for setting the frame.
#define PDG_API
Definition: PDG_API.h:23
**But if you need a result
Definition: thread.h:622
PDG_WorkItemPendingDirty
Enumeration of pending work item dirty states.
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
virtual bool setPlatformCommands(const UT_StringHolder &linux, const UT_StringHolder &mac, const UT_StringHolder &windows, bool shell=false)
Sets a per-platform work item command.
virtual void setPendingDirty(PDG_WorkItemPendingDirty pending)
Sets the pending dirty flag on the work item, used for regeneration.
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
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:283
GLuint index
Definition: glcorearb.h:786
virtual bool setCommand(const UT_StringHolder &command, bool shell=false)
Sets the work item command directly.
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.