Browse Source

Fixed linker issues with command queue
Fixed an issue where material was getting constantly switched every frame for GUIElements because GUI element mesh updates were done at the wrong time

Marko Pintera 12 years ago
parent
commit
7c0bafc517

+ 3 - 3
BansheeEngine/Source/BsGUIManager.cpp

@@ -507,7 +507,7 @@ namespace BansheeEngine
 					renderData.cachedMeshes.push_back(Mesh::create());
 				}
 
-				gMainSyncedCA().writeSubresource(renderData.cachedMeshes[groupIdx].getInternalPtr(), 0, meshData);
+				gMainCA().writeSubresource(renderData.cachedMeshes[groupIdx].getInternalPtr(), 0, meshData);
 
 				groupIdx++;
 			}
@@ -528,7 +528,7 @@ namespace BansheeEngine
 
 		data->setColorAt(mCaretColor, 0, 0);
 
-		gMainSyncedCA().writeSubresource(tex.getInternalPtr(), tex->mapToSubresourceIdx(0, 0), data);
+		gMainCA().writeSubresource(tex.getInternalPtr(), tex->mapToSubresourceIdx(0, 0), data);
 	}
 
 	void GUIManager::updateTextSelectionTexture()
@@ -545,7 +545,7 @@ namespace BansheeEngine
 
 		data->setColorAt(mTextSelectionColor, 0, 0);
 
-		gMainSyncedCA().writeSubresource(tex.getInternalPtr(), tex->mapToSubresourceIdx(0, 0), data);
+		gMainCA().writeSubresource(tex.getInternalPtr(), tex->mapToSubresourceIdx(0, 0), data);
 	}
 
 	bool GUIManager::onMouseDragEnded(const CM::PositionalInputEvent& event)

+ 7 - 16
CamelotCore/Include/CmCommandQueue.h

@@ -8,7 +8,7 @@
 
 namespace CamelotFramework
 {
-	class CM_EXPORT CommandQueueNoSync
+	class CommandQueueNoSync
 	{
 	public:
 		CommandQueueNoSync() {}
@@ -29,7 +29,7 @@ namespace CamelotFramework
 
 	};
 
-	class CM_EXPORT CommandQueueSync
+	class CommandQueueSync
 	{
 	public:
 		CommandQueueSync()
@@ -97,16 +97,9 @@ namespace CamelotFramework
 		/**
 		 * @brief	Constructor.
 		 *
-		 * @param	threadId	   	Identifier for the thread the command queue will be used on.
-		 * @param	allowAllThreads	Only matters for debug purposes. If false, then the queue
-		 * 							will throw an exception if accessed outside of the creation thread
-		 * 							(If in debug mode).
-		 * 							
-		 *							When you want to allow multiple threads to access it, set this to true,
-		 *							and also make sure you sync access to the queue properly.
-		 *							
+		 * @param	threadId	   	Identifier for the thread the command queue will be used on.						
 		 */
-		CommandQueueBase(CM_THREAD_ID_TYPE threadId, bool allowAllThreads = false);
+		CommandQueueBase(CM_THREAD_ID_TYPE threadId);
 		virtual ~CommandQueueBase();
 
 		CM_THREAD_ID_TYPE getThreadId() const { return mMyThreadId; }
@@ -194,8 +187,6 @@ namespace CamelotFramework
 	private:
 		CamelotFramework::Queue<QueuedCommand>::type* mCommands;
 
-		bool mAllowAllThreads;
-		
 		CM_THREAD_ID_TYPE mMyThreadId;
 
 		// Various variables that allow for easier debugging by allowing us to trigger breakpoints
@@ -240,14 +231,14 @@ namespace CamelotFramework
 	 * @copydoc CommandQueueBase
 	 */
 	template<class SyncPolicy = CommandQueueNoSync>
-	class CM_EXPORT CommandQueue : public CommandQueueBase, public SyncPolicy
+	class CommandQueue : public CommandQueueBase, public SyncPolicy
 	{
 	public:
 		/**
 		 * @copydoc CommandQueueBase::CommandQueueBase
 		 */
-		CommandQueue(CM_THREAD_ID_TYPE threadId, bool allowAllThreads = false)
-			:CommandQueueBase(threadId, allowAllThreads)
+		CommandQueue(CM_THREAD_ID_TYPE threadId)
+			:CommandQueueBase(threadId)
 		{ }
 
 		~CommandQueue() 

+ 0 - 1
CamelotCore/Include/CmCoreThread.h

@@ -3,7 +3,6 @@
 #include "CmPrerequisites.h"
 #include "CmModule.h"
 #include "CmCommandQueue.h"
-#include "CmCoreThreadAccessor.h"
 
 namespace CamelotFramework
 {

+ 1 - 0
CamelotCore/Include/CmCoreThreadAccessor.h

@@ -7,6 +7,7 @@
 #include "CmSamplerState.h"
 #include "CmGpuProgram.h"
 #include "CmCoreThread.h"
+#include "CmAsyncOp.h"
 #include "CmColor.h"
 
 namespace CamelotFramework

+ 4 - 4
CamelotCore/Source/CmCommandQueue.cpp

@@ -7,8 +7,8 @@
 namespace CamelotFramework
 {
 #if CM_DEBUG_MODE
-	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId, bool allowAllThreads)
-		:mMyThreadId(threadId), mAllowAllThreads(allowAllThreads), mMaxDebugIdx(0)
+	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId)
+		:mMyThreadId(threadId), mMaxDebugIdx(0)
 	{
 		mCommands = cm_new<CamelotFramework::Queue<QueuedCommand>::type, PoolAlloc>();
 
@@ -19,8 +19,8 @@ namespace CamelotFramework
 		}
 	}
 #else
-	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId, bool allowAllThreads)
-		:mMyThreadId(threadId), mAllowAllThreads(allowAllThreads)
+	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId)
+		:mMyThreadId(threadId)
 	{
 		mCommands = cm_new<CamelotFramework::Queue<QueuedCommand>::type, PoolAlloc>();
 	}

+ 2 - 1
CamelotCore/Source/CmCoreThread.cpp

@@ -1,4 +1,5 @@
 #include "CmCoreThread.h"
+#include "CmCoreThreadAccessor.h"
 
 namespace CamelotFramework
 {
@@ -11,7 +12,7 @@ namespace CamelotFramework
 		, mSyncedCoreAccessor(nullptr)
 	{
 		mCoreThreadId = CM_THREAD_CURRENT_ID;
-		mCommandQueue = cm_new<CommandQueue<CommandQueueSync>>(CM_THREAD_CURRENT_ID, true);
+		mCommandQueue = cm_new<CommandQueue<CommandQueueSync>>(CM_THREAD_CURRENT_ID);
 
 		initCoreThread();
 	}

+ 4 - 2
CamelotUtility/Include/CmThreadDefines.h

@@ -38,6 +38,8 @@ THE SOFTWARE
 #include <boost/thread/shared_mutex.hpp>
 #include <boost/thread/locks.hpp>
 
+#include <thread>
+
 #define CM_AUTO_MUTEX mutable boost::recursive_mutex CM_AUTO_MUTEX_NAME;
 #define CM_LOCK_AUTO_MUTEX boost::recursive_mutex::scoped_lock cmAutoMutexLock(CM_AUTO_MUTEX_NAME);
 #define CM_MUTEX(name) mutable boost::recursive_mutex name;
@@ -68,8 +70,8 @@ THE SOFTWARE
 #define CM_THREAD_CREATE(name, worker) boost::thread* name = new (CamelotFramework::MemoryAllocator<CamelotFramework::GenAlloc>::allocate(sizeof(boost::thread))) boost::thread(worker);
 #define CM_THREAD_DESTROY(name) CamelotFramework::cm_delete<CamelotFramework::GenAlloc, boost::thread>(name);
 #define CM_THREAD_HARDWARE_CONCURRENCY boost::thread::hardware_concurrency()
-#define CM_THREAD_CURRENT_ID boost::this_thread::get_id()
-#define CM_THREAD_ID_TYPE boost::thread::id
+#define CM_THREAD_CURRENT_ID std::this_thread::get_id()
+#define CM_THREAD_ID_TYPE std::thread::id
 #define CM_THREAD_WORKER_INHERIT
 // Utility
 #define CM_THREAD_SLEEP(ms) boost::this_thread::sleep(boost::posix_time::millisec(ms));

+ 23 - 3
TODO.txt

@@ -12,9 +12,29 @@ Optimization notes:
  - GUIManager updateMeshes seems to be executing every frame
 
 WEIRDNESS:
-Using gMainCA instead of gSyncedMainCA in GUIManager causes linker errors
-Calling syncedCA->submit in Application::update instead of GUIManager causes the textures to constantly switch out every frame
- - Calling it right after GUIManager::update also works, but if I call it after BsApp update it doesnt!? Even though nothing is done in BsApp update except for calling GUIManager::update...
+In GUIManager in 2 places I compare stuff by address. Make sure to use mesh or material address instead of material group address is isn't completely random
+A lot of stuff is still using GSyncedMainCA but it should be using gMainCA
+
+
+My idea of what is happening:
+ Update mesh commands for GUI elements get submitted on sync CA
+ Render commands for GUI elements gets submitted non-sync CA
+ Update mesh commands are executed before non-sync CA, old render commands now containing wrong mesh/material combinations
+
+
+ Temporarily disabled:
+ ProfilerOverlay
+ Helper windows
+ TestTextSprite
+ DebugAABoxDraw
+ Main menu items
+ Window frame
+
+Added a couple of debug logs in GUIManager::render
+
+
+
+
 
 TODO: Viewport can be modified from the sim thread, but is used on the core thread without any syncronization mechanisms. Maybe add a method that returns VIEWPORT_DATA, and have that used on the core thread.