summaryrefslogtreecommitdiff
path: root/materialsystem/occlusionquerymgr.h
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /materialsystem/occlusionquerymgr.h
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'materialsystem/occlusionquerymgr.h')
-rw-r--r--materialsystem/occlusionquerymgr.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/materialsystem/occlusionquerymgr.h b/materialsystem/occlusionquerymgr.h
new file mode 100644
index 0000000..2820e51
--- /dev/null
+++ b/materialsystem/occlusionquerymgr.h
@@ -0,0 +1,106 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================
+
+#ifndef OCCLUSIONQUERY_H
+#define OCCLUSIONQUERY_H
+
+#include "tier1/utlsymbol.h"
+#include "tier1/utlrbtree.h"
+
+#ifndef MATSYS_INTERNAL
+#error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal"
+#endif
+
+#if defined( _WIN32 )
+#pragma once
+#endif
+
+
+#include "tier1/utllinkedlist.h"
+#include "shaderapi/ishaderapi.h"
+
+
+class IMatRenderContextInternal;
+
+// because the GPU/driver can buffer frames we need to allow several queries to be in flight.
+// The game wants to reiusse the queries every frame so we buffer them here to avoid
+// having to block waiting for a query to be available for reissue.
+#define COUNT_OCCLUSION_QUERY_STACK 4
+
+//-----------------------------------------------------------------------------
+// Dictionary of all known materials
+//-----------------------------------------------------------------------------
+class COcclusionQueryMgr
+{
+public:
+ COcclusionQueryMgr();
+
+ // Allocate and delete query objects.
+ OcclusionQueryObjectHandle_t CreateOcclusionQueryObject( );
+ void OnCreateOcclusionQueryObject( OcclusionQueryObjectHandle_t h );
+ void DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t h );
+
+ // Bracket drawing with begin and end so that we can get counts next frame.
+ void BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t h );
+ void EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t h );
+
+ // Used to make the handle think it's never had a successful query before
+ void ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t );
+
+ // Get the number of pixels rendered between begin and end on an earlier frame.
+ // Calling this in the same frame is a huge perf hit!
+ int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t h, bool bDoQuery );
+ void OcclusionQuery_IssueNumPixelsRenderedQuery( OcclusionQueryObjectHandle_t h );
+
+ // Internal stuff for occlusion query
+ void AllocOcclusionQueryObjects( void );
+ void FreeOcclusionQueryObjects( void );
+
+ // Advance frame
+ void AdvanceFrame();
+
+private:
+ //-----------------------------------------------------------------------------
+ // Occlusion query objects
+ //-----------------------------------------------------------------------------
+ struct OcclusionQueryObject_t
+ {
+ ShaderAPIOcclusionQuery_t m_QueryHandle[COUNT_OCCLUSION_QUERY_STACK];
+ int m_LastResult;
+ int m_nFrameIssued;
+ int m_nCurrentIssue;
+ bool m_bHasBeenIssued[COUNT_OCCLUSION_QUERY_STACK];
+
+ OcclusionQueryObject_t(void)
+ {
+ for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++ )
+ {
+ m_QueryHandle[i] = INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE;
+ m_bHasBeenIssued[i] = false;
+ }
+ m_LastResult = -1;
+ m_nFrameIssued = -1;
+ m_nCurrentIssue = 0;
+ }
+ };
+
+ // Flushes an outstanding query
+ void FlushQuery( OcclusionQueryObjectHandle_t hOcclusionQuery, int nIndex );
+
+ // Occlusion query objects
+ CUtlFixedLinkedList<OcclusionQueryObject_t> m_OcclusionQueryObjects;
+ CThreadFastMutex m_Mutex;
+ int m_nFrameCount;
+};
+
+
+//-----------------------------------------------------------------------------
+// Singleton
+//-----------------------------------------------------------------------------
+extern COcclusionQueryMgr *g_pOcclusionQueryMgr;
+
+
+#endif // OCCLUSIONQUERY_H