Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.3 KiB

  1. //========== Copyright � Valve Corporation, All rights reserved. ========
  2. #if !defined( JOB_EDGE_GEOM_SHARED_HDR ) && defined( _PS3 )
  3. #define JOB_EDGE_GEOM_SHARED_HDR
  4. #include "ps3/spu_job_shared.h"
  5. #include "vjobs/pcring.h"
  6. #define EDGEGEOMRING_DEBUG_TRACE 128 // set to 0 to disable debug trace
  7. // the max allocation, in bytes, made from job_edgegeom
  8. #define EDGEGEOMRING_MAX_ALLOCATION ( 32 * 1024 )
  9. #define EDGEGEOMRING_JOBQUEUE_TAG_COUNT 4
  10. struct ALIGN16 EdgeGeomDebugTrace_t
  11. {
  12. uint8 m_nAllocResult;
  13. uint8 m_nQueueTag;
  14. uint16 m_nJobId;
  15. uint32 m_eaEdgeGeomJts;
  16. uint32 m_nPut;
  17. uint32 m_nEnd;
  18. uint32 m_nTagSignal[EDGEGEOMRING_JOBQUEUE_TAG_COUNT];
  19. }ALIGN16_POST;
  20. struct ALIGN16 CEdgeGeomRing_Mutable
  21. {
  22. SysFifo m_ibvbRing; // edge geom index buffer/vertex buffer ring
  23. // WARNING. Although logically there may be any (2^x) number of queue tags for edgegeom jobs,
  24. // The SPURS must only see 0 and 1 (even and odd) tags. Even tags must synchronize with even,
  25. // odd tags must synchronize with odd.
  26. uint32 m_ibvbRingSignal[EDGEGEOMRING_JOBQUEUE_TAG_COUNT];
  27. uint32 m_nMaxJobId[EDGEGEOMRING_JOBQUEUE_TAG_COUNT];
  28. uint m_nAtomicCollisionSpins;
  29. uint m_nRsxWaitSpins;
  30. uint m_nRingIncarnation;
  31. uint m_nUsedSpus;
  32. #if EDGEGEOMRING_DEBUG_TRACE
  33. uint m_nNextDebugTrace;
  34. #endif
  35. }
  36. ALIGN16_POST;
  37. struct ALIGN128 CEdgeGeomRing: public CEdgeGeomRing_Mutable
  38. {
  39. // immutable part
  40. uint m_eaLocalBaseAddress;
  41. uint m_nIoOffsetDelta;
  42. uint m_nIbvbRingLabel;
  43. uint32 * m_eaIbvbRingLabel;
  44. uint m_eaThis;
  45. uint m_nDebuggerBreakMask;
  46. #if EDGEGEOMRING_DEBUG_TRACE
  47. uint m_nUseCounter;
  48. EdgeGeomDebugTrace_t *m_eaDebugTrace;
  49. bool m_enableDebugTrace;
  50. #endif
  51. public:
  52. uintp Allocate( CellGcmContextData *pGcmCtx, uint nBytes, uint nTag );
  53. void Test();
  54. #ifndef SPU
  55. void Init( void* eaBuffer, uint nBufferSize, uint nIoOffsetDelta, void * eaLocalBaseAddress, uint nLabel );
  56. void Shutdown();
  57. #endif
  58. }
  59. ALIGN128_POST;
  60. enum EdgeGeomJobConstEnum_t
  61. {
  62. EDGEGEOMJOB_SCRATCH_SIZE = 64 * 1024
  63. };
  64. struct CEdgeGeomFeeder
  65. {
  66. uint m_nJobQueueTag; // the tag we're spawning jobs with, currently
  67. uint m_nSpawnedJobsWithTag; // number of jobs we spawned with the tag
  68. // max bytes that the jobs spawned with current tag can allocate;
  69. // must not exceed 1/8 of the full ring buffer size because there may be 4 full tag switches between setting label
  70. uint m_nSpawnedJobsWithTagReserveAllocate;
  71. uint m_nTotalEdgeGeomJobCounter;
  72. uint m_nIbvbRingSize;
  73. bool Tick( uint nReserve );
  74. #ifndef SPU
  75. void Init( uint nIbvbRingSize );
  76. #endif
  77. };
  78. inline bool CEdgeGeomFeeder::Tick( uint nReserve )
  79. {
  80. ++m_nTotalEdgeGeomJobCounter;
  81. ++m_nSpawnedJobsWithTag;
  82. m_nSpawnedJobsWithTagReserveAllocate += nReserve; // tentatively add the reserve to the same tag..
  83. //if( ++m_nSpawnedJobsWithTag > 6 )
  84. if( m_nSpawnedJobsWithTagReserveAllocate > m_nIbvbRingSize / 8 )
  85. {
  86. m_nJobQueueTag = ( m_nJobQueueTag + 1 ) & ( EDGEGEOMRING_JOBQUEUE_TAG_COUNT - 1 );
  87. m_nSpawnedJobsWithTag = 0;
  88. m_nSpawnedJobsWithTagReserveAllocate = nReserve;
  89. return true ;// !( m_nJobQueueTag & 1 ); // only insert labels in one tag, to make sure they insert in serial fashion
  90. }
  91. else
  92. {
  93. return false;
  94. }
  95. }
  96. namespace job_edgegeom
  97. {
  98. enum FlagEnum_t
  99. {
  100. FLAG_SWITCH_JOBQUEUE_TAG = 0x80,
  101. FLAG_SKIP_VERTEX_CACHE_INVALIDATE = 0x40000000
  102. };
  103. }
  104. #endif