00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __COP2_CookScheduler_h__
00023 #define __COP2_CookScheduler_h__
00024
00025 #include "COP2_API.h"
00026 #include <UT/UT_Rect.h>
00027 #include <UT/UT_RefArray.h>
00028 #include <UT/UT_PtrArray.h>
00029 #include <UT/UT_Lock.h>
00030 #include <UT/UT_IntArray.h>
00031 #include <LM/LM_Defines.h>
00032 #include <LM/LM_ProductInfo.h>
00033
00034 #include <TIL/TIL_Defines.h>
00035 #include "COP2_ThreadCookParms.h"
00036 class TIL_Raster;
00037 class TIL_TileMPlay;
00038 class TIL_Plane;
00039 class TIL_Sequence;
00040 class OP_Context;
00041 class COP2_Node;
00042 class COP2_Context;
00043 class COP2_CookAreaInfo;
00044 class COP2_CheckpointWrapper;
00045 class COP2_CheckpointPlaneWrapper;
00046 class COP2_CookAreaList;
00047
00048 class COP2_API COP2_CookScheduler
00049 {
00050 public:
00051 COP2_CookScheduler();
00052
00053
00054
00055 void cookNodeToRaster(COP2_Node &node, UT_PtrArray<OP_Context *> &contexts,
00056 UT_PtrArray<const TIL_Plane *> &ref_planes,
00057 UT_PtrArray<const int *> &compmap,
00058 UT_RefArray<UT_InclusiveRect> &bounds,
00059 UT_PtrArray<TIL_Raster *> &rasters,
00060 UT_PtrArray<TIL_Raster *> *tile_rasters,
00061 int tile_index,
00062 TIL_TileMPlay *output_device,
00063 UT_IntArray &array_indices, int compindex,
00064 float black, float white,
00065 int ignore_bwpoints,
00066 float gamma, bool clean_up_regions,
00067 int &num_threads, bool &completed);
00068
00069
00070
00071
00072
00073
00074
00075 static void *threadStartCallback(void *data);
00076
00077
00078
00079 COP2_ThreadCookParms *getThreadCookParms(int thread_index,
00080 bool &blocked);
00081
00082
00083 void doneWithThreadCookParms(COP2_ThreadCookParms &thread_parms);
00084
00085
00086
00087 float getPercentageComplete(int num_extra_tiles_cooked) const;
00088
00089
00090
00091
00092
00093
00094 static bool isPlaneStillCheckpointedCallback(void *opaque_cop_node,
00095 const char *plane_name,
00096 float cook_time);
00097
00098
00099
00100 bool isUsingCheckpointing() const { return myUseCheckpointing; }
00101
00102
00103
00104 bool isCookingSomething() const { return myFinalNode != 0; }
00105
00106
00107
00108 void getResScaleFactor(float &xres_scale_factor,
00109 float &yres_scale_factor) const;
00110
00111
00112
00113 void getScaledRes(const TIL_Sequence &sequence,
00114 int &scaled_xres, int &scaled_yres);
00115
00116
00117
00118
00119 int getNumThreadsToUse() const;
00120
00121
00122
00123 bool canUseGPU() const;
00124 bool canUseCellSPU() const;
00125
00126
00127
00128
00129
00130 int getNumThreadsUsedInCook() const;
00131
00132 const COP2_CookAreaInfo * getAreaInfo(COP2_Context &context,
00133 const COP2_Node *node) const;
00134
00135
00136
00137 bool getDependentsFor(COP2_Context &context,
00138 COP2_Node *cooknode,
00139 COP2_Node *ancestor,
00140 UT_PtrArray<COP2_Context *> &dependencies);
00141
00142
00143 void debugDumpPlaneOrder();
00144
00145
00146
00147
00148 void getPlanesForNode(COP2_Node *node,
00149 UT_PtrArray<const TIL_Plane *> &planes,
00150 UT_IntArray &array_index) const;
00151 void blockUntilReady();
00152 private:
00153
00154
00155
00156 void setOutputRaster(
00157 UT_PtrArray<TIL_Raster *> &raster,
00158 UT_PtrArray<TIL_Raster *> *tile_rasters,
00159 int tile_index,
00160 TIL_TileMPlay *output_device,
00161 int compindex);
00162
00163 void setFinalPlanesToCook(
00164 COP2_Node &node,
00165 UT_PtrArray<OP_Context *> &contexts,
00166 UT_PtrArray<const TIL_Plane *> &ref_planes,
00167 UT_IntArray &array_indicies,
00168 UT_RefArray<UT_InclusiveRect> &bounds,
00169 bool clean_up_regions);
00170
00171 void setThreadCommonParms(
00172 float black,
00173 float white,
00174 int ignore_bwpoints,
00175 float gamma);
00176
00177 void setRasterInThreadParms(
00178 COP2_Node &node,
00179 int thread_index,
00180 const TIL_Plane *for_plane,
00181 float t);
00182
00183 void clearCookInformation();
00184
00185
00186
00187
00188
00189 void createListOfPlanesBeingCooked(
00190 COP2_CheckpointPlaneWrapper &root_plane_wrapper);
00191
00192 COP2_CheckpointWrapper *getOrCreateNodeCheckpointWrapper(COP2_Node &node);
00193
00194 UT_PtrArray<COP2_CheckpointPlaneWrapper *> buildDependencyTree();
00195
00196 UT_PtrArray<COP2_CheckpointPlaneWrapper *> createWrappersForFinalOutput();
00197
00198 bool isPlaneCached(COP2_CheckpointPlaneWrapper &wrapper);
00199
00200 void checkpointCachedPlanes();
00201
00202 void getPossibleInputAreasForPlane(
00203 COP2_CheckpointPlaneWrapper &plane_wrapper,
00204 COP2_CookAreaList &input_areas);
00205
00206 void determinePlaneDependencies(
00207 COP2_CheckpointWrapper &wrapper,
00208 int &num_tiles, int &num_planes);
00209
00210 void applyResScaleFactor(
00211 int full_xres, int full_yres,
00212 int &scaled_xres, int &scaled_yres);
00213
00214 COP2_CheckpointPlaneWrapper *findCookOrderTarget(
00215 UT_PtrArray<COP2_CheckpointPlaneWrapper *> &votes,
00216 COP2_CheckpointPlaneWrapper *last_plane);
00217
00218 COP2_CheckpointPlaneWrapper *findCookOrderCurrent(
00219 COP2_CheckpointPlaneWrapper &target);
00220
00221 COP2_CheckpointPlaneWrapper *findCookOrderCurrent(
00222 COP2_CheckpointPlaneWrapper &plane_wrapper,
00223 COP2_CheckpointPlaneWrapper *result,
00224 int &max_depth,
00225 int &min_parents);
00226
00227 COP2_CheckpointPlaneWrapper *determineNextPlaneInCookOrder(
00228 UT_PtrArray<COP2_CheckpointPlaneWrapper *> &
00229 current_locks,
00230 UT_PtrArray<COP2_CheckpointPlaneWrapper *> &votes);
00231
00232 void determineCookingOrder();
00233
00234
00235
00236
00237
00238 COP2_CheckpointWrapper *findPlaneForThreadToCook(int thread_index);
00239
00240 void doneCookingPlane(
00241 int thread_index,
00242 COP2_Node &node,
00243 const TIL_Plane &plane,
00244 float time);
00245
00246 COP2_CheckpointPlaneWrapper *getPlaneToCook(int thread_index,
00247 bool &blocked);
00248
00249 bool isPlaneBeingCookedByAnyThread(
00250 COP2_CheckpointPlaneWrapper &plane_wrapper);
00251
00252 bool isPlaneBeingCookedByThreadOtherThan(
00253 COP2_CheckpointPlaneWrapper &plane_wrapper,
00254 int thread_index);
00255
00256 void getNumThreadsCookingNodeAndPlane(
00257 COP2_CheckpointPlaneWrapper &plane_wrapper,
00258 int &threads_in_node, int &threads_in_plane,
00259 int &threads_in_op_type);
00260
00261 void markPlaneAsBeingCooked(
00262 COP2_CheckpointPlaneWrapper &plane_wrapper,
00263 int thread_index);
00264
00265 int findPlaneParmIndexForWrapperPlane(
00266 int thread_index,
00267 int total_num_threads,
00268 COP2_CheckpointPlaneWrapper &plane_wrapper,
00269 bool &cooked_by_another_thread);
00270
00271 void unlockCheckpointsAfterCookingPlane(
00272 COP2_CheckpointPlaneWrapper &plane_wrapper,
00273 int thread_index);
00274
00275 void unlockAllCheckpointedPlanes(int thread_index);
00276
00277 void uncheckpointPlane(
00278 COP2_CheckpointPlaneWrapper &plane_wrapper,
00279 int thread_index);
00280
00281 void cleanUpAfterCookingNode(
00282 COP2_CheckpointWrapper &wrapper);
00283
00284
00285 COP2_CommonCookParms myCommonParms;
00286 COP2_PlaneCookParms myPlaneParms[TIL_MAX_THREADS];
00287 COP2_ThreadCookParms myThreadParms[TIL_MAX_THREADS];
00288
00289 UT_Lock myLock;
00290 UT_Lock myMessageLock;
00291
00292 COP2_Node *myFinalNode;
00293 UT_PtrArray<OP_Context *> myFinalContexts;
00294 UT_PtrArray<const TIL_Plane *> myFinalPlanes;
00295 UT_IntArray myFinalArrayIndices;
00296 UT_RefArray<UT_InclusiveRect> myFinalBounds;
00297 bool myCleanUpRegionsOfFinalNode;
00298 float myXResScaleFactor;
00299 float myYResScaleFactor;
00300
00301 UT_PtrArray<TIL_Raster *> myRasters;
00302 UT_PtrArray<TIL_Raster *> *myTileRasters;
00303 UT_PtrArray<const int *> myCompMaps;
00304 TIL_TileMPlay *myOutputDevice;
00305 int myTileIndex;
00306 int myCompIndex;
00307
00308
00309 UT_PtrArray<COP2_CheckpointPlaneWrapper *> myPlaneSet;
00310
00311 UT_PtrArray<COP2_CheckpointPlaneWrapper *> myPlaneOrder;
00312
00313 UT_PtrArray<COP2_CheckpointPlaneWrapper *> myCachedPlanes;
00314
00315 UT_PtrArray<COP2_Node *> myNodesWithWrappers;
00316
00317 int myIndexToNextPlaneToCook;
00318
00319
00320
00321
00322 COP2_CheckpointPlaneWrapper *myPlanesCookedByThreads[TIL_MAX_THREADS];
00323
00324 int myNumPlanesCooked;
00325 int myNumTilesCooked;
00326 int myTotalNumPlanes;
00327 int myTotalNumTiles;
00328
00329 bool myUseCheckpointing;
00330 bool myCheckpointAllFlag;
00331 bool myAllowGPUInOtherThreads;
00332 bool myGPUFatalError;
00333 };
00334
00335
00336 COP2_API extern COP2_CookScheduler &COP2getCookScheduler();
00337
00338 #endif