Quellcode durchsuchen

Fixed manual param block generation across all APIs
Fixed DX9 parameter block parsing

BearishSun vor 10 Jahren
Ursprung
Commit
458c080129

+ 12 - 8
BansheeCore/Include/BsParamBlocks.h

@@ -18,16 +18,19 @@ namespace BansheeEngine
 		Name()																												\
 		Name()																												\
 		{																													\
 		{																													\
 			SPtr<GpuParamDesc> paramsDesc = bs_shared_ptr_new<GpuParamDesc>();												\
 			SPtr<GpuParamDesc> paramsDesc = bs_shared_ptr_new<GpuParamDesc>();												\
-			paramsDesc->params = getEntries();																				\
+																															\
+			Vector<GpuParamDataDesc> params = getEntries();																	\
+			for(auto& param : params)																						\
+				paramsDesc->params[param.name] = param;																		\
 																															\
 																															\
 			RenderAPICore& rapi = RenderAPICore::instance();																\
 			RenderAPICore& rapi = RenderAPICore::instance();																\
 																															\
 																															\
-			GpuParamBlockDesc blockDesc = rapi.generateParamBlockDesc(#Name, paramsDesc->params);							\
+			GpuParamBlockDesc blockDesc = rapi.generateParamBlockDesc(#Name, params);										\
 			paramsDesc->paramBlocks[#Name] = blockDesc;																		\
 			paramsDesc->paramBlocks[#Name] = blockDesc;																		\
 																															\
 																															\
 			mParams = GpuParamsCore::create(paramsDesc, rapi.getGpuProgramHasColumnMajorMatrices());						\
 			mParams = GpuParamsCore::create(paramsDesc, rapi.getGpuProgramHasColumnMajorMatrices());						\
 																															\
 																															\
-			mBuffer = GpuParamBlockBufferCore::create(blockDesc.blockSize);													\
+			mBuffer = GpuParamBlockBufferCore::create(blockDesc.blockSize * sizeof(UINT32));								\
 			mParams->setParamBlockBuffer(#Name, mBuffer);																	\
 			mParams->setParamBlockBuffer(#Name, mBuffer);																	\
 			initEntries();																									\
 			initEntries();																									\
 		}																													\
 		}																													\
@@ -36,7 +39,7 @@ namespace BansheeEngine
 																															\
 																															\
 	private:																												\
 	private:																												\
 		struct META_FirstEntry {};																							\
 		struct META_FirstEntry {};																							\
-		static void META_GetPrevEntries(Map<String, 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 SPtr<GpuParamsCore>& params, META_FirstEntry id) { }									\
 																															\
 																															\
 		typedef META_FirstEntry 
 		typedef META_FirstEntry 
@@ -45,11 +48,12 @@ namespace BansheeEngine
 		META_Entry_##Name;																									\
 		META_Entry_##Name;																									\
 																															\
 																															\
 		struct META_NextEntry_##Name {};																					\
 		struct META_NextEntry_##Name {};																					\
-		static void META_GetPrevEntries(Map<String, GpuParamDataDesc>& params, META_NextEntry_##Name id)					\
+		static void META_GetPrevEntries(Vector<GpuParamDataDesc>& params, META_NextEntry_##Name id)							\
 		{																													\
 		{																													\
 			META_GetPrevEntries(params, META_Entry_##Name##());																\
 			META_GetPrevEntries(params, META_Entry_##Name##());																\
 																															\
 																															\
-			GpuParamDataDesc& newEntry = params[#Name];																		\
+			params.push_back(GpuParamDataDesc());																			\
+			GpuParamDataDesc& newEntry = params.back();																		\
 			newEntry.name = #Name;																							\
 			newEntry.name = #Name;																							\
 			newEntry.type = (GpuParamDataType)TGpuDataParamInfo<Type>::TypeId;												\
 			newEntry.type = (GpuParamDataType)TGpuDataParamInfo<Type>::TypeId;												\
 			newEntry.arraySize = NumElements;																				\
 			newEntry.arraySize = NumElements;																				\
@@ -71,9 +75,9 @@ namespace BansheeEngine
 #define BS_PARAM_BLOCK_END																									\
 #define BS_PARAM_BLOCK_END																									\
 		META_LastEntry;																										\
 		META_LastEntry;																										\
 																															\
 																															\
-		static Map<String, GpuParamDataDesc> getEntries()																	\
+		static Vector<GpuParamDataDesc> getEntries()																		\
 		{																													\
 		{																													\
-			Map<String, GpuParamDataDesc> entries;																			\
+			Vector<GpuParamDataDesc> entries;																				\
 			META_GetPrevEntries(entries, META_LastEntry());																	\
 			META_GetPrevEntries(entries, META_LastEntry());																	\
 			return entries;																									\
 			return entries;																									\
 		}																													\
 		}																													\

+ 1 - 1
BansheeCore/Include/BsRenderAPI.h

@@ -449,7 +449,7 @@ namespace BansheeEngine
 		 * @returns	Descriptor for the parameter block holding the provided parameters as laid out by the default render
 		 * @returns	Descriptor for the parameter block holding the provided parameters as laid out by the default render
 		 * 			API layout.
 		 * 			API layout.
 		 */
 		 */
-		virtual GpuParamBlockDesc generateParamBlockDesc(const String& name, Map<String, GpuParamDataDesc>& params) = 0;
+		virtual GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) = 0;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 							INTERNAL METHODS				        	*/
 		/* 							INTERNAL METHODS				        	*/

+ 1 - 1
BansheeD3D11RenderAPI/Include/BsD3D11RenderAPI.h

@@ -179,7 +179,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderAPICore::generateParamBlockDesc()
 		 * @copydoc RenderAPICore::generateParamBlockDesc()
 		 */
 		 */
-		GpuParamBlockDesc generateParamBlockDesc(const String& name, Map<String, GpuParamDataDesc>& params) override;
+		GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) override;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 				Internal use by DX11 RenderSystem only                  */
 		/* 				Internal use by DX11 RenderSystem only                  */

+ 6 - 6
BansheeD3D11RenderAPI/Source/BsD3D11RenderAPI.cpp

@@ -1055,20 +1055,16 @@ namespace BansheeEngine
 		return 1.0f;
 		return 1.0f;
 	}
 	}
 
 
-	GpuParamBlockDesc D3D11RenderAPI::generateParamBlockDesc(const String& name, Map<String, GpuParamDataDesc>& params)
+	GpuParamBlockDesc D3D11RenderAPI::generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params)
 	{
 	{
-		// TODO - Min 4 bytes, dont cross 16 byte boundary, arrays are always minimum four components
-
 		GpuParamBlockDesc block;
 		GpuParamBlockDesc block;
 		block.blockSize = 0;
 		block.blockSize = 0;
 		block.isShareable = true;
 		block.isShareable = true;
 		block.name = name;
 		block.name = name;
 		block.slot = 0;
 		block.slot = 0;
 
 
-		for (auto& entry : params)
+		for (auto& param : params)
 		{
 		{
-			GpuParamDataDesc& param = entry.second;
-
 			const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[param.type];
 			const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[param.type];
 			UINT32 size = typeInfo.size / 4;
 			UINT32 size = typeInfo.size / 4;
 
 
@@ -1117,6 +1113,10 @@ namespace BansheeEngine
 			param.paramBlockSlot = 0;
 			param.paramBlockSlot = 0;
 		}
 		}
 
 
+		// Constant buffer size must always be a multiple of 16
+		if (block.blockSize % 4 != 0)
+			block.blockSize += (4 - (block.blockSize % 4));
+
 		return block;
 		return block;
 	}
 	}
 
 

+ 1 - 1
BansheeD3D9RenderAPI/Include/BsD3D9RenderAPI.h

@@ -179,7 +179,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderAPICore::generateParamBlockDesc()
 		 * @copydoc RenderAPICore::generateParamBlockDesc()
 		 */
 		 */
-		GpuParamBlockDesc generateParamBlockDesc(const String& name, Map<String, GpuParamDataDesc>& params) override;
+		GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) override;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 				Internal use by DX9 RenderAPI only                   */
 		/* 				Internal use by DX9 RenderAPI only                   */

+ 7 - 3
BansheeD3D9RenderAPI/Source/BsD3D9EmulatedParamBlocks.cpp

@@ -31,12 +31,16 @@ namespace BansheeEngine
 			std::sregex_iterator paramNameIter(paramBlockString.begin(), paramBlockString.end(), paramNameRegex);
 			std::sregex_iterator paramNameIter(paramBlockString.begin(), paramBlockString.end(), paramNameRegex);
 			while (paramNameIter != iterEnd)
 			while (paramNameIter != iterEnd)
 			{
 			{
-				stdString = (*paramNameIter)[1];
+				if((*paramNameIter)[1].matched)
+					stdString = (*paramNameIter)[1];
+				else
+					stdString = (*paramNameIter)[2];
+
 				block.paramNames.push_back(String(stdString.begin(), stdString.end()));
 				block.paramNames.push_back(String(stdString.begin(), stdString.end()));
-				paramNameIter++;
+				++paramNameIter;
 			}
 			}
 
 
-			paramBlockIter++;
+			++paramBlockIter;
 		}
 		}
 
 
 		// Return string without param block definitions
 		// Return string without param block definitions

+ 6 - 4
BansheeD3D9RenderAPI/Source/BsD3D9RenderAPI.cpp

@@ -1474,7 +1474,7 @@ namespace BansheeEngine
 		dest[2][3] = (dest[2][3] + dest[3][3]) / 2;
 		dest[2][3] = (dest[2][3] + dest[3][3]) / 2;
 	}
 	}
 
 
-	GpuParamBlockDesc D3D9RenderAPI::generateParamBlockDesc(const String& name, Map<String, GpuParamDataDesc>& params)
+	GpuParamBlockDesc D3D9RenderAPI::generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params)
 	{
 	{
 		GpuParamBlockDesc block;
 		GpuParamBlockDesc block;
 		block.blockSize = 0;
 		block.blockSize = 0;
@@ -1482,10 +1482,12 @@ namespace BansheeEngine
 		block.name = name;
 		block.name = name;
 		block.slot = 0;
 		block.slot = 0;
 
 
-		// DX9 doesn't natively support parameter blocks but Banshee's emulation expects everything to be 16 byte aligned
-		for (auto& entry : params)
+		// DX9 doesn't natively support parameter blocks but Banshee's emulation expects everything to be 16 byte aligned.
+		// Iterate in reverse order because DX9's shader reflection API reports the variables in reverse order then they
+		// appear in code, and we want to match the auto-generated buffers that result from that layout.
+		for (auto riter = params.rbegin(); riter != params.rend(); ++riter)
 		{
 		{
-			GpuParamDataDesc& param = entry.second;
+			GpuParamDataDesc& param = *riter;
 
 
 			const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[param.type];
 			const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[param.type];
 			UINT32 size = typeInfo.size / 4;
 			UINT32 size = typeInfo.size / 4;

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

@@ -72,7 +72,7 @@ int CALLBACK WinMain(
 
 
 	__try
 	__try
 	{
 	{
-		EditorApplication::startUp(RenderAPIPlugin::DX11);
+		EditorApplication::startUp(RenderAPIPlugin::DX9);
 		EditorApplication::instance().runMainLoop();
 		EditorApplication::instance().runMainLoop();
 		EditorApplication::shutDown();
 		EditorApplication::shutDown();
 	}
 	}

+ 1 - 1
BansheeGLRenderAPI/Include/BsGLRenderAPI.h

@@ -177,7 +177,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @copydoc RenderAPICore::generateParamBlockDesc()
 		 * @copydoc RenderAPICore::generateParamBlockDesc()
 		 */
 		 */
-		GpuParamBlockDesc generateParamBlockDesc(const String& name, Map<String, GpuParamDataDesc>& params) override;
+		GpuParamBlockDesc generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params) override;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 				Internal use by OpenGL RenderSystem only                */
 		/* 				Internal use by OpenGL RenderSystem only                */

+ 6 - 4
BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -2123,7 +2123,7 @@ namespace BansheeEngine
 		return true; 
 		return true; 
 	}
 	}
 
 
-	GpuParamBlockDesc GLRenderAPI::generateParamBlockDesc(const String& name, Map<String, GpuParamDataDesc>& params)
+	GpuParamBlockDesc GLRenderAPI::generateParamBlockDesc(const String& name, Vector<GpuParamDataDesc>& params)
 	{
 	{
 		GpuParamBlockDesc block;
 		GpuParamBlockDesc block;
 		block.blockSize = 0;
 		block.blockSize = 0;
@@ -2131,10 +2131,8 @@ namespace BansheeEngine
 		block.name = name;
 		block.name = name;
 		block.slot = 0;
 		block.slot = 0;
 
 
-		for (auto& entry : params)
+		for (auto& param : params)
 		{
 		{
-			GpuParamDataDesc& param = entry.second;
-
 			const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[param.type];
 			const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[param.type];
 			UINT32 size = typeInfo.size / 4;
 			UINT32 size = typeInfo.size / 4;
 			UINT32 alignment = typeInfo.alignment / 4;
 			UINT32 alignment = typeInfo.alignment / 4;
@@ -2184,6 +2182,10 @@ namespace BansheeEngine
 			param.paramBlockSlot = 0;
 			param.paramBlockSlot = 0;
 		}
 		}
 
 
+		// Constant buffer size must always be a multiple of 16
+		if (block.blockSize % 4 != 0)
+			block.blockSize += (4 - (block.blockSize % 4));
+
 		return block;
 		return block;
 	}
 	}
 
 

+ 1 - 1
BansheeGLRenderAPI/Source/BsGLSLParamParser.cpp

@@ -431,7 +431,7 @@ namespace BansheeEngine
 		for (auto iter = foundStructs.begin(); iter != foundStructs.end(); ++iter)
 		for (auto iter = foundStructs.begin(); iter != foundStructs.end(); ++iter)
 			returnParamDesc.params.insert(std::make_pair(iter->first, iter->second));
 			returnParamDesc.params.insert(std::make_pair(iter->first, iter->second));
 
 
-		// Param blocks alway needs to be a multiple of 4, so make it so
+		// Param blocks always need to be a multiple of 4, so make it so
 		for (auto iter = returnParamDesc.paramBlocks.begin(); iter != returnParamDesc.paramBlocks.end(); ++iter)
 		for (auto iter = returnParamDesc.paramBlocks.begin(); iter != returnParamDesc.paramBlocks.end(); ++iter)
 		{
 		{
 			GpuParamBlockDesc& blockDesc = iter->second;
 			GpuParamBlockDesc& blockDesc = iter->second;

+ 21 - 0
RenderBeast/Include/BsStaticRenderableHandler.h

@@ -6,9 +6,30 @@
 #include "BsGpuParam.h"
 #include "BsGpuParam.h"
 #include "BsRenderableElement.h"
 #include "BsRenderableElement.h"
 #include "BsRenderBeast.h"
 #include "BsRenderBeast.h"
+#include "BsParamBlocks.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	BS_PARAM_BLOCK_BEGIN(PerFrameParamBuffer)
+		BS_PARAM_BLOCK_ENTRY(float, gTime)
+	BS_PARAM_BLOCK_END
+
+	BS_PARAM_BLOCK_BEGIN(PerCameraParamBuffer)
+		BS_PARAM_BLOCK_ENTRY(Vector3, gViewDir)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatView)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatProj)
+	BS_PARAM_BLOCK_END
+
+	BS_PARAM_BLOCK_BEGIN(PerObjectParamBuffer)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldViewProj)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorld)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorld)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatWorldNoScale)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvWorldNoScale)
+		BS_PARAM_BLOCK_ENTRY(float, gWorldDeterminantSign)
+	BS_PARAM_BLOCK_END
+
 	/**
 	/**
 	 * @brief	Renderable handler that manages initializing, updating and 
 	 * @brief	Renderable handler that manages initializing, updating and 
 	 * 			rendering of static renderable objects.
 	 * 			rendering of static renderable objects.

+ 1 - 0
TODOExperimentation.txt

@@ -19,6 +19,7 @@ Assign ViewOrigin, PreViewTranslation, TransViewProj
    - https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html
    - https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html
  - Replace param buffer generation by using a dummy shader with manual generation
  - Replace param buffer generation by using a dummy shader with manual generation
    - Test if this works on all rendder APIs (initially dont delete the old code so I can compare offsets)
    - Test if this works on all rendder APIs (initially dont delete the old code so I can compare offsets)
+    - Problem with DX9, parameters seem to be in different order, plus block buffer size is 4 instead of 52 (for perCamera buffer)
 
 
 Next week:
 Next week:
  - Deferred base and light passes use different PerCamera buffers, unify them (both in shader and in code)
  - Deferred base and light passes use different PerCamera buffers, unify them (both in shader and in code)