Kaynağa Gözat

Refactored param blocks so there is much less redundant work done during individual param block initialization, as well as memory used per param block

BearishSun 9 yıl önce
ebeveyn
işleme
1671597ec8

+ 11 - 6
Documentation/Manuals/Native/renderer.md

@@ -219,10 +219,10 @@ viewDirParam.set(Vector3(0.707.0, 0.707f, 0.0f));
 ... repeat for all other parameters
 ... repeat for all other parameters
 ~~~~~~~~~~~~~
 ~~~~~~~~~~~~~
 
 
-It is more efficient to assign them as a parameter block. Primarily because parameter blocks can be set once, and then shared between multiple materials. To set up a parameter block use the @ref BS_PARAM_BLOCK_BEGIN, @ref BS_PARAM_BLOCK_ENTRY and @ref BS_PARAM_BLOCK_END macros, like so:
+It is more efficient to assign them as a parameter block. Primarily because parameter blocks can be set once, and then shared between multiple materials. To set up a parameter block you must first set up its definition by using @ref BS_PARAM_BLOCK_BEGIN, @ref BS_PARAM_BLOCK_ENTRY and @ref BS_PARAM_BLOCK_END macros, like so:
 
 
 ~~~~~~~~~~~~~{.cpp}
 ~~~~~~~~~~~~~{.cpp}
-BS_PARAM_BLOCK_BEGIN(PerCameraParamBlock)
+BS_PARAM_BLOCK_BEGIN(PerCameraParamBlockDef)
 	BS_PARAM_BLOCK_ENTRY(Vector3, gViewDir)
 	BS_PARAM_BLOCK_ENTRY(Vector3, gViewDir)
 	BS_PARAM_BLOCK_ENTRY(Vector3, gViewOrigin)
 	BS_PARAM_BLOCK_ENTRY(Vector3, gViewOrigin)
 	BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 	BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
@@ -235,14 +235,19 @@ BS_PARAM_BLOCK_END
 
 
 By using this approach you lose all the error checking normally performed by @ref bs::Material "Material". You must make sure that the layout in C++ matches the layout in the GPU program. In case of GLSL you must also specify `layout(std140)` keyword to ensure its layout is compatible with C++ struct layout. You must also make sure that variable names match the names in the GPU program.
 By using this approach you lose all the error checking normally performed by @ref bs::Material "Material". You must make sure that the layout in C++ matches the layout in the GPU program. In case of GLSL you must also specify `layout(std140)` keyword to ensure its layout is compatible with C++ struct layout. You must also make sure that variable names match the names in the GPU program.
 
 
-Once your parameter block is created, you can instantiate it, assign values to it, and assign the blocks to materials, like so:
+Once your parameter block definition is created, you can instantiate a parameter block buffer, assign values to it, and assign the blocks to materials, like so:
 ~~~~~~~~~~~~~{.cpp}
 ~~~~~~~~~~~~~{.cpp}
-PerCameraParamBlock block; // Instantiate block, normally you'd want to store this
-block.gViewDir.set(Vector3(0.707.0, 0.707f, 0.0f));
+PerCameraParamBlockDef def; // Normally you want to make this global
+
+// Instantiates a new parameter block from the definition
+SPtr<GpuParamBlockBufferCore> paramBlock = def.createBuffer(); 
+
+// Assign a value to the gViewDir parameter of the parameter block
+def.gViewDir.set(paramBlock, Vector3(0.707.0, 0.707f, 0.0f));
 ... set other parameters in block ...
 ... set other parameters in block ...
 
 
 SPtr<MaterialCore> material = ...;
 SPtr<MaterialCore> material = ...;
-material->setParamBlockBuffer("PerCamera", block.getBuffer());
+material->setParamBlockBuffer("PerCamera", paramBlock);
 
 
 ... render using the material ...
 ... render using the material ...
 ~~~~~~~~~~~~~
 ~~~~~~~~~~~~~

+ 1 - 0
Source/BansheeCore/CMakeSources.cmake

@@ -341,6 +341,7 @@ set(BS_BANSHEECORE_SRC_RENDERER
 	"Source/BsRendererManager.cpp"
 	"Source/BsRendererManager.cpp"
 	"Source/BsCoreRenderer.cpp"
 	"Source/BsCoreRenderer.cpp"
 	"Source/BsRendererMeshData.cpp"
 	"Source/BsRendererMeshData.cpp"
+	"Source/BsParamBlocks.cpp"
 	"Source/BsCamera.cpp"
 	"Source/BsCamera.cpp"
 	"Source/BsPostProcessSettings.cpp"
 	"Source/BsPostProcessSettings.cpp"
 )
 )

+ 71 - 42
Source/BansheeCore/Include/BsParamBlocks.h

@@ -5,7 +5,6 @@
 #include "BsCorePrerequisites.h"
 #include "BsCorePrerequisites.h"
 #include "BsGpuParamDesc.h"
 #include "BsGpuParamDesc.h"
 #include "BsGpuParams.h"
 #include "BsGpuParams.h"
-#include "BsGpuPipelineParamInfo.h"
 #include "BsRenderAPI.h"
 #include "BsRenderAPI.h"
 #include "BsGpuParamBlockBuffer.h"
 #include "BsGpuParamBlockBuffer.h"
 
 
@@ -15,8 +14,55 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-// Note: Every time one of these param blocks is instantiated we generate its descriptor. It would be better to generate
-// it once, and then just quickly instantiate for subsequent creations.
+	/** Wrapper for a single parameter in a parameter block buffer. */
+	template<class T>
+	class BS_CORE_EXPORT ParamBlockParam
+	{
+	public:
+		ParamBlockParam() { }
+		ParamBlockParam(const GpuParamDataDesc& paramDesc);
+
+		/** 
+		 * Sets the parameter in the provided parameter block buffer. Caller is responsible for ensuring the param block
+		 * buffer contains this parameter. 
+		 */
+		void set(const SPtr<GpuParamBlockBufferCore>& paramBlock, const T& value, UINT32 arrayIdx = 0) const;
+
+		/** 
+		 * Gets the parameter in the provided parameter block buffer. Caller is responsible for ensuring the param block
+		 * buffer contains this parameter. 
+		 */
+		T get(const SPtr<GpuParamBlockBufferCore>& paramBlock, UINT32 arrayIdx = 0) const;
+
+	protected:
+		GpuParamDataDesc mParamDesc;
+	};
+
+	/** Base class for all parameter blocks. */
+	struct BS_CORE_EXPORT ParamBlock
+	{
+		virtual ~ParamBlock();
+		virtual void initialize() = 0;
+	};
+
+	/** 
+	 * Takes care of initializing param block definitions in a delayed manner since they depend on engine systems yet
+	 * are usually used as global variables which are initialized before engine systems are ready. 
+	 */
+	class BS_CORE_EXPORT ParamBlockManager : public Module<ParamBlockManager>
+	{
+	public:
+		ParamBlockManager();
+
+		/** Registers a new param block, and initializes it when ready. */
+		static void registerBlock(ParamBlock* paramBlock);
+
+		/** Removes the param block from the initialization list. */
+		static void unregisterBlock(ParamBlock* paramBlock);
+
+	private:
+		static Vector<ParamBlock*> sToInitialize;
+	};
 
 
 /**
 /**
  * Starts a new custom parameter block. Custom parameter blocks allow you to create C++ structures that map directly
  * Starts a new custom parameter block. Custom parameter blocks allow you to create C++ structures that map directly
@@ -24,49 +70,32 @@ namespace bs
  * BS_PARAM_BLOCK_END.
  * BS_PARAM_BLOCK_END.
  */
  */
 #define BS_PARAM_BLOCK_BEGIN(Name)																							\
 #define BS_PARAM_BLOCK_BEGIN(Name)																							\
-	struct Name																												\
+	struct Name	: ParamBlock																								\
 	{																														\
 	{																														\
 		Name()																												\
 		Name()																												\
 		{																													\
 		{																													\
-			static SPtr<GpuPipelineParamInfoCore> paramInfo = nullptr;														\
-			static GpuParamBlockDesc blockDesc;																				\
-																															\
-			if (paramInfo == nullptr)																						\
-			{																												\
-				Vector<GpuParamDataDesc> params = getEntries();																\
-				RenderAPICore& rapi = RenderAPICore::instance();															\
+			ParamBlockManager::registerBlock(this);																			\
+		}																													\
 																															\
 																															\
-				blockDesc = rapi.generateParamBlockDesc(#Name, params);														\
+		SPtr<GpuParamBlockBufferCore> createBuffer() const { return GpuParamBlockBufferCore::create(mBlockSize); }			\
 																															\
 																															\
-				SPtr<GpuParamDesc> paramsDesc = bs_shared_ptr_new<GpuParamDesc>();											\
-				paramsDesc->paramBlocks[#Name] = blockDesc;																	\
-				for (auto& param : params)																					\
-					paramsDesc->params[param.name] = param;																	\
+	private:																												\
+		friend class ParamBlockManager;																						\
 																															\
 																															\
-				GPU_PIPELINE_PARAMS_DESC pipelineParamDesc;																	\
-				pipelineParamDesc.vertexParams = paramsDesc;																\
-				paramInfo = GpuPipelineParamInfoCore::create(pipelineParamDesc);											\
-			}																												\
+		void initialize() override																							\
+		{																													\
+			mParams = getEntries();																							\
+			RenderAPICore& rapi = RenderAPICore::instance();																\
 																															\
 																															\
-			mParams = GpuParamsCore::create(paramInfo);																		\
+			GpuParamBlockDesc blockDesc = rapi.generateParamBlockDesc(#Name, mParams);										\
+			mBlockSize = blockDesc.blockSize * sizeof(UINT32);																\
 																															\
 																															\
-			mBuffer = GpuParamBlockBufferCore::create(blockDesc.blockSize * sizeof(UINT32));								\
-			mParams->setParamBlockBuffer(GPT_VERTEX_PROGRAM, #Name, mBuffer);												\
 			initEntries();																									\
 			initEntries();																									\
 		}																													\
 		}																													\
 																															\
 																															\
-		const SPtr<GpuParamBlockBufferCore>& getBuffer() const { return mBuffer; }											\
-		void setBuffer(const SPtr<GpuParamBlockBufferCore>& buffer)															\
-		{																													\
-				mBuffer = buffer;																							\
-				mParams->setParamBlockBuffer(GPT_VERTEX_PROGRAM, #Name, mBuffer);											\
-		}																													\
-		void flushToGPU(UINT32 queueIdx = 0) { mBuffer->flushToGPU(queueIdx); }												\
-																															\
-	private:																												\
 		struct META_FirstEntry {};																							\
 		struct META_FirstEntry {};																							\
 		static void META_GetPrevEntries(Vector<GpuParamDataDesc>& params, META_FirstEntry id) { }							\
 		static void META_GetPrevEntries(Vector<GpuParamDataDesc>& params, META_FirstEntry id) { }							\
-		void META_InitPrevEntry(const SPtr<GpuParamsCore>& params, META_FirstEntry id) { }									\
+		void META_InitPrevEntry(const Vector<GpuParamDataDesc>& params, UINT32 idx, META_FirstEntry id) { }					\
 																															\
 																															\
 		typedef META_FirstEntry 
 		typedef META_FirstEntry 
 
 
@@ -88,20 +117,20 @@ namespace bs
 			newEntry.arraySize = NumElements;																				\
 			newEntry.arraySize = NumElements;																				\
 		}																													\
 		}																													\
 																															\
 																															\
-		void META_InitPrevEntry(const SPtr<GpuParamsCore>& params, META_NextEntry_##Name id)								\
+		void META_InitPrevEntry(const Vector<GpuParamDataDesc>& params, UINT32 idx, META_NextEntry_##Name id)				\
 		{																													\
 		{																													\
-			META_InitPrevEntry(params, META_Entry_##Name());																\
-			params->getParam(GPT_VERTEX_PROGRAM, #Name, Name);																\
+			META_InitPrevEntry(params, idx - 1, META_Entry_##Name());														\
+			Name = ParamBlockParam<Type>(params[idx]);																		\
 		}																													\
 		}																													\
 																															\
 																															\
 	public:																													\
 	public:																													\
-		TGpuDataParam<Type, true> Name;																						\
+		ParamBlockParam<Type> Name;																							\
 																															\
 																															\
 	private:																												\
 	private:																												\
 		typedef META_NextEntry_##Name
 		typedef META_NextEntry_##Name
 
 
-/** 
- * Registers a new entry in a parameter block. Must be called in between BS_PARAM_BLOCK_BEGIN and BS_PARAM_BLOCK_END calls. 
+/**
+ * Registers a new entry in a parameter block. Must be called in between BS_PARAM_BLOCK_BEGIN and BS_PARAM_BLOCK_END calls.
  */
  */
 #define BS_PARAM_BLOCK_ENTRY(Type, Name) BS_PARAM_BLOCK_ENTRY_ARRAY(Type, Name, 1)
 #define BS_PARAM_BLOCK_ENTRY(Type, Name) BS_PARAM_BLOCK_ENTRY_ARRAY(Type, Name, 1)
 
 
@@ -118,11 +147,11 @@ namespace bs
 																															\
 																															\
 		void initEntries()																									\
 		void initEntries()																									\
 		{																													\
 		{																													\
-			META_InitPrevEntry(mParams, META_LastEntry());																	\
+			META_InitPrevEntry(mParams, (UINT32)mParams.size() - 1, META_LastEntry());										\
 		}																													\
 		}																													\
 																															\
 																															\
-		SPtr<GpuParamsCore> mParams;																						\
-		SPtr<GpuParamBlockBufferCore> mBuffer;																				\
+		Vector<GpuParamDataDesc> mParams;																					\
+		UINT32 mBlockSize;																									\
 	};
 	};
 
 
 	/** @} */
 	/** @} */

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

@@ -48,6 +48,7 @@
 #include "BsAudioManager.h"
 #include "BsAudioManager.h"
 #include "BsAudio.h"
 #include "BsAudio.h"
 #include "BsAnimationManager.h"
 #include "BsAnimationManager.h"
+#include "BsParamBlocks.h"
 
 
 namespace bs
 namespace bs
 {
 {
@@ -71,6 +72,7 @@ namespace bs
 		
 		
 		Input::shutDown();
 		Input::shutDown();
 
 
+		ParamBlockManager::shutDown();
 		StringTableManager::shutDown();
 		StringTableManager::shutDown();
 		Resources::shutDown();
 		Resources::shutDown();
 		ResourceListenerManager::shutDown();
 		ResourceListenerManager::shutDown();
@@ -146,6 +148,7 @@ namespace bs
 
 
 		mPrimaryWindow = RenderAPIManager::instance().initialize(mStartUpDesc.renderAPI, mStartUpDesc.primaryWindowDesc);
 		mPrimaryWindow = RenderAPIManager::instance().initialize(mStartUpDesc.renderAPI, mStartUpDesc.primaryWindowDesc);
 
 
+		ParamBlockManager::startUp();
 		Input::startUp();
 		Input::startUp();
 		RendererManager::startUp();
 		RendererManager::startUp();
 
 

+ 121 - 0
Source/BansheeCore/Source/BsParamBlocks.cpp

@@ -0,0 +1,121 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsParamBlocks.h"
+#include "BsGpuParam.h"
+
+namespace bs
+{
+	template<class T>
+	ParamBlockParam<T>::ParamBlockParam(const GpuParamDataDesc& paramDesc)
+		:mParamDesc(paramDesc)
+	{ }
+
+	template<class T>
+	void ParamBlockParam<T>::set(const SPtr<GpuParamBlockBufferCore>& paramBlock, const T& value, UINT32 arrayIdx) const
+	{
+#if BS_DEBUG_MODE
+		if (arrayIdx >= mParamDesc.arraySize)
+		{
+			BS_EXCEPT(InvalidParametersException, "Array index out of range. Array size: " +
+					  toString(mParamDesc.arraySize) + ". Requested size: " + toString(arrayIdx));
+		}
+#endif
+
+		UINT32 elementSizeBytes = mParamDesc.elementSize * sizeof(UINT32);
+		UINT32 sizeBytes = std::min(elementSizeBytes, (UINT32)sizeof(T)); // Truncate if it doesn't fit within parameter size
+
+		bool transposeMatrices = RenderAPICore::instance().getAPIInfo().getGpuProgramHasColumnMajorMatrices();
+		if (TransposePolicy<T>::transposeEnabled(transposeMatrices))
+		{
+			T transposed = TransposePolicy<T>::transpose(value);
+			paramBlock->write((mParamDesc.cpuMemOffset + arrayIdx * mParamDesc.arrayElementStride) * sizeof(UINT32), 
+				&transposed, sizeBytes);
+		}
+		else
+			paramBlock->write((mParamDesc.cpuMemOffset + arrayIdx * mParamDesc.arrayElementStride) * sizeof(UINT32), 
+				&value, sizeBytes);
+
+		// Set unused bytes to 0
+		if (sizeBytes < elementSizeBytes)
+		{
+			UINT32 diffSize = elementSizeBytes - sizeBytes;
+			paramBlock->zeroOut((mParamDesc.cpuMemOffset + arrayIdx * mParamDesc.arrayElementStride) * sizeof(UINT32) + 
+				sizeBytes, diffSize);
+		}
+	}
+
+	template<class T>
+	T ParamBlockParam<T>::get(const SPtr<GpuParamBlockBufferCore>& paramBlock, UINT32 arrayIdx) const
+	{
+#if BS_DEBUG_MODE
+		if (arrayIdx >= mParamDesc.arraySize)
+		{
+			LOGERR("Array index out of range. Array size: " + toString(mParamDesc.arraySize) + ". Requested size: " + 
+				toString(arrayIdx));
+			return T();
+		}
+#endif
+
+		UINT32 elementSizeBytes = mParamDesc.elementSize * sizeof(UINT32);
+		UINT32 sizeBytes = std::min(elementSizeBytes, (UINT32)sizeof(T));
+
+		T value;
+		paramBlock->read((mParamDesc.cpuMemOffset + arrayIdx * mParamDesc.arrayElementStride) * sizeof(UINT32), &value, 
+			sizeBytes);
+
+		bool transposeMatrices = RenderAPICore::instance().getAPIInfo().getGpuProgramHasColumnMajorMatrices();
+		if (TransposePolicy<T>::transposeEnabled(transposeMatrices))
+			return TransposePolicy<T>::transpose(value);
+		else
+			return value;
+	}
+
+	template class ParamBlockParam<float>;
+	template class ParamBlockParam<int>;
+	template class ParamBlockParam<Color>;
+	template class ParamBlockParam<Vector2>;
+	template class ParamBlockParam<Vector3>;
+	template class ParamBlockParam<Vector4>;
+	template class ParamBlockParam<Vector2I>;
+	template class ParamBlockParam<Vector3I>;
+	template class ParamBlockParam<Vector4I>;
+	template class ParamBlockParam<Matrix2>;
+	template class ParamBlockParam<Matrix2x3>;
+	template class ParamBlockParam<Matrix2x4>;
+	template class ParamBlockParam<Matrix3>;
+	template class ParamBlockParam<Matrix3x2>;
+	template class ParamBlockParam<Matrix3x4>;
+	template class ParamBlockParam<Matrix4>;
+	template class ParamBlockParam<Matrix4x2>;
+	template class ParamBlockParam<Matrix4x3>;
+
+	ParamBlock::~ParamBlock()
+	{
+		ParamBlockManager::unregisterBlock(this);
+	}
+
+	Vector<ParamBlock*> ParamBlockManager::sToInitialize;
+
+	ParamBlockManager::ParamBlockManager()
+	{
+		for (auto& entry : sToInitialize)
+			entry->initialize();
+
+		sToInitialize.clear();
+	}
+
+	void ParamBlockManager::registerBlock(ParamBlock* paramBlock)
+	{
+		if (isStarted())
+			paramBlock->initialize();
+		else
+			sToInitialize.push_back(paramBlock);
+	}
+
+	void ParamBlockManager::unregisterBlock(ParamBlock* paramBlock)
+	{
+		auto iterFind = std::find(sToInitialize.begin(), sToInitialize.end(), paramBlock);
+		if (iterFind != sToInitialize.end())
+			sToInitialize.erase(iterFind);
+	}
+}

+ 10 - 6
Source/BansheeEditor/Include/BsGizmoManager.h

@@ -502,16 +502,20 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-	BS_PARAM_BLOCK_BEGIN(GizmoParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(GizmoParamBlockDef)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gViewDir)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gViewDir)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
-	BS_PARAM_BLOCK_BEGIN(GizmoPickingParamBuffer)
+	extern GizmoParamBlockDef gHandleParamBlockDef;
+
+	BS_PARAM_BLOCK_BEGIN(GizmoPickingParamBlockDef)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(float, gAlphaCutoff)
 		BS_PARAM_BLOCK_ENTRY(float, gAlphaCutoff)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern GizmoPickingParamBlockDef gGizmoPickingParamBlockDef;
+
 	/**
 	/**
 	 * Core thread version of the gizmo manager that handles most of the rendering of meshes provided by the gizmo manager.
 	 * Core thread version of the gizmo manager that handles most of the rendering of meshes provided by the gizmo manager.
 	 */
 	 */
@@ -592,10 +596,10 @@ namespace bs
 		Vector<SPtr<GpuParamsSetCore>> mIconParamSets;
 		Vector<SPtr<GpuParamsSetCore>> mIconParamSets;
 		Vector<SPtr<GpuParamsSetCore>> mPickingParamSets[2];
 		Vector<SPtr<GpuParamsSetCore>> mPickingParamSets[2];
 
 
-		GizmoParamBuffer mMeshGizmoBuffer;
-		GizmoParamBuffer mIconGizmoBuffer;
-		GizmoPickingParamBuffer mMeshPickingParamBuffer;
-		GizmoPickingParamBuffer mIconPickingParamBuffer;
+		SPtr<GpuParamBlockBufferCore> mMeshGizmoBuffer;
+		SPtr<GpuParamBlockBufferCore> mIconGizmoBuffer;
+		SPtr<GpuParamBlockBufferCore> mMeshPickingParamBuffer;
+		SPtr<GpuParamBlockBufferCore> mIconPickingParamBuffer;
 
 
 		// Immutable
 		// Immutable
 		SPtr<MaterialCore> mMeshMaterials[(UINT32)GizmoMeshType::Count];
 		SPtr<MaterialCore> mMeshMaterials[(UINT32)GizmoMeshType::Count];

+ 4 - 2
Source/BansheeEditor/Include/BsHandleDrawManager.h

@@ -200,11 +200,13 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-	BS_PARAM_BLOCK_BEGIN(GizmoParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(HandleParamBlockDef)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gViewDir)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gViewDir)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern HandleParamBlockDef gHandleParamBlockDef;
+
 	/** Core thread specific portion of the HandleDrawManager that handles actual rendering. */
 	/** Core thread specific portion of the HandleDrawManager that handles actual rendering. */
 	class BS_ED_EXPORT HandleDrawManagerCore
 	class BS_ED_EXPORT HandleDrawManagerCore
 	{
 	{
@@ -270,7 +272,7 @@ namespace bs
 
 
 		Vector<QueuedData> mQueuedData;
 		Vector<QueuedData> mQueuedData;
 
 
-		GizmoParamBuffer mParamBuffer;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 		Vector<SPtr<GpuParamsSetCore>> mParamSets[(UINT32)MeshType::Count];
 		Vector<SPtr<GpuParamsSetCore>> mParamSets[(UINT32)MeshType::Count];
 		UINT32 mTypeCounters[(UINT32)MeshType::Count];
 		UINT32 mTypeCounters[(UINT32)MeshType::Count];
 
 

+ 4 - 2
Source/BansheeEditor/Include/BsScenePicking.h

@@ -98,12 +98,14 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-	BS_PARAM_BLOCK_BEGIN(PickingParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(PickingParamBlockDef)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Color, gColorIndex)
 		BS_PARAM_BLOCK_ENTRY(Color, gColorIndex)
 		BS_PARAM_BLOCK_ENTRY(float, gAlphaCutoff)
 		BS_PARAM_BLOCK_ENTRY(float, gAlphaCutoff)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern PickingParamBlockDef gPickingParamBlockDef;
+
 	/** Core thread version of the ScenePicking manager. Handles actual rendering. */
 	/** Core thread version of the ScenePicking manager. Handles actual rendering. */
 	class ScenePickingCore
 	class ScenePickingCore
 	{
 	{
@@ -152,7 +154,7 @@ namespace bs
 
 
 		SPtr<MaterialCore> mMaterials[6];
 		SPtr<MaterialCore> mMaterials[6];
 		Vector<SPtr<GpuParamsSetCore>> mParamSets[6];
 		Vector<SPtr<GpuParamsSetCore>> mParamSets[6];
-		Vector<PickingParamBuffer*> mParamBuffers;
+		Vector<SPtr<GpuParamBlockBufferCore>> mParamBuffers;
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 20 - 12
Source/BansheeEditor/Source/BsGizmoManager.cpp

@@ -907,6 +907,9 @@ namespace bs
 		return HSceneObject();
 		return HSceneObject();
 	}
 	}
 
 
+	GizmoParamBlockDef gHandleParamBlockDef;
+	GizmoPickingParamBlockDef gGizmoPickingParamBlockDef;
+
 	const float GizmoManagerCore::PICKING_ALPHA_CUTOFF = 0.5f;
 	const float GizmoManagerCore::PICKING_ALPHA_CUTOFF = 0.5f;
 
 
 	GizmoManagerCore::GizmoManagerCore(const PrivatelyConstuct& dummy)
 	GizmoManagerCore::GizmoManagerCore(const PrivatelyConstuct& dummy)
@@ -931,6 +934,11 @@ namespace bs
 		mIconMaterial = initData.iconMat;
 		mIconMaterial = initData.iconMat;
 		mPickingMaterials[0] = initData.pickingMat;
 		mPickingMaterials[0] = initData.pickingMat;
 		mPickingMaterials[1] = initData.alphaPickingMat;
 		mPickingMaterials[1] = initData.alphaPickingMat;
+
+		mMeshGizmoBuffer = gHandleParamBlockDef.createBuffer();
+		mIconGizmoBuffer = gHandleParamBlockDef.createBuffer();
+		mMeshPickingParamBuffer = gGizmoPickingParamBlockDef.createBuffer();
+		mIconPickingParamBuffer = gGizmoPickingParamBlockDef.createBuffer();
 	}
 	}
 
 
 	void GizmoManagerCore::updateData(const SPtr<CameraCore>& camera, const Vector<GizmoManager::MeshRenderData>& meshes,
 	void GizmoManagerCore::updateData(const SPtr<CameraCore>& camera, const Vector<GizmoManager::MeshRenderData>& meshes,
@@ -965,7 +973,7 @@ namespace bs
 			if (paramsIdx >= mMeshParamSets[typeIdx].size())
 			if (paramsIdx >= mMeshParamSets[typeIdx].size())
 			{
 			{
 				SPtr<GpuParamsSetCore> paramsSet = mMeshMaterials[typeIdx]->createParamsSet();
 				SPtr<GpuParamsSetCore> paramsSet = mMeshMaterials[typeIdx]->createParamsSet();
-				paramsSet->setParamBlockBuffer("Uniforms", mMeshGizmoBuffer.getBuffer(), true);
+				paramsSet->setParamBlockBuffer("Uniforms", mMeshGizmoBuffer, true);
 
 
 				mMeshParamSets[typeIdx].push_back(paramsSet);
 				mMeshParamSets[typeIdx].push_back(paramsSet);
 			}
 			}
@@ -982,7 +990,7 @@ namespace bs
 			if (iconMeshIdx >= mIconParamSets.size())
 			if (iconMeshIdx >= mIconParamSets.size())
 			{
 			{
 				mIconMaterial->createParamsSet();
 				mIconMaterial->createParamsSet();
-				paramsSet->setParamBlockBuffer("Uniforms", mIconGizmoBuffer.getBuffer(), true);
+				paramsSet->setParamBlockBuffer("Uniforms", mIconGizmoBuffer, true);
 
 
 				mIconParamSets.push_back(paramsSet);
 				mIconParamSets.push_back(paramsSet);
 			}
 			}
@@ -1028,8 +1036,8 @@ namespace bs
 
 
 		if (!usePickingMaterial)
 		if (!usePickingMaterial)
 		{
 		{
-			mMeshGizmoBuffer.gMatViewProj.set(viewProjMat);
-			mMeshGizmoBuffer.gViewDir.set((Vector4)camera->getForward());
+			gHandleParamBlockDef.gMatViewProj.set(mMeshGizmoBuffer, viewProjMat);
+			gHandleParamBlockDef.gViewDir.set(mMeshGizmoBuffer, (Vector4)camera->getForward());
 
 
 			for (auto& entry : meshes)
 			for (auto& entry : meshes)
 			{
 			{
@@ -1057,7 +1065,7 @@ namespace bs
 				if (paramsIdx >= mPickingParamSets[typeIdx].size())
 				if (paramsIdx >= mPickingParamSets[typeIdx].size())
 				{
 				{
 					SPtr<GpuParamsSetCore> paramsSet = mPickingMaterials[typeIdx]->createParamsSet();
 					SPtr<GpuParamsSetCore> paramsSet = mPickingMaterials[typeIdx]->createParamsSet();
-					paramsSet->setParamBlockBuffer("Uniforms", mMeshPickingParamBuffer.getBuffer(), true);
+					paramsSet->setParamBlockBuffer("Uniforms", mMeshPickingParamBuffer, true);
 
 
 					mPickingParamSets[typeIdx].push_back(paramsSet);
 					mPickingParamSets[typeIdx].push_back(paramsSet);
 				}
 				}
@@ -1072,7 +1080,7 @@ namespace bs
 				if (iconData.paramsIdx >= mPickingParamSets[1].size())
 				if (iconData.paramsIdx >= mPickingParamSets[1].size())
 				{
 				{
 					SPtr<GpuParamsSetCore> paramsSet = mPickingMaterials[1]->createParamsSet();
 					SPtr<GpuParamsSetCore> paramsSet = mPickingMaterials[1]->createParamsSet();
-					paramsSet->setParamBlockBuffer("Uniforms", mIconPickingParamBuffer.getBuffer(), true);
+					paramsSet->setParamBlockBuffer("Uniforms", mIconPickingParamBuffer, true);
 
 
 					mPickingParamSets[1].push_back(paramsSet);
 					mPickingParamSets[1].push_back(paramsSet);
 				}
 				}
@@ -1080,8 +1088,8 @@ namespace bs
 				pickingCounters[1]++;
 				pickingCounters[1]++;
 			}
 			}
 
 
-			mMeshPickingParamBuffer.gMatViewProj.set(viewProjMat);
-			mMeshPickingParamBuffer.gAlphaCutoff.set(PICKING_ALPHA_CUTOFF);
+			gGizmoPickingParamBlockDef.gMatViewProj.set(mMeshPickingParamBuffer, viewProjMat);
+			gGizmoPickingParamBlockDef.gAlphaCutoff.set(mMeshPickingParamBuffer, PICKING_ALPHA_CUTOFF);
 
 
 			for (auto& entry : meshes)
 			for (auto& entry : meshes)
 			{
 			{
@@ -1134,8 +1142,8 @@ namespace bs
 
 
 		if (!usePickingMaterial)
 		if (!usePickingMaterial)
 		{
 		{
-			mIconGizmoBuffer.gMatViewProj.set(projMat);
-			mIconGizmoBuffer.gViewDir.set(Vector4::ZERO);
+			gHandleParamBlockDef.gMatViewProj.set(mIconGizmoBuffer, projMat);
+			gHandleParamBlockDef.gViewDir.set(mIconGizmoBuffer, Vector4::ZERO);
 
 
 			for (UINT32 passIdx = 0; passIdx < 2; passIdx++)
 			for (UINT32 passIdx = 0; passIdx < 2; passIdx++)
 			{
 			{
@@ -1153,8 +1161,8 @@ namespace bs
 		}
 		}
 		else
 		else
 		{
 		{
-			mMeshPickingParamBuffer.gMatViewProj.set(projMat);
-			mMeshPickingParamBuffer.gAlphaCutoff.set(PICKING_ALPHA_CUTOFF);
+			gGizmoPickingParamBlockDef.gMatViewProj.set(mIconPickingParamBuffer, projMat);
+			gGizmoPickingParamBlockDef.gAlphaCutoff.set(mIconPickingParamBuffer, PICKING_ALPHA_CUTOFF);
 
 
 			for (auto& iconData : *renderData)
 			for (auto& iconData : *renderData)
 			{
 			{

+ 7 - 3
Source/BansheeEditor/Source/BsHandleDrawManager.cpp

@@ -242,6 +242,8 @@ namespace bs
 		mActiveMeshes.clear();
 		mActiveMeshes.clear();
 	}
 	}
 
 
+	HandleParamBlockDef gHandleParamBlockDef;
+
 	HandleDrawManagerCore::HandleDrawManagerCore(const PrivatelyConstruct& dummy)
 	HandleDrawManagerCore::HandleDrawManagerCore(const PrivatelyConstruct& dummy)
 		:mTypeCounters()
 		:mTypeCounters()
 	{ }
 	{ }
@@ -259,6 +261,8 @@ namespace bs
 		mMaterials[(UINT32)MeshType::Text] = textMat;
 		mMaterials[(UINT32)MeshType::Text] = textMat;
 
 
 		mClearMaterial = clearMat;
 		mClearMaterial = clearMat;
+
+		mParamBuffer = gHandleParamBlockDef.createBuffer();
 	}
 	}
 
 
 	void HandleDrawManagerCore::queueForDraw(const SPtr<CameraCore>& camera, Vector<MeshData>& meshes)
 	void HandleDrawManagerCore::queueForDraw(const SPtr<CameraCore>& camera, Vector<MeshData>& meshes)
@@ -280,7 +284,7 @@ namespace bs
 				if (paramsIdx >= mParamSets[typeIdx].size())
 				if (paramsIdx >= mParamSets[typeIdx].size())
 				{
 				{
 					paramsSet = mMaterials[typeIdx]->createParamsSet();
 					paramsSet = mMaterials[typeIdx]->createParamsSet();
-					paramsSet->setParamBlockBuffer("Uniforms", mParamBuffer.getBuffer(), true);
+					paramsSet->setParamBlockBuffer("Uniforms", mParamBuffer, true);
 
 
 					mParamSets[typeIdx].push_back(paramsSet);
 					mParamSets[typeIdx].push_back(paramsSet);
 				}
 				}
@@ -334,8 +338,8 @@ namespace bs
 
 
 		Matrix4 viewProjMat = camera->getProjectionMatrixRS() * camera->getViewMatrix();
 		Matrix4 viewProjMat = camera->getProjectionMatrixRS() * camera->getViewMatrix();
 
 
-		mParamBuffer.gMatViewProj.set(viewProjMat);
-		mParamBuffer.gViewDir.set((Vector4)camera->getForward());
+		gHandleParamBlockDef.gMatViewProj.set(mParamBuffer, viewProjMat);
+		gHandleParamBlockDef.gViewDir.set(mParamBuffer, (Vector4)camera->getForward());
 
 
 		UINT32 currentType = -1;
 		UINT32 currentType = -1;
 		for (auto& meshData : meshes)
 		for (auto& meshData : meshes)

+ 8 - 9
Source/BansheeEditor/Source/BsScenePicking.cpp

@@ -243,6 +243,8 @@ namespace bs
 		return (r & 0xFF) | ((g & 0xFF) << 8) | ((b & 0xFF) << 16);
 		return (r & 0xFF) | ((g & 0xFF) << 8) | ((b & 0xFF) << 16);
 	}
 	}
 
 
+	PickingParamBlockDef gPickingParamBlockDef;
+
 	void ScenePickingCore::initialize()
 	void ScenePickingCore::initialize()
 	{
 	{
 		// Do nothing
 		// Do nothing
@@ -250,9 +252,6 @@ namespace bs
 
 
 	void ScenePickingCore::destroy()
 	void ScenePickingCore::destroy()
 	{
 	{
-		for (auto& entry : mParamBuffers)
-			bs_delete(entry);
-
 		bs_delete(this);
 		bs_delete(this);
 	}
 	}
 
 
@@ -324,22 +323,22 @@ namespace bs
 			else
 			else
 				paramsSet = mParamSets[typeIdx][renderableIdx];
 				paramsSet = mParamSets[typeIdx][renderableIdx];
 
 
-			PickingParamBuffer* paramBuffer;
+			SPtr<GpuParamBlockBufferCore> paramBuffer;
 			if (idx >= mParamBuffers.size())
 			if (idx >= mParamBuffers.size())
 			{
 			{
-				paramBuffer = bs_new<PickingParamBuffer>();
+				paramBuffer = gPickingParamBlockDef.createBuffer();
 				mParamBuffers.push_back(paramBuffer);
 				mParamBuffers.push_back(paramBuffer);
 			}
 			}
 			else
 			else
 				paramBuffer = mParamBuffers[idx];
 				paramBuffer = mParamBuffers[idx];
 
 
-			paramsSet->setParamBlockBuffer("Uniforms", paramBuffer->getBuffer(), true);
+			paramsSet->setParamBlockBuffer("Uniforms", paramBuffer, true);
 
 
 			Color color = ScenePicking::encodeIndex(renderable.index);
 			Color color = ScenePicking::encodeIndex(renderable.index);
 
 
-			paramBuffer->gMatViewProj.set(renderable.wvpTransform);
-			paramBuffer->gAlphaCutoff.set(ALPHA_CUTOFF);
-			paramBuffer->gColorIndex.set(color);
+			gPickingParamBlockDef.gMatViewProj.set(paramBuffer, renderable.wvpTransform);
+			gPickingParamBlockDef.gAlphaCutoff.set(paramBuffer, ALPHA_CUTOFF);
+			gPickingParamBlockDef.gColorIndex.set(paramBuffer, color);
 
 
 			typeCounters[typeIdx]++;
 			typeCounters[typeIdx]++;
 			idx++;
 			idx++;

+ 4 - 2
Source/BansheeEngine/Include/BsGUIManager.h

@@ -421,13 +421,15 @@ namespace bs
 		HEvent mMouseLeftWindowConn;
 		HEvent mMouseLeftWindowConn;
 	};
 	};
 
 
-	BS_PARAM_BLOCK_BEGIN(GUISpriteParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(GUISpriteParamBlockDef)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gWorldTransform)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gWorldTransform)
 		BS_PARAM_BLOCK_ENTRY(float, gInvViewportWidth)
 		BS_PARAM_BLOCK_ENTRY(float, gInvViewportWidth)
 		BS_PARAM_BLOCK_ENTRY(float, gInvViewportHeight)
 		BS_PARAM_BLOCK_ENTRY(float, gInvViewportHeight)
 		BS_PARAM_BLOCK_ENTRY(Color, gTint)
 		BS_PARAM_BLOCK_ENTRY(Color, gTint)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern GUISpriteParamBlockDef gGUISpriteParamBlockDef;
+
 	/**	Handles GUI rendering on the core thread. */
 	/**	Handles GUI rendering on the core thread. */
 	class BS_EXPORT GUIManagerCore
 	class BS_EXPORT GUIManagerCore
 	{
 	{
@@ -451,7 +453,7 @@ namespace bs
 		void render(const SPtr<CameraCore>& camera);
 		void render(const SPtr<CameraCore>& camera);
 
 
 		UnorderedMap<SPtr<CameraCore>, Vector<GUIManager::GUICoreRenderData>> mPerCameraData;
 		UnorderedMap<SPtr<CameraCore>, Vector<GUIManager::GUICoreRenderData>> mPerCameraData;
-		Vector<GUISpriteParamBuffer*> mParamBlocks;
+		Vector<SPtr<GpuParamBlockBufferCore>> mParamBlocks;
 		SPtr<SamplerStateCore> mSamplerState;
 		SPtr<SamplerStateCore> mSamplerState;
 	};
 	};
 
 

+ 12 - 13
Source/BansheeEngine/Source/BsGUIManager.cpp

@@ -1738,14 +1738,13 @@ namespace bs
 		return GUIManager::instance();
 		return GUIManager::instance();
 	}
 	}
 
 
+	GUISpriteParamBlockDef gGUISpriteParamBlockDef;
+
 	GUIManagerCore::~GUIManagerCore()
 	GUIManagerCore::~GUIManagerCore()
 	{
 	{
 		SPtr<CoreRenderer> activeRenderer = RendererManager::instance().getActive();
 		SPtr<CoreRenderer> activeRenderer = RendererManager::instance().getActive();
 		for (auto& cameraData : mPerCameraData)
 		for (auto& cameraData : mPerCameraData)
 			activeRenderer->unregisterRenderCallback(cameraData.first.get(), 30);
 			activeRenderer->unregisterRenderCallback(cameraData.first.get(), 30);
-
-		for(auto& entry : mParamBlocks)
-			bs_delete(entry);
 	}
 	}
 
 
 	void GUIManagerCore::initialize()
 	void GUIManagerCore::initialize()
@@ -1822,7 +1821,7 @@ namespace bs
 				mParamBlocks.resize(numBuffers);
 				mParamBlocks.resize(numBuffers);
 
 
 				for (UINT32 i = numAllocatedBuffers; i < numBuffers; i++)
 				for (UINT32 i = numAllocatedBuffers; i < numBuffers; i++)
-					mParamBlocks[i] = bs_new<GUISpriteParamBuffer>();
+					mParamBlocks[i] = gGUISpriteParamBlockDef.createBuffer();
 			}
 			}
 
 
 			UINT32 curBufferIdx = 0;
 			UINT32 curBufferIdx = 0;
@@ -1830,10 +1829,10 @@ namespace bs
 			{
 			{
 				for(auto& entry : cameraData.second)
 				for(auto& entry : cameraData.second)
 				{
 				{
-					GUISpriteParamBuffer* buffer = mParamBlocks[curBufferIdx];
+					SPtr<GpuParamBlockBufferCore> buffer = mParamBlocks[curBufferIdx];
 
 
-					buffer->gTint.set(entry.tint);
-					buffer->gWorldTransform.set(entry.worldTransform);
+					gGUISpriteParamBlockDef.gTint.set(buffer, entry.tint);
+					gGUISpriteParamBlockDef.gWorldTransform.set(buffer, entry.worldTransform);
 
 
 					entry.bufferIdx = curBufferIdx;
 					entry.bufferIdx = curBufferIdx;
 					curBufferIdx++;
 					curBufferIdx++;
@@ -1853,12 +1852,12 @@ namespace bs
 
 
 		for (auto& entry : renderData)
 		for (auto& entry : renderData)
 		{
 		{
-			GUISpriteParamBuffer* buffer = mParamBlocks[entry.bufferIdx];
+			SPtr<GpuParamBlockBufferCore> buffer = mParamBlocks[entry.bufferIdx];
 
 
-			buffer->gInvViewportWidth.set(invViewportWidth);
-			buffer->gInvViewportHeight.set(invViewportHeight);
+			gGUISpriteParamBlockDef.gInvViewportWidth.set(buffer, invViewportWidth);
+			gGUISpriteParamBlockDef.gInvViewportHeight.set(buffer, invViewportHeight);
 
 
-			buffer->getBuffer()->flushToGPU();
+			buffer->flushToGPU();
 		}
 		}
 
 
 		for (auto& entry : renderData)
 		for (auto& entry : renderData)
@@ -1866,9 +1865,9 @@ namespace bs
 			// TODO - I shouldn't be re-applying the entire material for each entry, instead just check which programs
 			// TODO - I shouldn't be re-applying the entire material for each entry, instead just check which programs
 			// changed, and apply only those + the modified constant buffers and/or texture.
 			// changed, and apply only those + the modified constant buffers and/or texture.
 
 
-			GUISpriteParamBuffer* buffer = mParamBlocks[entry.bufferIdx];
+			SPtr<GpuParamBlockBufferCore> buffer = mParamBlocks[entry.bufferIdx];
 
 
-			entry.material->render(entry.mesh, entry.texture, mSamplerState, buffer->getBuffer(), entry.additionalData);
+			entry.material->render(entry.mesh, entry.texture, mSamplerState, buffer, entry.additionalData);
 		}
 		}
 	}
 	}
 }
 }

+ 4 - 2
Source/RenderBeast/Include/BsLightRendering.h

@@ -12,7 +12,7 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-	BS_PARAM_BLOCK_BEGIN(PerLightParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(PerLightParamDef)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightPositionAndType)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightPositionAndType)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightColorAndIntensity)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightColorAndIntensity)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightSpotAnglesAndSqrdInvRadius)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightSpotAnglesAndSqrdInvRadius)
@@ -21,6 +21,8 @@ namespace bs
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatConeTransform)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatConeTransform)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern PerLightParamDef gPerLightParamDef;
+
 	/** Manipulates parameters used in various light rendering shaders. */
 	/** Manipulates parameters used in various light rendering shaders. */
 	class LightRenderingParams
 	class LightRenderingParams
 	{
 	{
@@ -43,7 +45,7 @@ namespace bs
 		GpuParamTextureCore mGBufferA;
 		GpuParamTextureCore mGBufferA;
 		GpuParamTextureCore mGBufferB;
 		GpuParamTextureCore mGBufferB;
 		GpuParamTextureCore mGBufferDepth;
 		GpuParamTextureCore mGBufferDepth;
-		PerLightParamBuffer mBuffer;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 	};
 	};
 
 
 	/** Shader that renders directional light sources during deferred rendering light pass. */
 	/** Shader that renders directional light sources during deferred rendering light pass. */

+ 4 - 2
Source/RenderBeast/Include/BsObjectRendering.h

@@ -18,10 +18,12 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-	BS_PARAM_BLOCK_BEGIN(PerFrameParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(PerFrameParamDef)
 		BS_PARAM_BLOCK_ENTRY(float, gTime)
 		BS_PARAM_BLOCK_ENTRY(float, gTime)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern PerFrameParamDef gPerFrameParamDef;
+
 	/** Manages initialization and rendering of individual renderable object, represented as RenderableElement%s. */
 	/** Manages initialization and rendering of individual renderable object, represented as RenderableElement%s. */
 	class BS_BSRND_EXPORT ObjectRenderer
 	class BS_BSRND_EXPORT ObjectRenderer
 	{
 	{
@@ -35,7 +37,7 @@ namespace bs
 		void setParamFrameParams(float time);
 		void setParamFrameParams(float time);
 
 
 	protected:
 	protected:
-		PerFrameParamBuffer mPerFrameParams;
+		SPtr<GpuParamBlockBufferCore> mPerFrameParamBuffer;
 	};
 	};
 
 
 	/** Basic shader that is used when no other is available. */
 	/** Basic shader that is used when no other is available. */

+ 28 - 14
Source/RenderBeast/Include/BsPostProcessing.h

@@ -28,10 +28,12 @@ namespace bs
 		INT32 lastEyeAdaptationTex = 0;
 		INT32 lastEyeAdaptationTex = 0;
 	};
 	};
 
 
-	BS_PARAM_BLOCK_BEGIN(DownsampleParams)
+	BS_PARAM_BLOCK_BEGIN(DownsampleParamDef)
 		BS_PARAM_BLOCK_ENTRY(Vector2, gInvTexSize)
 		BS_PARAM_BLOCK_ENTRY(Vector2, gInvTexSize)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern DownsampleParamDef gDownsampleParamDef;
+
 	/** Shader that downsamples a texture to half its size. */
 	/** Shader that downsamples a texture to half its size. */
 	class DownsampleMat : public RendererMaterial<DownsampleMat>
 	class DownsampleMat : public RendererMaterial<DownsampleMat>
 	{
 	{
@@ -49,19 +51,21 @@ namespace bs
 		/** Returns the render texture where the output will be written. */
 		/** Returns the render texture where the output will be written. */
 		SPtr<RenderTextureCore> getOutput() const { return mOutput; }
 		SPtr<RenderTextureCore> getOutput() const { return mOutput; }
 	private:
 	private:
-		DownsampleParams mParams;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 		GpuParamTextureCore mInputTexture;
 		GpuParamTextureCore mInputTexture;
 
 
 		POOLED_RENDER_TEXTURE_DESC mOutputDesc;
 		POOLED_RENDER_TEXTURE_DESC mOutputDesc;
 		SPtr<RenderTextureCore> mOutput;
 		SPtr<RenderTextureCore> mOutput;
 	};
 	};
 
 
-	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramParams)
+	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramParamDef)
 		BS_PARAM_BLOCK_ENTRY(Vector4I, gPixelOffsetAndSize)
 		BS_PARAM_BLOCK_ENTRY(Vector4I, gPixelOffsetAndSize)
 		BS_PARAM_BLOCK_ENTRY(Vector2, gHistogramParams)
 		BS_PARAM_BLOCK_ENTRY(Vector2, gHistogramParams)
 		BS_PARAM_BLOCK_ENTRY(Vector2I, gThreadGroupCount)
 		BS_PARAM_BLOCK_ENTRY(Vector2I, gThreadGroupCount)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern EyeAdaptHistogramParamDef gEyeAdaptHistogramParamDef;
+
 	/** Shader that creates a luminance histogram used for eye adaptation. */
 	/** Shader that creates a luminance histogram used for eye adaptation. */
 	class EyeAdaptHistogramMat : public RendererMaterial<EyeAdaptHistogramMat>
 	class EyeAdaptHistogramMat : public RendererMaterial<EyeAdaptHistogramMat>
 	{
 	{
@@ -93,7 +97,7 @@ namespace bs
 		
 		
 		static const UINT32 HISTOGRAM_NUM_TEXELS = (THREAD_GROUP_SIZE_X * THREAD_GROUP_SIZE_Y) / 4;
 		static const UINT32 HISTOGRAM_NUM_TEXELS = (THREAD_GROUP_SIZE_X * THREAD_GROUP_SIZE_Y) / 4;
 	private:
 	private:
-		EyeAdaptHistogramParams mParams;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 		GpuParamTextureCore mSceneColor;
 		GpuParamTextureCore mSceneColor;
 		GpuParamLoadStoreTextureCore mOutputTex;
 		GpuParamLoadStoreTextureCore mOutputTex;
 
 
@@ -104,10 +108,12 @@ namespace bs
 		static const UINT32 LOOP_COUNT_Y = 8;
 		static const UINT32 LOOP_COUNT_Y = 8;
 	};
 	};
 
 
-	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramReduceParams)
+	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramReduceParamDef)
 		BS_PARAM_BLOCK_ENTRY(int, gThreadGroupCount)
 		BS_PARAM_BLOCK_ENTRY(int, gThreadGroupCount)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern EyeAdaptHistogramReduceParamDef gEyeAdaptHistogramReduceParamDef;
+
 	/** Shader that reduces the luminance histograms created by EyeAdaptHistogramMat into a single histogram. */
 	/** Shader that reduces the luminance histograms created by EyeAdaptHistogramMat into a single histogram. */
 	class EyeAdaptHistogramReduceMat : public RendererMaterial<EyeAdaptHistogramReduceMat>
 	class EyeAdaptHistogramReduceMat : public RendererMaterial<EyeAdaptHistogramReduceMat>
 	{
 	{
@@ -125,7 +131,7 @@ namespace bs
 		/** Returns the render texture where the output was written. */
 		/** Returns the render texture where the output was written. */
 		SPtr<RenderTextureCore> getOutput() const { return mOutput; }
 		SPtr<RenderTextureCore> getOutput() const { return mOutput; }
 	private:
 	private:
-		EyeAdaptHistogramReduceParams mParams;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 
 
 		GpuParamTextureCore mHistogramTex;
 		GpuParamTextureCore mHistogramTex;
 		GpuParamTextureCore mEyeAdaptationTex;
 		GpuParamTextureCore mEyeAdaptationTex;
@@ -134,10 +140,12 @@ namespace bs
 		SPtr<RenderTextureCore> mOutput;
 		SPtr<RenderTextureCore> mOutput;
 	};
 	};
 
 
-	BS_PARAM_BLOCK_BEGIN(EyeAdaptationParams)
+	BS_PARAM_BLOCK_BEGIN(EyeAdaptationParamDef)
 		BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gEyeAdaptationParams, 3)
 		BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gEyeAdaptationParams, 3)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern EyeAdaptationParamDef gEyeAdaptationParamDef;
+
 	/** Shader that computes the eye adaptation value based on scene luminance. */
 	/** Shader that computes the eye adaptation value based on scene luminance. */
 	class EyeAdaptationMat : public RendererMaterial<EyeAdaptationMat>
 	class EyeAdaptationMat : public RendererMaterial<EyeAdaptationMat>
 	{
 	{
@@ -149,11 +157,11 @@ namespace bs
 		/** Executes the post-process effect with the provided parameters. */
 		/** Executes the post-process effect with the provided parameters. */
 		void execute(PostProcessInfo& ppInfo, float frameDelta);
 		void execute(PostProcessInfo& ppInfo, float frameDelta);
 	private:
 	private:
-		EyeAdaptationParams mParams;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 		GpuParamTextureCore mReducedHistogramTex;
 		GpuParamTextureCore mReducedHistogramTex;
 	};
 	};
 
 
-	BS_PARAM_BLOCK_BEGIN(CreateTonemapLUTParams)
+	BS_PARAM_BLOCK_BEGIN(CreateTonemapLUTParamDef)
 		BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gTonemapParams, 2)
 		BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gTonemapParams, 2)
 		BS_PARAM_BLOCK_ENTRY(float, gGammaAdjustment)
 		BS_PARAM_BLOCK_ENTRY(float, gGammaAdjustment)
 		BS_PARAM_BLOCK_ENTRY(int, gGammaCorrectionType)
 		BS_PARAM_BLOCK_ENTRY(int, gGammaCorrectionType)
@@ -163,11 +171,15 @@ namespace bs
 		BS_PARAM_BLOCK_ENTRY(Vector3, gOffset)
 		BS_PARAM_BLOCK_ENTRY(Vector3, gOffset)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
-	BS_PARAM_BLOCK_BEGIN(WhiteBalanceParams)
+	extern CreateTonemapLUTParamDef gCreateTonemapLUTParamDef;
+
+	BS_PARAM_BLOCK_BEGIN(WhiteBalanceParamDef)
 		BS_PARAM_BLOCK_ENTRY(float, gWhiteTemp)
 		BS_PARAM_BLOCK_ENTRY(float, gWhiteTemp)
 		BS_PARAM_BLOCK_ENTRY(float, gWhiteOffset)
 		BS_PARAM_BLOCK_ENTRY(float, gWhiteOffset)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern WhiteBalanceParamDef gWhiteBalanceParamDef;
+
 	/** 
 	/** 
 	 * Shader that creates a 3D lookup texture that is used to apply tonemapping, color grading, white balancing and gamma
 	 * Shader that creates a 3D lookup texture that is used to apply tonemapping, color grading, white balancing and gamma
 	 * correction.
 	 * correction.
@@ -188,15 +200,17 @@ namespace bs
 		/** Size of the 3D color lookup table. */
 		/** Size of the 3D color lookup table. */
 		static const UINT32 LUT_SIZE = 32;
 		static const UINT32 LUT_SIZE = 32;
 	private:
 	private:
-		CreateTonemapLUTParams mParams;
-		WhiteBalanceParams mWhiteBalanceParams;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
+		SPtr<GpuParamBlockBufferCore> mWhiteBalanceParamBuffer;
 	};
 	};
 
 
-	BS_PARAM_BLOCK_BEGIN(TonemappingParams)
+	BS_PARAM_BLOCK_BEGIN(TonemappingParamDef)
 		BS_PARAM_BLOCK_ENTRY(float, gRawGamma)
 		BS_PARAM_BLOCK_ENTRY(float, gRawGamma)
 		BS_PARAM_BLOCK_ENTRY(float, gManualExposureScale)
 		BS_PARAM_BLOCK_ENTRY(float, gManualExposureScale)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern TonemappingParamDef gTonemappingParamDef;
+
 	/** Shader that applies tonemapping and converts a HDR image into a LDR image. */
 	/** Shader that applies tonemapping and converts a HDR image into a LDR image. */
 	template<bool GammaOnly, bool AutoExposure>
 	template<bool GammaOnly, bool AutoExposure>
 	class TonemappingMat : public RendererMaterial<TonemappingMat<GammaOnly, AutoExposure>>
 	class TonemappingMat : public RendererMaterial<TonemappingMat<GammaOnly, AutoExposure>>
@@ -211,7 +225,7 @@ namespace bs
 			PostProcessInfo& ppInfo);
 			PostProcessInfo& ppInfo);
 
 
 	private:
 	private:
-		TonemappingParams mParams;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 
 
 		GpuParamTextureCore mInputTex;
 		GpuParamTextureCore mInputTex;
 		GpuParamTextureCore mColorLUT;
 		GpuParamTextureCore mColorLUT;

+ 5 - 3
Source/RenderBeast/Include/BsRendererCamera.h

@@ -15,7 +15,7 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-	BS_PARAM_BLOCK_BEGIN(PerCameraParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(PerCameraParamDef)
 		BS_PARAM_BLOCK_ENTRY(Vector3, gViewDir)
 		BS_PARAM_BLOCK_ENTRY(Vector3, gViewDir)
 		BS_PARAM_BLOCK_ENTRY(Vector3, gViewOrigin)
 		BS_PARAM_BLOCK_ENTRY(Vector3, gViewOrigin)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
@@ -28,6 +28,8 @@ namespace bs
 		BS_PARAM_BLOCK_ENTRY(Vector4, gClipToUVScaleOffset)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gClipToUVScaleOffset)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern PerCameraParamDef gPerCameraParamDef;
+
 	/** Contains information about a Camera, used by the Renderer. */
 	/** Contains information about a Camera, used by the Renderer. */
 	class RendererCamera
 	class RendererCamera
 	{
 	{
@@ -97,7 +99,7 @@ namespace bs
 		void updatePerCameraBuffer();
 		void updatePerCameraBuffer();
 
 
 		/** Returns a buffer that stores per-camera parameters. */
 		/** Returns a buffer that stores per-camera parameters. */
-		PerCameraParamBuffer& getPerCameraBuffer() { return mParams; }
+		SPtr<GpuParamBlockBufferCore> getPerCameraBuffer() const { return mParamBuffer; }
 
 
 	private:
 	private:
 		/**
 		/**
@@ -118,7 +120,7 @@ namespace bs
 		PostProcessInfo mPostProcessInfo;
 		PostProcessInfo mPostProcessInfo;
 		bool mUsingRenderTargets;
 		bool mUsingRenderTargets;
 
 
-		PerCameraParamBuffer mParams;
+		SPtr<GpuParamBlockBufferCore> mParamBuffer;
 		Vector<bool> mVisibility;
 		Vector<bool> mVisibility;
 	};
 	};
 
 

+ 10 - 4
Source/RenderBeast/Include/BsRendererObject.h

@@ -14,7 +14,7 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
-	BS_PARAM_BLOCK_BEGIN(PerObjectParamBuffer)
+	BS_PARAM_BLOCK_BEGIN(PerObjectParamDef)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorld)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorld)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorld)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorld)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldNoScale)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldNoScale)
@@ -22,10 +22,14 @@ namespace bs
 		BS_PARAM_BLOCK_ENTRY(float, gWorldDeterminantSign)
 		BS_PARAM_BLOCK_ENTRY(float, gWorldDeterminantSign)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
-	BS_PARAM_BLOCK_BEGIN(PerCallParamBuffer)
+	extern PerObjectParamDef gPerObjectParamDef;
+
+	BS_PARAM_BLOCK_BEGIN(PerCallParamDef)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldViewProj)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldViewProj)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
+	extern PerCallParamDef gPerCallParamDef;
+
 	struct MaterialSamplerOverrides;
 	struct MaterialSamplerOverrides;
 
 
 	/**
 	/**
@@ -76,6 +80,8 @@ namespace bs
 	 /** Contains information about a Renderable, used by the Renderer. */
 	 /** Contains information about a Renderable, used by the Renderer. */
 	struct RendererObject
 	struct RendererObject
 	{
 	{
+		RendererObject();
+
 		/** Updates the per-object GPU buffer according to the currently set properties. */
 		/** Updates the per-object GPU buffer according to the currently set properties. */
 		void updatePerObjectBuffer();
 		void updatePerObjectBuffer();
 
 
@@ -90,8 +96,8 @@ namespace bs
 		RenderableCore* renderable;
 		RenderableCore* renderable;
 		Vector<BeastRenderableElement> elements;
 		Vector<BeastRenderableElement> elements;
 
 
-		PerObjectParamBuffer perObjectParams;
-		PerCallParamBuffer perCallParams;
+		SPtr<GpuParamBlockBufferCore> perObjectParamBuffer;
+		SPtr<GpuParamBlockBufferCore> perCallParamBuffer;
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 12 - 8
Source/RenderBeast/Source/BsLightRendering.cpp

@@ -12,6 +12,8 @@
 
 
 namespace bs
 namespace bs
 {
 {
+	PerLightParamDef gPerLightParamDef;
+
 	LightRenderingParams::LightRenderingParams(const SPtr<MaterialCore>& material, const SPtr<GpuParamsSetCore>& paramsSet)
 	LightRenderingParams::LightRenderingParams(const SPtr<MaterialCore>& material, const SPtr<GpuParamsSetCore>& paramsSet)
 		:mMaterial(material), mParamsSet(paramsSet)
 		:mMaterial(material), mParamsSet(paramsSet)
 	{
 	{
@@ -32,6 +34,8 @@ namespace bs
 	void LightRenderingParams::setStaticParameters(const SPtr<RenderTargets>& gbuffer, 
 	void LightRenderingParams::setStaticParameters(const SPtr<RenderTargets>& gbuffer, 
 		const SPtr<GpuParamBlockBufferCore>& perCamera)
 		const SPtr<GpuParamBlockBufferCore>& perCamera)
 	{
 	{
+		mParamBuffer = gPerLightParamDef.createBuffer();
+
 		mGBufferA.set(gbuffer->getTextureA());
 		mGBufferA.set(gbuffer->getTextureA());
 		mGBufferB.set(gbuffer->getTextureB());
 		mGBufferB.set(gbuffer->getTextureB());
 		mGBufferDepth.set(gbuffer->getTextureDepth());
 		mGBufferDepth.set(gbuffer->getTextureDepth());
@@ -62,7 +66,7 @@ namespace bs
 			break;
 			break;
 		}
 		}
 
 
-		mBuffer.gLightPositionAndType.set(positionAndType);
+		gPerLightParamDef.gLightPositionAndType.set(mParamBuffer, positionAndType);
 			
 			
 		Vector4 colorAndIntensity;
 		Vector4 colorAndIntensity;
 		colorAndIntensity.x = light->getColor().r;
 		colorAndIntensity.x = light->getColor().r;
@@ -70,7 +74,7 @@ namespace bs
 		colorAndIntensity.z = light->getColor().b;
 		colorAndIntensity.z = light->getColor().b;
 		colorAndIntensity.w = light->getIntensity();
 		colorAndIntensity.w = light->getIntensity();
 
 
-		mBuffer.gLightColorAndIntensity.set(colorAndIntensity);
+		gPerLightParamDef.gLightColorAndIntensity.set(mParamBuffer, colorAndIntensity);
 
 
 		Radian spotAngle = Math::clamp(light->getSpotAngle() * 0.5f, Degree(1), Degree(90));
 		Radian spotAngle = Math::clamp(light->getSpotAngle() * 0.5f, Degree(1), Degree(90));
 		Radian spotFalloffAngle = Math::clamp(light->getSpotFalloffAngle() * 0.5f, Degree(1), (Degree)spotAngle);
 		Radian spotFalloffAngle = Math::clamp(light->getSpotFalloffAngle() * 0.5f, Degree(1), (Degree)spotAngle);
@@ -81,9 +85,9 @@ namespace bs
 		spotAnglesAndInvSqrdRadius.z = 1.0f / (Math::cos(spotFalloffAngle) - spotAnglesAndInvSqrdRadius.y);
 		spotAnglesAndInvSqrdRadius.z = 1.0f / (Math::cos(spotFalloffAngle) - spotAnglesAndInvSqrdRadius.y);
 		spotAnglesAndInvSqrdRadius.w = 1.0f / (light->getBounds().getRadius() * light->getBounds().getRadius());
 		spotAnglesAndInvSqrdRadius.w = 1.0f / (light->getBounds().getRadius() * light->getBounds().getRadius());
 
 
-		mBuffer.gLightSpotAnglesAndSqrdInvRadius.set(spotAnglesAndInvSqrdRadius);
+		gPerLightParamDef.gLightSpotAnglesAndSqrdInvRadius.set(mParamBuffer, spotAnglesAndInvSqrdRadius);
 
 
-		mBuffer.gLightDirection.set(-light->getRotation().zAxis());
+		gPerLightParamDef.gLightDirection.set(mParamBuffer, -light->getRotation().zAxis());
 
 
 		Vector4 lightGeometry;
 		Vector4 lightGeometry;
 		lightGeometry.x = light->getType() == LightType::Spot ? (float)LightCore::LIGHT_CONE_NUM_SIDES : 0;
 		lightGeometry.x = light->getType() == LightType::Spot ? (float)LightCore::LIGHT_CONE_NUM_SIDES : 0;
@@ -93,17 +97,17 @@ namespace bs
 		float coneRadius = Math::sin(spotAngle) * light->getRange();
 		float coneRadius = Math::sin(spotAngle) * light->getRange();
 		lightGeometry.w = coneRadius;
 		lightGeometry.w = coneRadius;
 
 
-		mBuffer.gLightGeometry.set(lightGeometry);
+		gPerLightParamDef.gLightGeometry.set(mParamBuffer, lightGeometry);
 
 
 		Matrix4 transform = Matrix4::TRS(light->getPosition(), light->getRotation(), Vector3::ONE);
 		Matrix4 transform = Matrix4::TRS(light->getPosition(), light->getRotation(), Vector3::ONE);
-		mBuffer.gMatConeTransform.set(transform);
+		gPerLightParamDef.gMatConeTransform.set(mParamBuffer, transform);
 
 
-		mBuffer.flushToGPU();
+		mParamBuffer->flushToGPU();
 	}
 	}
 
 
 	const SPtr<GpuParamBlockBufferCore>& LightRenderingParams::getBuffer() const
 	const SPtr<GpuParamBlockBufferCore>& LightRenderingParams::getBuffer() const
 	{
 	{
-		return mBuffer.getBuffer();
+		return mParamBuffer;
 	}
 	}
 	
 	
 	DirectionalLightMat::DirectionalLightMat()
 	DirectionalLightMat::DirectionalLightMat()

+ 9 - 5
Source/RenderBeast/Source/BsObjectRendering.cpp

@@ -14,8 +14,12 @@
 
 
 namespace bs
 namespace bs
 {
 {
+	PerFrameParamDef gPerFrameParamDef;
+
 	ObjectRenderer::ObjectRenderer()
 	ObjectRenderer::ObjectRenderer()
-	{ }
+	{
+		mPerFrameParamBuffer = gPerFrameParamDef.createBuffer();
+	}
 
 
 	void ObjectRenderer::initElement(RendererObject& owner, BeastRenderableElement& element)
 	void ObjectRenderer::initElement(RendererObject& owner, BeastRenderableElement& element)
 	{
 	{
@@ -35,16 +39,16 @@ namespace bs
 		for (auto& paramBlockDesc : paramBlockDescs)
 		for (auto& paramBlockDesc : paramBlockDescs)
 		{
 		{
 			if (paramBlockDesc.second.rendererSemantic == RBS_PerFrame)
 			if (paramBlockDesc.second.rendererSemantic == RBS_PerFrame)
-				element.params->setParamBlockBuffer(paramBlockDesc.second.name, mPerFrameParams.getBuffer(), true);
+				element.params->setParamBlockBuffer(paramBlockDesc.second.name, mPerFrameParamBuffer, true);
 			else if (paramBlockDesc.second.rendererSemantic == RBS_PerObject)
 			else if (paramBlockDesc.second.rendererSemantic == RBS_PerObject)
 			{
 			{
 				element.params->setParamBlockBuffer(paramBlockDesc.second.name,
 				element.params->setParamBlockBuffer(paramBlockDesc.second.name,
-													owner.perObjectParams.getBuffer(), true);
+													owner.perObjectParamBuffer, true);
 			}
 			}
 			else if (paramBlockDesc.second.rendererSemantic == RBS_PerCall)
 			else if (paramBlockDesc.second.rendererSemantic == RBS_PerCall)
 			{
 			{
 				element.params->setParamBlockBuffer(paramBlockDesc.second.name,
 				element.params->setParamBlockBuffer(paramBlockDesc.second.name,
-													owner.perCallParams.getBuffer(), true);
+													owner.perCallParamBuffer, true);
 			}
 			}
 		}
 		}
 
 
@@ -66,7 +70,7 @@ namespace bs
 
 
 	void ObjectRenderer::setParamFrameParams(float time)
 	void ObjectRenderer::setParamFrameParams(float time)
 	{
 	{
-		mPerFrameParams.gTime.set(time);
+		gPerFrameParamDef.gTime.set(mPerFrameParamBuffer, time);
 	}
 	}
 
 
 	void DefaultMaterial::_initDefines(ShaderDefines& defines)
 	void DefaultMaterial::_initDefines(ShaderDefines& defines)

+ 49 - 27
Source/RenderBeast/Source/BsPostProcessing.cpp

@@ -10,9 +10,13 @@
 
 
 namespace bs
 namespace bs
 {
 {
+	DownsampleParamDef gDownsampleParamDef;
+
 	DownsampleMat::DownsampleMat()
 	DownsampleMat::DownsampleMat()
 	{
 	{
-		mParamsSet->setParamBlockBuffer("Input", mParams.getBuffer());
+		mParamBuffer = gDownsampleParamDef.createBuffer();
+
+		mParamsSet->setParamBlockBuffer("Input", mParamBuffer);
 		mParamsSet->getGpuParams()->getTextureParam(GPT_FRAGMENT_PROGRAM, "gInputTex", mInputTexture);
 		mParamsSet->getGpuParams()->getTextureParam(GPT_FRAGMENT_PROGRAM, "gInputTex", mInputTexture);
 	}
 	}
 
 
@@ -30,7 +34,7 @@ namespace bs
 		const RenderTextureProperties& rtProps = target->getProperties();
 		const RenderTextureProperties& rtProps = target->getProperties();
 		Vector2 invTextureSize(1.0f / rtProps.getWidth(), 1.0f / rtProps.getHeight());
 		Vector2 invTextureSize(1.0f / rtProps.getWidth(), 1.0f / rtProps.getHeight());
 
 
-		mParams.gInvTexSize.set(invTextureSize);
+		gDownsampleParamDef.gInvTexSize.set(mParamBuffer, invTextureSize);
 
 
 		// Set output
 		// Set output
 		const TextureProperties& colorProps = colorTexture->getProperties();
 		const TextureProperties& colorProps = colorTexture->getProperties();
@@ -61,9 +65,12 @@ namespace bs
 		mOutput = nullptr;
 		mOutput = nullptr;
 	}
 	}
 
 
+	EyeAdaptHistogramParamDef gEyeAdaptHistogramParamDef;
+
 	EyeAdaptHistogramMat::EyeAdaptHistogramMat()
 	EyeAdaptHistogramMat::EyeAdaptHistogramMat()
 	{
 	{
-		mParamsSet->setParamBlockBuffer("Input", mParams.getBuffer());
+		mParamBuffer = gEyeAdaptHistogramParamDef.createBuffer();
+		mParamsSet->setParamBlockBuffer("Input", mParamBuffer);
 
 
 		SPtr<GpuParamsCore> params = mParamsSet->getGpuParams();
 		SPtr<GpuParamsCore> params = mParamsSet->getGpuParams();
 		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gSceneColorTex", mSceneColor);
 		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gSceneColorTex", mSceneColor);
@@ -87,11 +94,11 @@ namespace bs
 		const RenderTextureProperties& props = target->getProperties();
 		const RenderTextureProperties& props = target->getProperties();
 		int offsetAndSize[4] = { 0, 0, (INT32)props.getWidth(), (INT32)props.getHeight() };
 		int offsetAndSize[4] = { 0, 0, (INT32)props.getWidth(), (INT32)props.getHeight() };
 
 
-		mParams.gHistogramParams.set(getHistogramScaleOffset(ppInfo));
-		mParams.gPixelOffsetAndSize.set(Vector4I(offsetAndSize));
+		gEyeAdaptHistogramParamDef.gHistogramParams.set(mParamBuffer, getHistogramScaleOffset(ppInfo));
+		gEyeAdaptHistogramParamDef.gPixelOffsetAndSize.set(mParamBuffer, Vector4I(offsetAndSize));
 
 
 		Vector2I threadGroupCount = getThreadGroupCount(target);
 		Vector2I threadGroupCount = getThreadGroupCount(target);
-		mParams.gThreadGroupCount.set(threadGroupCount);
+		gEyeAdaptHistogramParamDef.gThreadGroupCount.set(mParamBuffer, threadGroupCount);
 
 
 		// Set output
 		// Set output
 		UINT32 numHistograms = threadGroupCount.x * threadGroupCount.y;
 		UINT32 numHistograms = threadGroupCount.x * threadGroupCount.y;
@@ -143,9 +150,12 @@ namespace bs
 		return Vector2(scale, offset);
 		return Vector2(scale, offset);
 	}
 	}
 
 
+	EyeAdaptHistogramReduceParamDef gEyeAdaptHistogramReduceParamDef;
+
 	EyeAdaptHistogramReduceMat::EyeAdaptHistogramReduceMat()
 	EyeAdaptHistogramReduceMat::EyeAdaptHistogramReduceMat()
 	{
 	{
-		mParamsSet->setParamBlockBuffer("Input", mParams.getBuffer());
+		mParamBuffer = gEyeAdaptHistogramReduceParamDef.createBuffer();
+		mParamsSet->setParamBlockBuffer("Input", mParamBuffer);
 
 
 		SPtr<GpuParamsCore> params = mParamsSet->getGpuParams();
 		SPtr<GpuParamsCore> params = mParamsSet->getGpuParams();
 		params->getTextureParam(GPT_FRAGMENT_PROGRAM, "gHistogramTex", mHistogramTex);
 		params->getTextureParam(GPT_FRAGMENT_PROGRAM, "gHistogramTex", mHistogramTex);
@@ -175,7 +185,7 @@ namespace bs
 		Vector2I threadGroupCount = EyeAdaptHistogramMat::getThreadGroupCount(ppInfo.downsampledSceneTex->renderTexture);
 		Vector2I threadGroupCount = EyeAdaptHistogramMat::getThreadGroupCount(ppInfo.downsampledSceneTex->renderTexture);
 		UINT32 numHistograms = threadGroupCount.x * threadGroupCount.y;
 		UINT32 numHistograms = threadGroupCount.x * threadGroupCount.y;
 
 
-		mParams.gThreadGroupCount.set(numHistograms);
+		gEyeAdaptHistogramReduceParamDef.gThreadGroupCount.set(mParamBuffer, numHistograms);
 
 
 		// Set output
 		// Set output
 		mOutputDesc = POOLED_RENDER_TEXTURE_DESC::create2D(PF_FLOAT16_RGBA, EyeAdaptHistogramMat::HISTOGRAM_NUM_TEXELS, 2,
 		mOutputDesc = POOLED_RENDER_TEXTURE_DESC::create2D(PF_FLOAT16_RGBA, EyeAdaptHistogramMat::HISTOGRAM_NUM_TEXELS, 2,
@@ -204,9 +214,12 @@ namespace bs
 		mOutput = nullptr;
 		mOutput = nullptr;
 	}
 	}
 
 
+	EyeAdaptationParamDef gEyeAdaptationParamDef;
+
 	EyeAdaptationMat::EyeAdaptationMat()
 	EyeAdaptationMat::EyeAdaptationMat()
 	{
 	{
-		mParamsSet->setParamBlockBuffer("Input", mParams.getBuffer());
+		mParamBuffer = gEyeAdaptationParamDef.createBuffer();
+		mParamsSet->setParamBlockBuffer("Input", mParamBuffer);
 		mParamsSet->getGpuParams()->getTextureParam(GPT_FRAGMENT_PROGRAM, "gHistogramTex", mReducedHistogramTex);
 		mParamsSet->getGpuParams()->getTextureParam(GPT_FRAGMENT_PROGRAM, "gHistogramTex", mReducedHistogramTex);
 	}
 	}
 
 
@@ -256,9 +269,9 @@ namespace bs
 		eyeAdaptationParams[2].z = 0.0f; // Unused
 		eyeAdaptationParams[2].z = 0.0f; // Unused
 		eyeAdaptationParams[2].w = 0.0f; // Unused
 		eyeAdaptationParams[2].w = 0.0f; // Unused
 
 
-		mParams.gEyeAdaptationParams.set(eyeAdaptationParams[0], 0);
-		mParams.gEyeAdaptationParams.set(eyeAdaptationParams[1], 1);
-		mParams.gEyeAdaptationParams.set(eyeAdaptationParams[2], 2);
+		gEyeAdaptationParamDef.gEyeAdaptationParams.set(mParamBuffer, eyeAdaptationParams[0], 0);
+		gEyeAdaptationParamDef.gEyeAdaptationParams.set(mParamBuffer, eyeAdaptationParams[1], 1);
+		gEyeAdaptationParamDef.gEyeAdaptationParams.set(mParamBuffer, eyeAdaptationParams[2], 2);
 
 
 		// Render
 		// Render
 		SPtr<PooledRenderTexture> eyeAdaptationRT = ppInfo.eyeAdaptationTex[ppInfo.lastEyeAdaptationTex];
 		SPtr<PooledRenderTexture> eyeAdaptationRT = ppInfo.eyeAdaptationTex[ppInfo.lastEyeAdaptationTex];
@@ -273,10 +286,16 @@ namespace bs
 		rapi.setRenderTarget(nullptr);
 		rapi.setRenderTarget(nullptr);
 	}
 	}
 
 
+	CreateTonemapLUTParamDef gCreateTonemapLUTParamDef;
+	WhiteBalanceParamDef gWhiteBalanceParamDef;
+
 	CreateTonemapLUTMat::CreateTonemapLUTMat()
 	CreateTonemapLUTMat::CreateTonemapLUTMat()
 	{
 	{
-		mParamsSet->setParamBlockBuffer("Input", mParams.getBuffer());
-		mParamsSet->setParamBlockBuffer("WhiteBalanceInput", mWhiteBalanceParams.getBuffer());
+		mParamBuffer = gCreateTonemapLUTParamDef.createBuffer();
+		mWhiteBalanceParamBuffer = gWhiteBalanceParamDef.createBuffer();
+
+		mParamsSet->setParamBlockBuffer("Input", mParamBuffer);
+		mParamsSet->setParamBlockBuffer("WhiteBalanceInput", mWhiteBalanceParamBuffer);
 	}
 	}
 
 
 	void CreateTonemapLUTMat::_initDefines(ShaderDefines& defines)
 	void CreateTonemapLUTMat::_initDefines(ShaderDefines& defines)
@@ -289,11 +308,11 @@ namespace bs
 		const StandardPostProcessSettings& settings = *ppInfo.settings;
 		const StandardPostProcessSettings& settings = *ppInfo.settings;
 
 
 		// Set parameters
 		// Set parameters
-		mParams.gGammaAdjustment.set(2.2f / settings.gamma);
+		gCreateTonemapLUTParamDef.gGammaAdjustment.set(mParamBuffer, 2.2f / settings.gamma);
 
 
 		// Note: Assuming sRGB (PC monitor) for now, change to Rec.709 when running on console (value 1), or to raw 2.2
 		// Note: Assuming sRGB (PC monitor) for now, change to Rec.709 when running on console (value 1), or to raw 2.2
 		// gamma when running on Mac (value 2)
 		// gamma when running on Mac (value 2)
-		mParams.gGammaCorrectionType.set(0);
+		gCreateTonemapLUTParamDef.gGammaCorrectionType.set(mParamBuffer, 0);
 
 
 		Vector4 tonemapParams[2];
 		Vector4 tonemapParams[2];
 		tonemapParams[0].x = settings.tonemapping.filmicCurveShoulderStrength;
 		tonemapParams[0].x = settings.tonemapping.filmicCurveShoulderStrength;
@@ -306,18 +325,18 @@ namespace bs
 		tonemapParams[1].z = settings.tonemapping.filmicCurveLinearWhitePoint;
 		tonemapParams[1].z = settings.tonemapping.filmicCurveLinearWhitePoint;
 		tonemapParams[1].w = 0.0f; // Unused
 		tonemapParams[1].w = 0.0f; // Unused
 
 
-		mParams.gTonemapParams.set(tonemapParams[0], 0);
-		mParams.gTonemapParams.set(tonemapParams[1], 1);
+		gCreateTonemapLUTParamDef.gTonemapParams.set(mParamBuffer, tonemapParams[0], 0);
+		gCreateTonemapLUTParamDef.gTonemapParams.set(mParamBuffer, tonemapParams[1], 1);
 
 
 		// Set color grading params
 		// Set color grading params
-		mParams.gSaturation.set(settings.colorGrading.saturation);
-		mParams.gContrast.set(settings.colorGrading.contrast);
-		mParams.gGain.set(settings.colorGrading.gain);
-		mParams.gOffset.set(settings.colorGrading.offset);
+		gCreateTonemapLUTParamDef.gSaturation.set(mParamBuffer, settings.colorGrading.saturation);
+		gCreateTonemapLUTParamDef.gContrast.set(mParamBuffer, settings.colorGrading.contrast);
+		gCreateTonemapLUTParamDef.gGain.set(mParamBuffer, settings.colorGrading.gain);
+		gCreateTonemapLUTParamDef.gOffset.set(mParamBuffer, settings.colorGrading.offset);
 
 
 		// Set white balance params
 		// Set white balance params
-		mWhiteBalanceParams.gWhiteTemp.set(settings.whiteBalance.temperature);
-		mWhiteBalanceParams.gWhiteOffset.set(settings.whiteBalance.tint);
+		gWhiteBalanceParamDef.gWhiteTemp.set(mWhiteBalanceParamBuffer, settings.whiteBalance.temperature);
+		gWhiteBalanceParamDef.gWhiteOffset.set(mWhiteBalanceParamBuffer, settings.whiteBalance.tint);
 
 
 		// Set output
 		// Set output
 		POOLED_RENDER_TEXTURE_DESC outputDesc = POOLED_RENDER_TEXTURE_DESC::create3D(PF_B8G8R8X8, 
 		POOLED_RENDER_TEXTURE_DESC outputDesc = POOLED_RENDER_TEXTURE_DESC::create3D(PF_B8G8R8X8, 
@@ -339,10 +358,13 @@ namespace bs
 		RenderTexturePool::instance().release(ppInfo.colorLUT);
 		RenderTexturePool::instance().release(ppInfo.colorLUT);
 	}
 	}
 
 
+	TonemappingParamDef gTonemappingParamDef;
+
 	template<bool GammaOnly, bool AutoExposure>
 	template<bool GammaOnly, bool AutoExposure>
 	TonemappingMat<GammaOnly, AutoExposure>::TonemappingMat()
 	TonemappingMat<GammaOnly, AutoExposure>::TonemappingMat()
 	{
 	{
-		mParamsSet->setParamBlockBuffer("Input", mParams.getBuffer());
+		mParamBuffer = gTonemappingParamDef.createBuffer();
+		mParamsSet->setParamBlockBuffer("Input", mParamBuffer);
 
 
 		SPtr<GpuParamsCore> params = mParamsSet->getGpuParams();
 		SPtr<GpuParamsCore> params = mParamsSet->getGpuParams();
 		params->getTextureParam(GPT_VERTEX_PROGRAM, "gEyeAdaptationTex", mEyeAdaptationTex);
 		params->getTextureParam(GPT_VERTEX_PROGRAM, "gEyeAdaptationTex", mEyeAdaptationTex);
@@ -368,8 +390,8 @@ namespace bs
 	void TonemappingMat<GammaOnly, AutoExposure>::execute(const SPtr<RenderTextureCore>& sceneColor, const SPtr<ViewportCore>& outputViewport,
 	void TonemappingMat<GammaOnly, AutoExposure>::execute(const SPtr<RenderTextureCore>& sceneColor, const SPtr<ViewportCore>& outputViewport,
 		PostProcessInfo& ppInfo)
 		PostProcessInfo& ppInfo)
 	{
 	{
-		mParams.gRawGamma.set(1.0f / ppInfo.settings->gamma);
-		mParams.gManualExposureScale.set(Math::pow(2.0f, ppInfo.settings->exposureScale));
+		gTonemappingParamDef.gRawGamma.set(mParamBuffer, 1.0f / ppInfo.settings->gamma);
+		gTonemappingParamDef.gManualExposureScale.set(mParamBuffer, Math::pow(2.0f, ppInfo.settings->exposureScale));
 
 
 		// Set parameters
 		// Set parameters
 		SPtr<TextureCore> colorTexture = sceneColor->getColorTexture(0);
 		SPtr<TextureCore> colorTexture = sceneColor->getColorTexture(0);

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

@@ -596,7 +596,7 @@ namespace bs
 			for (auto& element : mRenderables[i]->elements)
 			for (auto& element : mRenderables[i]->elements)
 				element.material->updateParamsSet(element.params, element.techniqueIdx);
 				element.material->updateParamsSet(element.params, element.techniqueIdx);
 
 
-			mRenderables[i]->perObjectParams.flushToGPU();
+			mRenderables[i]->perObjectParamBuffer->flushToGPU();
 		}
 		}
 
 
 		// Render everything, target by target
 		// Render everything, target by target
@@ -630,8 +630,8 @@ namespace bs
 
 
 		const CameraCore* camera = rtInfo.cameras[camIdx];
 		const CameraCore* camera = rtInfo.cameras[camIdx];
 		RendererCamera* rendererCam = mCameras[camera];
 		RendererCamera* rendererCam = mCameras[camera];
-		PerCameraParamBuffer& parCameraBuffer = rendererCam->getPerCameraBuffer();
-		parCameraBuffer.flushToGPU();
+		SPtr<GpuParamBlockBufferCore> perCameraBuffer = rendererCam->getPerCameraBuffer();
+		perCameraBuffer->flushToGPU();
 
 
 		assert(!camera->getFlags().isSet(CameraFlag::Overlay));
 		assert(!camera->getFlags().isSet(CameraFlag::Overlay));
 
 
@@ -653,7 +653,7 @@ namespace bs
 			for (auto& element : mRenderables[i]->elements)
 			for (auto& element : mRenderables[i]->elements)
 			{
 			{
 				if (element.perCameraBindingIdx != -1)
 				if (element.perCameraBindingIdx != -1)
-					element.params->setParamBlockBuffer(element.perCameraBindingIdx, parCameraBuffer.getBuffer(), true);
+					element.params->setParamBlockBuffer(element.perCameraBindingIdx, perCameraBuffer, true);
 			}
 			}
 		}
 		}
 
 
@@ -692,8 +692,6 @@ namespace bs
 
 
 		//// Render light pass
 		//// Render light pass
 		{
 		{
-			SPtr<GpuParamBlockBufferCore> perCameraBuffer = rendererCam->getPerCameraBuffer().getBuffer();;
-
 			mDirLightMat->bind(renderTargets, perCameraBuffer);
 			mDirLightMat->bind(renderTargets, perCameraBuffer);
 			for (auto& light : mDirectionalLights)
 			for (auto& light : mDirectionalLights)
 			{
 			{
@@ -805,7 +803,7 @@ namespace bs
 
 
 		SPtr<ViewportCore> viewport = camera->getViewport();
 		SPtr<ViewportCore> viewport = camera->getViewport();
 		RendererCamera* rendererCam = mCameras[camera];
 		RendererCamera* rendererCam = mCameras[camera];
-		rendererCam->getPerCameraBuffer().flushToGPU();
+		rendererCam->getPerCameraBuffer()->flushToGPU();
 
 
 		rendererCam->beginRendering(false);
 		rendererCam->beginRendering(false);
 
 

+ 16 - 11
Source/RenderBeast/Source/BsRendererCamera.cpp

@@ -9,13 +9,18 @@
 
 
 namespace bs
 namespace bs
 {
 {
+	PerCameraParamDef gPerCameraParamDef;
+
 	RendererCamera::RendererCamera()
 	RendererCamera::RendererCamera()
 		:mCamera(nullptr), mUsingRenderTargets(false)
 		:mCamera(nullptr), mUsingRenderTargets(false)
-	{ }
+	{
+		mParamBuffer = gPerCameraParamDef.createBuffer();
+	}
 
 
 	RendererCamera::RendererCamera(const CameraCore* camera, StateReduction reductionMode)
 	RendererCamera::RendererCamera(const CameraCore* camera, StateReduction reductionMode)
 		:mCamera(camera), mUsingRenderTargets(false)
 		:mCamera(camera), mUsingRenderTargets(false)
 	{
 	{
+		mParamBuffer = gPerCameraParamDef.createBuffer();
 		update(reductionMode);
 		update(reductionMode);
 	}
 	}
 
 
@@ -179,11 +184,11 @@ namespace bs
 		Matrix4 viewProj = proj * view;
 		Matrix4 viewProj = proj * view;
 		Matrix4 invViewProj = viewProj.inverse();
 		Matrix4 invViewProj = viewProj.inverse();
 
 
-		mParams.gMatProj.set(proj);
-		mParams.gMatView.set(view);
-		mParams.gMatViewProj.set(viewProj);
-		mParams.gMatInvViewProj.set(invViewProj); // Note: Calculate inverses separately (better precision possibly)
-		mParams.gMatInvProj.set(proj.inverse());
+		gPerCameraParamDef.gMatProj.set(mParamBuffer, proj);
+		gPerCameraParamDef.gMatView.set(mParamBuffer, view);
+		gPerCameraParamDef.gMatViewProj.set(mParamBuffer, viewProj);
+		gPerCameraParamDef.gMatInvViewProj.set(mParamBuffer, invViewProj); // Note: Calculate inverses separately (better precision possibly)
+		gPerCameraParamDef.gMatInvProj.set(mParamBuffer, proj.inverse());
 
 
 		// Construct a special inverse view-projection matrix that had projection entries that affect z and w eliminated.
 		// Construct a special inverse view-projection matrix that had projection entries that affect z and w eliminated.
 		// Used to transform a vector(clip_x, clip_y, view_z, view_w), where clip_x/clip_y are in clip space, and 
 		// Used to transform a vector(clip_x, clip_y, view_z, view_w), where clip_x/clip_y are in clip space, and 
@@ -196,10 +201,10 @@ namespace bs
 		projZ[3][2] = proj[3][2];
 		projZ[3][2] = proj[3][2];
 		projZ[3][3] = 0.0f;
 		projZ[3][3] = 0.0f;
 
 
-		mParams.gMatScreenToWorld.set(invViewProj * projZ);
-		mParams.gViewDir.set(mCamera->getForward());
-		mParams.gViewOrigin.set(mCamera->getPosition());
-		mParams.gDeviceZToWorldZ.set(getDeviceZTransform(proj));
+		gPerCameraParamDef.gMatScreenToWorld.set(mParamBuffer, invViewProj * projZ);
+		gPerCameraParamDef.gViewDir.set(mParamBuffer, mCamera->getForward());
+		gPerCameraParamDef.gViewOrigin.set(mParamBuffer, mCamera->getPosition());
+		gPerCameraParamDef.gDeviceZToWorldZ.set(mParamBuffer, getDeviceZTransform(proj));
 
 
 		SPtr<ViewportCore> viewport = mCamera->getViewport();
 		SPtr<ViewportCore> viewport = mCamera->getViewport();
 		SPtr<RenderTargetCore> rt = viewport->getTarget();
 		SPtr<RenderTargetCore> rt = viewport->getTarget();
@@ -233,6 +238,6 @@ namespace bs
 		if (!rapiInfo.getNDCYAxisDown())
 		if (!rapiInfo.getNDCYAxisDown())
 			clipToUVScaleOffset.y = -clipToUVScaleOffset.y;
 			clipToUVScaleOffset.y = -clipToUVScaleOffset.y;
 
 
-		mParams.gClipToUVScaleOffset.set(clipToUVScaleOffset);
+		gPerCameraParamDef.gClipToUVScaleOffset.set(mParamBuffer, clipToUVScaleOffset);
 	}
 	}
 }
 }

+ 16 - 7
Source/RenderBeast/Source/BsRendererObject.cpp

@@ -4,25 +4,34 @@
 
 
 namespace bs
 namespace bs
 {
 {
+	PerObjectParamDef gPerObjectParamDef;
+	PerCallParamDef gPerCallParamDef;
+
+	RendererObject::RendererObject()
+	{
+		perObjectParamBuffer = gPerObjectParamDef.createBuffer();
+		perCallParamBuffer = gPerCallParamDef.createBuffer();
+	}
+
 	void RendererObject::updatePerObjectBuffer()
 	void RendererObject::updatePerObjectBuffer()
 	{
 	{
 		Matrix4 worldTransform = renderable->getTransform();
 		Matrix4 worldTransform = renderable->getTransform();
 		Matrix4 worldNoScaleTransform = renderable->getTransformNoScale();
 		Matrix4 worldNoScaleTransform = renderable->getTransformNoScale();
 
 
-		perObjectParams.gMatWorld.set(worldTransform);
-		perObjectParams.gMatInvWorld.set(worldTransform.inverseAffine());
-		perObjectParams.gMatWorldNoScale.set(worldNoScaleTransform);
-		perObjectParams.gMatInvWorldNoScale.set(worldNoScaleTransform.inverseAffine());
-		perObjectParams.gWorldDeterminantSign.set(worldTransform.determinant3x3() >= 0.0f ? 1.0f : -1.0f);
+		gPerObjectParamDef.gMatWorld.set(perObjectParamBuffer, worldTransform);
+		gPerObjectParamDef.gMatInvWorld.set(perObjectParamBuffer, worldTransform.inverseAffine());
+		gPerObjectParamDef.gMatWorldNoScale.set(perObjectParamBuffer, worldNoScaleTransform);
+		gPerObjectParamDef.gMatInvWorldNoScale.set(perObjectParamBuffer, worldNoScaleTransform.inverseAffine());
+		gPerObjectParamDef.gWorldDeterminantSign.set(perObjectParamBuffer, worldTransform.determinant3x3() >= 0.0f ? 1.0f : -1.0f);
 	}
 	}
 
 
 	void RendererObject::updatePerCallBuffer(const Matrix4& viewProj, bool flush)
 	void RendererObject::updatePerCallBuffer(const Matrix4& viewProj, bool flush)
 	{
 	{
 		Matrix4 worldViewProjMatrix = viewProj * renderable->getTransform();
 		Matrix4 worldViewProjMatrix = viewProj * renderable->getTransform();
 
 
-		perCallParams.gMatWorldViewProj.set(worldViewProjMatrix);
+		gPerCallParamDef.gMatWorldViewProj.set(perCallParamBuffer, worldViewProjMatrix);
 
 
 		if(flush)
 		if(flush)
-			perCallParams.flushToGPU();
+			perCallParamBuffer->flushToGPU();
 	}
 	}
 }
 }