Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoLDMResourceManager.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : J.HUMMEL (Dec 2002)
22** Modified by : T.DUFOUR (MMM yyyy)
23**=======================================================================*/
24#ifndef _SO_LDM_RESOURCE_MANAGER_
25#define _SO_LDM_RESOURCE_MANAGER_
26
27#ifdef _MSC_VER
28#pragma warning( push )
29#pragma warning(disable:4251)
30#endif
31
32#include <LDM/SoLDMLargeDataManagement.h>
33#include <LDM/nodes/SoLDMResourceParameters.h>
34#include <Inventor/SbVec.h>
35#include <Inventor/STL/vector>
36#include <LDM/SoLDMTopoOctree.h>
37#define MIN_RES_THRESHOLD 10000 //high number meaning not set
38
39class SoDataSet;
40
41// callback function prototypes
43typedef void SoLDMTexFrontCB (void *userData);
44
62SoEXTENDER_Documented class SoLDMResourceManager : public SoLDMLargeDataManagement
63{
64public:
69
74
75
76private:
77
78 enum LoadPolicy {
79 NO_USER_INTERACTION, // Only load when no user interaction
80 ALWAYS, // Always load
81 NEVER // Never. No loading happens anymore. Allows suspending loading process.
82 };
83
88 void invalidateData();
89
95 static void setMultiIO(SbBool on);
100 static SbBool getMultiIO();
101
102 static void setMonitoringAmount(int);
103 static int getMonitoringAmount();
104
108 SbVec3i32 getTileSize() const;
109
113 int getDataSize();
114
118 void setTexelSize( int texelSize );
119
123 int getTexelSize();
124
128 const SbVec3i32& getVolumeDim() const;
129
130#if 1 SoDEPRECATED
133 void setTex3LoadRate( int loadRate );
134SoDEPRECATED
136 int getTex3LoadRate();
137SoDEPRECATED
139 void setTex2LoadRate( int loadRate );
140SoDEPRECATED
142 int getTex2LoadRate();
143SoDEPRECATED
145 void setMinResolutionThreshold( int threshold = MIN_RES_THRESHOLD ); // don't unload above this threshold.
146SoDEPRECATED
148 int getMinResolutionThreshold();
149SoDEPRECATED
151 void setMaxResolutionThreshold( int threshold ); // don't load below this threshold.
152SoDEPRECATED
154 int getMaxResolutionThreshold();
155
156#endif
159#if 1 SoDEPRECATED
162 int getTileDimension();
163
164#endif
166#if 1 SoDEPRECATED
172 void setMaxMainMemory( int maxMainMemory );
173SoDEPRECATED
178 int getMaxMainMemory();
179SoDEPRECATED
181 void setMaxTexMemory( int maxTexMemoryMB );
182SoDEPRECATED
184 int getMaxTexMemory();
185SoDEPRECATED
190 int getMaxTilesInMainMem();
191SoDEPRECATED
193 int getMaxTilesInTexMem();
194#endif
196#if 1 SoDEPRECATED
206 void setTileHalfLife( float timeInSec );
207SoDEPRECATED
212 float getTileHalfLife();
213SoDEPRECATED
224 void setLoadPolicy( LoadPolicy loadPolicy );SoDEPRECATED
229 LoadPolicy getLoadPolicy();
230
231 /*
232 * Sets the time (in seconds) for which VViz does not load once a user
233 * stopped interaction
234 * Consulted only in NO_USER_INTERACTION mode
235 * Default is 0.3 seconds.
236 */SoDEPRECATED
238 void setMovingTimeOut( float );
239
240 /*
241 * gets the time for which VViz should not load once a user
242 * stopped interaction
243 */SoDEPRECATED
245 float getMovingTimeOut();
246SoDEPRECATED
252 static void setTex2VVizLoadRate( int loadRate );
253SoDEPRECATED
259 static int getTex2VVizLoadRate();
260SoDEPRECATED
266 static void setTex3VVizLoadRate( int loadRate );
267SoDEPRECATED
273 static int getTex3VVizLoadRate();
274SoDEPRECATED
281 static void setMaxVVizMainMemory( int maxMainMemoryMB ); // set/get the allowed main memory in MB
282SoDEPRECATED
289 static void setMaxVVizTexMemory( int maxTexMemoryMB );
290SoDEPRECATED
295 static int getMaxVVizMainMemory(); // for all the LDM datasets.
296SoDEPRECATED
301 static int getMaxVVizTexMemory();
302SoDEPRECATED
308 static void setNumIO( unsigned int numIO );
309SoDEPRECATED
315 static unsigned int getNumIO();
316SoDEPRECATED
323 static void setLoadNotificationRate( int rate );
324SoDEPRECATED
329 static int getLoadNotificationRate();
330
331#endif
333private:
334 float m_decreaseWeightFactor;
335 float getDecreaseWeightFactor() {return m_decreaseWeightFactor;};
336
340 void setTileSize( SbVec3i32 tileDim );
341
345 void setDataSize( int dataSize );
346
350 void setVolumeDim( const SbVec3i32& dim );
351
352 int getNumTileToTime();
353
354 /*
355 * Enum used to store wich resources has changed. Can be cumulative to
356 * represent several resources modification
357 * ie: GPU resources and CPU resource updated -> value =GPU_MEM_UPDATED | CPU_MEM_UPDATED
358 */
359 enum State
360 {
361 NO_UPDATE = 0x00,
362 CPU_MEM_UPDATED = 0x01, // cpu memory has been changed
363 GPU_MEM_UPDATED = 0x02, // gpu memory has been changed
364 GPU_2D_UPDATED = 0x04, // gpu 2d memory has been changed
365 LOADRATE_2D_UPDATED = 0x08, // LoadRate 2D has been changed
366 LOADRATE_3D_UPDATED = 0x10, // LoadRate 3D has been changed
367 LOAD_RATE_UPDATED = 0x20, // Load notification rate has been updated
368 UPDATE_ALL = 0xFF // Special value to include all previous state
369 };
370
371 // Update all is needed according to the given state
372 virtual void updateResources(unsigned short resourceState);
373
374 // Internal method
375 int getMaxMainMemoryInKB() const; // return amount of main memory in KB
376 int getMaxTexMemoryInKB() const; // return amount of tex memory in KB
377 int getMax2DTexMemoryInKB() const; // return amount of 2D tex memory in KB
378
379 /*
380 Those set of functions returns the sum of resources of all data sets registered
381 */
382 int getSumOfMaxTilesInTexMem();
383 int getSumOfTex3LoadRate();
384 int getSumOfMax2DTextures();
385 int getSumOfTex2LoadRate();
386 void getSumOfMemAndTileSize(uint64_t &memByte, int& tileSize);
387 void getSumOfNumTileInMem( uint64_t &maxTileInMem );
388
389 static void computeInternalCounters(const std::vector<SoLDMResourceManager*>& rsToUpdate);
390 static void shareSpareResources(const std::vector<SoLDMResourceManager*>& rsToUpdate,
391 size_t spareAmount, SoLDMResourceManager::State resourceType);
392
393 /* *
394 * Set of method to compute and allocate internally amount of resources for each dataset
395 * Each method works on a specific resources and determine how much of this resource can
396 * be spared between all dataset. The computation is based on global value for each resources,
397 * and the amount manually set by application
398 */
399 void allocateGPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
400 void allocateCPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
401 void allocateGPU2DResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
402 void allocateTex2LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
403 void allocateTex3LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
404
405 void setIdealTextFrontCb( SoLDMTexFrontCB *func, void* userData = NULL);
406 void idealTexFrontReached();
407 SoLDMTexFrontCB* m_callbackFunc;
408 void* m_userData;
409 SoDataSet* getDataSet() { return m_ds; };
410
414 static uint64_t getMaxVViz2DTexMemory();
415
419 static void setMaxVViz2DTexMemory(uint64_t maxMemory);
420
424 void setMax2DTexMemory(int max2DTexMemory);
425
429 int getMax2DTexMemory();
430
432 void enableTileBorders( bool enableTileBorders );
433
435 bool areTileBordersEnabled() const;
436
438 void setMinTilesToLoad( int minTilesToLoad );
439
441 int getMinTilesToLoad() const
442 {
443 return m_minTilesToLoad;
444 }
445
447 void setViewpointRefinement( SoLDMResourceParameters::ViewpointRefinementPolicy viewportRefinementPolicy );
448
450 bool getViewpointRefinement() const;
451
453 void setScreenResolutionCulling(SoLDMResourceParameters::ScreenResolutionCullingPolicy screenResolutionCullingPolicy);
454
456 bool getScreenResolutionCulling() const;
457
459 uint64_t getDataTileSizeInBytes() const;
460
462 uint64_t getTexTileSizeInBytes(bool is3DTile = false) const;
463
464private:
465
466 int m_minResThreshold; // minimum resolution required (0:1/1, 1:1/2, 2:1/4, ...), default is 100.
467 int m_maxResThreshold; // maximum resolution allowed (0:1/1, 1:1/2, 2:1/4, ...), default is 0.
468
469 bool m_tileBordersEnabled;
470 int m_minTilesToLoad;
471 SoLDMResourceParameters::ViewpointRefinementPolicy m_viewpointRefinementPolicy;
472 SoLDMResourceParameters::ScreenResolutionCullingPolicy m_screenResolutionCullingPolicy;
473
474 // TODO: these 2 methods should be removed while the following friend dependencies will be managed
476 friend class SoLDMMediator;
477
478 //static void updateMainMemParams( int mem, SoLDMResourceManager* exclude );
479 static void updateNumTilesInMainMem();
480
482 static void updateMaxMainMem();
483
485 static void updateSumMax2DTextures();
486
491 static const std::vector<SoLDMResourceManager*>& getRSToUpdate();
492
494 // texture memory controls (for SoVolumeRender, SoVolumeGeometry)
495 static int s_maxVVizTexMemoryKB; // amount in KB of texture memory allowed for all the LDM datasets, default is 0 KB.
496
497 int m_maxTexMemoryKB; // amount in KB of texture memory allowed for the corresponding dataset.
498 int m_max2DTexMemoryKB; // amount in KB of 2D texture memory allowed for the corresponding dataset.
499
500 int m_numTilesInTexMem; // num tiles allowed in texture memory = m_maxTexMemory / tileTexSize
501
502 static void updateNumTilesInTexMem();
503
505 static void updateMaxTexMem();
506
507 // Check that all dataSets parameters are consistent with global ones.
508 // If, for each dataSet, one parameter is not consistent with the global one, it
509 // is reset to -1 in these dataSets.
510 static void checkParametersConsistency(const std::vector<SoLDMResourceManager*>& rsToUpdate);
511
513 // texture 3 memory load rate controls (for SoVolumeRender, SoVolumeGeometry)
514 static int s_tex3VVizLoadRate; // num tiles allowed to load in tex mem per frame for all the LDM datasets, default is 1.
515 int m_tex3LoadRate; // num tiles allowed to load in tex mem per frame for the corresponding dataset.
516
517
518 // texture 2 memory controls (for SoOxxSlice, SoVolumeSkin)
519 static uint64_t s_maxVViz2DTexMemory; // 2D tiles memory allowed in texture memory for all LDM datasets, default is 64M ( ~5% of 1G ).
520
521 // texture 2 memory load rate controls (for SoOxxSlice, SoVolumeSkin)
522 static int s_tex2VVizLoadRate; // num tiles allowed to load in tex mem per frame for all the LDM datasets, default is 64.
523 int m_tex2LoadRate; // num tiles allowed to load in tex mem per frame for the corresponding dataset.
524
525
526
527 static int s_maxVVizMainMemoryKB; // amount in KB of main memory allowed for all the LDM datasets, default is 256 MB.
528 int m_maxMainMemoryKB; // amount in KB of main memory allowed for the corresponding dataset.
529
530 int m_numTilesInMainMem; // num tiles allowed in main memory = m_maxMainMemory / tileSize
531
532 static int s_loadNotificationRate;
533 static int s_memToLoad;
534
535 //number of IO:
536 static unsigned int s_numIO;
537 static SbBool s_isMultiIO;
538
539
540 SbVec3i32 m_tileDimension; // tile dimension, default is 64.
541 int m_dataSize; // data size in bytes (1,2 or 4), default is 1.
542 int m_texelSize; // texel size in bits, default is 8.
543 // =8 for 8 bits indexed 3D textures
544 // =32 for RGBA 3D textures
545 // =24 for 8 bits indexed 2D textures
546 // =96 for RGBA 2D textures
547 SbVec3i32 m_volDim; // dataset dimension
548
549
550
551 static std::vector<SoLDMResourceManager*> s_resourceManagers; // list of all ResourceManager's
552
553
554 // Internal octree needed to compute resources
555 SoLDMTopoOctree m_topoOctree;
556
557 // Adjust the CPU memory allocated per dataset by taking in account
558 // dataset that needs less memory
559 void adjustMemPerDataset(const std::vector<SoLDMResourceManager*>& rsToUpdate);
560
561 SoDataSet* m_ds;
562
563 // cache value before and after ajustMaxTilesInTexMem
564 int m_getSumOfMaxTilesInTexMemAdjusted;
565 int m_getSumOfMaxTilesInTexMem;
566
571 size_t m_maxNeededMemKB;
572
573 // List of resourceManager to take in account for
574 // resource sharing
575 static std::vector<SoLDMResourceManager*> s_rsToUpdate;
576
577 // Store the number of mask associated to each data set
578 static std::map<SoLDMMediator*, int> s_maskPerMediator;
579
580 // Store the number of volume data that are not volumeMask, by cumulating their datasize.
581 // For example dataset in float will count for 4, while a dataset in byte will count
582 // for one. This allow to ponderate properly the amount of resources to
583 // dataset, taking in account their datasize.
584 static size_t s_nbVolumeData;
585
586 // store the amount of GPU memory available for dataset not manually configured
587 // ie : ( s_MaxVVizTexMemory - ( Sum of memory of all datasets with #maxTexMem != -1 )) / ( number of datasets with #maxTexMem == -1 )
588 static size_t s_gpuMemPerDataSetKB;
589
590 // store the amount of CPU memory available for dataset not manually configured
591 // ie : ( s_MaxVVizMainMemory - ( Sum of memory of all dataset with #maxMainMem != -1 )) / ( number of datasets with #maxMainMem == -1 )
592 static size_t s_cpuMemPerDataSetKB;
593
594 // store the 2D tiles memory in texture (GPU) memory available for dataset not manually configured MB
595 // ie : (s_maxVViz2DTexMemory - ( Sum of memory of all dataset with #max2DTextures != -1 )) / ( number of datasets with #max2DTextures == -1 )
596 static uint64_t s_2DGpuTexMemoryPerDataSetMB;
597
598 // store the amount of 2D Load Rate available for dataset not manually configured
599 // ie : (s_tex2VVizLoadRate - ( Sum of 2DLoadRate of all dataset with #tex2LoadRate != -1 )) / ( number of datasets with #tex2LoadRate == -1 )
600 static size_t s_tex2LoadRatePerDataSet;
601
602 // store the amount of 3D Load Rate available for dataset not manually configured
603 // ie : (s_tex3VVizLoadRate - ( Sum of 3DLoadRate of all dataset with #tex3LoadRate != -1 )) / ( number of datasets with #tex3LoadRate == -1 )
604 static size_t s_tex3LoadRatePerDataSet;
605
606 // store the remainder amount of GPU Memory
607 static size_t s_spareGpuMemoryKB;
608
609 // store the remainder amount of CPU Memory
610 static size_t s_spareCpuMemoryKB;
611
612 // store the remainder amount of tex2 LoadRate
613 static size_t s_spareTex2LoadRate;
614
615 // store the remainder amount of tex3 LoadRate
616 static size_t s_spareTex3LoadRate;
617
618 // if true, prints MaxMain(MiB), Max2DTex(MiB), Max3DTex(MiB), Tex2LoadRate, Tex3LoadRate.
619 static bool s_debugResourceValues;
620
625 static SbThreadMutex s_globalResourcesMutex;
626};
627
628
629#ifdef _MSC_VER
630#pragma warning( pop )
631#endif
632
633#endif // _SO_LDM_RESOURCE_MANAGER_
634
635
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Data set...
Definition SoDataSet.h:139
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Large Da...
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Resource...
virtual ~SoLDMResourceManager()
Destructor.
void SoLDMTexFrontCB(void *userData)
SoLDMResourceManager(SoDataSet *ds)
Constructor.
ViewpointRefinementPolicy
Viewpoint refinement policies.
ScreenResolutionCullingPolicy
Screen resolution culling policies.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Octree t...
int SbBool
Boolean type.
Definition SbBase.h:87