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.

106 lines
3.3 KiB

  1. //========== Copyright � 2005, Valve Corporation, All rights reserved. ========
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef OCCLUSIONQUERY_H
  7. #define OCCLUSIONQUERY_H
  8. #include "tier1/utlsymbol.h"
  9. #include "tier1/utlrbtree.h"
  10. #ifndef MATSYS_INTERNAL
  11. #error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal"
  12. #endif
  13. #if defined( _WIN32 )
  14. #pragma once
  15. #endif
  16. #include "tier1/utllinkedlist.h"
  17. #include "shaderapi/ishaderapi.h"
  18. class IMatRenderContextInternal;
  19. // because the GPU/driver can buffer frames we need to allow several queries to be in flight.
  20. // The game wants to reiusse the queries every frame so we buffer them here to avoid
  21. // having to block waiting for a query to be available for reissue.
  22. #define COUNT_OCCLUSION_QUERY_STACK 4
  23. //-----------------------------------------------------------------------------
  24. // Dictionary of all known materials
  25. //-----------------------------------------------------------------------------
  26. class COcclusionQueryMgr
  27. {
  28. public:
  29. COcclusionQueryMgr();
  30. // Allocate and delete query objects.
  31. OcclusionQueryObjectHandle_t CreateOcclusionQueryObject( );
  32. void OnCreateOcclusionQueryObject( OcclusionQueryObjectHandle_t h );
  33. void DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t h );
  34. // Bracket drawing with begin and end so that we can get counts next frame.
  35. void BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t h );
  36. void EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t h );
  37. // Used to make the handle think it's never had a successful query before
  38. void ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t );
  39. // Get the number of pixels rendered between begin and end on an earlier frame.
  40. // Calling this in the same frame is a huge perf hit!
  41. int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t h, bool bDoQuery );
  42. void OcclusionQuery_IssueNumPixelsRenderedQuery( OcclusionQueryObjectHandle_t h );
  43. // Internal stuff for occlusion query
  44. void AllocOcclusionQueryObjects( void );
  45. void FreeOcclusionQueryObjects( void );
  46. // Advance frame
  47. void AdvanceFrame();
  48. private:
  49. //-----------------------------------------------------------------------------
  50. // Occlusion query objects
  51. //-----------------------------------------------------------------------------
  52. struct OcclusionQueryObject_t
  53. {
  54. ShaderAPIOcclusionQuery_t m_QueryHandle[COUNT_OCCLUSION_QUERY_STACK];
  55. int m_LastResult;
  56. int m_nFrameIssued;
  57. int m_nCurrentIssue;
  58. bool m_bHasBeenIssued[COUNT_OCCLUSION_QUERY_STACK];
  59. OcclusionQueryObject_t(void)
  60. {
  61. for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++ )
  62. {
  63. m_QueryHandle[i] = INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE;
  64. m_bHasBeenIssued[i] = false;
  65. }
  66. m_LastResult = -1;
  67. m_nFrameIssued = -1;
  68. m_nCurrentIssue = 0;
  69. }
  70. };
  71. // Flushes an outstanding query
  72. void FlushQuery( OcclusionQueryObjectHandle_t hOcclusionQuery, int nIndex );
  73. // Occlusion query objects
  74. CUtlFixedLinkedList<OcclusionQueryObject_t> m_OcclusionQueryObjects;
  75. CThreadFastMutex m_Mutex;
  76. int m_nFrameCount;
  77. };
  78. //-----------------------------------------------------------------------------
  79. // Singleton
  80. //-----------------------------------------------------------------------------
  81. extern COcclusionQueryMgr *g_pOcclusionQueryMgr;
  82. #endif // OCCLUSIONQUERY_H