2020-01-30 08:15:10 +00:00
|
|
|
# Vk-Bootstrap
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
A Vulkan utility library meant to jump start any Vulkan Application
|
2020-01-30 08:15:10 +00:00
|
|
|
|
|
|
|
This library simplifies the tedious process of:
|
|
|
|
|
|
|
|
* Instance Creation
|
2020-02-19 02:12:31 +00:00
|
|
|
* Picking a Physical Device
|
2020-01-30 08:15:10 +00:00
|
|
|
* Device Creation
|
|
|
|
* Getting Queues
|
|
|
|
* Swapchain Creation
|
|
|
|
|
2020-02-04 03:51:52 +00:00
|
|
|
It also adds several conveniences for:
|
2020-02-04 03:34:46 +00:00
|
|
|
|
|
|
|
* enabling validation layers
|
|
|
|
* setting up a debug callback
|
2020-02-19 02:12:31 +00:00
|
|
|
* select a gpu based on a set of common criteria like features, extensions, memory, etc.
|
2020-02-04 03:34:46 +00:00
|
|
|
|
2020-01-30 08:15:10 +00:00
|
|
|
## Example
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
2020-02-04 03:51:52 +00:00
|
|
|
#include "VkBootstrap.h"
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
void init_vulkan()
|
2020-02-04 03:51:52 +00:00
|
|
|
{
|
|
|
|
vkb::InstanceBuilder builder;
|
2020-03-08 00:19:58 +00:00
|
|
|
builder.request_validation_layers()
|
2020-02-19 02:12:31 +00:00
|
|
|
.set_app_name ("Example Vulkan Application")
|
2020-03-08 00:19:58 +00:00
|
|
|
.use_default_debug_messenger ();
|
2020-02-04 03:51:52 +00:00
|
|
|
auto inst_ret = builder.build();
|
|
|
|
if (!inst_ret.has_value()) {
|
|
|
|
// error
|
|
|
|
}
|
2020-02-19 02:12:31 +00:00
|
|
|
vkb::Instance vkb_inst = inst_ret.value();
|
2020-02-04 03:51:52 +00:00
|
|
|
|
|
|
|
vkb::PhysicalDeviceSelector selector{ inst };
|
|
|
|
selector.set_surface (/* from user created window*/)
|
2020-02-19 02:12:31 +00:00
|
|
|
.set_minimum_version (1, 1) //require a vulkan 1.1 capable device
|
2020-03-08 00:19:58 +00:00
|
|
|
.require_dedicated_transfer_queue();
|
2020-02-04 03:51:52 +00:00
|
|
|
auto phys_ret = selector.select ();
|
|
|
|
if (!phys_ret.has_value()) {
|
|
|
|
// error
|
|
|
|
}
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
vkb::DeviceBuilder device_builder{ phys_ret.value() };
|
2020-02-04 03:51:52 +00:00
|
|
|
auto dev_ret = device_builder.build ();
|
|
|
|
if (!dev_ret.has_value()){
|
|
|
|
// error
|
|
|
|
}
|
2020-03-08 00:19:58 +00:00
|
|
|
vkb::Device dev = dev_ret.value();
|
2020-02-04 03:51:52 +00:00
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
// Get the VkDevice handle used in the rest of a vulkan application
|
2020-03-08 00:19:58 +00:00
|
|
|
VkDevice device = dev.device;
|
2020-02-19 02:12:31 +00:00
|
|
|
|
|
|
|
// Get the graphics queue with a helper function
|
2020-03-08 00:19:58 +00:00
|
|
|
auto graphics_queue_ret = dev.get_queue(vkb::QueueType::graphics);
|
2020-02-17 20:13:09 +00:00
|
|
|
if (!graphics_queue_ret.has_value()){
|
2020-02-19 02:12:31 +00:00
|
|
|
// error
|
2020-02-17 20:13:09 +00:00
|
|
|
}
|
|
|
|
VkQueue graphics_queue = graphics_queue_ret.value();
|
2020-02-19 02:12:31 +00:00
|
|
|
|
2020-03-08 00:19:58 +00:00
|
|
|
// Turned 400-500 lines of boilerplate into less than fifty.
|
2020-01-30 08:15:10 +00:00
|
|
|
}
|
2020-02-04 03:34:46 +00:00
|
|
|
|
2020-02-04 03:51:52 +00:00
|
|
|
```
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
See `example/triangle.cpp` for an example that renders a triangle to the screen.
|
|
|
|
|
|
|
|
## Setting up vk-bootstrap
|
2020-02-04 03:51:52 +00:00
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
### Simple
|
2020-02-04 03:51:52 +00:00
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
This library has no external dependencies.
|
|
|
|
Simply copy the `src/VkBootstrap.h` and `src/VkBootstrap.cpp` files into your project and compile them as you normally would
|
2020-02-04 03:54:03 +00:00
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
### With git-submodule + CMake
|
2020-02-04 03:54:03 +00:00
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
Add this project as a git-submodule
|
2020-02-04 03:51:52 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
git submodule add https://github.com/charles-lunarg/vk-bootstrap
|
|
|
|
```
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
With CMake, add the project as a subdirectory
|
2020-02-04 03:34:46 +00:00
|
|
|
|
2020-02-04 03:51:52 +00:00
|
|
|
```cmake
|
|
|
|
add_subdirectory(vk-bootstrap)
|
2020-02-19 02:12:31 +00:00
|
|
|
|
|
|
|
target_link_libraries(your_application_name vk-bootstrap)
|
2020-01-30 08:15:10 +00:00
|
|
|
```
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
### Manually Building
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-01-30 09:01:49 +00:00
|
|
|
```bash
|
|
|
|
git clone https://github.com/charles-lunarg/vk-bootstrap
|
|
|
|
cd vk-bootstrap
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
```
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
## Testing
|
|
|
|
|
|
|
|
To test, glfw and Catch2 are automatically included using git submodules.
|
2020-01-30 09:01:49 +00:00
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
In the project directory, run the following to get the required dependencies to test.
|
2020-01-30 09:01:49 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
git submodule update --init
|
|
|
|
```
|
|
|
|
|
2020-02-19 02:12:31 +00:00
|
|
|
In the build directory, enable tests by adding `-DVK_BOOTSTRAP_TEST` to the cmake command line arguments
|
2020-01-30 09:01:49 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
cmake ../path/to/vk-bootstrap/ -DVK_BOOTSTRAP_TEST=ON
|
|
|
|
```
|
|
|
|
|
2020-02-04 03:34:46 +00:00
|
|
|
## Todo's
|
2020-01-30 09:01:49 +00:00
|
|
|
|
2020-02-04 03:34:46 +00:00
|
|
|
* Package library to be usable
|
|
|
|
* More examples
|
|
|
|
* Testing
|
|
|
|
* Documenting API
|