This project is a basic implementation of a rendering engine using Vulkan and GLFW. It walks through setting up a Vulkan environment from initializing a window to rendering a simple scene.
- Introduction
- Features
- Prerequisites
- Installation
- Running the Engine
- Vulkan Setup Steps
- Key Components
- Resources
This project implements a Vulkan-based rendering engine with essential Vulkan components, including instance creation, device selection, swap chain setup, and command buffer management. It's built to serve as a foundation for learning Vulkan and starting more complex graphical projects.
- Window Management: Using GLFW for creating a Vulkan-compatible window.
- Vulkan Setup: Initialization of Vulkan instance, logical device, and swap chain.
- Rendering Pipeline: Basic rendering pipeline setup, including shaders and framebuffers.
- Synchronization: Implementing fences and semaphores to ensure proper frame rendering and GPU-CPU synchronization.
- Error Handling: Debugging layers for error reporting.
Before running this project, make sure your system meets the following requirements:
- Vulkan SDK: Install the Vulkan SDK.
- GLFW: Ensure GLFW is installed on your system. You can get it from the GLFW website.
- CMake: Install CMake to handle building the project. You can get it from the CMake website.
- C++ Compiler: A modern C++ compiler that supports C++11 or newer (e.g., GCC, Clang, or MSVC).
For Linux-based systems, you may also need to install the following:
sudo apt-get install libglfw3 libglfw3-dev vulkan-tools libglm-dev libxxf86vm-dev libxi-dev
First, clone the repository to your local machine:
git clone https://github.com/acharlas/vulkan-engine
cd vulkan-engine
Make sure Make is installed, and then build the project.
make
Make sure the Vulkan SDK is correctly set up. On Linux or macOS, follow the instructions from Vulkan SDK.
Once the project is built, you can run the executable :
./VulkanEngine
If you encounter issues, verify that the Vulkan SDK is correctly installed and that your environment is set up to detect the Vulkan library.
Here is an overview of the key files and directories in this project:
Here are the high-level steps followed in the project to set up Vulkan and render a basic scene:
-
Initialize GLFW Window: A window is created using GLFW with Vulkan as the rendering API.
-
Create Vulkan Instance: A Vulkan instance is created. This is the connection between the application and the Vulkan library.
-
Set Up Validation Layers: Debugging layers are set up to track errors during development. This is disabled in release mode.
-
Create Surface: A surface for rendering is created using GLFW's native Vulkan surface creation functions.
-
Pick Physical Device: The system's GPU is selected based on its Vulkan compatibility.
-
Create Logical Device: A logical device (software interface to the GPU) is created, enabling the use of queues for rendering.
-
Create Swap Chain: A swap chain is created to handle frame presentation and buffering.
-
Create Image Views: Image views are set up to interface between Vulkan images and the swap chain.
-
Create Render Pass: A render pass is set up, defining how Vulkan will handle drawing operations and frame output.
-
Create Graphics Pipeline: The graphics pipeline is defined, including shaders, vertex input, assembly, rasterization, and color blending settings.
-
Framebuffers and Command Buffers: Framebuffers are set up to hold render targets, and command buffers are allocated for recording rendering commands.
-
Synchronization Objects: Fences and semaphores are used to synchronize frame rendering and ensure proper resource management between the CPU and GPU.
GLFW is used to manage the windowing system, handling window creation, resizing, and Vulkan surface creation.
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
The Vulkan instance is created to interact with the Vulkan API.
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Vulkan Engine";
appInfo.apiVersion = VK_API_VERSION_1_0;
The swap chain is created to manage the images that are presented to the screen. It controls the buffering of frames and presentation of images.
VkSwapchainCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
createInfo.surface = surface;
The graphics pipeline is responsible for configuring how the GPU processes the rendering pipeline, from vertex shaders to rasterization and fragment shaders.
VkGraphicsPipelineCreateInfo pipelineInfo = {};
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.stageCount = 2;
pipelineInfo.pStages = shaderStages;
Command buffers are used to record and submit rendering commands to the GPU.
VkCommandBufferAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = commandPool;
allocInfo.commandBufferCount = (uint32_t)commandBuffers.size();
Feel free to contribute or raise issues in the repository to further improve the engine!


