Vulkan, Wanna Be Friends? #3 Window Resize and SwapChain Recreation

We want to be able to resize our window. 
Many Games don't let dynamic and flexible resize maybe because of the check and additional work each frame and It's not logical to change windows size and resolution so often, so It's a win-win!
After one resize we are freeing and allocating memory which has cost, thus hard to do each frame when resizing dynamically.

Here's a version where we don't handle Resize:

Handling Resize In Vulkan To Resize our window we have to Recreate our whole SwapChain and thus these below as before when initiating Vulkan: ReCreate Image Views Because of New SwapChain Images.ReCreate FrameBuffers Because Width and Height and Image Views(Views to SwapChain Images) ChangedReCreate Graphics Pipeline Because viewport and scissor need to change.ReCreate and Record new Command Buffers Because of New SwapChain ImagesVulkan Tutorial: The render pass needs to be recreated because it depends on the format of the swap chain images.Note (Step 5): It's …

Finally! a Triangle with Vulkan API


Triangle Finally! , but I was 1 day and 3 hours late for my Goal




 1K Lines of Code + 2.5 Earth Days of Vulkan Learning

Oh man! I didn't think It was that hard. but finally did it. WOW Just Look at That. :)

https://github.com/Erfan-Ahmadi/vulkan-learn 

What were my backgrounds?


  • I had experience with C++ programming
  • I knew what textures and some other basic graphics terms were
  • I Read the first two chapters of Real-Time Rendering (Into + Pipeline)
  • I had done a triangle with DirectX 11 but copy pasted all the code and I'm not proud of that but I think it had little influence on my mental model of Vulkan API



What steps did I take?


 1. Setting my Mind Set 


 I think the most important step of learning something new is to set the mindset and create a better mental model of the subject in your mind.

In the case of Vulkan it was :

  • Watch Youtube videos comparing Vulkan with other APIs
  • Watched GDC and Khronos Group Video Conferences, although most of them were very technical and needed very good experience with Vulkan I tried to get as much as I can.
  • Vulkan Tutorial Overview of Vulkan API
  • Read some web pages and lots of Googling.
  • Play just a little bit with ShaderToy
  • I Read and Recommend How to Learn Vulkan which helped me a lot. 

2. Selecting a Guide/Tutorial 




Well if you look at the Vulkan bookmark folder in my browser You'll find a lot of tutorials but I just followed one.

It's just a matter of finding a guide that best suits you.

I came down to two choices, Intel's Guide and Vulkan Tutorial and I started Intel's Guide and learned to dynamically load Vulkan Functions but I really had a hard time understanding Vulkan concepts when it started with loading function pointers.
I told a friend of mine that I really wanted to read Intel's Guide because it is more low level and that I had problems understanding it, He then replied, "Did you get the whole picture and mindset of the thing you're learning". I said no. And made myself switch to another Tutorial and leave Intel's Guide for later.

So I chose the Vulkan Tutorial which explains the concepts pretty well.

 3. Writing Code and Learning


2:00 AM Learning Vulkan


For every chapter it was somehow like this for me:

  1. Read and Understand the concepts
  2. Search if something is ambiguous for me
  3. Try a little to write the code I learned (not memorized) from Tutorial.
  4. Continue and Read the codes from Tutorial
  5. Read Vulkan API Specs whenever I was too curious about other options.

 4. Problems I encountered


  1. My Desktop PC's GPU, NVIDIA GeForce GT 730 seems to support Vulkan 1.1  but no physical devices could be found by VulkanAPI and I tried a lot and updated my driver but nothing happened. So I had to run my tests on my Surface Pro 6 on Intel UHD Graphics 620 which fortunately supports Vulkan 1.1 without any problem.
  2. Just that 😁. Except for University 😑

5. What did I actually learn?



  • How To Setup Vulkan
  • I got the way that Vulkan works with structs and I'm becoming more comfortable with it.
  • How to enable Vulkan Validation layer and understood what a great feature they are
  • What framebuffers are and how shaders output are bound to the pipeline and RenderPass
  • How to pass values between shaders
  • Command Buffers
  • Vulkan works multi-threaded and How Command Buffers work with it
  • A great feature that Command Buffers are PRIMARY or SECONDARY  so some of them may be reused for optimization
  • Some functions don't wait for output and run async and you have to use semaphores for them.
  • I DIDN'T Learn about Vertex Buffers (hardcoded shapes in the vertex shader) but I know what the are. 


6. Questions and the things I didn't understand completely 


  1. Subpass Dependencies
  2. What does vkBindGraphicsPipeline do exactly?  Can I switch to a new Pipeline in runtime in every frame?
  3. I haven't dug deep enough into Fixed-Function pipeline stages and their Options.
  4. Why we need 4 Command Buffers for 4 ImageViews?
  5. What exactly a surface instance extension is? Is it OS dependent?
  6. Need more info to work with VkQueue's
  7. What if the formats in ImageView or SwapChain or Render and Sub Passes don't match? 
  8. And many other thing I'll remember while reviewing my codes.

7. What are my plans for the future?

The good thing that happened today was that I knew what my plans are for the future of my Vulkan Journey (for the next month at least).
  1. Read the code again and review the concepts for better understanding
  2. Read the codes and Try to change Vulkan samples and try to understand the parts I haven't reached in the tutorial yet by searching.
  3. Heard SaschaWillems Samples are good
  4. Following Intel's Guide to challenge my self with dynamic linking problems and to fill in the blanks of the current Tutorial I'm following.
  5. Try to change my code and play with(try different options) it to get comfortable, maybe added runtime dynamic pipeline changes.
  6. Add UI to my projects with ImGui + Vulkan to be able to change the options and graphics pipeline and other options runtime and by UI.
  7. Play with shaders and be more comfortable writing them



And a lot of other fun stuff I'm really excited about. I'm so excited about this blog. 😋😋😋


and here is a square I did 5 min after the Triangle.


Simply, Thanks :)

Comments