Browse Source

Removed beginFrame/endFrame methods from RenderAPI as they weren't really used
Profiling GPU queries now properly end before command buffer submission

BearishSun 9 years ago
parent
commit
d25432623f

+ 1 - 1
Source/BansheeCore/Include/BsProfilerCPU.h

@@ -411,7 +411,7 @@ namespace bs
 		CPUProfilerPreciseSamplingEntry mPreciseSamplingRootEntry;
 	};
 
-	/** Easier way to access ProfilerCPU. */
+	/** Provides global access to ProfilerCPU instance. */
 	BS_CORE_EXPORT ProfilerCPU& gProfilerCPU();
 
 	/** Shortcut for profiling a single function call. */

+ 3 - 0
Source/BansheeCore/Include/BsProfilerGPU.h

@@ -173,5 +173,8 @@ namespace bs
 		Mutex mMutex;
 	};
 
+	/** Provides global access to ProfilerGPU instance. */
+	BS_CORE_EXPORT ProfilerGPU& gProfilerGPU();
+
 	/** @} */
 }

+ 0 - 33
Source/BansheeCore/Include/BsRenderAPI.h

@@ -111,20 +111,6 @@ namespace bs
 		static void setRenderTarget(const SPtr<RenderTarget>& target, bool readOnlyDepthStencil = false, 
 			RenderSurfaceMask loadMask = RT_NONE);
 
-		/** 
-		 * @see RenderAPICore::beginFrame() 
-		 * 
-		 * @note This is an @ref asyncMethod "asynchronous method".
-		 */
-		static void beginRender();
-
-		/** 
-		 * @see RenderAPICore::endFrame() 
-		 * 
-		 * @note This is an @ref asyncMethod "asynchronous method".
-		 */
-		static void endRender();
-
 		/** 
 		 * @see RenderAPICore::clearRenderTarget() 
 		 * 
@@ -310,25 +296,6 @@ namespace bs
 		virtual void setComputePipeline(const SPtr<ComputePipelineStateCore>& pipelineState,
 			const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
 
-		/**
-		 * Signals that rendering for a specific viewport has started. Any draw calls need to be called between beginFrame()
-		 * and endFrame(). 
-		 * 
-		 * @param[in]	commandBuffer	Optional command buffer to queue the operation on. If not provided operation
-		 *								is executed immediately. Otherwise it is executed when executeCommands() is called.
-		 *								Buffer must support graphics operations.
-		 */
-		virtual void beginFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
-		
-		/** 
-		 * Ends that rendering to a specific viewport has ended. 
-		 *
-		 * @param[in]	commandBuffer	Optional command buffer to queue the operation on. If not provided operation
-		 *								is executed immediately. Otherwise it is executed when executeCommands() is called.
-		 *								Buffer must support graphics operations.
-		 */
-		virtual void endFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) = 0;
-
 		/**
 		 * Sets the active viewport that will be used for all render operations.
 		 *

+ 0 - 2
Source/BansheeCore/Source/BsCoreApplication.cpp

@@ -332,12 +332,10 @@ namespace bs
 	void CoreApplication::beginCoreProfiling()
 	{
 		gProfilerCPU().beginThread("Core");
-		ProfilerGPU::instance().beginFrame();
 	}
 
 	void CoreApplication::endCoreProfiling()
 	{
-		ProfilerGPU::instance().endFrame();
 		ProfilerGPU::instance()._update();
 
 		gProfilerCPU().endThread();

+ 5 - 0
Source/BansheeCore/Source/BsProfilerGPU.cpp

@@ -204,4 +204,9 @@ namespace bs
 
 		return OcclusionQuery::create(false);
 	}
+
+	ProfilerGPU& gProfilerGPU()
+	{
+		return ProfilerGPU::instance();
+	}
 }

+ 0 - 10
Source/BansheeCore/Source/BsRenderAPI.cpp

@@ -91,16 +91,6 @@ namespace bs
 			RenderAPICore::instancePtr(), target->getCore(), readOnlyDepthStencil, loadMask, nullptr));
 	}
 
-	void RenderAPI::beginRender()
-	{
-		gCoreThread().queueCommand(std::bind(&RenderAPICore::beginFrame, RenderAPICore::instancePtr(), nullptr));
-	}
-
-	void RenderAPI::endRender()
-	{
-		gCoreThread().queueCommand(std::bind(&RenderAPICore::endFrame, RenderAPICore::instancePtr(), nullptr));
-	}
-
 	void RenderAPI::clearRenderTarget(UINT32 buffers, const Color& color, float depth, 
 		UINT16 stencil, UINT8 targetMask)
 	{

+ 0 - 6
Source/BansheeD3D11RenderAPI/Include/BsD3D11RenderAPI.h

@@ -36,12 +36,6 @@ namespace bs
 		void setGpuParams(const SPtr<GpuParamsCore>& gpuParams, 
 			const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
 
-		/** @copydoc RenderAPICore::beginFrame */
-		void beginFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
-
-		/** @copydoc RenderAPICore::endFrame */
-		void endFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
-
 		/** @copydoc RenderAPICore::clearRenderTarget */
 		void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, 
 			UINT8 targetMask = 0xFF, const SPtr<CommandBuffer>& commandBuffer = nullptr) override;

+ 0 - 10
Source/BansheeD3D11RenderAPI/Source/BsD3D11RenderAPI.cpp

@@ -598,16 +598,6 @@ namespace bs
 		BS_INC_RENDER_STAT(NumGpuParamBinds);
 	}
 
-	void D3D11RenderAPI::beginFrame(const SPtr<CommandBuffer>& commandBuffer)
-	{
-		// Not used
-	}
-
-	void D3D11RenderAPI::endFrame(const SPtr<CommandBuffer>& commandBuffer)
-	{
-		// Not used
-	}
-
 	void D3D11RenderAPI::setViewport(const Rect2& vp, const SPtr<CommandBuffer>& commandBuffer)
 	{
 		auto executeRef = [&](const Rect2& vp)

+ 0 - 2
Source/BansheeEditor/Source/BsScenePicking.cpp

@@ -286,7 +286,6 @@ namespace bs
 		
 		mPickingTexture = RenderTextureCore::create(pickingMRT);
 
-		rs.beginFrame();
 		rs.setRenderTarget(mPickingTexture);
 		rs.setViewport(viewportArea);
 		rs.clearRenderTarget(FBT_COLOR | FBT_DEPTH | FBT_STENCIL, Color::White);
@@ -382,7 +381,6 @@ namespace bs
 		const RenderTargetProperties& rtProps = target->getProperties();
 		RenderAPICore& rs = RenderAPICore::instance();
 
-		rs.endFrame();
 		rs.setRenderTarget(nullptr);
 
 		if (rtProps.isWindow())

+ 1 - 6
Source/BansheeGLRenderAPI/Include/BsGLRenderAPI.h

@@ -39,12 +39,6 @@ namespace bs
 		void setGpuParams(const SPtr<GpuParamsCore>& gpuParams,
 			const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
 
-		/** @copydoc RenderAPICore::beginFrame() */
-		void beginFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
-
-		/** @copydoc RenderAPICore::endFrame() */
-		void endFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
-
 		/** @copydoc RenderAPICore::setViewport() */
 		void setViewport(const Rect2& area, const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
 
@@ -375,6 +369,7 @@ namespace bs
 		Rect2 mViewportNorm;
 		UINT32 mScissorTop, mScissorBottom, mScissorLeft, mScissorRight;
 		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
+		bool mScissorEnabled;
 
 		UINT32 mStencilReadMask;
 		UINT32 mStencilWriteMask;

+ 8 - 39
Source/BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -42,6 +42,7 @@ namespace bs
 		: mViewportNorm(0.0f, 0.0f, 1.0f, 1.0f)
 		, mScissorTop(0), mScissorBottom(720), mScissorLeft(0), mScissorRight(1280)
 		, mViewportLeft(0), mViewportTop(0), mViewportWidth(0), mViewportHeight(0)
+		, mScissorEnabled(false)
 		, mStencilReadMask(0xFFFFFFFF)
 		, mStencilWriteMask(0xFFFFFFFF)
 		, mStencilRefValue(0)
@@ -788,44 +789,6 @@ namespace bs
 		BS_INC_RENDER_STAT(NumRenderTargetChanges);
 	}
 
-	void GLRenderAPI::beginFrame(const SPtr<CommandBuffer>& commandBuffer)
-	{
-		auto execute = [=]()
-		{
-			THROW_IF_NOT_CORE_THREAD;
-
-			// Activate the viewport clipping
-			glEnable(GL_SCISSOR_TEST);
-		};
-
-		if (commandBuffer == nullptr)
-			execute();
-		else
-		{
-			SPtr<GLCommandBuffer> cb = std::static_pointer_cast<GLCommandBuffer>(commandBuffer);
-			cb->queueCommand(execute);
-		}
-	}
-
-	void GLRenderAPI::endFrame(const SPtr<CommandBuffer>& commandBuffer)
-	{
-		auto execute = [=]()
-		{
-			THROW_IF_NOT_CORE_THREAD;
-
-			// Deactivate the viewport clipping.
-			glDisable(GL_SCISSOR_TEST);
-		};
-
-		if (commandBuffer == nullptr)
-			execute();
-		else
-		{
-			SPtr<GLCommandBuffer> cb = std::static_pointer_cast<GLCommandBuffer>(commandBuffer);
-			cb->queueCommand(execute);
-		}
-	}
-
 	void GLRenderAPI::setVertexBuffers(UINT32 index, SPtr<VertexBufferCore>* buffers, UINT32 numBuffers, 
 		const SPtr<CommandBuffer>& commandBuffer)
 	{
@@ -1500,6 +1463,8 @@ namespace bs
 
 			glScissor(x, y, w, h);
 		}
+
+		mScissorEnabled = enable;
 	}
 
 	void GLRenderAPI::setMultisamplingEnable(bool enable)
@@ -2251,7 +2216,11 @@ namespace bs
 		glViewport(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
 
 		// Configure the viewport clipping
-		glScissor(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
+		if (!mScissorEnabled)
+		{
+			glEnable(GL_SCISSOR_TEST);
+			glScissor(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);
+		}
 	}
 
 	/************************************************************************/

+ 0 - 6
Source/BansheeVulkanRenderAPI/Include/BsVulkanRenderAPI.h

@@ -36,12 +36,6 @@ namespace bs
 		void setGpuParams(const SPtr<GpuParamsCore>& gpuParams, 
 			const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
 
-		/** @copydoc RenderAPICore::beginFrame */
-		void beginFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
-
-		/** @copydoc RenderAPICore::endFrame */
-		void endFrame(const SPtr<CommandBuffer>& commandBuffer = nullptr) override;
-
 		/** @copydoc RenderAPICore::clearRenderTarget */
 		void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, 
 			UINT8 targetMask = 0xFF, const SPtr<CommandBuffer>& commandBuffer = nullptr) override;

+ 3 - 0
Source/BansheeVulkanRenderAPI/Source/BsVulkanCommandBufferManager.cpp

@@ -89,6 +89,9 @@ namespace bs
 
 	void VulkanTransferBuffer::flush(bool wait)
 	{
+		if (mCB == nullptr)
+			return;
+
 		UINT32 syncMask = mSyncMask & ~mQueueMask; // Don't sync with itself
 
 		mCB->end();

+ 0 - 10
Source/BansheeVulkanRenderAPI/Source/BsVulkanRenderAPI.cpp

@@ -355,16 +355,6 @@ namespace bs
 		BS_INC_RENDER_STAT(NumGpuParamBinds);
 	}
 
-	void VulkanRenderAPI::beginFrame(const SPtr<CommandBuffer>& commandBuffer)
-	{
-		// Do nothing
-	}
-
-	void VulkanRenderAPI::endFrame(const SPtr<CommandBuffer>& commandBuffer)
-	{
-		// Do nothing
-	}
-
 	void VulkanRenderAPI::setViewport(const Rect2& vp, const SPtr<CommandBuffer>& commandBuffer)
 	{
 		VulkanCommandBuffer* cb = getCB(commandBuffer);

+ 8 - 5
Source/RenderBeast/Source/BsRenderBeast.cpp

@@ -14,6 +14,7 @@
 #include "BsCoreThread.h"
 #include "BsGpuParams.h"
 #include "BsProfilerCPU.h"
+#include "BsProfilerGPU.h"
 #include "BsShader.h"
 #include "BsGpuParamBlockBuffer.h"
 #include "BsTime.h"
@@ -560,6 +561,7 @@ namespace bs
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
+		gProfilerGPU().beginFrame();
 		gProfilerCPU().beginSample("renderAllCore");
 
 		// Note: I'm iterating over all sampler states every frame. If this ends up being a performance
@@ -605,8 +607,6 @@ namespace bs
 			SPtr<RenderTargetCore> target = rtInfo.target;
 			Vector<const CameraCore*>& cameras = rtInfo.cameras;
 
-			RenderAPICore::instance().beginFrame();
-
 			UINT32 numCameras = (UINT32)cameras.size();
 			for (UINT32 i = 0; i < numCameras; i++)
 			{
@@ -616,11 +616,14 @@ namespace bs
 				else
 					renderOverlay(frameInfo, rtInfo, i);
 			}
-
-			RenderAPICore::instance().endFrame();
-			RenderAPICore::instance().swapBuffers(target);
 		}
 
+		gProfilerGPU().endFrame();
+
+		// Present render targets with back buffers
+		for (auto& rtInfo : mRenderTargets)
+			RenderAPICore::instance().swapBuffers(rtInfo.target);
+
 		gProfilerCPU().endSample("renderAllCore");
 	}