niagara: Building a Vulkan renderer from scratch*

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right let's do a sound check as usual all right things seem to be working fine hello welcome to the first in the series of multiple streams where we will be writing some welcome code so I want to first talk about kind of what the stream will be about what the process will be whatever even writing etc etc so we will be writing a Vulcan renderer from scratch my stream set from scratch with an asterisk this means that we will be we will not be using any Vulcan libraries but we will be using some libraries that aren't about Vulcan but help us actually progress so we'll be using gfw to create a window will be using GLM at some point to do math and a bunch of other libraries like this we'll be using some profiler library that I haven't decided on yet but we will try to run write all the Vulcan code that we need ourselves depending on how streams will go I'm planning to basically write all of the code that we have that we need on stream but we'll see how it goes all of the code will be of course posted on github there's a github repository it's called Niagara it stands for next generation renderer which is what we will be trying to do so I don't want to do like a normal you know here's how to draw like a triangle and Vulcan and then here's how to draw a mesh and bulk and then here's how to use textures in Vulcan and that's kind of a tutorial like content it's not very interesting for me you can I'm sure there's like a lot of tutorials out there to do this instead I want to do something that sort of interesting for me so what we will be trying to do is we trying to write a renderer that he is doing as many things as it can do on GPU we will be doing calling on the GPU we will be doing potentially triangle a cone culling on GPU we will potentially be using new r-tx tasks and math shader pipeline if I get an RT X at some point so it will be a bit of a sort of hardcore Vulcan renderer not necessarily something that you can use on every single Vulcan supported hardware but something that's kind of interesting and that feels like it's the future so yeah so the plan is let's see if that works so yeah so the plan is we will have some pipeline that has a bunch of objects then on the GPU we will say only some of these objects are visible so we will have the objects that are visible potentially we will say one of these objects is a complicated triangle mesh with a lot of triangles all right I will not run the tessellation and then half these triangles are not visible so maybe we can call them more efficiently on GPU and then we'll be rendering off this I want to also try to do GPU based occlusion culling if you'll have time for this and in general it kind of depends I don't know exactly how this videos will go we will write the code that we can we will see what works and what doesn't and yeah I will try to kind of enjoy the process and then maybe learn something some of the stuff that I will be talking about I kind of know some of the stuff that I'll be talking about I have not have haven't done ever so we'll see how it goes by necessity we will have to cut corners because we don't have a lot of time which means that we might be sort of calling out some things that you not been doing in the production Vulcan codebase and I can talk about what you should be doing a product in a production Alton codebase but you might be like we will ignore error handling unless they're actually does happen to us on stream we will start by ignoring some aspects of synchronization and I'll talk about this a bit later and the channel will try to make progress as fast as we can and then clean things up also we are not gonna be making a Vulcan framework or a Vulcan like abstraction layer or nothing like this our goal is to say hey how can you write efficient renderer in Vulcan ignoring everything else out there in enduring parts of Vulcan that don't work on maybe mobile hardware we will be exclusively focused on desktop we will start with whatever works on my current GPU which is Intel HD something 620 no and then hopefully in a few weeks we will get a snarky X and then there will be mesh shaders and task shaders and God knows what else it's unlikely it will actually get to there in a few weeks but you'll see how that goes yeah and I'll try to sort of mix up the stream with between like writing code and talking about how things work in Vulcan and why and answering questions and all of that so that's kind of the plan and to start we will start our new Vulcan application and my hope is that we can get to a triangle on screen which might be challenging because a triangle screen is like half of the renderer in Vulcan but we'll see how it goes so that's kind of the plan and let's see and let's see what the chat says try writing it in language other than C++ the next challenge No so my goal is to experiment with some new welcome stuff and to try things that I wanted to try for some time my goal is not to experiment other than C++ you know you could have picked rust or something but that that would just delay the progress unnecessarily for people who are a Mac we will not guarantee that the code works basically yeah like I'll try to use yellow W and some other stuff that should sort of maybe work on other platforms but I won't use C make or any of that like the goal is not portability the goal is to get Vulcan running to get something cool running in welcome and see how that goes so if you want to follow along so the code will be on this github repository and basically all I will be using is the Vulcan SDK and the Visual Studio so whatever like if you are on some other platform maybe the code works maybe it doesn't I don't know I already have installed well Calista key suppose just go from there and you kind of just go ahead and try to create a window and try to draw a triangle and then I'll talk once we create a window without a triangle I'll talk roughly about this sort of welcome pipeline that we are going through today if if we get up there and then we'll go from there so let's go so we will start by cloning I haven't like I'm starting from zero my repository has one readme file that's empty so I'm starting from zero and let's just look at this I've cloned my repository there is a readme file there it's amazing so we will be using GFW and there is multiple ways how you can add GL fw to your project you can you see make you can use and you get whatever but we will just go you know hardcore and just say hey everything that we will be using all third-party libraries will be just linked from our repository and then they will just be built as part of our project that way if something doesn't work if something like if you need to debug something would change something it will be easy for us to do so let's create an extern folder and let's do you get sub module in it [Music] great it's a module alright this is the time when I like I don't add some modules often oh maybe it's get someone to add that would make sense alright good um so that was good and we need to create a visual studio project so yeah we will not be using see make I could use see make but I don't like to make too much and see makers integrated into visual studio but integration is kind of not awesome so I feel like we'll just lose time if we do this we will not do this instead we will just create a visual studio project we'll call it Niagara and we'll have to shuffle some files around after we do this because the way visual studio grace projects by default isn't super nice also it takes it way too long to create a project file alright okay that's nice I guess or we tended to precompiled header file damn it I should have just all right so no precompiled headers see what it did okay this is not terrible I was it could be worse all right so disable precompiled headers oh and here we will be will basically be writing 64-bit code because there's no point reusing 32 bits in this day and age I I mean I'll keep this the 32-bit configuration I suppose in the solution because hey doesn't hurt but it doesn't help us out all right and we'll be using a console application despite the fact that you'll have a window because I want to be able to log things to the console alright so let's clean up after Visual Studio a bit so I want the folder to be called SRC I don't want precompiled headers stuff and I want right I don't want this file I want this stuff Visual Studio should have git integration will be oh my god alright we'll be trying to use that but come on get how do you do this III set head it's amazing how like it's impossible to remember commands and get that you need all the time because they're so cool renamed like why is anyway okay this is not a stream where I rant about get this is a stream where we write welcome code alright so we have a project file maybe it compiles and then we'll have to ignore a bunch of temporary files and get to make it easier for us to write this code going forward so let's build this and see what happens alright I think we have hello world we are making progress well technically it's not hello world well I guess it's [Music] alright not a triangle yet but we are making progress um yeah I won't not a fan of the folder being here but I will not do anything with this so let's just ignore let's just try to get ignore file where we will ignore what will be ignore we will nor this folder this and I guess this alright alright first commit so now let's try to actually build GL fw and create a window because we are using console problems so that we can easily print out the status of various welcome commands and whatnot but obviously we're not gonna render a triangle like this so let's just see if GL fw use a well-behaved libraries so for well-behaved libraries you should be able to just add all of the sources to the project and have it work oh and I'll have to add mmm I guess I'll need let's see so I need all of the windows stuff what is welcome see I don't I don't know what this is figure it out later and basically I need everything that's not platform specific so just add the stuff that seems tangentially related or relevant and then build it and see what happens right so I guess we need to say that we are compiling a win32 build yes oh gee lfw has some Vulcan supports but it's really minimal and we will not be relying on this too much okay that's fine hmm can I just like add this here right so there is a lot of warnings that are completely completely and utterly insane we will not be fixing them obviously because they are not in our code but even if they were in our code we would not be fixing them oh it added it I did it wrong okay so let's do this all right so that's pretty good we didn't add oh there's some OpenGL stuff that we won't really need why is it this is oh so you have to okay I see so if you're using Windows you kind of have to build egl and dub GL and and everything so fine that's fine and I guess we need welcome see I don't know what this is let's see yeah I don't think we want to do this unless you love w says that you kind of need this code that there are the right this code oh we do need walk and then we need to ask Messer all right sure fine interesting yeah okay all right so I guess it's all or nothing we need to add Meza and welcome why do we need Meza I should have just added like all C files all right so the code still builds now let's oh that is interesting all right we'll have to pause the stream for a second [Music] [Music] all right this is what happens when somebody gets delivery and it's not me and whoever gets it is not home let me look at chat to make sure that things work maybe have a look on Moulton if you're on Mac yeah so Moulton Vicki looks pretty well on Mac I covered the end goal why not see instead of C++ I'll talk a bit more about this Deb's Welkin c c c++ amazon time yeah it's not even my amazon time it's somebody else's havin some time would have been easier and she make I don't know if that's true I just added a bunch of files it worked I just didn't know which files do it anyway it would've been easier with CAA but the would have been some other issues with C make and also I will be adding some third-party stuff later that may or may not have to make support and if it doesn't that have to edit and it's just let's just not go there all right so let's create a window and then see if that works and then if that does work then we will actually talk about welcome so I wanna add I want to add so this is basically I wanna add this folder with include path and then I can encode kill of W this and I don't work too often with the GL fw let's just wing it I guess monitor right sure I should have really Oh so the other thing that I want to do is I want to be lazy and I wanna just not do error handling much and in order to be able to do that I will just yeah let's do this why does it all right so let's just enable assertions basically I don't keep this macro I don't even need this macro I don't know what this is all right so this will make sure that assertion czar compiled in and release as well so we can just like not worry about this stuff for now and then if we need to worry about this stuff later we'll worry about this stuff so yes I should probably read some gfw sample I don't use it very often that's like she W pull events I don't know should I show the window should they destroy the window I don't know oh yeah nobody has to build everything because we had this include path all right oh yeah you have to call jail of double unit or something like this I think all right come on what does it return is one good or bad all right the returns gmw true this is the like benefit I guess of heaven I guess we see make I would have gotten the same thing but I tried using gel fw through and you get and it's like a prebuilt binary so I can't just go into jail fw source and look at what's happening but okay so i guess and doesn't return an error code alright so we have a window and we can't close the window I think there is she loved W shoot close it's there no all right whatever let's just leave this for now no go back here hmm all right let me cheat and I will look at the other thing that I was yeah G L if W window should close oh I was okay alright hopefully now we can close the window I don't think we need to terminate jail of W why does it rebuild everything again what did I do alright alright uh let me just make sure that so I change this VB file alright good all right so we have a window now let's talk about well so when you use Vulcan and this is kind of touching on there was a question and chat about C versus C++ so I will be using C++ because I find some minor things more pleasant to use in C++ however it won't be like hardcore C++ with like a lot of classes and templates and whatever it will be like a sort of see like C++ when we use welcome in theory you have two options available to you you can use the C++ address for mail cannot see Heather's Falken and I will you see hundreds for welcome it's personal preference or it's sort of it's a personal preference that motivated less motivated by sort of technical quality I should say so if you look at C headers then they are 400k all of them well I guess maybe that's not true I think my some of these well whatever these are like small so this is roughly at all of the he Henderson Malcolm's so this is like 400k so one welcome suppose plot scatter that I believe includes all of the sea headers is like 1.8 megabytes so that's quite a bit larger it also takes quite a bit longer to compile with this hazard included and I don't feel like it provides value honestly or that much value enough well to be useful and also a lot of the documentation that you might see on the web a lot of tutorials they don't use this so it feels like this header just introduces unnecessary fragmentation so you will not be using this we will be using welcome that age speaking of all conduct age sea I installed the Vulcan SDK we will not be including falcon sdk on as like a gift hub sub-module we could i guess i guess we could should we there might not be Lib files in the github thing so I guess yeah we probably won't let's just use welcome SDK directly now so if you are using a production problem if you are using sorry what am I even saying if you're writing a production Vulcan render you might not want to use the Vulcan is the key directly for a couple of reasons one is that using it generally means that you link your application to the Vulcan runtime and then the Falcon runtime isn't available then you can't easily fall back to a different renderer now you can solve this problem but there's also some performance caveats so normally I would use my own Vulcan library which is called Volk which is a metal order for Vulcan the only reason why I will not use it on stream is because I said that we will not be using other Vulcan like third-party stuff and this is sort of third party Vulcan thing right so and it's not part of Alken SDK obviously right I guess it's not okay to use it so we will not use it but normally I would just use this and then I could just put this to get and put maybe welcome Heather's to github and then it would be completely self-contained you will need welcome this decayed to to build necessary but since we'll need the shader compilers to build our project because you'll need to compile shaders from source we kind of need welcome SDK no matter what so let's just assume we the only problem with that is that I don't have to hard code the path to like welcome this decay that we use in the project file because right now if I do like an clock include welcome it doesn't do anything right so there's that so that's not great but we will survive and then maybe at some point we'll clean something up but for now I will just oh is there actually wait maybe I'm doing this wrong is there oh ok nevermind we will not have to hard code this because there is the environment variable for Vulcan is the game that we can use so we'll just say that we add Vulcan SDK include to our include path so let's see if that works alright so as I said we will be using this header there's also there is also this header just as a just as a point of curiosity let's see so let's do this 1 2 3 so it takes like 3 seconds 1 2 3 it takes like three seconds to compile this CBP file and it takes like half a second or something to compile the CPP file with the see headers for welcome this is why I don't you I don't like this is one of the reasons why I don't like the C++ welcome header it's just too large it's too bulky it's not it's useful but it's not that useful so you will not be using it all right um so let me quick let me stop coding for a bit I will look at chat and also I wanna kind of talk a bit about the Vulcan initialization sequence that we'll be writing code for right now before I start actually doing this also can I under all this chat somehow and oh there is like a pop out somewhere all right maybe that will make it easier to read this thing so yeah so why not see instead of C++ a mostly countess I'm a bit more comfortable writing C++ code I usually write C++ code that's really close to C but it's not exactly seen what do you think of anvil framework I have not looked at angle framework it's probably good this is an videos one right yeah I haven't looked at this but they use it internally for research help tab you can create well convene the surface for you yes we might use that or might not use this is like five lines of code so you might not use that Oh kids really good it would be great to see this part of alchemist decay yeah it would be nice so Volk technically violates Vulcan specification as far as I remember there is like this weird bit in Lockland specification where you can't really declare a symbol in global namespace that starts with VK because it might conflict with fusion releases and hope solves these problems on the practical level but I think yeah I don't know anyway yeah it would be nice if it were a part of Falcon SDK but you can just use it 20 lines let's take a break yeah so let's I just wanna I kind of know what I will be doing now but not all people on the stream will so I want to talk a bit about Vulcan initialization so the way Vulcan works is that most of the operations that you need to do they involve welcome device in one way or another so you kinda need to get to the Vulcan device but to get a welcome device there are several steps that you have to take so so we want what we want is we want to create a Vulcan device what we need to create a Vulcan device is we need to pick a physical device physical device corresponds to a GPU like if you have five GPUs hope you don't have five GPUs but if you have like two or three GPUs which can happen then generally there's a physical device per one GPU and then from a physical device you can create a logical device or just device and there's some and there's a reason why this separation exists like for example if you have to if you have an SLI system with two NVIDIA GPUs you could create one device you could create two devices one device per GPU or you could create one device that kind of corresponds to both of them and then you can submit some commands to both of them at once and some commands to just one this is I think part of parts of this feature are new in Vulcan 1:1 so there is a reason why the separation exists but the more important thing is that when you create welcome device you have to pick the correct physical device that you want to use very very loosely if people who watch this are familiar with direct3d 11 very very loosely these corresponds to device and this corresponds to adapter it's not quite precise but close enough and so to start creating device or picking physical device or do other things like this we need an instance you generally have just one instance in the problem although if you have some complicated setup where maybe you are integrating with QT + QT for some reason decides to use welcome then maybe they want to create their own instance machinery you only have one instance in the problem and instance is kind of your interface to everything Valken before creating an instance there's like two functions that you can call one is create an instance and one is get the version of the loader or whatever instance corresponds to vulcan runtime or vulcan loader to be more precise more or less so for example you might have some might have different GPUs installed in your system you also might have different programs installed on your system that try to integrate with Vulcan applications for example we will be using Vulcan validation layers that are a set of DLL that can sort of be added to your program whenever you create an instance and the Vulcan loader is the part of the system that manages all of this it's generally just a DLL so it should be installed in the system folder hopefully yeah so as you can see I have two dll's one is Vulcan one yellow and one is Vulcan one 9900 DLL I think this is a weird way to deal with some backwards compatibility concerns of ours compatibility concerns but whatever yeah so basically this D levels the loader and this Yale is mostly what you talk to when you create an instance and then once you create a device that mostly goes to the driver or to some other layers you that you may have the system so we have to create an instance we have to pick the physical device and then we have to create the device now the other thing that we need to do once we create the device we could start submitting GPU commands once you create a few other structures that I'll talk about later the other thing that we will need to do is we'll need to draw something on screen right so for that we need to create another thing that I think is created from the instance I mean from physical device which is called surface and from surface you can create swap chain so this is loosely so this in DX terms is loosely swatching same thing and surface in the X terms is loosely I guess the xgi Factory it's not super precise once again but that's close enough so swap chain is the thing that you can render into swaption has or rather it can give you images that you can render Ito's watching has a size right so if you have a window that's 1024 by 768 swap chain can be 1024 by 768 to destroy the old swap scene and create an useful option for the new window size the surface is the thing that can manage all of these interactions that actually give you a new swap scene and the surface is tied to the window handle which we should be able to get from 0w and yeah that's kind of the basic structure that we'll have to start with so you can see so you'll need what like you need five objects this is not enough yet to render a triangle random triangle we might have to have five to ten probably like ten more objects but let's start with this so we'll initialize welcome pick the physical device only one in my system and then create a device and then create a surface and create a swap chain and then go from there if you had an elfin GPU and discrete device issues which one is use yes we will quickly go over this we won't have much of a choice but we'll quickly go over this all right Oh something that I forgot to mention on stream so I guess I did say that I am NOT going to create like Vulcan abstractions or whatever I will be mostly just writing code and then when the code becomes a bit gnarly and a bit hard to deal with we will refactor this as we go this is loosely related to term semantic compression there is an article by kasemir Ettore about this I recommend you read this it's a good article it's kind of a different way of how to work with code compared to what you might be used to or what you know you were taught in high school or university or wherever you learn how to program so yeah we'll kind of just be writing code and then once code becomes too painful to deal with we'll make it less painful to deal with and we'll remove a printf so alright so to create an instance we need to call VK create instance function maybe I'll learn to type bedroom most of the code in Vulcan should I start using yeah this one so most of the functions in Vulcan they don't take a bunch of parameters they take a bunch of structs and then you have to fill the struts so this means to create in form and then this needs a location callbacks which is kind of a thing that we will not use it's not often useful not all drivers have been implemented well and then it returns as an instance oh and it actually returns by the C return value VK result which we have to check and the member we are not doing error checking so the only thing is something that we will need a lot is let's just define this will define the v-chip macro because there is a lot of functions in Vulcan that return a result and I don't want for every call for these two like manually check that so we'll just do this I think you visual studio alright and we'll just assert that result is a key success come on stop formatting my code when I don't need you to write so now we can basically just a week a quickie grid instance creating full 0 and then instance and then if they call fails then we will deal with that at some point obviously if you're writing a production button renderer then you will have to handle some of these like this can fail if it fails just means your system doesn't support welcome so instead of a certain you should probably either tell the user oh hey you need Vulcan drivers of all compatible hardware to run this or you should switch to OpenGL or direct3d or some other API that you use but we will not be doing this to save time so yeah so let's briefly talk about how well constructors work most of them for reasons that have to do with being able to extend the API with extensions have the same structure there is a type of the structure that's the first field and it has to be the specific value which is the enum corresponding to the type of the structure you may be familiar with this from some other c-like api's win32 api does things that are sort of similar but slightly more obnoxious we're often the first field in destructor win32 api is the size of the structure mine anyway yeah so then there's this P next pointer that basically has to be null it can not be now but I will not cover this up until we get there and then there's stuff that you can feel some of these are optional some of these are mandatory so we will great oh this is like I see this is for compatibility what is chasm something that I forgot to mention is that when you write welcome code you kind of have to have the Vulcan spec open basically most of the time the reason is there is subtlety in Vulcan API that is easy to miss if you just look at structures and functions and it's kind of good to be reading the spec as you write code to make sure you haven't missed anything so we have it open spec is a very very very large HTML document there are some versions of the spec that are split into pages but this is the full spec this is the full spec of welcome 1.1 with all extensions so I think by now this might have r-tx extension so maybe not it depends on when this was published so as you can see there's a lot of text here you're not supposed to have read the entire spec although I highly recommend that if you actually are serious about Vulcan and want to ship welcome code like have a Vulcan renderer in your next large title or whatever it is you should probably read most of the spec it's still scrolling should we wait till the end is getting close the size of this is slightly misleading because this is all extensions like the GL spec does not include extensions for example but it's still pretty big alright suffice is to say we will not be using the entire Vulkan API in these streams it's just a large alright so yeah so the way you should deal with the structs is i initialize them with the correct enum value and 0 initialize everything else like this and then I just fill things that I need and then here I only need this stuff and I will need some of these now and I will need some of these later so when you initialize the in Valken instance you can a say that you want to enable some layers for example we will be enabling validation layers that help us verify that the code that we write is actually correct so layers are dll's mostly that are injected into your program and then you can enable some extensions and extensions are used to allow you to use some function dealt functionality that's not present in the course back if you are used to OpenGL you might be used to saying hey just like pick an extension and use it in Vulcan you have to upfront declare every single extension you might be using in the future this is actually valuable and important because this means that there's never surprises that you don't know about because if a device doesn't support an extension creating an instance will fail right so this prevents situations where you use an extension somewhere deep in your rendering code and everything works and then you test this on some configuration that doesn't have this extension and you've forgotten that you use a substantial in the first place and then it doesn't work and there are some other subtleties about extension labeling some of them actually can change the behavior of existing core api's but yeah oh yeah so we will still need alright yeah so we will need application info as well we will need application info because we want to create a Vulcan one point one instance we might not be using welcome to op 1 1 stuff much right now but oh this is assuming that my Intel drivers actually support 1:1 which I'm not sure about we will find out is there like a Vulcan version aha yeah um so I'm I want to leave comments I want to start leaving comments in the code that are kind of like this is a shortcut this is something that we are not intending to fix necessarily but this some that you should not be doing a production renderer so shortcut in real welcome applications you should probably check if one one is available via there's a function V key and and reads something something or at this function but we'll just say hey one one is always the thing hopefully it's not actually true but it might be true for us right and then I want to set up some code to just support enabling layers there's a slight problem with let's just let's let's just create something see if it worked and then we'll do the rest and then we need to destroy the instance at the end also we'll find out oh I guess yeah this will succeed because my loader has won one all right here and now we are actually using welcome so we will need to link to something hmm this is like a really long list I I'm pretty sure I'm not using half of this but okay so so we need this library and I guess there's a 32-bit version um I don't really wanna be testing the 32-bit stuff much but maybe I should still do due diligence and try to make sure it works so for 64-bit we basically need this and for 32-bit stuff we basically in this alright alright so nothing is broken we have created the Vulcan instance and that's good now the thing that I want to do immediately is I wanna enable validation layers in debug and I have removed the debug configuration macro so that's not gonna make it very easy so let's just add it back to debug builds validation layers slow down your program but they are indispensable if you want your code to actually work so we will say that we need layers so yeah this is what I I wasn't sure about the problem as C doesn't let you have a race and don't have elements in this we could just use the director but using C++ sir early in the stream feels wrong so I don't remember how the validation the hairs are called so let's just google this it's like lunar G something something aha lunar G standard validation oh I guess we will not use any other yes I guess we can just say that debug layers and we'll just say that if we are in bebop we will just add them to I mean it's technically just one layer but maybe we'll need more in the future so there's that oh right and the other thing that we might as well just do just now so I was talking about the surface stuff that you need a surface to be able to render into the window surface is not a core object it's an extension so we'll have to enable an extension like right now to be able to present anything into our beautiful window which is interesting but whatever this is like we keep th our surface extension name which is really key to our surface I'm not sure why they have these macros because it's not like you can actually change this value after the fact but whatever I can't type today so as you may be starting to see welcome is a beautiful your bows API although I forgot to do a GL thing should I do a GL thing whatever somebody on Twitter said that they want to troll me on chat by posting code that's sufficient to draw a triangle we have get our first validation error by the way right yeah that like you can draw a triangle in OpenGL 1 or something in like three lines and I was thinking of doing this on stream but whatever I will not waste time doing this so what the hell oh fantastic fantastic ok this was wrong never mind so this is why validation layers are useful right like this code worked perfectly without without validation like to be created and instance without problems but this code was broken because I used the wrong enum it's not even an enum it's like a define so all right so now our code works so that's great oh and yeah the validation error layers printed the error in the console which means it's helpful to have a console window alright so now we are we should be ready to create the device speak the device and all that so let's go there so we need a physical device and then we need to create the device from this so there is a function we can create physical devices this function is in typical wind API style you should call it twice you should call it once to figure out how many you have and then you should call it another time to figure out which devices you have but we will be cutting a corner by saying that if you have more than 8 physical devices can you put more than 8 GPUs ok if you have more than 16 physical devices we will only pick one of the first 16 this feels like a file compare to simplify our code so yeah we will say that there is like at most 16 Oh intellisense is interesting okay and remember I said like you need these instances and devices to do everything so you have to pass all these pointers explicitly into every single function so welcome you guys will Bose but explicit explicit is nice oh and you have to initialize this guy actually 2:16 so I should just make a macro for this but whatever alright so now we have a bunch of devices and devices just a pointer it's not like doesn't mean anything so we can say get physical device properties I suppose that will return us a struct with the name of the device and the vendor ID and whatever else intellisense is not very fastly so you can get a struct that tells you things about the physical device right [Applause] [Music] so at this point we'll just let's just write a function well it's hard for me to write the word physical I don't know why all right so you might have more than one GPU and we only have 1 GPU but you might have more than one and if you have more than one you have to make a conscious choice of which one you need maybe I'm just bad at typing today so there's not a really good way for doing this necessarily there's not like a standard way of doing this but what we will do is that will go over all devices we will look at so let's say yeah so what we will do is we'll just pick the first discrete GPU if we have one and if you don't have a discrete GPU then we'll just pick the first GPU period so we'll go over all and for us we will actually don't have a discrete GPU right now so we'll end up picking our integrated GPU yeah ok so we can get physical device properties this function can never fail so that's good and then if props device type is a key device type a physical device type just to give you and then we'll just say hey begin discrete GPU device name if we haven't found one then we'll just pick the first one if there is one it is possible for the device count to be zero this is a relatively standard actually so creating an instance just means that you have Vulcan runtime installed in the system but you can still have no drivers that support Vulcan or GPU doesn't support Valken or it's called fallback oh damn it alright let's just create it again it doesn't matter much and otherwise you'll be like hey no physical devices available so there is a like null handle for every Vulkan API which is null handle but also zero and I don't like typing mush so we'll just do this and then we will not actually do error handling here you would exit you would either show message to the user and exit in this case or you would fall back to different renderer all right let's run and see what happens alright so we don't have a discrete GPU anyone really have one GPU in the first place so we're picking the Intel let's do less than this all right now we need to create advice to create a device you call Vicki create device so you need the physical device that we have just picked you need create info that will fill within Xero as allocator and we'll get device and we'll need into the cage around this so most of the Vicki checks that I'm writing are basically things that you'd have to handle in the production render let's do the code begins to get unwieldy so let's start refactoring this a bit because I want yeah I want like shorter names for variables so let's just say that we'll move all of the code that creates an instance into here and keep going well right now we will need great info and we'll have to move device initialization out at some point end but whatever so let's see what do we need to create oh right do I need to pass this thing too oh is this the deprecated stuff device layers have the deprecated device layers the problem with the Vulcan spec being really large is that browsers aren't very fast maybe they haven't all right let's ignore us for now I don't know if I need to do anything here I think I will need to I may need to do something here but let's ignore this for now ignore this we will need this unfortunately and all right he will not need this yeah so when you create the device you are supposed to say which device cues you need and we will not go over device cues right now oh do I really have to fill this in I think I do yeah yeah so this is another place where we'll cut corners because I don't want to do the correct thing right now you're supposed to a device can have multiple views and issue can be used to submit commands but you don't know which hue you need without looking at what hues can do like there could be a few that only can do compute and there can be a few that can do graphics and presentation and there can be a cue that can only do copy technical computer you can also do copy and you're supposed to kind of look at the device properties and figure it out but in the interests of in the interests of getting something going which we probably will not get to anyway but hey we should try we'll just say that all right yeah zero we'll just say that we will assume that the family index is zero shortcuts this needs to be computed from cue properties and then maybe we'll get to it or maybe we won't like theoretically zero might not correspond to a few that can do anything useful on some GPUs and then it's feared that you have to fill some of this stuff like it's just it's not I don't feel like I'm doing useful work right now but I get whatever mm-hmm all rights creating you readin ow creating you enforce cute info so we might have a device now especially if the code compiles oh this is valid C++ C++ is an amazing language maybe I should have used C all right no what do we have oh no our shortcut didn't work the validation layers insist on us doing the right thing which I mean as good I guess but it's so painful so yeah they want us to get like to examine the Q properties before actually picking this as the Q that we will use because they say hey if you haven't ever looked at the Q then you're using a shortcut shortcuts are not nice I really don't want to deal with this stuff like I might deal with the stuff at some point but they don't want to deal with the stuff now okay okay okay should I ignore this I don't want to ignore errors let's just ignore this for now so this is something we'll actually have to fix because I wanted to be validation clean but I don't want to spend time on this right now all right so we have created the device now we need the surface and then we will need a surface a swab chain and then we can can we do anything with a swab chain yeah we can't do much with a swab chain so we are not close yet but we are making progress let me look at chat yeah device layers are deprecated that's what I thought which ms serfs are using for vulcan development this is streamed from a surface pro vulcan works on it if you install Intel drivers from the Intel driver website it does not work if you just use Windows Update like my hardware I'm not sure what that means thanks for walk metal order you're welcome what do you think about the easy I am NOT a fan of EEZ it's a good idea but they are redefining the meaning of existing Vulcan concepts like they have a VK buffer Creek info that is not VK buffer creed we can create buffer or something that matches the name perfectly to the Vulcan we can create buffer but it doesn't do the same thing at all it doesn't even have the same interface so yeah I'm not a fan Oh is it possible to write 1080p stream I don't know oh I looked at this before and I thought the stream was 1080p but that somehow wasn't but I don't know if I can swish it now I should have looked at this before what happens if I change the streaming resolution like midstream I don't even remember where it well yeah I guess video output is currently active yeah it's my bad I should have done this before so we'll do this next time you can get a black window with swap chain well yeah I guess there's that clear color yeah no so for clear color you need to do a bit more but yes so we will get to a non black window probably earlier what as well could interest we have trying to send would welcome is build on top of um I guess I don't really understand this question but mostly it interfaces with a graphics driver it doesn't the stuff that I'm doing now so like from Vicki Curie device and there on out I'm just talking to Nvidia graphics drivers plus the validation layers there is nothing else really in between I don't think alright let's do the surface stuff so so yeah I think somebody was mentioning that gfw has a function creates a surface by the technically I'm not allowed to use it because it's like part of GL f W and if GL of W has get platform and get window handle or something like this we should should just then we'll just create the thing ourselves I guess the problem is if we do that we will not work on any other platform and if we don't do this you know what maybe let's just creates yes so there was like some Vulcan stuff see yes that is this guy which basically abstracts the stuff that you'd have to you know what now I kind of wanna yes forget win32 V new I kind of want to just write the code that you would have to write in terms of whether you use G lm/w so we will say that if they have the key platform right OU's win32 I don't remember use platform Oh God okay let's go and look at this code so most of welcome code is cross-platform the only exception is the major exception I should say is the code that creates the surface unfortunately there's different exemptions for this and they are basically all the same so that's not very nice do we have to define this I think we have to define us ourselves so there's that and then okay so we need to create the surface and to create the surface on Windows you do create window create win-win thirty-two surface eh are you pass it on instance you pass it creating foil as usual which is the point where we'll make a function right now the key surface key char so yeah this is the function that is available in jail of w but if you don't use jail of w then you can use the function right obviously so we will do this and this is where you would add support for Linux or molten V key or you know I don't know what else Nintendo switch all right oh yeah and we'll need an instance this is like the only really platform-specific part that you would need to write for most welcome applications which is nice [Music] and yeah so we'll need the cretan for win32 surface Cretan form so yeah if we used C++ wrapper then the big thing that it saves is it saves typing on these things which I don't consider worth it but if you consider worth it You Know Who am I to tell you what you should or should not be doing so we need an H instance which can be retrieved by doing this on Windows and we need a shoe and which was like chill of EE what was it between 32 gets now ready for that yet we're in 32 window there's a thing it's not a thing I might need to include something to get this thing all right I don't have it is not helpful jealous fw 3 native all right now that I can do um so this code becomes cross-platform [Music] that not work oh oh oh okay I guess I need more defiance more defiance oh did I alright that's I think I didn't all right does this work now all right so yeah so the basically these piece of code is the piece of code that we valent Lee ignored the existence of in jail of w and assuming this works we got the same thing but now all right this does not work all right we forgot to do something oh yeah oh yeah I forgot about this yeah right right right this is like a device abstention hmm all right I'm at the point where I want to extract this code so this is how device compression works right sorry semantic compression works you sort of write code and yeah and you like this code gets ugly let's just move it out and it's really easy to do that in some in some cases in some software programming like environments this is called extract method or something but really you're just moving code to functions all right so there's that all right so the thing that the reason why the code didn't work is because this function is part of the extension I forgot that it's not part of the extension that we have already enabled which is this one it's part of a different extension it's Windows 32 specific and my recollection is that it's a device extension so in welcome you can enable extensions on an instance basis and on a device basis device stuff goes I guess more direct into the driver there is like reasons for why some of this stuff is done this way like I don't know if the problem is the load rope has to know about the extensions that you can enable through it as far as I know so I guess if we are dealing with something like r-tx where there's new and media extensions you can't really enable them in the loader because the water doesn't know about them but you can enable them on device goes to device to us I don't know maybe there's a different reason for some of this stuff I am a bit fuzzy on some of these no.not spec version extends name I'm also really hoping that validation layers thoroughly verify this so normally I guess I was talking about this before so it must not be it must be device extension but then why interesting all right so it must be like an instance extension oh I guess right sorry I'm being stupid it cannot be device extension because we haven't even all right nevermind so it cannot be device extension because device extensions work with things that you need to device for and to make a surface you don't need the device it cannot be a device extension I don't know how to format this oh no wait this is this is a little bit okay this might work so we still are getting this error above the EQ family stuff and it would be nice to clean that up it kind of depends on whether I think we can get to something on screen today maybe so I don't think we could get to triangle on screen and I figured we wouldn't be able to because I will need a shader to render a triangle but we should be able to get to like a magenta screen hopefully even that's a bit of a stretch all right let's let's write a bit of code a bit more code and then see where we land and maybe I'll fix the validation thing before we stop yeah I do need to include gel three native GL fw three native and then turns out i also have to enable some macro for this alright so yeah so we have created the surface now we need a swab chain so to create a swab chain we need to do create swap chain again and so surface is the thing that manages to option to swap chain is the thing that knows the specific size and and stuff like that swap chain management in Vulcan is tricky I might not you will notice that I'm mostly not looking at the spec so normally when you write Vulcan code you should be looking at the spec looking at what it says and then like writing code based on that and then maybe look at some tutorials although tutorials are not always correct even really widespread tutorials there is like bugs in some of them so don't assume that just because the code is in some tutorial on Vulcan the code is perfect you should read the spec try to understand the spec if you can't understand the spec then and you know you can ask people who you think might understand this place oh yes so the device extension is for swaption creation right right is that right KK char swap chained yes all right um so yeah I guess I need that right I remember the was a device extension that you basically need all the time but they didn't remember what it was so I guess it's this one oh and I'll just copy this code all right so there's this weird naming stuff about basically a lot of words that look like they're two words but they actually one so swatching is one word which is why C is not capitalized frame buffer is one word although a lot of people spell it like this a physical device is two words so go figure all right so yes we don't need and so this watching is something that you'll have to recreate when the window size changes we will try to not do this today because it's more code and you know code is painful to write Oh swaption counter all right I have not seen this extension before why does it really really Oh xed what okay oh good never mind all right yeah so this guy has a lot of properties so this is where we will look at the spec and you know look at this stuff so yeah this family index thing we will need later so let's just say that if you're writing a Vulcan application that is really really advanced you might want to use multiple cues in which case you need multiple P weaknesses and multiple like a lot of these things there are reasons for why you might want to do that we might get to that at some point but definitely not now all right all right so now let's look at the spec I guess I don't know while I remember most of these and some of these are slightly tricky to deal with and we'll be cutting corners so maybe I don't let's just wing it and then we'll see how we did hmm so I don't need flags I do need surface oops so you remember all of these structures you don't neutralize everything that I haven't filled is just filled with zero so minimis counts when you play the swap chain that's what shield will manage several images for you in an image is just an array of pixels essentially but it's visible to the GPU you generally need a double buffered setup so this is what mean image count is for it says I need at least two images or buffers well buffer is like the wrong term but in Vulcan buffer means a different thing but double BA in double buffer context buffer means the same thing so whatever so yeah image formats so this is the thing that will determine what you use to what format you use to render into the surface so some devices and I don't know what until does but some devices only support bheegi bheegi are a output not RGB a output so you have to kind of figure out which format you should use dynamically and I think the same thing this is like wrong enum no this is the right enum yeah I knew this guy wait I think I need this guy I don't remember if this is wearin t to be supported but I guess it's the only in our entry that is not like crazy high numbers so I guess it must be guaranteed English extent is the size of the swap chain and he has like within high probably so this will just feel with just and Oh she'll W get window with is that the thing get me those sighs okay all right intellisense works really weirdly with this partially written code so the stats so this basically these parameters tell the driver or not really the driver but tell Vulcan what how you will like what parameters they want the images to be created with so the science is pretty straightforward there are some use cases where you might want the image to be at actuary but we definitely are not gonna do that and then you have to say what I'm gonna do with the swaption images so we will render to the swaption image which is this thing you can do other stuff with the swaption image so like maybe you want to copy things to the swaption image with this will not be using that so there's that this is for cross process sharing we don't need this just don't feel that see yeah this is the weird like I wish I didn't have to fill this yeah this is all not useful present mode is this is for whether you whether you need to sync or not or there's some other values here we might need to I think Pfeiffer's should be guaranteed though so there's that all right um we might be done with that part oh so validation layers have been difficult again it feels like whenever I say that we'll make a shortcut here validation layer say no you have to do the right thing which is nice so it tells me that this is thing I was talking about not like there is not a single format that is guaranteed to be always supported so you have to always check which formats are supported so you have to call this thing and then it complains about some other stuff oh yeah and tells us that you have to check if the physical device actually supports rendering into the image which we haven't checked all right whatever we will clean this up later the code works for now you should never ship the code with validation errors and if there's ever a bug in the code and you have validation errors you should probably fix them first but there is no rule that says that you can't ever write code with validation errors you just shouldn't ship it right we'll fix it later alright so I might be able to can I present now I might be able to present is that true I don't remember only the cue well device swap chain I think I'll need the semaphore yeah so I think I can basically write a loop here all right so how much work will it be for me to actually clear is there Vickie MD clear no oh but because mg means that I'll need to suggest Russ this guy but I'll need a command buffer and to make a command buffer and in the command pool all right we'll probably just not get to this today I'm trying to figure out if it should be fixed in validation errors or if I have a reasonable chance of getting something on screen that's not a blank window [Music] you know what I think we can try it yeah maybe you can try together so let me look at chat and then I will yeah so five is guaranteed mailbox there is like a reason for why you might want to use mailbox but there is also reasons for why you might not want to use mailbox so mailboxes yeah how large is the Welcome codebase I guess I don't know which codebase you mean so if you can be more specific I can maybe answer this yeah so I can use I was planning to do device wait item I think I still need the semaphore but I don't need some other stuff so yeah so let's try to do this alright so the so we have a swap chain so that's nice now what we need is to present the swap chain to the window so we need to for each iteration in our loop we need to say first let's get the image from the swap chain that we can render to then ideally render something to that image because otherwise I don't know what you're doing and then tell the presentation system here's the image please use it to display the windows content contents and that operations called present so we can do that we can try to do that let's try to do this so to do the first thing you need to do wiki acquire next image so this says given a swap chain please give me an image or rather like an index that we can use later so you need the device you need a swap change you need timeouts is there like a timeout infinite became out I'm out come on intellisense work with me here okay basically I don't know what the spec says here now we need the semaphore I think fans can now I not I might talk about this stuff later but if I talk about this stuff now we will definitely not get this done so I'll just ignore this for now I think I need either a fence or a semaphore so civil to use a semaphore a fence would be easier because reasons okay um yeah let's let's do this okay these are the abundance of the create infrastructures it probably is a good idea when you write Vulcan code specifically to just immediately move things like this to functions and again I think this C++ wrapper makes some of these things less painful but it also makes combining my code more painful so I don't want to go into this land of C++ stuff just here they don't think there's anything useful here like in some other languages you could imagine that you can do like this whatever like that you can just have a stroke literal and then take a pointer to it and then just use it don't think in C++ you can take a pointer to a struct literal so alright so I want a function to create a swap chain and I want a function to create a semaphore because this is getting unwieldy Oh aunt's family index I might cover the cue feminist on the surface oh my I might cover the cue family stuff on a subsequent stream definitely not now come on I'm heating oh okay I'm accidentally hitting the window scheme and let's just do some before fine all right it's kind unfortunate that you have to this is why so somebody was asking about vici easy so the not nice part about welcome is that to get to interesting bits that I actually want to talk about on stream we did migrate in flow I think I raised something I shouldn't have okay to actually get to the interesting parts you need to wade through the non interesting parts now I could just take a framework right but then you would not be right learning how to write welcome code from scratch some food might be interesting should type semaphore yeah so but this is why frameworks like be easy could be good because they let you skip all of the stuff that honestly isn't super interesting I mean it's interesting occasionally but not it's not that interesting and then just get to be to the fun stuff alright so yeah so now we have a semaphore the semaphore is used assistant synchronization mechanism so when we call this function it says here's an image index that you can use in the future but its uses conditional on the fact that the GPU stops using this image before you start using it again and the way how you know when it stopped is you use the semaphore so this is why I need a semaphore and to present the image you need to serve to render the image on screen roughly speaking you need to call this guy so for this we need a few which we don't have yet and also we need present and for which we really don't have yet and I and I anticipate a problem with all of this stuff because I might oh yeah I might need the command buffer already at this stage which would be slightly painful motherly um yeah so let's see this is a different semaphore I don't think I will need this later but I don't need this now so we will not fill this in you can present more than one image for example in in the stuff that I do at work like one I work with Dropbox for people who don't know and we have an editor the editor has Windows and many of these windows are rendered with graphics API for example Vulcan and for that to work you have to present multiple images and we do this like with this see there is a reason why you might want to say swaption count to be 2 or 3 this is when you have multiple windows and you want to just render into all of them at the same time what is this interesting I never use that all right so right so we don't have a queue so the queue is the thing that you submit work to for GPU to work on it and this is where this this is what this feminine this was about so if you have like a graphics Q and the compute Q graphics Q might have a family of 0 and compute you might have a family of 1 but we only use one and I don't remember how you get it you get device Q all right device family index cue index I really hope validation layers won't complain more about this stuff but alright so I suspect this will not work or I suspect this will fail validation but let's see if it compiles mmm-hmm it emphatically doesn't work it crashes oh I forgot to the device wait idle mmm which mind a problem but might not be a problem all right let's see what it once alright so Oh Oh [Music] validation layers crashed nice okay let's that was interesting this is not a problem but probably but I will do this anyway yeah that's interesting hmm so the reason this is this is also not gonna help but the reason I want to do this here for now is because normally you have to deal with some complicated synchronization mechanics when you wanna run GPU and CPU in parallel and here I will just wait for GPU to complete everything that it's doing to not have to deal with this but the code will still crash so we are crashing inside validation layers which is not fun generally validation layers aren't supposed to crash they're supposed to tell you what you're doing wrong so that's not great what wait so yes I'm passionately pointer to the image syndics it gets a pointer from the driver it gets a value from the drivers value is 0 and then it performs some validation shaking and then it wants to see but there's no mm-hmm all right I mean I can't like blame the validation layers cuz nobody should write code like this because we are writing code like in small B's pieces right like this code doesn't work yet but yes I think what happens is this you're supposed so we are dealing with the image index here but this is just an index it's not an object right so you're supposed to get objects from this chain that are indexed with this index right and then like use them but if you never do this I my guess is that the validation layers don't initialize some code that is like important and then crash will file a bug on this if this was if this is true so my guess is that if we do BK yet swap chain images which says given a swap chain give me the images that you have and then my guess is that the crash will go away but it's kind of not ideal that you have to do this so there is that and here we will do our usual I don't yeah normally you need to ask the swaption how many images it has and then create some sort of dynamic radius for this but this is so not worth our time so we will not do this oh and you learn how my name is just how my name is just we have and this is there's some functions in welcome that can fail so they return we get resolved and there are some functions that can so then you turn void so this apparently can fail sometimes so let's see if that fixed the problem with validation layers if it did we will file a bug it did we have a black screen you can see that we are not doing things correctly there is like problems here right because yes this is what I was thinking it would be the problem but hey until drivers don't care so we won't care for a bit and the member will clean all of this up later all right so we found both invalidation layers validation layers crash if you call this guy before this guy because this guy neutralizes some state in validation internals did I specify a queue in the device create info yeah specified the queue index it's like zero I just hard coded it as zero for now so yeah let's just do this now because it'll take us a minute whenever you have issues with Vulcan ever you should file them as bugs obviously validation layers contain bugs for relation layers there's some other repositories that you should file bugs to if you find one yes there's nothing already reported like this one unless it's been closed now all right good so we will say crashes in validation layers hasn't being called or calling which could be potentially invalid if the spec says so but eh I don't know that it's invalid B even if it's invalid you shouldn't crash you should have an error validation layer scratch here let's just ship where the crash so that we can file a better bug report all right like all right there is that I think it was emptying right yeah hmm and that'll be just the reference it with a little zero and then we crash alright cool so so we have ourselves a black window we have validation errors we'll have to fix them but not today I want to see if we can get the window I kind of wanted to spend like two hours on this and we are getting really close but I really wants to see a color that is not black and I think we can get there pretty quickly so normally you have to create a few extra structures like like many more extra structures to be able to render things to an image and we will try to like clear the image in the sort of least number of operations possible even though this is not good practice so we will try to say that once we acquire the image index we want to clear the image and we will do this is with this V key CMD clear color image that emits a clear command now for these we need to learn how to emit commands and I want to see if I can just write code write this code in like five minutes without talking about this and then have an image and then answer questions and then end the stream and then next time we will clean up the validation issues and actually get the triangle on screen all right so yeah so we need a common buffer so let's just try this so there is no whiny the command pool is I need a command buffer and the reason I need the command buffer is I need to be able to submit commands what so command pool isn't managing commands command pool is managing command buffers so trigger should be called command buffer pool but what can you do and when I create it I need to specify like which [Music] which which queue I will be using to submit these commands to but also I should probably be destroying some stuff all right let's alright there's that and then let's just destroy a bunch of stuff that you forgot to relation layers should actually track memory leaks so maybe let's not bother doing this and let's clean this up later hmm alright so what we need to do is we need to reset the pool so that we can use it so that we don't like leak memory and remember so we are waiting for GPU right now we are we are like recording a frame submitting a frame to GPU waiting for GP to be done with this and then do the next one when you are not doing this and we will not do this at some point in the future you need more complicated code but for now the code will be simple alright so now we need to allocate a command buffer just one there's a lot of I kind of forgot how no I kind of forgot how much code it was cause like I mean we have welcome Grindr at work a few people wrote it I wrote parts of it and then it like works and then when it doesn't work you like fix it and you kind of don't worry about this stuff cuz you've already written this code turns out writing this stuff from scratch is not like it's been I mean I haven't been just writing code like I think if I was writing code without talking which would not be very fun then I think I would have had that triangle I think I would have gotten a triangle on screen but that's still like not very good even though so OpenGL is more of an verbose but like in Morden OpenGL you still have to allocate a lot of stuff hmm like not like a like prepare a lot of stuff oh I actually I can allocate this thing once and then I can just reuse it because reset command pool should make it usable again all right um so begin one thing that annoys me about Vulcan is these endless structures that you have to fill and like like the fact that they are present it's not like it's very hard to fill them but this turns every single function that I want to call into like multiple lines of code and there is a reason why they do this it's to make extendibility easier but this right that is like a function with two input arguments flags and inheritance info and both of them can be 0 I think well this should really be this for performance but like and I need to spend like three lines of code instead of one line of code and it accumulates let's return yeah okay all right so that will and command buffer also intelligence is really slow it's kind of interesting it looks like it takes it a while even with the C headers I'm glad I'm not using C++ letters all right finally we can record the clear we will have validation errors we are not doing things well or we are not doing things right and I will not bother unless the colleges doesn't work and we'll talk about this stuff later in the next stream so we need an image we need an image layout let's just pretend it's like I don't know in general or something I don't care we need the color we need the range okay okay hopefully this is just for floats oh it's a union okay so yeah let's see if we can clear the screen and then there was like sub resource range I am NOT so yeah I'm including some parts of the like I'm not explaining some parts of the code that I'm writing we will do this next time if we rewrite some of this stuff to be less obnoxious common buffer all right and then the other thing that we need to do is we need to submit to this command buffer for execution and you know what we need to do for this we need to fill a few more structures it's amazing and we need the fans do we need any defense I don't think we need offense I hope we can not use offense I think we can not use offense King like the nice thing is that when you know what you need to write the code kind of writes itself plus or minus validation errors the not nice thing is that it takes a lot of code so this is actually important so when we I talked about this when we called this image we passed at the semaphore and the semi sure turned us an image index but the GPU might still be using this image so we can only really use this image once the semaphore is cleared this means that if we're on the command buffer it clears the image before the image is done like before the GPU is done using it weird things can happen so we need to make sure that when we give commands to the GPU we say hey don't run the commands up until the semaphore this one is radio and also we need this thing which I will talk about next time and we are not doing some of the stuff correctly anyways mid-stage mask but yeah we need to wait for this guy this is like a very tricky things that have to do with synchronizations in synchronization the Vulcan a very tricky this particular thing is really really really tricky it's so tricky that there is a Cronus Vulcan Doc's repository and has a wiki pages pages that only has one page that synchronization examples and one of it's a long page but it's not that long again and one of the things that they tell you how to do is to do this thing somewhere I don't remember where should be like presentation yes it's what she knew miss you weren't present so really you should be like looking at this code and then using this code but we pretend that we know what we are doing which is not true but we don't care no so you say this we want to submit our command buffer um yeah okay I need the second semaphore let's just do this now because I don't forget later so so there's two things one I just talked about where you have to wait for the GPU to be done working with the image before you render it into it into it again the other thing is that you have to wait up until our commands have finished executing like after we have cleared the image before actually showing the image on screen to do that we need to when the image has done like processing we need to say that we need to signal this the other semaphore and I will I'll draw I'll draw a diagram of this if this works and if it doesn't work then I don't know and then when you are rendering this image or when you're like display in this image on screen you have to wait yeah you have to wait for it to be done rendering so we haven't even like rendered to triangle and we had already had to deal with synchronization in two places and this is despite the fact that we are waiting for the GPU after every frame so that's gonna end well let's see if this works if this works then we are done and if this doesn't work then it's gonna be painful all right so there is a lot of validation stuff that we have been ignoring some of this validation stuff is super legit and like the fact that the code is working right now is sort of accidental like it will not work on a different GPU potentially but it's been a while so this seems like a good place to stop the stream so let me quickly draw this picture with the queries and then I will look at the chat and then I'll answer your questions and then we'll end the stream so yes what happens is this first there is a choir and there's kind of two timelines there's the CPU frame and the GPU frame so on the CPU in our loop we say hey here's the index right but the cheapy you might still be using let's say we got zero the GPU might still be using this index for previous frame for example to display this image on screen so display zero this means that and then we are saying okay let's do clear write with index zero and then let's do present this is one submission this is like when we say what was it when you say vkq submit for the command buffer that contained this clear command this is when this clear command goes to the GPU and can start running there but see in this case if we start running it like here then the GPUs in process of displaying the image and we will try to clear it during that time and then maybe you have cheering where part of the image is clears and part of it isn't or maybe the you will just crash because there's some memory controller issue with concurrent accesses like this so because of these the clear says that there is a dependency so aquire says that there is a semaphore that we have called acquire semaphore and the GPU knows to signal the semaphore once it's done so here it will signal acquire semaphore which is when this thing can start running because this thing is waiting for the acquire semaphore and then the same thing happens later when we say present if we were to immediately submit the command to GP like this then it will start running before we have even finished clearing I guess right especially if it's a different view but even on the same view there are some cases where present may start running before all clear operations have completed so instead we are saying that on GPU there will be a clear and then it will signal the release semaphore and this is what this code is doing and then we are saying when present execute to all like to execute present we have to wait for the release semaphore which is when essentially display will happen again right and this is what this code does and yes so this code is almost correct there is something like around here that's not correct that will deal with next time but hey the code worked it rendered a beautiful magenta image in the window it also has a lot of validation errors all right let's look at what Chad thinks [Music] yeah tough first steps yeah so I was kind of expecting to will not get to a triangle coz to get the triangle I have to compile a shader two of them I have to create shaders which is like three new object or something and then I'll have to create a render pass and create a frame buffer and a bunch of well and I guess that could be it I don't need buffers yeah so but then I don't I also have to clean clean up the leash snares right and then I don't want to just gloss over like everything that I was doing in the last 10 minutes or 15 minutes so that will be a subject of the next stream where we'll clean up the violation errors and actually render triangle stream all right have I considered using c99 designated initializers for BK structs yes so the problem is c++ doesn't support this which means C++ compilers basically don't support this in C++ mode I think it's a feature in C++ 20 [Music] yeah oops wait yeah so suppose first onee will include support limited support for c99 designated initializers I don't find them that much shorter I guess they basically remove like this stuff and allow you to do something like this Plus this right so it's like a shorter but also man whatever like this is not why this goal is painful it's cause you have to fill a lot of stuff out let's submit the code while it works I mean it has validation errors but it works why doesn't it show Oh what oh no is this this amazing Visual Studio thing that somebody was tweeting about oh studios so this file is encoded in utf-8 steen I just I don't I don't know okay all we committed this a CDF 16 of course because it was encoded the CDF 16 in the first place okay Wow let's fix this first to have a diff should I like file this as a bug right now let's find us a bug right now because seriously Microsoft this is insane like why does it create new cpp files with utf-16 encoding if there's no reason in this world to have a CPP file and utf-16 encoding I didn't I'm will have Unicode there in the first place like this is just insane oh my god oh my god like seriously who came up with this I think I I think guys I didn't even realize I would ever see this I was like yeah whatever I think somebody complained about this on Twitter like a month ago so and I was like yeah this is really weird but whatever is probably some like weird wizard in the visual studio that we ended up using and then I hit the same problem all right yeah like you should not use utf-16 ever but especially not for files this is like oh all right so let's fix it and wear them I forgot how to do this this no I mess it up every time was passing yes was passing and we saved like a weird file somewhere okay that didn't help that's made it worse all right okay and now it has a bomb why doesn't beams oh there was a bomb so it saved the bomb [Laughter] software is broken okay how'd I disable bomb really really no bomb like it makes sense that it I guess sort of makes sense that beam kept a bomb because there was a bomb in the utf-16 file but this is like wolf this is so broken okay all right so alright now let's unstack the stuff that we have done sure whatever and then repeat this process right because now well don't tell me this will be not fun all right no hmm this will be incredibly unfun yeah see ya so while it does it oh it's just can't merge binary files how can I force it to merge a binary file computers suck if it turns out that we've just lost the stuff that you've done this will not be fun yes it should should I just check out theirs oh my god all right great right I will figure it off after this I don't know what happens binary files suck Visual Studio is horrible we will I will figure out what happened offline and like restore this stuff and then she is covered in after the stream but this was like ridiculous right like why why was this file utf-16 to begin with like this is just insane visual studios I really messed this up all right cool he has if there's any other questions about this stream I can answer them right now if there is nothing then we will end the stream and then I will figure out I think the changes are there they're just like in in women to history or something I have to figure out where they went and then just submit them in the correct encoding this time so close this close this file this bug yeah we popped out that's what happens all right all right um yeah let's just under stream I guess because I don't think let me just scroll back just to make sure I haven't fixed anything I haven't missed anything yeah right yeah so I will fix this stream resolution for next time I think it might be that Oh actually wait how come hold on oh yeah yeah yeah so I will fix this thing next thing will be 1080p well I feel be good I don't I think we might do the next stream tomorrow same time I'll double-check I think my I think we might do maybe an hour earlier would be better yeah I think we might do next stream tomorrow just to sort of get the triangle done and you know claim victory on that part see a tentatively tomorrow 10:00 a.m. I'll post a Twitter update all right thank you for watching the stream we have recent welcome code we've cleared the window to magenta we have hit a lot of validation errors and most of technology we've hit the foundation air above and reported this it will also hit the crazy Visual Studio binary utf-16 issue this is just insane that I've reported hopefully they will fix it I've reported some other stuff to Visual Studio and they have generally been reasonable about fixing stuff however it's not always superfast right like I think this thing is still not fixed I guess I deported well no if that's unfair right here I reported this and then they closed it and then I have to report it again but yeah so who knows when they will fix stuff they did fix this issue so that's good all right thank you see you guys next time mmm let me kill
Info
Channel: Arseny Kapoulkine
Views: 41,761
Rating: undefined out of 5
Keywords:
Id: BR2my8OE1Sc
Channel Id: undefined
Length: 142min 39sec (8559 seconds)
Published: Sat Sep 29 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.