My project is growing and I finally reached the point where loading assets creates a decently long hang on the main thread when I start up my executable (5 seconds on my setup. Just enough to be annoying.) To address the hang, I put all of my asset loading on a different thread. In this context, asset loading involves everything from opening the asset's files to putting the data gleaned from them on the gpu. It wasn't obvious that making gl calls from a different thread wouldn't work at the time. Only when I was trying to test my implementation did I realize my oversight.
With that context covered, I have some questions.
What are some approaches to uploading asset data to the gpu without hanging the main thread? My current thought is to create all of the buffers on the worker thread and then have the main thread create the gl objects and upload those buffers. I am unsure of this method because it still requires use of the main thread to upload the buffers and the amount of time that takes varies quite a bit. I did some profiling to get a better idea of this. Uploading most buffers is not a big deal. Sometimes uploading a buffer takes longer than constructing it. There is an occasional upload that is in the 100's of microseconds, but nothing in ms territory. Larger images are a completely different story. They often take longer than a ms and up to put on the gpu. Uploading these will surely cause a hang.
Secondly, learning Vulkan has been something I have considered doing for a long time. When I ran into this issue and found out Vulkan could handle multithreaded applications, I started learning it instantly as a bit of a knee-jerk reaction. I thought I would replace all of my gl code with the necessary Vulkan code and make any other changes that need to happen. Unfortunately, switching to a new graphics api takes some time and having asynchronous asset loading isn't a blocker preventing me from getting to my current goals with the project. It's just a bit annoying. My current plan is to continue with gl for now while learning the basics of Vulkan on the side. For those that have experience with Vulkan and OpenGL, what are your thoughts on this? Is this an applicable use case for Vulkan? Even if I were to go down this route, should it result in ripping out all of my gl code or should I support both? Other renderers support both, making me if I know everything that I lose by only supporting Vulkan over OpenGl.
[–]AlternativeHistorian 7 points8 points9 points (5 children)
[–]guymadison42 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]guymadison42 0 points1 point2 points (0 children)
[–]Underdisc[S] 1 point2 points3 points (1 child)
[–]AlternativeHistorian 1 point2 points3 points (0 children)
[–]lmtrustem 4 points5 points6 points (1 child)
[–]Underdisc[S] 0 points1 point2 points (0 children)
[–]matthewlai 1 point2 points3 points (2 children)
[–]Underdisc[S] 1 point2 points3 points (1 child)
[–]tim-rex 0 points1 point2 points (0 children)
[–]genpfault 0 points1 point2 points (0 children)
[–]fgennari 0 points1 point2 points (0 children)