Restructure the readme

This commit is contained in:
maik klein 2016-12-28 04:31:48 +01:00
parent 9aa7281645
commit 3d2e5d166c

View file

@ -23,6 +23,8 @@ No.
- [x] Extensions have their own loader
## What does it do?
### Explicit returns with `Result`
Functions return a `type VkResult<T> = Result<T, vk::Result>` instead of an error code. No mutable references for the output are required.
```Rust
pub fn create_swapchain_khr(&self,
@ -39,6 +41,8 @@ pub fn get_swapchain_images_khr(&self,
-> VkResult<Vec<vk::Image>>;
let present_images = device.get_swapchain_images_khr(swapchain).unwrap();
```
### Slices
Ash always uses slices in functions.
```Rust
// C
@ -81,6 +85,8 @@ let slice = device.map_memory::<Vertex>(vertex_input_buffer_memory,
.unwrap();
slice.copy_from_slice(&vertices);
```
### Type safety
Ash still uses raw Vulkan structs. The only difference is type safety. Everything that can be an enum is an enum like `vk::StructureType`, flags are implemented similar to the `Bitflags` crate. Ash also follows the Rust style guide. The reason that Ash uses raw Vulkan structs is to be extensible, just like the Vulkan spec.
```Rust
let pool_create_info = vk::CommandPoolCreateInfo {
@ -91,6 +97,10 @@ let pool_create_info = vk::CommandPoolCreateInfo {
};
let pool = device.create_command_pool(&pool_create_info).unwrap();
```
Additionally pointers like `Instance`, `Device`, `Queue` etc are hidden behind a type. Those pointers can only be constructed from within `Ash` which elimites invalid API usage and has the benefit of making some functions in Vulkan **safe**.
### Function pointer loading
Ash also takes care of loading the function pointers. Function pointers are split into 3 categories. Entry, Instance and Device. The reason for not loading it into a global is that in Vulkan you can have multiple devices and each device must load its own function pointers.
```Rust
// Looks for the vulkan lib in your path, alternatively you can supply the path explicitly.
@ -99,12 +109,16 @@ let instance: Instance = entry.create_instance(&create_info).expect("Instance cr
let device: Device = instance.create_device(pdevice, &device_create_info)
.unwrap();
```
### Extension loading
Additionally, every Vulkan extension has to be loaded explicity. You can find all extensions under [ash::extensions](https://github.com/MaikKlein/ash/tree/master/src/extensions). You still have to tell Vulkan which instance or device extensions you want to load.
```Rust
use ash::extensions::Swapchain;
let swapchain_loader = Swapchain::new(&instance, &device).expect("Unable to load swapchain");
let swapchain = swapchain_loader.create_swapchain_khr(&swapchain_create_info).unwrap();
```
### Implicit handles
You don't have to pass an Instance or Device handle anymore, this is done implicitly for you.
```Rust
// C
@ -122,7 +136,7 @@ pub fn create_command_pool(&self,
let pool = device.create_command_pool(&pool_create_info).unwrap();
```
Support for extension names
### Support for extension names
```Rust
use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport};
#[cfg(all(unix, not(target_os = "android")))]