Hello guys,
I want to implement a loading screen for my game. Resources such as texture should be loaded without blocking the main thread to deal with Monogame APIs. How can I make resource loading in a worker thread? It is sufficient if the method only works on Windows DirectX platforms. I welcome such a method rather than being dragged down by the circumstances of other platforms.
I know the usual answer for the situation is processing the resource loading queue in the remaining time of Draw
method until the next frame. But loading each resource may take more time than the remaining time. It causes frame rate drop. Therefore I hope other worker threads to load resources than the main thread.
I read a source code of ContentManager and I found it looks thread-safe, but the Microsoft document says ID3D11DeviceContext::UpdateSubresource
is not thread-safe so that Texture2DReader.Read
which calls ID3D11DeviceContext::UpdateSubresource is also not thread-safe. When I tried ignoring this and creating and executing code to load textures in a worker thread, the program did not stall or fail to use the textures that were supposed to be loaded. However, since the code is not thread-safe, this is just a coincidence. Therefore, simply calling ContentManager.Load<Texture2D>
method in the worker thread is not an appropriate approach.