Thursday 2 August 2018

Dev Update 4: Rendering: Check. Minimizing: Check. Restoring: CRASH!

- Image views for each swapchain image.
- Selecting which memory heap to choose. Will need later.
- More Vulkan learning, Command buffers and pools.
- Actual Rendering!
- Code refactoring. Preparing for some actual rendering.

New Week. New Progress!

This week has been the first steps towards making Vulkan do some actual work! The code for this week added the following:
  • Image Views.
  • Detecting and Selecting "Memory heaps".
  • The start of Command Buffers and Command Pools.
  • Actual Rendering!
  • Finally, refactoring the code.

Image Views: What are they?

They are objects that allow the images to be used. Thing about it like this: Images are just the raw data. That's it. It could be in RGBA format, or BGRA, or any other. The computer doesn't care. Vulkan doesn't care. It's just data.
The Image View is a "view" into the image, it translates that data to useful data. Are we dealing with a 2D or 3D image? What format is it in? What are we using it for? Even how many layer's we're dealing with and the mipmap levels!
All that is contained in the Image View. Without it, the image is just raw data.
So yeah...Learned how to make them this week.

Memory Heaps. Heaps of Memory. 

As in, area of RAM (VRAM, SDRAM, basically all and any RAM that Vulkan has access to) Each different type of RAM has a different way to access it, and what part of the computer can see what. Some parts the CPU can read and write, while others the CPU can't, therefore it needs to ask the GPU to upload data into it, or download data into RAM the CPU can see. Of course, that goes the same for the GPU as well. Some VRAM the CPU can see though (not sure how true this is, but either way the CPU can freely use it), and the CPU uses that for things that change all the time that the GPU will need, things like (simplifying here) where the camera is and where it's pointing at, any change in colour for that 3D model that can change it's colour, and more. 
So I built something to easily give me the index of the memory heap which has the requested attributes.

I Command you to Pool and Buffer!

Command Pools. They're just this big pool of memory for commands to the GPU to go into. These commands are held in a buffer. In Vulkan, instead of saying, "Do this NOW!" You say, "Here's a list of things I want you to do. Do them."
So in this metaphor, a command pool is a pile of papers, maybe a notebook. A buffer is a page in the notebook. You then write commands to the page, then give the page to the GPU, and the GPU follows them. This way, you could have a book of commands you already want to do, and then tell the GPU to turn to page 20, and do your thing!
Of course, that metaphor is grossly lacking details, but if you want a real Vulkan tutorial, you're reading the wrong blog.

Screenshots!

Erm...Screenshot actually...Just one:
I know, it's not super impressive. But hey, that took about 600 lines of code to do!
Yes. 600 lines of code. To make an orange screen. Not to mention that at the time of that screenshot, if you minimized then restored, or resized, it would crash.
I fixed that shortly after. Can't have a game crash on you when you decide 800x600 is too small and you want 1080p.

Finally, some refactoring!

I decided to clean up my code as there was one part that kept on repeating over and over again. It was error handling for Vulkan, as most Vulkan functions up to this point would report VK_SUCCESS if it worked, or something else if it didn't. And if it didn't, we wanted to make sure to gracefully crash.

And the conclusion:

This week was busy with coding. It was a good week and now I'm learning more about Vulkan, and how to render! I'll be dealing with a lot more this coming week, both in learning Vulkan, and some personal stuff which may slow down development for a bit. Hopefully it won't be too bad though.
Anyhow, I gotta finish this and start working on some more game related stuff (Like playing No Man's Sky Next). So thanks for reading this far and don't work too hard!

No comments:

Post a Comment