Reducing Graphics API Complexity: A Clean Slate Design for Modern GPUs
Blog post: https://www.sebastianaaltonen.com/blog/no-graphics-api Comments
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
Hi, I'm Sebastian. Today I'm going to be
talking about graphics API complexity.
In the past 10 years, graphics APIs have grown a lot in complexity. So, this is a
discussion topic we have to have. This
is an extended cut of my secret presentation. I also had a a big 50page blog post uh last Christmas about the same topic. I have 30 years of 3D graphics experience uh starting from OpenGL 1.1 and DX 5 back in the day and then uh I
was early adopter of Vulcan. This t-shirt is actually from the first Vulcan advisory panel meeting that I attended. And then in the
last uh four five years I have been working on mobile graphics at high pipe doing metal on iOS uh and uh Mac and
then of course Vulcan on Android. [snorts] I have been also working on web technologies. Nowadays AI is a big thing and people are doing a lot of web games. So webTL and webTPU have been my focus on the on the past years. Uh I was also giving like early feedback on webtu design back in the day when I was working at Unity. Uh during my early career I was working at Ubisoft and doing console rendering uh for Xbox,
Nintendo, PlayStation and also uh on Ngates and of course we have multiple other platforms as well like uh for example the streaming platform.
Uh I have been working on pretty much every operating system uh that is on consumer devices and and this also gives me a lot of experience on uh this topic like how how do we design crossplatform APIs
uh normally I'm talking about our achievements new algorithms like how do we improve things on the rendering and I
have had a lot of craft and GDC talks about uh our advances like GPU rendering
11 years ago with Assassin's Creed team at Ubisoft and then uh playbook had GPGPU physics simulator uh distance field rate tracing and many other topics that were hot uh roughly 9 years ago.
And then uh I was working at Unity talking about uh Unity's rendering architecture uh especially related to dots technology stack and then uh doing similar kind of uh rendering architecture talks about the high pipe's new uh mobile and web renderer. Uh but today I'm going to be talking about completely different topic. This is not about my achievements. This is uh
about all of the pain that we have been enduring to get all of these achievements done, especially in in the past 10 years when we got the new modern graphics APIs. And of course, the complexity, the API surface increased drastically compared to the older APIs. And
and this this is uh pretty much the topic of my talk like uh my opinions about that like how we should improve that and and where we should be going in the future. But before we talk about the future, let's talk about fast about the past. And this is the 3D effects voodoo graphics card. I it was one of the first graphics cards I owned personally and I wrote code to. And this card is uh a
really good example of how GPUs differed
drastically from the modern GPUs. For example, there is no big uniform memory pool. You have two texture memory units and then both of them have their own separate 4 GB memory chips connected to them and then you have a separate rasterizer chip which has their own memory. Uh this means that the rasterizer cannot uh write textures. So you just have one pass and then that one pass is displayed. Uh also there is no 2D rendering on this card. Uh this has this kind of back cable design. You are connecting your 2D graphics card directly to this 3D graphics card and this only operates on exclusive full screen mode. So if you are not playing games like this just loops through the 2D image. So you you see your Windows desktop or whatever you want to see.
Uh so memory architecture completely different uh compared to modern GPUs. Uh
there is of course no shaders, no CMD units, uh no geometry processing. you are transforming geometry on your CPU and this is why we get news extensions like uh SSC and three 3D now on for AMD
for example for like doing vector processing on CPU fast so that you can transform your vertices and this GPU was hugely influential and and other TPS of this era for the design of direct access and open graphics API and and this is why these APIs were
designed in this way. So you had to abstract hardware like this. There was of course other vendors with on completely different designs and you had to abstract all of them. So this is why we got this kind of graphics APIs that that we have right now. Uh they were really not showing you what the hardware was actually doing but it was kind of abstraction of that. And this is why kind of the early early design of the graphics APIs which still uh affects u modern graphics APIs and how they are designed today. So uh when we go 10 years into the future this is 20 years ago we got the first programmable GPUs and again like
hardware divergence is really huge. We have multiple execution models VW some tech four hardware some tech 4 plus one. So you could run a scaler in addition to vector and then some uh like uh this modern style CD hardware still started to appear. So we had to abstract this hardware and the way we do it is that we create this kind of framework style element transform language. Uh and you are as a
user you are writing a vertx share and pixel share and each of the vertx share is processing one vertx and pixel share is processing one pixel and there is
only system provided inputs. You get vertices in the vertex share and then those vertex outputs are interpolated for each pixel and then pixels there gets the interpolated outputs and just write one pixel to the frame buffer you don't have any access to other pixels
and these element transform shaders started to become really like when they when they were introduced in direct tax 8 they were really small only
eight instructions but then they were growing to 64 in share model 2 and tax 9
and then 512 and later like larger
numbers and nowadays they are pretty much unlimited. So this is like a really big difference like it was just like basically a replacement for register combiners in the beginning. Texture samplers were read only. uh you could not write to
arbitrary locations in textures or buffers because there was of course no buffers in those APIs or at least no buffers visible for the share.
So you wouldn't need to have generic readr caches in your GPUs. uh many GPU
cast hierarchies are completely custom and just optimized for these kind of workloads for these 3D simple shares
and this uh kind of hardware this vertx pixel share hardware that these are actually different hardware blocks in the in the in the older GPUs. So this
has a huge influence on our shader language design and when when the instructions grow like from 8 to 64 uh
then we actually get HLS and GLSL. In the beginning we didn't have anything we had just direct shader assembler or stuff like that. So now we get these new highle shading languages and they are designed for uh two entry point. You have vertx share entry point and fix share end point. It's like a framework basically. You are just filling out the element transform and the framework does uh all the other thing like scheduling and stuff like that. But today we have up to 16 shader entry points like they have been added like every year or every API introduces new ones. So it's starting to show uh limitations like now we have so much API complexity because of this uh early design we made back in 20 years ago.
So then let's go forward five years. Uh
now we had unified shaders uh uh and
this means that we can also run computers because now we don't have specific units for vertex and pixel share anymore. We can start adding a lot of more shader types. And the Nvidia's
8000 GTX series was an front runner of
adding computers. They added a new CUDA
API also uh for running uh compute work
uh on the GPU. Of course, CUDA nowadays is a massive business as you know. uh we have uh first time Nvidia adds this kind of single instruction multiple threads programming model simply meaning that we are mapping each of these elements that we are processing to one sim delay one
instead of doing some kind of like a small vector vector four optimization for example inside the lanes.
So now uh we also get read write buffers and uh meaning that GPU can read and write from any memory locations or basically from buffers or textures and then this of course requires us to have proper cache hierarchies and this of course brings a lot of complexity on the hardware. Uh suddenly
the GPU is u a real processing unit. it
can do memory operations and and how do we handle this on the hardware level is that the texture samplers uh evolve to become uh uh texel
buffers. So you can now have basically a 1D texture a little bit wider 1D texture and you can sample textels from that. This is the main building block on direct tax 11's uh buffers and called
aster basically shader reser view. Uh this is like textures are also sh resarch using direct. So they basically like buffer it's just a variation of a texture and this is of course completely natural because how the hardware is evolving. You have gather hardware already on texture unit. So why not why just not reuse that for buffers. But this this design gives complexities and issues when we extend this to read fright buffers. Uh suddenly like the texture casses that are read only uh are not a really good u fit for this. Of course the texture conversion units as well like if you are bypassing the samplers then suddenly you don't have support for all of the the texel types. And now we have this kind of limitations when we have retype buffers. we can only support uh certain types of data for uh in the
beginning it was only 32-bit integers and floats and there was this kind of tight UAV load extension indirect tax uh gradually adding more and more uh textual buffer support for uh writing data. Uh also there was a bite address buffer kind of similar to the raw memory in C and C++ uh but this was quite limited. It it required four byte align and it was never going to support wider aligns except for like really late in the there's a new share model that actually adds proper support for aligned loads if you want to have 16 byt align for example for ve 4 or 84 ve 2 you can have
it and this allows the uh the the shader
compiler to actually emit proper white loads on some hardware. uh this design was quite AMDcentric. AMD only required four by a line and AMD was kind of in the new console. So this this was good for their hardware but not good for everybody else. And then we had structure buffers and this is the closest we get for C pod
strs. Unfortunately, this was also uh
riddled with an issue uh
because there still existed old ve hardware and they allowed this kind of uh swizzled data layout for the structured buffers uh which was kind of slightly bit more optimal to load on those older hardware. Uh this meant that structured buffers were not guaranteed to have linear memory layout. So you could not have a structured buffer view of any of the other buffers. For example, you couldn't use it to write data to vertx buffer for example. So this this kind of limited the usability of the structure buffers which was quite of a shame because this was the only like CPOD style buffer that supported writing on that API.
Constant buffers, everybody still remembers how horrible they were. Like people of course still use them. Uh but uh the main limitation here is that on mobile you had 16 kilobyte size limit on desktop 64 and you had 16 byt aligned
for arrays meaning that you couldn't have compact like single element arrays you had to have like four arrays
to make it work and which also was quite wasteful for memory and caches. Uh vertx buffers were actually really nice. If you had proper pod data layout with compact types and everything intermixed together in the same strct uh unfortunately you couldn't program the vertx fetch on on directx 11. So the input assembler were providing you the vertices and and that's it. You couldn't like dynamically index them or anything like that. So this is the API complexity we just got like we just got read buffers but uh the complexity of that was massive on the API surface and if you go five years in the future now we are at at like uh the like when Wanda textile and metal were born basically and
at this time consoles just got new hardware there was a PlayStation uh 4 and Xbox uh one launching and those
[snorts] consoles had fast multiate rendering and really fast draw calls. They they were based on the AMD's new GCN architecture and of course the console APIs give you really low-level access to the GCN hardware. [snorts] So this didn't require this kind of massive complexity of of Datax 11 and OpenGL drivers anymore. and AMD with dice were bringing this kind of API uh to PC uh on their mantle
API and these consoles and the mantle API they gave us huge amount of pressure for uh hardware vendors on PC space to to have similar kind of fast draw calls and multiate rendering uh instead of of like having this slow old APIs and this is uh what basically
mantle evolved to Vulcan and of course Microsoft had their own competitor Twitter and then Apple has have their own as well. The problem uh was kind of timing. Uh these were done the main idea of these
APIs was that that now we can do multi rendering. We can do faster draw calls. Uh but uh we still had to support several years older hardware. On mobile we had like 12 to 13 years old hardware that Vulcan had to support and on desktop direct tax had to support even like 16 years old hardware because of course you cannot release a new API without any hardware support. So this means that we had to support like Nvidia's Fermy and AMD's GCN1 and
Intel's HD 4000 series on on PC. And
then on mobile we had like really old
GPUs like Adreno 400 midcart Mali GPUs
and power series 6 which were like barely uh capable of of of supporting
like Vulcan spec but but like uh the abstraction had to support these GPUs
and this is like why the binding model
had to be so complicated on those APIs uh because all the hardware was or there was still a lot of hardware around that that required like um really special
kind of binding code and it was only doable on the CPU driver. So we couldn't like have bindless as our main primitive
of of fetching textures and and buffer data. So uh all of this has to be designed around this kind of like driver managed binding code and of course like that is one of the most slowest thing that driver can do. So this was a huge
influence on the API design because the draw had to be fast. So that there had to be some kind of workaround and I will become I will uh return to that topic later. what what was the workar around? Basically, there was also a massive difference on cast coherencies on the GPUs. Uh the barriers had to become really complicated because Vulcan and other tax 12 expose the barriers to userland. Uh texture layouts had to be supported because some GPUs couldn't like do all of the operations on compressed textures. So in certain cases like where you were for example sampling a texture or a render target, you could have to run a driver specific decode shader to decode the compressed layout to uncompressed one. And of course this require your barrier APIs to list resources because of course some of those uh texture resources uh had to be decoded.
And then we also had an the last problem was was about like uh visibility of GPU
memory. Uh back in the day we still had only 256 megaby aperture of of visible
GPU memory and and of course managing this aperture is quite complicated. So it was uh still managed by the driver. So we had lot of APIs for data uploading and descriptor uploading and so on because uh the driver had to manage the visibility and the data upload like so we couldn't still expose like direct GPU pointers for example. So this is why we got this API complexity and this is how it looked
like when those APIs were released. Uh
3D Mark was one of the first uh benchmarks to use Dart 11 or Dart 12 and
it was showing massive performance increases like people were really excited that okay this is going to be super nice improvement for gaming and 3D market is of course created by Finnish people like me. They have lot of demo scene rules. they are in traditionally writing really fast code but of course like it is a synthetic benchmark so much
simpler code base compared to big AA engines and when we see the AI engine adoption like we see really bad numbers like uh
every engine unity, Unreal, Ubisoft
engines like I was working at Ubisoft back in the day and also So, Electronic Arts, everybody was showing worse performance in DirectX 12 compared to DirectX 11 and also Volcan similar issues on Android as well. So, you get
less performance compared to GL and this
of course wasn't really good like uh these new APIs were supposed to drastically improve our rendering performance but suddenly we just get worse performance instead. And the main issue here is that the
APIs, the modern APIs don't match the design of our rendering hardware interfaces. Uh we designed the rendering hardware interfaces to be immediate mode. So that uh basically allows the game and engine code to have as much flexibility as they want. Uh game and engine code traditionally is uh platform independent code. So we need this kind of interface to uh put put all of the platform specific code below that. So this interface allowed us to do
stuff like change or blending models or materials, change texture bindings uh do just do what kind of draw calls we wanted and we could just do stuff like change triangle windings for every draw. For example, like artists like do mirroring on objects. So mirroring of course means that you have to change your triangle winding and on these new APIs this actually like all of these
state changes these rasterizer state changes would require you to compile a new pipeline state objects which is super expensive operation. So, so this this was the main issue uh that these modern APIs were actually bundling stuff together and this this
was kind of their way of making draw calls fast and so so it's not that the
draw path would just do the same things faster. It was that okay let's offload all of these heavy operations. So if you have driver specific mappings so for example I was talking about the bindings like the bindings were completely platform specific back in the day bindless didn't exist so you had to configure like the texture units and so on by the driver so all of these mapping
tables everything like that h it's of course heavy to do so so the strategy was that okay we do this like when we create the pipelines or we do this when we create like the bindings for the pipine there was new objects like dextor sets and dex tables that were kind of designed in a way that I compile my shader and then I have some kind of binding layout and then on the other side like where the data is coming in I need I can pre-generate it in a certain layout that they can just plug it in like really fast at roll time. So this this meant that we had to create these binding tables uh ahead of time. So we have to know what we are rendering what kind of data sets we are combining together for these protocols and even on Vulcan you had to pre-create rendered passes you have to know like which resolutions and which which render targets and which which kind of like passes you have on your frame graph before you even started rendering
and and of course on the pipeline state objects this is kind of the new shader abstraction but this shader abstraction combines all of the input assembler state, rasterizer state, blending state, depth standal state together in a massive object and if any of these state
changes, any bit of this state changes, you have to compile a new permutation. So you have and to the two to the power of an permutation of PSOS and the PSO is
super heavy because it comp it includes all the shader bite code. uh in certain GPUs in certain um vendors you have to sometimes incorporate some of these state uh to the shader bite code. For example, you might like um on mobile GPUs for example you might uh incorporate the blending state at the end of the pixel shader. So the pixel shader is is doing manual blending with instructions. So it was kind of u reasonable that okay we combine all of this state together because some GPU vendor might need some state to be compiled in the shader and they maybe shave one instruction but in the reality like this was uh really like overconervative like they were just putting like let's put all the state in the PSO because uh maybe somebody needs something there uh instead of like really thinking about like uh how much uh permutation
explosion this will give us and and this
is kind of the main issue here that now we have so many different permutations of bindings PSOS everything we we cannot create it ahead of time we we there is just no way of us knowing like during the rendering of a modern game that has lot of different like streaming everything happening what kind of permutations we might need so so the solution Solution here is that we put hashmaps under the rendering hardware interface and these hashmaps are a kind of combining all the all the fine grain inputs from the rendering hardware interface and and backing them
with uh driver specific uh persistent objects like the editor sets or pipeline state objects or or whatever.
And the problem with hashmaps is that hashmap is or h has function is designed to randomize your memory access patterns to kind of avoid collisions. And now when we have massive big hashmaps uh and we are doing multiple hashmap requests per draw call we are doing a lot of cash
misses on the CPU which is causing lot
of like L1 cash thrashing and when we are trying to scale our rendering to multiple threads because this was what wander text and metal were supposed to do. You can do multi rendering like in consoles. Suddenly we have uh multiple
cores trashing their level one caches which means that the level two caches and the last level caches will be trashing massively and this actually means that you don't get scaling at all like basically the scaling is super flat [snorts] and this is one of the main reasons why the steady state performance of these APIs ended up being much slower than we expected on real engines.
Uh but there is a even bigger problem and this is like when your hashmap is missing you don't have the pipeline state object for example available then you will see a stutter you will see a frame drop and frame drops as we know have become really common in modern games. uh for example you have slightly bit different state you had like mirroring enabled now like you had different triangle binding for example and now you have to compile a completely new uh pipeline state object and and and new pipeline state object creation always requires invoking the driver specific shader compiler. So you will create a microode shader at that point which is of course heavily like heavy cost.
So, so this is basically why the steady frames rate is low and why we get these stores. Both of these can be explained by this architecture.
There has been a kind of workar around ideas to how we can reduce the PSL stalls. Now, instead of invoking the shader compiler, we can just take a cast version from our SSD. And
this was fine for a moment, but games grow and people get even more and more PSOS. And now Nvidia's default is 16 GB
of PSO cache on your driver. But even this is not enough for modern games. You have to increase your PSO cache to 100 GB to get rid of the stutter in some games. For example, here you can see Borderland 4 uh results with 100 GB
cache and 16 GB default cache size. And you can see that 1% lows are much better if you increase the gas so that the game data set actually fits there, which is crazy of course like you have to spend like 100 gigs of your SSD just to cast DSO. And of course when you do a driver update and you launch a game then you wait for half an hour for your shader to recompile and of course gamers really hate that and there was a workar around for this as well and this is called advanced share delivery uh introduced by Microsoft uh last GDC and now uh we know that okay
somebody is updating driver or whatever and we don't want to recompile the PSOS so we put massive cloud cloud servers uh caching the shares of all of the different vendors, all of the different uh driver variants. So we have a massive massive amount of shares uh of all of the games in these cloud servers now.
And this is um kind of works. It makes game loading faster if you update the driver, if you update the game. But uh the downside of course like like lot of cloud servers and of course lot of internet traffics. Instead of like fixing the root cause we are kind of getting more and more architecture to kind of fight against the explosion. Uh which of course we should be solving instead. Uh another big deal about the new APIs is that we as a developer have to take a lot more responsibility of writing low-level um graphics code. basically the the outer layer of the driver is now our responsibility.
So we were expecting the driver complexity to drop drastically so that now the driver is just u doing the the small parts of the code uh and we are doing the bigger parts and
but this this wasn't really the case. Uh Microsoft caved in really quickly with DirectX 12 and they allowed background shader compilations to become a thing again like uh in the early Dark Tax 12 and Wulcon uh the driver was not allowed to spawn extra threads but the the hardware
vendors wanted this. So so they they got it. So now uh you still have magic share uh optimizations happening in the background which can of course affect your performance profile and it of course affects the driver complexity massively because the driver has to be analyzing your code behind the scene and kind of doing optimization for that and this is why we still see massive uh performance increases on on new drivers. uh we developers still cannot make a code like like we do on console that we write the code once and it runs well. We don't need Microsoft or Sony to optimize our code. We we can do it ourselves and and we can kind of control the hardware uh on uh PC APIs. This is still not the case. You still have to wait for for vendors to actually give you a path to make the game actually run well. And this is of course not what we wanted.
Uh fortunately if we go back to the GPU history uh and take a look at the last 10 years of history now with DartX 12 and Vulcan and Metal on board we see a massive convergence in hardware. Uh all the hardware is now SIMD. So you have SIMD32 on AMD, Nvidia and Apple and SIMD
16 on on most mobile vendors. And and
this means that we can now expose uh CIMD intex. can make the programming model more CID like instead of kind of doing this abstraction of frameworks of like different like pixel vertx lanes for example which of course gives us nice opportunities for improving performance and writing more hardware specific uh code we also have coherent last level caches now on the GPUs uh meaning that we don't need to flush separate caches to VM On GCN based consoles, for example, the rasterizer caches were not connected to the last level cache. So you had to flush them to memory and then flask the last level cache as well so that it could have visibility to the new rasterizer inputs which made it the barriers quite complicated because the barriers were super expensive. So you had to had to manage them in in a specific way.
Uh, another improvement for barriers is
the texture layout thinging. Uh, back in the day, uh, GPUs uh, didn't support reading delta compressed uh, texels like if you were writing uh, on a rasterizer to delta compressed target. You had to decode it before samplers could read it. But nowadays, every GPU does support that. And also display output does support color compression. So you can send compressed data direct to the display engine, meaning that we don't need these texture layouts anymore. And there was a Vulcan recent Vulcan extension for uh removing the texture layers completely, which is super nice.
We also have fully bindless texture samples nowadays. As I said previously, like setting up the bindings was one of the expensive things that the driver had to do and we had to abstract this for these older hardware. But nowadays everybody supports bindless textures. So we don't need to set up the samplers at all and the hardware can simply pull data from texture descriptor directly. So this is a massive improvement that can allow us to do simpler API design.
Similarly uh now we have full virtual memory 64-bit GPU pointers. Uh we don't need to have these older buffer abstractions anymore that you have to fetch a buffer descriptor and then you can fetch data. you can just directly use a 64-bit pointer for fetching data which kind of allows us to uh get rid of
some of the driver specific optimizations that are flattening your data inputs like uh of course uh getting
like multiple um like indirection is of course slower for GPUs and this is something that uh drivers of course really want to optimize for and now we can just do it ourselves in the most optimal way and we don't have the small
AGB aperture anymore. Now, uh we can persistently map all of the GPU pointers on CPU side because we have PCI Express rebar on on PCs on discrete GPUs and then we have unified memory access on mobile and console. So, every buffer can be persistently mapped and we can just write data directly from CPU to GPU. We don't need any abstractions for this including all of the stuff like descriptors for example. So we don't need to abstract our descriptor or heaps anymore. Uh and the hardware in general has improved a lot. Uh we can have dynamic register allocations. Now day we have share execution reordering. Apple has their new uh register files that basically sit on the L1 cache and and
and all of these hardware improvement kind of make it so that uh the memory access is more flexible. We can run more flexible shaders. We don't need to compile pre-ompile that many different uh permutations assuming that we expose of course all of this in a nice way on the APIs because modern workloads are much different compared to the older workloads. For example, we have GPUdriven rendering. We were talking about that already 11 years ago and now Nano has made it really popular.
So we are running like a lot of workloads. in addition to rendering on GPU like calling for example and and LOD selection and and the data is persistent
in GPU memory. So instead of like us setting up in on the CPU side and the shaders are kind of pulling the data what they want from the scene data structure that lives on the GPU memory. And of course vbuffer is an continuation on that like you just have like triangle ids basically on your buffer and then you are fetching like the mesh data also in in the same way and rate tracing is is pretty much the same as vbuffer at unity. we were kind of writing shaders that the same shader could kind of do the vbuffer thing and the rate tracing thing because they are so similar.
So now um we also get like pointer based
languages in metal and QAN of course open CL also had that and and this this expose us as the AI tensor course as
well and and these kind of languages are
usually intrinsic based. You are adding new features with intrinsics instead of like adding new shader types which is
seems to be a better approach in the future. And and of course all the memory accesses are much more dynamic like when we are not rendering single objects we are casting rays that can eat for example any objects. We cannot just put everything to a small uniform buffer. So the hardware has to be quite different. And this is what what the vendors have been doing. They have been improving their caches. They have been improving their raw memory data paths and so on. So the hardware has been tailored for
modern workloads and this is like what the API should also be doing and and this is this is pretty much the topic of my discussion today. Even though direct tax and volcan have had extensions to support some of these new features um they they are still based on
these older uh hardware design where CPU was driving the show. So now now we if you design a new API uh from ground up
uh with modern hardware only in mind we can get a much cleaner result and this is what we are going to be talking about next.
The first thing of course when we talk about an API is memory management. Nowadays we have full access to GPU memory as I said previously. Uh we are just borrowing ideas from CUDA of course because CUDA has really clean memory management. It just has C style GPU maloc CPU free and then we can add some
uh nice additions here like temp allocator for example because we already have command buffers and command buffer is a temp all algorithm by design. So if you want to allocate some root data for example in the comment buffer or some local parameters or whatever you you can just do that like that should definitely be allowed instead of like having API abstractions for that. metal metal has an abstraction for that called like set um set vertx vertx buffer and and set
bytes it's called actually metal and then vulcan now has this kind of command push data extension which allows you to
have all of your uh push data like you
have a push constant but now you can have a push strct you can just put the push the truck and then you can just read the strct in the shader uh these kind of extensions like we just should should start just have like a GPU temp allocator instead for uh more flexibility. So uh in my presentations I'm going to be showing you a single pointer that is both visible on CPU and GPU side. This is called shared virtual memory. Nvidia CUDA for example supports that. But in reality like the more most of the graphics APIs nowadays are having a CPU GPU pointer pair. So you have a CPU mapped version of the same pointer and then GPU pointer. So if you are passing data
to a shader uh you have to pass the GPU pointer and then on CPU when you are writing to the GPU memory directly you are using the CPU mapped pointer.
So this this is why this is how dark text fail bulcan and metal do it and uh
but uh in my slides I'm using the shirt virtual memory pointer instead because this makes the slice slightly bit easier but you can just think about them as pairs if you if you want to support all of the different hardware available today because this API has been designed
so that we can actually run it today
and by default the memory should be visible for both CPU and GPU so that it lives on on GPU and then you can uh write it from the CPU because this this makes uh the communication easy and uh in CUDA this is pretty much what you get but instead of the memory being on GPU memory it's actually on CPU side so it's slower for a GPU to access because CUDA was made before we had PCI rebar and all of that so so we can we can actually make it the memory manage % better than it is on CUDA by default and still make it as easy to use.
So let's talk about bindings like how we create the pipelines. Uh the the trader creates code is usually massively complicated in our back ends and um this is what we want to of course improve on. And if you look at unique speed thread create API or Windows equivalent and this uh spawning and thread is really similar to spawning a kernel on GPU because this is just just kind of like asynchronous task spawning. And now we see that okay we don't have any of data layout setting here. We don't need uh kind of we don't need to describe to the operating system like what kind of data we are passing to our worker thread. We are just passing one void pointer and
and then the working thread can just render cast it whatever strct layout they use. Of course you are using the same truck layout in your uh main thread code and in your worker thread code and then that's it. Uh operating system doesn't need to know what what you are doing with the data you know and you have your data contract and that's enough with the pointer and this is what graphics API should do as well. And this
is actually what CUDA and metal also are doing. So direct tax fulcan should also
be doing the same thing basically. And once we get to this kind of data layout uh creating a pipeline becomes really trivial. For example, compute pipeline create is just uh you just pass your widespan of of IR and then you can just get your pipeline compiled because
you don't have any binding configurations anymore. You just had the void pointer and that's it. It's the same for all the shaders. So there is no configuration required. Similarly, if you're creating graphics pipelines, you are you are getting in like the vertex IR pixel IR or like if of course if you're doing a mesh share pipeline, you are putting in the mesh share IR instead of the vertical share. And then you need some kind of compact rasterizer description for setting up the rasterizer. I will be coming back to that topic later. So this way we don't need any root and post argument APIs, no descriptor set or table APIs, no buffer and texture binding APIs. All of that API complexity is gone.
So how do you render with this API? Uh
basically like I said previously a root data is a 64-bit GPU pointer. So now we can do a common C header POD header. Uh
for example here we are declaring a strct uh with our uniform data and some pointers uh to input output data arrays and these we put GPU pointers here so
the GPU can directly access TPU memory from these pointers and now we can in CUDA it's really common to align your structures like if you are aligning the struct by 16 for example then you can enable the the GPU hardware to use this kind of wider load instructions which make data loading faster. So for example, this data struct could be loaded with two wide load instructions. And if you look at the code on the CPU side, uh we are setting up a pipeline of course we commonly want to bat by pipeline because pipeline changing is still quite expensive on GPUs. Uh our setup makes it slightly less expensive, but [snorts] still uh it is quite expensive. So you want to be able to setting up a pipeline and then rendering with that pipeline. And now our data management is super simple. We are calling the GPU temp allocator. I just described allocating some bite from the common buffer. You could just have your own bump allocator. Uh that is exactly the same thing. I I brought a C++ wrapper for this temp allocator so that we can just get rid of the render cast in the examples. make it a slightly bit more clean to read. And now you get this
GPU pointer which is visible also for CPU. And we are just writing uh our uh
root data basically directly to GPU memory. And these input and output pointers like I said they are GPU pointers. So we are writing GPU pointers to our strct and then we are calling GPU dispatch uh for the common buffer and we are providing this one root data pointer as the parameter. This is our sole parameter. We don't have any uh functions here to call like bind some bind groups or tables or or whatever.
This is just a single API call for drawing which is of course much nicer that we get right now in direct and and vulcan and metal. And now in the kernel you are getting a const const pointer to this data as parameter. This is of course con data because it's your root data and other shared links are accessing the same data. And of course when we make it const we can also employ some optimizations on GPUi. And
now the shadow simply like dreers this data. This





