Просмотр исходного кода

Extended GPU query creation so they accept a GPU index, in order to support creation on multiple GPUs in the future

BearishSun 9 лет назад
Родитель
Сommit
aaaf9d4c33
23 измененных файлов с 85 добавлено и 53 удалено
  1. 6 2
      Source/BansheeCore/Include/BsEventQuery.h
  2. 6 5
      Source/BansheeCore/Include/BsOcclusionQuery.h
  3. 15 8
      Source/BansheeCore/Include/BsQueryManager.h
  4. 6 2
      Source/BansheeCore/Include/BsTimerQuery.h
  5. 2 2
      Source/BansheeCore/Source/BsEventQuery.cpp
  6. 2 2
      Source/BansheeCore/Source/BsOcclusionQuery.cpp
  7. 2 2
      Source/BansheeCore/Source/BsTimerQuery.cpp
  8. 1 1
      Source/BansheeD3D11RenderAPI/Include/BsD3D11EventQuery.h
  9. 1 1
      Source/BansheeD3D11RenderAPI/Include/BsD3D11OcclusionQuery.h
  10. 3 3
      Source/BansheeD3D11RenderAPI/Include/BsD3D11QueryManager.h
  11. 1 1
      Source/BansheeD3D11RenderAPI/Include/BsD3D11TimerQuery.h
  12. 3 1
      Source/BansheeD3D11RenderAPI/Source/BsD3D11EventQuery.cpp
  13. 3 1
      Source/BansheeD3D11RenderAPI/Source/BsD3D11OcclusionQuery.cpp
  14. 7 6
      Source/BansheeD3D11RenderAPI/Source/BsD3D11QueryManager.cpp
  15. 3 1
      Source/BansheeD3D11RenderAPI/Source/BsD3D11TimerQuery.cpp
  16. 1 1
      Source/BansheeGLRenderAPI/Include/BsGLEventQuery.h
  17. 1 1
      Source/BansheeGLRenderAPI/Include/BsGLOcclusionQuery.h
  18. 3 3
      Source/BansheeGLRenderAPI/Include/BsGLQueryManager.h
  19. 1 1
      Source/BansheeGLRenderAPI/Include/BsGLTimerQuery.h
  20. 3 1
      Source/BansheeGLRenderAPI/Source/BsGLEventQuery.cpp
  21. 3 1
      Source/BansheeGLRenderAPI/Source/BsGLOcclusionQuery.cpp
  22. 9 6
      Source/BansheeGLRenderAPI/Source/BsGLQueryManager.cpp
  23. 3 1
      Source/BansheeGLRenderAPI/Source/BsGLTimerQuery.cpp

+ 6 - 2
Source/BansheeCore/Include/BsEventQuery.h

@@ -41,8 +41,12 @@ namespace BansheeEngine
 		/**	Triggered when GPU starts processing the query. */
 		Event<void()> onTriggered;
 
-		/**	Creates a new query, but does not schedule it on GPU. */
-		static SPtr<EventQuery> create();
+		/**	
+		 * Creates a new query, but does not schedule it on GPU. 
+		 * 
+		 * @param[in]	deviceIdx	Index of the GPU device to create the query on. 
+		 */
+		static SPtr<EventQuery> create(UINT32 deviceIdx = 0);
 
 	protected:
 		friend class QueryManager;

+ 6 - 5
Source/BansheeCore/Include/BsOcclusionQuery.h

@@ -53,12 +53,13 @@ namespace BansheeEngine
 		/**
 		 * Creates a new occlusion query. 
 		 *
-		 * @param[in] binary	If query is binary it will not give you an exact count of samples rendered, but will instead
-		 *						just return 0 (no samples were rendered) or 1 (one or more samples were rendered). Binary
-		 *						queries can return sooner as they potentially do not need to wait until all of the geometry
-		 *						is rendered.
+		 * @param[in] binary		If query is binary it will not give you an exact count of samples rendered, but will
+		 *							instead just return 0 (no samples were rendered) or 1 (one or more samples were 
+		 *							rendered). Binary queries can return sooner as they potentially do not need to wait
+		 *							until all of the geometry is rendered.
+		 * @param[in]	deviceIdx	Index of the GPU device to create the query on. 
 		 */
-		static SPtr<OcclusionQuery> create(bool binary);
+		static SPtr<OcclusionQuery> create(bool binary, UINT32 deviceIdx = 0);
 
 	protected:
 		friend class QueryManager;

+ 15 - 8
Source/BansheeCore/Include/BsQueryManager.h

@@ -23,24 +23,31 @@ namespace BansheeEngine
 		QueryManager();
 		~QueryManager();
 
-		/** Creates a new event query that allows you to get notified when GPU starts executing the query. */
-		virtual SPtr<EventQuery> createEventQuery() const = 0;
+		/** 
+		 * Creates a new event query that allows you to get notified when GPU starts executing the query.  
+		 *
+		 * @param[in]	deviceIdx	Index of the GPU device to create the query on. 
+		 */
+		virtual SPtr<EventQuery> createEventQuery(UINT32 deviceIdx = 0) const = 0;
 
 		/**
 		 * Creates a new timer query that allows you to get notified of how much time has passed between query start and end.
+		 * 
+		 * @param[in]	deviceIdx	Index of the GPU device to create the query on. 
 		 */
-		virtual SPtr<TimerQuery> createTimerQuery() const = 0;
+		virtual SPtr<TimerQuery> createTimerQuery(UINT32 deviceIdx = 0) const = 0;
 
 		/**
 		 * Creates a new occlusion query that allows you to know how many fragments were rendered between query start and 
 		 * end.
 		 *
-		 * @param[in] binary	If query is binary it will not give you an exact count of fragments rendered, but will 
-		 *						instead just return 0 (no fragments were rendered) or 1 (one or more fragments were 
-		 *						rendered). Binary queries can return sooner as they potentially do not need to wait until 
-		 *						all of the geometry is rendered.
+		 * @param[in]	binary		If query is binary it will not give you an exact count of fragments rendered, but will 
+		 *							instead just return 0 (no fragments were rendered) or 1 (one or more fragments were 
+		 *							rendered). Binary queries can return sooner as they potentially do not need to wait
+		 *							until all of the geometry is rendered.
+		 * @param[in]	deviceIdx	Index of the GPU device to create the query on. 
 		 */
-		virtual SPtr<OcclusionQuery> createOcclusionQuery(bool binary) const = 0;
+		virtual SPtr<OcclusionQuery> createOcclusionQuery(bool binary, UINT32 deviceIdx = 0) const = 0;
 
 		/** Triggers completed queries. Should be called every frame. */
 		void _update();

+ 6 - 2
Source/BansheeCore/Include/BsTimerQuery.h

@@ -46,8 +46,12 @@ namespace BansheeEngine
 		/** Triggered when GPU processes the query. As a parameter it provides query duration in milliseconds. */
 		Event<void(float)> onTriggered;
 
-		/**	Creates a new query, but does not schedule it on GPU. */
-		static SPtr<TimerQuery> create();
+		/**	
+		 * Creates a new query, but does not schedule it on GPU. 
+		 * 
+		 * @param[in]	deviceIdx	Index of the GPU device to create the query on. 
+		 */
+		static SPtr<TimerQuery> create(UINT32 deviceIdx = 0);
 
 	protected:
 		friend class QueryManager;

+ 2 - 2
Source/BansheeCore/Source/BsEventQuery.cpp

@@ -5,8 +5,8 @@
 
 namespace BansheeEngine
 {
-	SPtr<EventQuery> EventQuery::create()
+	SPtr<EventQuery> EventQuery::create(UINT32 deviceIdx)
 	{
-		return QueryManager::instance().createEventQuery();
+		return QueryManager::instance().createEventQuery(deviceIdx);
 	}
 }

+ 2 - 2
Source/BansheeCore/Source/BsOcclusionQuery.cpp

@@ -9,8 +9,8 @@ namespace BansheeEngine
 		:mActive(false), mBinary(binary)
 	{ }
 
-	SPtr<OcclusionQuery> OcclusionQuery::create(bool binary)
+	SPtr<OcclusionQuery> OcclusionQuery::create(bool binary, UINT32 deviceIdx)
 	{
-		return QueryManager::instance().createOcclusionQuery(binary);
+		return QueryManager::instance().createOcclusionQuery(binary, deviceIdx);
 	}
 }

+ 2 - 2
Source/BansheeCore/Source/BsTimerQuery.cpp

@@ -5,8 +5,8 @@
 
 namespace BansheeEngine
 {
-	SPtr<TimerQuery> TimerQuery::create()
+	SPtr<TimerQuery> TimerQuery::create(UINT32 deviceIdx)
 	{
-		return QueryManager::instance().createTimerQuery();
+		return QueryManager::instance().createTimerQuery(deviceIdx);
 	}
 }

+ 1 - 1
Source/BansheeD3D11RenderAPI/Include/BsD3D11EventQuery.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11EventQuery : public EventQuery
 	{
 	public:
-		D3D11EventQuery();
+		D3D11EventQuery(UINT32 deviceIdx);
 		~D3D11EventQuery();
 
 		/** @copydoc EventQuery::begin */

+ 1 - 1
Source/BansheeD3D11RenderAPI/Include/BsD3D11OcclusionQuery.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11OcclusionQuery : public OcclusionQuery
 	{
 	public:
-		D3D11OcclusionQuery(bool binary);
+		D3D11OcclusionQuery(bool binary, UINT32 deviceIdx);
 		~D3D11OcclusionQuery();
 
 		/** @copydoc OcclusionQuery::begin */

+ 3 - 3
Source/BansheeD3D11RenderAPI/Include/BsD3D11QueryManager.h

@@ -16,13 +16,13 @@ namespace BansheeEngine
 	{
 	public:
 		/** @copydoc QueryManager::createEventQuery */
-		SPtr<EventQuery> createEventQuery() const override;
+		SPtr<EventQuery> createEventQuery(UINT32 deviceIdx = 0) const override;
 
 		/** @copydoc QueryManager::createTimerQuery */
-		SPtr<TimerQuery> createTimerQuery() const override;
+		SPtr<TimerQuery> createTimerQuery(UINT32 deviceIdx = 0) const override;
 
 		/** @copydoc QueryManager::createOcclusionQuery */
-		SPtr<OcclusionQuery> createOcclusionQuery(bool binary) const override;
+		SPtr<OcclusionQuery> createOcclusionQuery(bool binary, UINT32 deviceIdx = 0) const override;
 	};
 
 	/** @} */

+ 1 - 1
Source/BansheeD3D11RenderAPI/Include/BsD3D11TimerQuery.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_D3D11_EXPORT D3D11TimerQuery : public TimerQuery
 	{
 	public:
-		D3D11TimerQuery();
+		D3D11TimerQuery(UINT32 deviceIdx);
 		~D3D11TimerQuery();
 
 		/** @copydoc TimerQuery::begin */

+ 3 - 1
Source/BansheeD3D11RenderAPI/Source/BsD3D11EventQuery.cpp

@@ -8,9 +8,11 @@
 
 namespace BansheeEngine
 {
-	D3D11EventQuery::D3D11EventQuery()
+	D3D11EventQuery::D3D11EventQuery(UINT32 deviceIdx)
 		:mQuery(nullptr)
 	{
+		assert(deviceIdx == 0 && "Multiple GPUs not supported natively on DirectX 11.");
+
 		D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPICore::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
 

+ 3 - 1
Source/BansheeD3D11RenderAPI/Source/BsD3D11OcclusionQuery.cpp

@@ -8,9 +8,11 @@
 
 namespace BansheeEngine
 {
-	D3D11OcclusionQuery::D3D11OcclusionQuery(bool binary)
+	D3D11OcclusionQuery::D3D11OcclusionQuery(bool binary, UINT32 deviceIdx)
 		:OcclusionQuery(binary), mContext(nullptr), mQuery(nullptr), mNumSamples(0), mFinalized(false), mQueryEndCalled(false)
 	{
+		assert(deviceIdx == 0 && "Multiple GPUs not supported natively on DirectX 11.");
+
 		D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPICore::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
 

+ 7 - 6
Source/BansheeD3D11RenderAPI/Source/BsD3D11QueryManager.cpp

@@ -7,25 +7,26 @@
 
 namespace BansheeEngine
 {
-	SPtr<EventQuery> D3D11QueryManager::createEventQuery() const
+	SPtr<EventQuery> D3D11QueryManager::createEventQuery(UINT32 deviceIdx) const
 	{
-		SPtr<EventQuery> query = SPtr<D3D11EventQuery>(bs_new<D3D11EventQuery>(), &QueryManager::deleteEventQuery, StdAlloc<D3D11EventQuery>());
+		SPtr<EventQuery> query = SPtr<D3D11EventQuery>(bs_new<D3D11EventQuery>(deviceIdx), &QueryManager::deleteEventQuery, StdAlloc<D3D11EventQuery>());
 		mEventQueries.push_back(query.get());
 
 		return query;
 	}
 
-	SPtr<TimerQuery> D3D11QueryManager::createTimerQuery() const
+	SPtr<TimerQuery> D3D11QueryManager::createTimerQuery(UINT32 deviceIdx) const
 	{
-		SPtr<TimerQuery> query = SPtr<D3D11TimerQuery>(bs_new<D3D11TimerQuery>(), &QueryManager::deleteTimerQuery, StdAlloc<D3D11TimerQuery>());
+		SPtr<TimerQuery> query = SPtr<D3D11TimerQuery>(bs_new<D3D11TimerQuery>(deviceIdx), &QueryManager::deleteTimerQuery, StdAlloc<D3D11TimerQuery>());
 		mTimerQueries.push_back(query.get());
 
 		return query;
 	}
 
-	SPtr<OcclusionQuery> D3D11QueryManager::createOcclusionQuery(bool binary) const
+	SPtr<OcclusionQuery> D3D11QueryManager::createOcclusionQuery(bool binary, UINT32 deviceIdx) const
 	{
-		SPtr<OcclusionQuery> query = SPtr<D3D11OcclusionQuery>(bs_new<D3D11OcclusionQuery>(binary), &QueryManager::deleteOcclusionQuery, StdAlloc<D3D11OcclusionQuery>());
+		SPtr<OcclusionQuery> query = SPtr<D3D11OcclusionQuery>(bs_new<D3D11OcclusionQuery>(binary, deviceIdx), 
+			&QueryManager::deleteOcclusionQuery, StdAlloc<D3D11OcclusionQuery>());
 		mOcclusionQueries.push_back(query.get());
 
 		return query;

+ 3 - 1
Source/BansheeD3D11RenderAPI/Source/BsD3D11TimerQuery.cpp

@@ -8,10 +8,12 @@
 
 namespace BansheeEngine
 {
-	D3D11TimerQuery::D3D11TimerQuery()
+	D3D11TimerQuery::D3D11TimerQuery(UINT32 deviceIdx)
 		:mFinalized(false), mContext(nullptr), mBeginQuery(nullptr), 
 		mEndQuery(nullptr), mDisjointQuery(nullptr), mTimeDelta(0.0f), mQueryEndCalled(false)
 	{
+		assert(deviceIdx == 0 && "Multiple GPUs not supported natively on DirectX 11.");
+
 		D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPICore::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
 

+ 1 - 1
Source/BansheeGLRenderAPI/Include/BsGLEventQuery.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_RSGL_EXPORT GLEventQuery : public EventQuery
 	{
 	public:
-		GLEventQuery();
+		GLEventQuery(UINT32 deviceIdx);
 		~GLEventQuery();
 
 		/** @copydoc EventQuery::begin */

+ 1 - 1
Source/BansheeGLRenderAPI/Include/BsGLOcclusionQuery.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_RSGL_EXPORT GLOcclusionQuery : public OcclusionQuery
 	{
 	public:
-		GLOcclusionQuery(bool binary);
+		GLOcclusionQuery(bool binary, UINT32 deviceIdx);
 		~GLOcclusionQuery();
 
 		/** @copydoc OcclusionQuery::begin */

+ 3 - 3
Source/BansheeGLRenderAPI/Include/BsGLQueryManager.h

@@ -16,13 +16,13 @@ namespace BansheeEngine
 	{
 	public:
 		/** @copydoc QueryManager::createEventQuery */
-		SPtr<EventQuery> createEventQuery() const override;
+		SPtr<EventQuery> createEventQuery(UINT32 deviceIdx = 0) const override;
 
 		/** @copydoc QueryManager::createTimerQuery */
-		SPtr<TimerQuery> createTimerQuery() const override;
+		SPtr<TimerQuery> createTimerQuery(UINT32 deviceIdx = 0) const override;
 
 		/** @copydoc QueryManager::createOcclusionQuery */
-		SPtr<OcclusionQuery> createOcclusionQuery(bool binary) const override;
+		SPtr<OcclusionQuery> createOcclusionQuery(bool binary, UINT32 deviceIdx = 0) const override;
 	};
 
 	/** @} */

+ 1 - 1
Source/BansheeGLRenderAPI/Include/BsGLTimerQuery.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_RSGL_EXPORT GLTimerQuery : public TimerQuery
 	{
 	public:
-		GLTimerQuery();
+		GLTimerQuery(UINT32 deviceIdx);
 		~GLTimerQuery();
 
 		/** @copydoc TimerQuery::begin */

+ 3 - 1
Source/BansheeGLRenderAPI/Source/BsGLEventQuery.cpp

@@ -5,9 +5,11 @@
 
 namespace BansheeEngine
 {
-	GLEventQuery::GLEventQuery()
+	GLEventQuery::GLEventQuery(UINT32 deviceIdx)
 		:mQueryObj(0)
 	{
+		assert(deviceIdx == 0 && "Multiple GPUs not supported natively on OpenGL.");
+
 		glGenQueries(1, &mQueryObj);
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Query);
 	}

+ 3 - 1
Source/BansheeGLRenderAPI/Source/BsGLOcclusionQuery.cpp

@@ -6,9 +6,11 @@
 
 namespace BansheeEngine
 {
-	GLOcclusionQuery::GLOcclusionQuery(bool binary)
+	GLOcclusionQuery::GLOcclusionQuery(bool binary, UINT32 deviceIdx)
 		:OcclusionQuery(binary), mQueryObj(0), mFinalized(false), mEndIssued(false), mNumSamples(0)
 	{
+		assert(deviceIdx == 0 && "Multiple GPUs not supported natively on OpenGL.");
+
 		glGenQueries(1, &mQueryObj);
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Query);
 	}

+ 9 - 6
Source/BansheeGLRenderAPI/Source/BsGLQueryManager.cpp

@@ -7,25 +7,28 @@
 
 namespace BansheeEngine
 {
-	SPtr<EventQuery> GLQueryManager::createEventQuery() const
+	SPtr<EventQuery> GLQueryManager::createEventQuery(UINT32 deviceIdx) const
 	{
-		SPtr<EventQuery> query = SPtr<GLEventQuery>(bs_new<GLEventQuery>(), &QueryManager::deleteEventQuery, StdAlloc<GLEventQuery>());
+		SPtr<EventQuery> query = SPtr<GLEventQuery>(bs_new<GLEventQuery>(deviceIdx), 
+			&QueryManager::deleteEventQuery, StdAlloc<GLEventQuery>());
 		mEventQueries.push_back(query.get());
 
 		return query;
 	}
 
-	SPtr<TimerQuery> GLQueryManager::createTimerQuery() const
+	SPtr<TimerQuery> GLQueryManager::createTimerQuery(UINT32 deviceIdx) const
 	{
-		SPtr<TimerQuery> query = SPtr<GLTimerQuery>(bs_new<GLTimerQuery>(), &QueryManager::deleteTimerQuery, StdAlloc<GLTimerQuery>());
+		SPtr<TimerQuery> query = SPtr<GLTimerQuery>(bs_new<GLTimerQuery>(deviceIdx), 
+			&QueryManager::deleteTimerQuery, StdAlloc<GLTimerQuery>());
 		mTimerQueries.push_back(query.get());
 
 		return query;
 	}
 
-	SPtr<OcclusionQuery> GLQueryManager::createOcclusionQuery(bool binary) const
+	SPtr<OcclusionQuery> GLQueryManager::createOcclusionQuery(bool binary, UINT32 deviceIdx) const
 	{
-		SPtr<OcclusionQuery> query = SPtr<GLOcclusionQuery>(bs_new<GLOcclusionQuery>(binary), &QueryManager::deleteOcclusionQuery, StdAlloc<GLOcclusionQuery>());
+		SPtr<OcclusionQuery> query = SPtr<GLOcclusionQuery>(bs_new<GLOcclusionQuery>(binary, deviceIdx), 
+			&QueryManager::deleteOcclusionQuery, StdAlloc<GLOcclusionQuery>());
 		mOcclusionQueries.push_back(query.get());
 
 		return query;

+ 3 - 1
Source/BansheeGLRenderAPI/Source/BsGLTimerQuery.cpp

@@ -6,9 +6,11 @@
 
 namespace BansheeEngine
 {
-	GLTimerQuery::GLTimerQuery()
+	GLTimerQuery::GLTimerQuery(UINT32 deviceIdx)
 		:mQueryStartObj(0), mQueryEndObj(0), mFinalized(false), mEndIssued(false), mTimeDelta(0.0f)
 	{
+		assert(deviceIdx == 0 && "Multiple GPUs not supported natively on OpenGL.");
+
 		GLuint queries[2];
 		glGenQueries(2, queries);