9 ms·
Multithreading for Game Engines
- vvanders 6y agoWhile broadly right this has some inaccurate parts, in particular: > If we were talking about OpenGL, there would be absolutely nothing you can do. In OpenGL or other older APIs, it’s only possible to do API calls from one thread. Isn't really true. You can load textures off thread[1] and other things which come in handy. Vulkan expands that but I've done multithreaded texture loading for instance almost a decade ago. This is particular important if your not loading compressed textures as there's usually a tiling/swizzle pass and the texture copy can be significant on large textures(unless you're using something like eglCreateImageKHR). [1] https://www.khronos.org/opengl/wiki/OpenGL_and_multithreading https://www.khronos.org/opengl/wiki/OpenGL_and_multithreadin...
- hertzrat 6y ago> Unreal Engine 4 is open source Another small mistake here as well. The source is available to read and modify under license but it’s not open source
- xyzzy_plugh 6y agoThe fact that this "mistake" occurs so frequently and is so trivial to make just tells me that the meaning you want it to have will not survive in the long run. You are correct that it isn't Open Source as defined by the Open Source Initiative, nor does it use an Open Source Initiative Approved License. None of that information, however, is helpful to the author or really changes anything about the article.
- willis936 6y agoJust because there are people who don’t understand what “free as in beer” means doesn’t mean that people should stop teaching them what it means.
- JohnJamesRambo 6y agoI have never understood what the hell "free as in beer" means either.
- dodobirdlord 6y agoIf you see a sign advertising “Free Beer” you understand that the meaning of “free” in this context means “goods and/or services available at no cost”. The English word “free” means a lot of things and the meaning of “free” in the expression “Free Beer” is very different from the meaning in the expression “Free Speech”, where it is used to mean “not legally restricted”.
- JohnJamesRambo 6y agoI guess I just don't know any places that have free beer.
- garmaine 6y ago"Free beer" is often used to describe a social or work gathering. If the host/company pays for drinks, it's "free beer." As in, "hey come to the seminar with me on Thursday: there's pizza and free beer."
- humbledrone 6y agoIt's confusing to me too when it's phrased that way. Stallman's original quote makes much more sense, "Think free as in free speech, not free beer." In other words, contrasting free as in "no restrictions", versus free as in "no cost".
- dijit 6y agoGratis vs Libre. Even as a non-latin speaking person I can identify the difference between those types of "free". Or, alternatively "Free as in Freedom", which is another phrase I've heard coming from the FSF.
- skohan 6y agoIt's an extremely important distinction. There's a term for software like Unreal Engine, which is "source available", and the difference between this and "open source" has massive categorical differences in terms of what you can legally do with this source code. If an important distinction like this is fading from our language, it's probably evidence that newer members of the community haven't been fully educated on the implications of software licensing terms, and if that's the case we should focus on improving that education, not resign ourselves to important knowledge being lost by the community. For instance, if you learned that young people were not aware of the dangers of exposure to lead, you would not throw up your hands and say: "I guess we'll just start using lead pipes again". You would make an effort to pass on that knowledge.
- MaxBarraclough 6y agoThis topic turned up on HN 6 weeks ago: https://news.ycombinator.com/item?id=26079067 https://news.ycombinator.com/item?id=26079067 I agree with your position. Open Source is not a meaninglessly unclear term, it is a precise term of art. It makes good sense to resist efforts to turn it into a meaningless marketing term like premium. Some people point out that the term isn't trademarked. That doesn't matter. That isn't how terms of art work.
- ekianjo 6y agoBecause "open source" means absolutely nothing. We should use "Libre/Free Software" or refer to actual licenses to be more accurate.
- yellowapple 6y agoExcept "open source" does have a meaning - specifically, the one defined by the Open Source Initiative.
- tremon 6y agoStallman already wrote years ago why "open source" was a bad name. From https://www.gnu.org/philosophy/open-source-misses-the-point.html https://www.gnu.org/philosophy/open-source-misses-the-point.... : The official definition of “open source software” [..] agrees with our definition in most cases. However, the obvious meaning for the expression “open source software”—and the one most people seem to think it means—is “You can look at the source code.” That criterion is much weaker than the free software definition, much weaker also than the official definition of open source. [..] Since the obvious meaning for “open source” is not the meaning that its advocates intend, the result is that most people misunderstand the term.
- remram 6y ago"Free" is also ambiguous in English, even more than "open". I suppose "libre" is explicit but also not an actual common word. "Open" is clear, widely accepted by the community including businesses, and is defended by the Open Source Initiative (think of them what you will, they do a good job of keeping that definition true, by doing things such as approving licenses). "Open" has also been extended to other areas, such as "open science" (which does not refer to science for which a paper is available, but to actual reusable science). I don't see any problem with "open", other than the fact RMS doesn't like it.
- garmaine 6y ago> "Open" has also been extended to other areas, such as "open science" (which does not refer to science for which a paper is available, but to actual reusable science). That meaning predates the use of "open" to describe software, hence why "open source" isn't that great of a term for something truly new. It co-opts the much older term "open source" which means freely available through non-protected sources. Like, in the intelligence services "open sources" has meant non-classified, non-restricted sources. There's a similar meaning in journalism.
- swalsh 6y agoI call it "source available"
- Bekwnn 6y agoI've always referred to it as "(has) source access". It is a bit frustrating and misleading when people refer to it as open source.
- brobdingnagians 6y agoLanguage develops according to how people actually use it. There are two competing camps on the meaning of "open source"; I understand why there is a battle over it on ideological grounds, but I don't think it is necessarily a mistake, more of a different side of the debate. Much like how some people are pedantic about calling them "tissues", while a large body of people know the difference but just go on calling it kleenex. Not wrong, just a different culture of usage.
- hvis 6y agoOne of the camps are members of the open source movement (developers, promoters and satisfied users) and the other comes from corporations trying to co-opt the term and its good reputation. It's not really a "everyone has a right to an opinion" type of situation. You can go on and support the dilution of the term, just remember when the software development culture has another turn to the worst, you had been a part of the problem.
- deleted 6y ago[deleted]
- Jasper_ 6y agoIn my experience, even the best Android drivers just took locks when using OpenGL from multiple threads, even for resource creation, so it's sort of moot.
- vvanders 6y agoThat depends largely on the driver. It's not a guarantee but I've seen pretty solid perf wins on the drivers that support it. From a hardware perspective just about every Android SoC minus a few odd ones have unified memory so there's really no reason for them to take a lock, at least for the heavy part of the operations that copy the texture and tile/swizzle.
- withinboredom 6y ago> just about every Android SoC minus a few odd ones All those users will leave you a one star review when it crashes on their device.
- Cullinet 6y agosometimes I cry a little over the fact that people who only have access to under powered phones are the most incentivised to criticise apps despite being consigned to ultimate futility regardless of their actions, whilst it's a rare occasion when the owner of a flagship phone is going to give feedback of any kind about performance to the developers of a poorly performing app that may be software atrocities but given more hardware than the average high end laptop to consume...
- kevingadd 6y agoThreaded OpenGL is something you only do if you either have a death wish or a phone number you can dial to speak to a VP at NVIDIA. Everyone I know who's shipped it in games regretted it, and I've had driver developers explicitly tell me I shouldn't bother. Vulkan is indeed threading-friendly, though.
- Arelius 6y agoYeah, it’s technically supported, and I have seen the patient ship it in limited use. But it’s certinally not a well tested path and the stability leaves a lot to be desired.
- josefx 6y agoI work on a program that consistently uses it read and load large textures. Never had an issue with it outside of getting the barriers right.
- gmueckl 6y agoLoading buffers and textures are about the only things that are kind of stable in multithreaded OpenGL. This is the probably the only use case anybody cares about. Go beyond that and you'll have a high chance to hit strange driver bugs.
- vblanco 6y agoGood catch, i was unaware that loading textures off threads in opengl was possible, given that ive never seen it used even on commercial engines. Ill update the article to reflect that.
- Cullinet 6y agothis immediately reminded me of SGI's Open Performer and the subsequent failed OpenGL++ efforts : https://en.m.wikipedia.org/wiki/OpenGL_Performer https://en.m.wikipedia.org/wiki/OpenGL_Performer
- Animats 6y ago"Unreal Engine 4 will have a Game Thread and a Render Thread ..." This seems dated. UE4 shipped in 2015.
- jayd16 6y agoProbably just poor word choice. Links from 2018 and maybe younger are referenced.
- geswit2x 6y ago>”Unreal 4 will have...” Unreal Engine 5 is coming...
- ozarker 6y agoIt's just badly worded. I remember following this blog last year when new articles were being posted.
- m12k 6y agoIMO the Burst compiler that can "jobify" and multi-thread your code relatively painlessly is the most impressive piece of tech Unity has produced (disclosure: used to work there, though this was made after my time there). It's not that hard to fit into its constraints, and it often provides 2x-200x speedups. It's still mind-boggling to me that it's possible to get (a constrained subset of) C# to beat hand-optimized C++.
- vanderZwan 6y agoIs there a technical write-up of what it does and how it works somewhere? I'm not about to write any games, let alone use Unity, so Unity-specific tutorials wouldn't really help me (plus they're just going to be focused on how to use it, not on how it works).
- sharpercoder 6y agohttps://xoofx.com/blog/2019/03/28/behind-the-burst-compiler/ https://xoofx.com/blog/2019/03/28/behind-the-burst-compiler/
- vanderZwan 6y agoThanks!
- jstimpfle 6y ago> It's still mind-boggling to me that it's possible to get (a constrained subset of) C# to beat hand-optimized C++. To me the interesting question is -- what can you do within this constrained subset?
- camjw 6y agoThe restrictions are: no reference types, manually manage your memory. My previous job was basically writing loads of burst code and it was so ergonomic and fun to write, and (as the GP says) you basically get 200x speed up for free.
- 6y ago
- bullen 6y agoWhen you multi-thread the rendering you _always_ push the motion-to-photon latency up, because you need to hand off the previous work to the renderer, sometimes by up to 10 frames!? That's is why AAA titles like the last guardian and RDR2 are unplayable. The only way to solve this is to make the GPU concurrent so it can receive instuctions on separate threads at the same time!
- HelloNurse 6y ago"To make the GPU concurrent so it can receive instructions on separate threads at the same time" has been one of the major reasons to use Vulkan instead of OpenGL since the beginning, it isn't only a wish. Reducing dependencies and organizing scheduling of simulation and rendering tasks in order to perform useful work in parallel, both on the CPU and the GPU, remains challenging, but an important bottleneck has been lifted. What horrible practices can introduce 10 frames of latency, besides generic slowness and gratuitous buffering?
- bullen 6y agoI don't think you can send instructions on multiple cores at the same time with Vulkan, if so why is it so hard to find examples of it?
- HelloNurse 6y agoYou can both build command buffers simultaneously (example by Sascha Willems: https://github.com/SaschaWillems/Vulkan/blob/master/examples/multithreading/multithreading.cpp https://github.com/SaschaWillems/Vulkan/blob/master/examples...) and submit unrelated command buffers to different queues simultaneously. Using multiple queues is not difficult, just somewhat rare: there should never be so many command submissions that parallelization matters for quantitative performance reasons, it's a niche for unusually independent and/or asynchronous tasks.
- bullen 6y agoBut I have to use commandbuffers right? I prefer direct/forward rendering... I wish you could do that directly to the GPU with multiple cores... I heard you "can" do that with OpenGL... but I don't think it accepts more than one context simoultaneously.
- Dowwie 6y agoDoes anyone know of a collection of coding problems like "Dining Philosophers" for working through common concurrency scenarios and synchronization issues?
- vanderZwan 6y agoI assume you're already familiar with Rosetta Code and are asking for something subtly different? https://rosettacode.org/wiki/Dining_philosophers https://rosettacode.org/wiki/Dining_philosophers
- Dowwie 6y agoThis is what I was referring to. I'm looking for a collection of these.
- IdiocyInAction 6y agoThere's the "Little Book of Semaphores".
- imtringued 6y agoHere is an easy (or extremely hard) problem. Build a 2d grid with two objects. A chest and a hopper. Chests and hoppers are containers that hold up to 64 items. When a hopper (they can point in 4 directions) is pointing at a chest it will insert its inventory into the chest, until the chest is full (one item at a time). If there is a chest on the funnel side of the hopper then extract items from the chest and put the items into the hopper (again one item at a time). Chaining hoppers is allowed. Now go out and enjoy multithreading hell. Hint: through weird contortions it is possible to do this without any synchronization and keep it data parallel at the same time. If you did this in a production codebase you would be the only person on the planet that will understand the code.
- tempnowreal 6y agoCan someone point me to good sourced where I can learn more about the inner workings of graphics? Something thats probably beginner friendly?
- wernsey 6y agoGabriel Gambetta's book Computer Graphics from Scratch is available freely online and was discussed here just the other day: https://gabrielgambetta.com/computer-graphics-from-scratch/ https://gabrielgambetta.com/computer-graphics-from-scratch/ Another link I found interesting is this one: https://github.com/ssloy/tinyrenderer/wiki https://github.com/ssloy/tinyrenderer/wiki