{"id":35550,"date":"2016-11-22T06:00:24","date_gmt":"2016-11-22T10:00:24","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=35550"},"modified":"2016-11-22T20:06:12","modified_gmt":"2016-11-23T00:06:12","slug":"this-dumb-industry-what-is-vulkan","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=35550","title":{"rendered":"This Dumb Industry: What is Vulkan?"},"content":{"rendered":"<p>People have been asking me about Vulkan. Maybe you&#8217;ve seen it in the gaming news: Vulkan is coming! Vulkan is the next big thing! Developers are excited about Vulkan! Being a naturally curious gamer, you want to know what this new thing is and what it means. So you <a href=\"https:\/\/en.wikipedia.org\/wiki\/Vulkan_(API)\">look it up<\/a>, and you find something to the effect of:<\/p>\n<blockquote><p>Vulkan is a graphics and compute API from Kronos Group that provides high-efficiency, cross-platform access to modern GPU.<\/p><\/blockquote>\n<p>It&#8217;s a definition that explains one thing you don&#8217;t know in terms of half a dozen other words you don&#8217;t know. All you know is that it has something to do with graphics, and figuring out what this is and why it&#8217;s happening is starting to look like more trouble than it&#8217;s worth.<\/p>\n<p>Sorry about that. We programmers are really bad at explaining things. We over-use jargon and are generally bad at adjusting explanations for non-technical people. But you&#8217;re in luck. While all the other programmers are min-maxers who dumped their skill points into logic and mathematics or whatever, I actually snuck a few points into communication skills. So I think I can untangle this for you.<\/p>\n<p>But we are going to need just a little bit of jargon. Going back to that original definition of Vulkan, there&#8217;s at least one mystery term we need to sort out. That&#8217;s this one:<\/p>\n<p><!--more--><\/p>\n<h3>API<\/h3>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/tdi_vulkan_code.jpg' width=100% alt='Light text on a black background? For coding? Heresy!' title='Light text on a black background? For coding? Heresy!'\/><\/div><div class='mouseover-alt'>Light text on a black background? For coding? Heresy!<\/div><\/p>\n<p>You don&#8217;t actually need to know what this stands for. It doesn&#8217;t matter. It&#8217;s just an acronym of more jargon<span class='snote' title='1'>&#8221;Application Programming Interface&#8221;. See? Not very interesting.<\/span>, and if we try to define those terms then we&#8217;ll end up needing to define other terms and we&#8217;d be here all day. For our purposes, API is just a tool. Or actually it&#8217;s a way of using a tool made by other programmers.<\/p>\n<p>See, back in the day &#8211; and I mean WAY back in the day &#8211; back in the days of big iron, mainframes, and punch cards &#8211; back when I was just a wee baby Shamus<span class='snote' title='2'><img decoding=\"async\" src=\"images\/archer_seamus.jpg\"><\/span> &#8211; most projects were written from scratch. You need to sort a list of stuff in alphabetical order, or handle something the user typed, or print something out? You just sit down and hammer it out yourself. It&#8217;s not like you could go on the internet and ask for help. The web didn&#8217;t exist yet.<\/p>\n<p>But as time went on, things began to get complicated. So maybe a game developer is working on sound code. In the early days, it&#8217;s easy. You just write a little code to have the speaker blurt out one sound. But as the years go on, and games become more complex, you sometimes need to layer many sounds together. And you need sounds to pan between left \/ right speakers so the player can tell where that monster is coming from. Distance attenuation. Surround sound. Doppler effects. Reverb.<\/p>\n<p>Eventually our hard-working programmer will think to themselves, &#8220;Gosh. It sure is a lot of work to add all of these features to my sound code. Hang on. I&#8217;m obviously not the first person to write something like this. Lots of other people must have written sound code. Maybe I can use their solution instead of writing my own, and I&#8217;ll be able to spend more time working on the game parts of my videogame.&#8221; So they go out and see if anyone else has already solved the problem and is willing to share.<\/p>\n<p>Sometimes a programmer will share their solution out of the kindness of their heart. Sometimes they charge money for it. In any case, when a programmer bundles a bunch of code like this for other people to use, it&#8217;s called a library. You can think of a library as a black box. You know what it does and how to use it, but you have no idea how it works inside. You can find out if you want, of course. Assuming you&#8217;ve got the source code, you can just read it to see how the library works inside. But to a certain extent this would defeat the purpose of using a library in the first place. You don&#8217;t want to have to worry about reading someone else&#8217;s code. You just want to plug it in and have it work.<\/p>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/tdi_vulkan_controls.jpg' width=100% alt='Look, don&apos;t make me read the manual. Just tell me which one of these buttons I need to press to get it to do the thing.' title='Look, don&apos;t make me read the manual. Just tell me which one of these buttons I need to press to get it to do the thing.'\/><\/div><div class='mouseover-alt'>Look, don&apos;t make me read the manual. Just tell me which one of these buttons I need to press to get it to do the thing.<\/div><\/p>\n<p>So API is how your program talks to this library. It is the control panel by which you manipulate what&#8217;s going on inside the black box. Maybe this sound library has a function to begin a new sound or set the volume of the sound effects. But if for some reason the programmer that made the library forgot to add a function to lower the volume, then you wouldn&#8217;t be able to do that. Which would kind of make this particular library useless. <\/p>\n<p>The programmers out there are likely freaking out by this point because I&#8217;m being sloppy with terms and making broad over-simplifications. But I&#8217;m okay with that. This need for precision at all times is one of the reasons they&#8217;re sometimes bad at explaining things to non-coders. <\/p>\n<p>There is a certain art to making a good API. You want the controls to be as simple as possible without taking away functionality. A well-designed library should be obvious to use and shouldn&#8217;t require you to worry about any messy details of what might be going on inside of that black box. <\/p>\n<p>When you&#8217;re using a toaster, you don&#8217;t care about the voltage the device is using, the temperature of the heating coils, or the specific electrical resistance being used by the heating elements. You just know you want your toast to be medium. If a toaster forced you to worry about all those details, then the controls would be too complicated. If it just had an on and off button with no way to choose how dark to make the toast, then it would be too simple. A good API should be designed to hit that sweet spot between complexity and features, and it should gracefully hide everything you don&#8217;t need to worry about.<\/p>\n<p>But Vulkan isn&#8217;t a sound library, and you&#8217;ve hopefully already figured out that it&#8217;s not a toaster. It&#8217;s a graphics library. So now it&#8217;s time to talk about just one more bit of jargon:<\/p>\n<h3>OpenGL<\/h3>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier2_6.jpg' width=100% alt='Images are made from polygons. Polygons are made from pixels. Pixels are made from code. Code is made from caffeine, madness, and profanity.' title='Images are made from polygons. Polygons are made from pixels. Pixels are made from code. Code is made from caffeine, madness, and profanity.'\/><\/div><div class='mouseover-alt'>Images are made from polygons. Polygons are made from pixels. Pixels are made from code. Code is made from caffeine, madness, and profanity.<\/div><\/p>\n<p>If you&#8217;ve done any PC gaming over the years, you&#8217;ve probably heard the term OpenGL, even if you didn&#8217;t know what it was or why you should care. <\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/OpenGL\">OpenGL<\/a> stands for Open Graphics Library. It&#8217;s a library for making graphics happen. It&#8217;s one of only two libraries that can accomplish this. Any game made in the last 20 years or so is going to use either DirectX or OpenGL to draw polygons using your graphics card<span class='snote' title='3'>Yes, there are occasionally <a href=\"?p=890\">obscure examples<\/a> that don&#8217;t use either, but let&#8217;s keep this simple.<\/span>. I don&#8217;t care if the game looks like Crysis or Minecraft, somewhere between the game and the stuff that shows up on your monitor, you&#8217;ve got either DirectX or OpenGL making those visuals happen. At least, on personal computers. Let&#8217;s leave consoles out for now, since that&#8217;s another whole can of worms.<\/p>\n<p>The problem with DirectX is that it was created by Microsoft and they decide where it will be available, which tends to be limited to Microsoft devices.<\/p>\n<p>But now you&#8217;re asking, &#8220;Shamus, what about game engines like Unity, Frostbite, or the Unreal Engine?&#8221; <\/p>\n<p>Well, I was hoping you wouldn&#8217;t bring this up, but now you&#8217;ve forced my hand. Graphics libraries are complicated. So complicated that it&#8217;s tempting to take the black box and stick it inside of <em>another<\/em> box to hide away some of the complexity. If you were to open up the black box of a modern game engine, you&#8217;d find they contain either OpenGL or DirectX. Or even both.<\/p>\n<p>Game &raquo; Engine &raquo; OpenGL &raquo; GFX Driver &raquo; GFX Card &raquo; Monitor &raquo; YOUR AMAZED EYEBALLS<\/p>\n<p>OpenGL dates all the way back to 1991. You may notice that this is several years before the first consumer-level graphics cards appeared. I know it&#8217;s strange to think about today, but there was a time when games didn&#8217;t require special graphics hardware. Games drew their simple graphics using nothing more than the processor that was already busy running the rest of the computer. As you can imagine, this was pretty slow.<\/p>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/tdi_vulkan_pc.jpg' width=100% alt='Man, I get exhausted just remembering what it was like to move these things around. What was the case made of? Lead?' title='Man, I get exhausted just remembering what it was like to move these things around. What was the case made of? Lead?'\/><\/div><div class='mouseover-alt'>Man, I get exhausted just remembering what it was like to move these things around. What was the case made of? Lead?<\/div><\/p>\n<p>Rendering graphics was very different in 1991 than it is today. Few games did 3D graphics, and those that did probably relied on flat-color polygons with no lighting effects. Over the years we&#8217;ve introduced texture maps, transparency, lighting, fog, shadows, specular effects, bump mapping, god rays, subsurface scattering, refraction, ambient occlusion, depth of field, motion blur, and dozens of other things. OpenGL grew in complexity as we came up with newer, better, faster ways of drawing things. <\/p>\n<p>More importantly, we keep adding more and more processors to graphics cards, which means they can draw more things at the same time. If you&#8217;ve got a kitchen with one chef, it doesn&#8217;t matter how you send him the orders, since he can only do one at a time. But if you have fifty chefs then you can theoretically prepare things fifty times faster, but only if you can organize them so the entire group is always busy. So a lot of changes have been made to OpenGL to keep your graphics card as busy as possible. But this means changing the entire way you approach rendering. To do that, the authors of OpenGL needed to add a lot more buttons to the outside of the OpenGL black box. Every few years there was a new gizmo added on, a new way of doing things. <\/p>\n<p>The trick is that you don&#8217;t want to remove the old things from OpenGL. You need to leave them there because some people are still using them. Sure, a modern AAA game should <strong>not<\/strong> be using the old ways, but OpenGL isn&#8217;t just used by AAA studios. It&#8217;s used by hobby projects, retro games, old engines, educational projects, and non-game applications like CAD and such. There&#8217;s a whole world of different projects out there who use the old bits of OpenGL because they&#8217;re so much simpler than the new ways, and because performance isn&#8217;t a priority for them.<\/p>\n<p>But adding to a system like this causes a new problem, which is&#8230; <\/p>\n<h3>Cruft<\/h3>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/tdi_vulkan_cruft.jpg' width=100% alt='Damn it, I said cruft, not crust. Stupid stock photos.' title='Damn it, I said cruft, not crust. Stupid stock photos.'\/><\/div><div class='mouseover-alt'>Damn it, I said cruft, not crust. Stupid stock photos.<\/div><\/p>\n<p>To explain this, I&#8217;m going to have to resort to the time-honored tradition of the terrible car analogy. Let&#8217;s imagine there&#8217;s this car that&#8217;s been modernized over the years.  Instead of making a whole new model every few years, they took the existing model and added new stuff to it without ever taking anything away. It began as a Ford Model T in 1908 and they tinkered with it until it had all the capabilities of a fully loaded 2016 Ford Fusion. But like I said above, you can&#8217;t remove the old stuff. <\/p>\n<p>So our 2016 Ford Fusion still has that 1908 crank on the front to start the engine. But it&#8217;s also got a push-button on the dash that does the same thing. Or you can use the ignition key. Or the remote starter. Or the phone app, but only if you&#8217;ve already enabled the Bluetooth systems.<\/p>\n<p>In the 30&#8217;s they added an AM radio. In the 1950&#8217;s they added another radio that did both AM and FM. A CB was added in the 70&#8217;s, along with an 8-track player. Then in the 80&#8217;s we got another AM\/FM radio, plus a cassette player. A car phone. A CD player. Satellite radio. USB music player. A GPS.<\/p>\n<p>It still has the original kerosene engine in the trunk, and then a gasoline engine under the hood, which can be switched between using leaded and unleaded gas using some levers that are hard to find and confusingly labeled. Or you can use the electric engine. Or you can run in hybrid mode, although hybrid mode only works with the unleaded version of the gasoline engine. That fact isn&#8217;t documented, because &#8220;everyone knows it&#8221;. <\/p>\n<p>The windows still have the old crank controls, but also electric control, although if you switch between the two systems it will get stuck and you won&#8217;t be able to close it all the way.<\/p>\n<p>There&#8217;s a shifter for the original engine to the left of the driver&#8217;s seat, then controls for the automatic transmission on the steering column, then a manual transmission to the right. There are three different sets of headlights, two different sets of turn signals, and five different gauges for reporting the status of the three different gas tanks you have connected to your two different engines.<\/p>\n<p>Try to picture this car in your mind. The controls would be horrendous. There would be so many levers, switches, knobs, and buttons for all of these different systems from all of these various time periods. It would look like some kind of steampunk space shuttle. There would be six ways to do everything and dozens of different, conflicting versions of the user&#8217;s manual. <\/p>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/tdi_vulkan_modelt.jpg' width=100% alt='All these new controls confuse me. The stuff I&apos;ve been using seems to work well enough, so why change?' title='All these new controls confuse me. The stuff I&apos;ve been using seems to work well enough, so why change?'\/><\/div><div class='mouseover-alt'>All these new controls confuse me. The stuff I&apos;ve been using seems to work well enough, so why change?<\/div><\/p>\n<p>Even if all you want to do is a very simple task &#8211; like driving to the store without crashing or breaking any traffic laws &#8211; you&#8217;ll likely have to deal with all sorts of confusing frustrations as you struggle to figure out which of the half-dozen similarly labeled things actually does the thing you need to do. The interface has become confusing and there are lots of systems &#8211; like the old-time AM radio &#8211; that nobody wants or needs and that only serve to confuse you when you&#8217;re looking for something else.<\/p>\n<p>When a piece of software is under development long enough, this kind of thing tends to happen. When it does, the extraneous stuff is called cruft. OpenGL has accumulated a lot of cruft over the years.<\/p>\n<p>Cruft is a bad thing, but in a strange way it&#8217;s also a mark of distinction. OpenGL only got this crufty because it&#8217;s been so useful for so long. Most software libraries don&#8217;t survive for a quarter century, and it&#8217;s to the credit of OpenGL that so many people found it so indispensable for all these years. <\/p>\n<p>It&#8217;s not just the software that acquires cruft. The documentation does, too. You&#8217;ll find a tutorial saying, &#8220;NOTICE! Don&#8217;t use <em>(this old system)<\/em> anymore! From now on, you should use <em>(some other system that&#8217;s not nearly as well documented)<\/em> at ALL TIMES!&#8221; This tutorial doesn&#8217;t have a date on it, but it&#8217;s actually from 2004. It&#8217;s all outdated and the &#8220;new&#8221; way it talks about is now terrible and wrong, because there&#8217;s something even newer you should be using. The well of documentation is poisoned, and a generation of young coders are busy soaking up bad habits and destructive advice.<\/p>\n<p>But cruft isn&#8217;t just an annoying headache for coders. It&#8217;s actually really bad for our games. Because&#8230;<\/p>\n<h3>Simplicity is Stability<\/h3>\n<p><div class='imagefull'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/tdi_vulkan_stable.jpg' width=100% alt='I have some great ideas for a bunch of features we could add to this.' title='I have some great ideas for a bunch of features we could add to this.'\/><\/div><div class='mouseover-alt'>I have some great ideas for a bunch of features we could add to this.<\/div><\/p>\n<p>In an ideal world, programs would fall neatly into one of two categories: Either it&#8217;s Totally Wrong and it doesn&#8217;t work at all, or it&#8217;s Totally Correct and it works flawlessly. But there&#8217;s a third option that&#8217;s actually far worse than being wrong and broken, which is being Nearly Correct.<\/p>\n<p>Nearly Correct is bad because to our programmer it looks indistinguishable from Totally Correct. The programmer moves on, assuming their software works. But because it&#8217;s not Totally Correct, it will exhibit problems. Maybe it will run slower than it should. Maybe it will have occasional, inexplicable visual glitches. Maybe it will crash, but only on some systems and in some rare circumstances. <\/p>\n<p>As an API accumulates cruft, the number of &#8220;Nearly Correct&#8221; solutions increases. More solutions fall into the dangerous &#8220;Nearly Correct&#8221; zone. It&#8217;s easier to create bugs, harder to detect them, much harder to track them down, and impossible to be 100% certain that you&#8217;ve done things properly. Each new layer of features brings with it a new layer of confusion and uncertainty. <\/p>\n<p>Now, the obvious solution is to just remove those old controls. Get rid of that old AM radio. And that CB? Who uses those these days? But the problem is that some programmers actually do use the old stuff. They shouldn&#8217;t. You&#8217;re only supposed to use the most recent features. But programmers don&#8217;t want to have to re-write code that works. So then they won&#8217;t want to use the new versions of OpenGL, which would split the community and further complicate the documentation, which is already byzantine enough as it is. <\/p>\n<p>So rather than tamper with the existing OpenGL controls, Vulkan is an attempt to wipe the slate clean. Kronos Group &#8211; the people behind OpenGL &#8211; have gotten rid of the cruft and designed a totally new set of controls for us to use. These controls are designed around the way you&#8217;re supposed to render things today, and aren&#8217;t hobbled by 1991 paradigms. Rather than trying to get everyone to update all of their old engines, those old engines can continue to use old OpenGL and they&#8217;ll work as well as they ever did.<\/p>\n<p>Vulkan is for people making new engines. If it works out, games written under Vulkan will be a little faster and (we hope) less buggy. As of this writing, a few games have been made with it. (Notably Talos Principle, and DOTA.) The real test will come when the really big games start using it: Open world games, shooters, and &#8220;cinematic&#8221; games built around 3D spectacle.<\/p>\n<p>So that&#8217;s Vulkan. You don&#8217;t need to worry about it unless it&#8217;s your job to worry about it, in which case you should probably get started worrying about it as soon as you can.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>People have been asking me about Vulkan. Maybe you&#8217;ve seen it in the gaming news: Vulkan is coming! Vulkan is the next big thing! Developers are excited about Vulkan! Being a naturally curious gamer, you want to know what this new thing is and what it means. So you look it up, and you find [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[],"class_list":["post-35550","post","type-post","status-publish","format-standard","hentry","category-weekly-column"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/35550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35550"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/35550\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}