Vulkan API Tutorial - 6 - Window Surface

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to another Vulkan API tutorial this tutorial will go through all the required steps to create a window surface we need this surface to display Vulcan images in a specific operating system window to create a surface we need some special local extension functions and we'll go through that process in this video this is last operating system specific stuff we're going to do prior to entering into a window the Vulcan extension will be using is called WSI which stands for windows system integration it enables us to easily connect Vulcan to our operating system window it's also included with Vulcan and in lurches Vulcan SDK we can render images is fine without the WSI extension but we cannot display anything in a window without it embedded systems like vacuum cleaners for example also have the possibility to render directly to a screen but if you have an operating system like windows linux or android then the only way you'll be able to display images on screen is through the operating system and through the operating system window manager this is where we need the surface for i also have a small announcement at the end of this video but let's do the tutorial first we are going to have to access some of the Vulcan instances and devices and the cue from the window and I don't want to access those member variables of renderer class directly so the first thing I'm going to do is go to the render header and then i'm going to introduce some gator functions the exact things i want to get is the vulcan instance walk and physical device vulcan device or con q vulcan traffics in q family index and Vulcan physical device properties the physical device properties is a structure so I'm going to return it as a reference as a constants and you can see the functions in here the only thing they do is basically just return in GPU device give graphics family index and GPU properties the window objects will definitely at some point of reference renderer and to do that we need to store the parent pointer so renderer pointer to render default value is null pointer let's also declare the renderer in here and also let's modify this constructor a little bit now we're going to ask a renderer as well in the window dot CPP file let's modify this constructor a little bit again like this that makes our life a lot easier now in the previous tutorial we created a function that we didn't define so in it OS surface is declared in the window glass but it's not defined anywhere so we're going to do that in the window underscore win32 dot CPP file and we're going to add a new function which is this function within this function we're going to now call a function that's available only in the WSI extension and this function is called VK create win32 surface khr on an xep this would be VK create xeb surface khr this function takes an instance now that we have a renderer getting the instance is pretty easy the next is the create info allocation callbacks on the surface so let's do the easy one first we'll go back to the window dot H file we're going to add a new member variable which is going to be VK surface k HR and we're going to name this as surface and the default value is BK a null handle will go back to window underscore win32 dot CPP will give that handle in here so or pointer to this handle in here now the only thing missing is the create info which is a VK win32 surface creating for k HR this creating for has a few fields we need to put in s type is VK structured structure type win32 surface create info k HR the flags is reserved for you to use and the p next we're not going to put in there so that leaves us hinstance and hwnd so let's put in the hinstance first and that's exactly the same thing as in here get module handle when we created a window so win32 instance and the next thing is the handle to the window so hwnd which is the handle to the window which we get when we create the window in Windows lots of Windows anyway so let's give it that let's just give it the create info pointer to that in here that's everything you need to create a surface now we do need to destroy this surface as well and in the window H file we need to create a couple more functions the first one I'm going to call it's going to be a void function again in its surface the second one will be D in its surface I created these functions within the window dot CPP file these are going to be basically multi-platform files and before I forget let's take the in its surface and call it in the cone structure within the D structure we cannot the image visualize the surface so d in it surface now this D in its surface well the only job for this function is basically to just destroy the surface and that's really easy we don't have to call any platform specific functions for this so BK destroy surface khr the first parameter is an instance again so renderer we need the header file include renderer get instance the second parameter is the surface itself so surface the last one is a null pointer that's the whole T in its surface function that's all we need to do in it now let's go back to the image surface function within this function I want to call the platform specific function so i'm going to call in it OS surface then after that there's a few more other things but let's try running this now I'm waiting for it to compile error okay I've got one thing that is to when we create the window where I need to give the renderer to this window so this now should work okay it almost works and plays it compiles so what we are missing in here mmm VK create win32 service cage khr called even though the VK k HR win32 surface extension was not enabled in this VK instance so what are we missing in here if you take a look at this instance extensions vector we don't give it the right strings it doesn't load up the right extensions for Vulcan to be for us to be able to use those functions that we need so let's go to the render o dot H and let's add a new function void setup layers and extensions and let's create this function in the renderer dot cpp so right before in it instance i thinkyeah here and before I forget I'm also going to call this function that construction constructor so the first function we're gonna call is this one within this function i'm going to set up some instance extensions and we can also set up other stuff in this function as well later on but for now instance extensions we need to push back a string and there's actually handy macro for this so we don't have to fiddle around with strings and this macro is v k KH r should be here somewhere surface extension name there we go the other thing we need to push back is a VK KH r win32 surface extension name we need both of these to be able to use the functions within this WSI extension and if we compile it now now it just works is fine no errors at all as an extra there's also an bkk HR display extension name we cannot use these display function is going to give us errors if we try to do that it says that VK error extension not present and the error is returned by the error checking runtime error checking this display extension name is not available to most computers and cell phones this is if someone wants to make a custom embedded system and you want to descend directly to the screen then you can use this function or this extension but like I said in the beginning of this tutorial if you have an operating system in that case you don't use the display directly you only um give images to your operating system window manager and that's basically it one more thing about this VK k HR win32 surface extension name if we are using Linux then this one doesn't fly we need to go to the platform and you can see that I changed this file at a little bit since last time but anyways I'm going to define a new macro which i'm going to call platform surface extension name on Windows it's going to be weak AK HR and win32 surface extension name and on the linux on the x cb platform it's going to be v k KH r XZ b surface extension name and now which is use this new macro to determine our extension name surface extension name and running just to make sure it works so yeah like to work just fine ok and moving on in the window dot cpp in this in it surface function there's a few things that we can do now since we're making the surface in this function in here in its always surface after we create it we can actually get some information from that surface and there's a few things I want to know at this point in the application because this is the best place to actually grow a query this on this stuff the first thing I want to know is the surface capabilities and you can ask this from Vulcan directly basically the function for this is VK get physical device surface capabilities khr this function takes this physical device so render up get Vulcan physical device then we need the surface and it returns in the last parameter the surface capabilities let's create a new structure for this right out of the window name and what it actually wants to give us is VK surface capabilities khr let's call it surface capabilities but default I'm going to initialize it as empty and this is a structure if we take a look at it there's a bunch of stuff we can actually get from the surface through this one structure so let's give a point of that in here and a break points and let's see what we get we get min image count max image count these two are basically the frame by frame of account you can do up to eight bothering on Vulcan usually you just use double patterning or triple buffering the current extent sells you the current surface area size and the rest were going to take a look at that later but it's sick this is a good point to ask these surface capabilities we should also ask actually before we ask about the surface capabilities is the WSI extension enabled in this system to do that we can ask it from the Vulcan so basically VK get physical device let's see if we can find it there we go BK can physical device surface support this death takes their physical device so render up get Vulcan physical device then the next thing we need to give this function is the family that we are using to render and display images on the window surface we need to give that Q family index of the Q family that we plan to use to display images on windows so to get this renderer again get bulking traffic skew family index then the surface and lastly a VK ball 32 pointer to that which tells is it support it or not so VK all 32 double yes I support it give a pointer of that in here and then on the next line we can just check if it's supported or not so if support it or not support it in that case we can assert let's include reserving as well like this then let's also exit like this the last step in this function is going to be getting the surface formats that the surface support so to get that we are going to call the function called VK get physical device surface formats khr and this again takes a physical device actually this function is the physical device climbed a lot so I'm going to create a local variable for that and I'm going to call use this variable wherever wherever we need the physical device ok so the second parameter and let's not forget the other small things the next parameter is the surface this kind of works the same way as enumerate physical devices so the third parameter in this case is a pointer to u int32 t so let's create that u int32 t format count by default let's initialize to be zero and let's give a point of that in this function now the last parameter is going to be a null pointer on the first girl this function tells how many surface formats there are so we can actually create a vector sault ste d vector and the type of this vector will be VK surface format k HR i'm going to call it formats and i'm going to initialize it with the signs of format count the next line is going to be basically the same as the second line in this case except then the last parameter takes in the pointer to the data and this gets us all the surface formats now we can see that it does by running this code and let's see what it actually gives us formats size one form of EK formats be eight g8 or 8 a-8 you norm and the second one it gave me is basically the same except that is a srgb so what significance is this well it tells us what kind of frame buffers we need to create later on what kind of format should the frame buffers of the frame buffer images have when we actually create it the frame buffer format the image format needs needs to match the surface format or either one of these ones anyways we need to pick either one of these surface formats for that I'm going to create a new structure again so it's going to be VK surface formats I'm going to call it surface format let's initialize it to be empty and let's get back to this window dot CPP file it would be a good idea to actually check that we get something from this function we need to get something otherwise this doesn't really work so if format count is zero in that case we're going to assert and exit now this is called a surface formats missing or something if the first surface formats is undefined in that case the surface does not care about the format that we choose so if formats 0 or the first format is VK format undefined in that case the surface does not care about the format so we can just choose whatever we want usually it's not like that but just in case we can check this if we can actually choose it ourselves we can just set the surface format format to VK format p 8 g 8 or 88 you norm and the surface format color space there's actually only one option in here so yeah it's a BK color space or srgb non-linear khr this might change in the future but for the time being there's only one option so that should it be if it's not undefined usually it is defined so in that case we're just going to set the surface format to the first available or to the first format it's recommended to use the first format available on your system so that chooses our format and in my system that's it should be let's see what it is actually okay my surface format is VK format be eight g8 or 888 you norm the colors basis is only available so this seems to be working just fine so far and that's basically all I had to show you in this tutorial now for that final note I talked about earlier so far making these tutorials has been an awesome experience for me and they're taking a lot more time and effort than I originally thought they would take so this is my first time making any kind of video tutorials and being a bit of a noob I thought I'd be able to make a lot more in a shorter time but I guess that's always the case exactly why I'm making this announcement is because I will be starting full-time work soon for the summer and that unfortunately takes a lot of my available time my girlfriend also suggested I start accepting donations for making videos in what spare time I've left I thought this over for about two months since I do these videos for passion i will continue making these video tutorials as frequently as i can with the best quality i can if you appreciate the work i do though and would like to contribute to the time and energy I put into these videos please feel free to buy me a cup of coffee and support my work that way imma fins I basically run on the stuff special thanks in advance to everyone who donates and thank you all for your likes comments and subscribes I'll be seeing you soon
Info
Channel: Niko Kauppi
Views: 12,004
Rating: undefined out of 5
Keywords: vulkan, api, tutorial, specification, graphics, programming, gpu, graphics card, c++, cpp, code, coding, advanced, close to metal, glnext, window, surface, integration, operating system, native window, WSI
Id: 36Zj8fa3iyg
Channel Id: undefined
Length: 26min 36sec (1596 seconds)
Published: Fri Apr 15 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.