Merge pull request #159 from Ralith/readme-tweaks

Clarify some patterns in the README
This commit is contained in:
Maik Klein 2018-11-20 07:58:35 +01:00 committed by GitHub
commit ea1a6164c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -55,6 +55,12 @@ pub fn cmd_pipeline_barrier(&self,
image_memory_barriers: &[vk::ImageMemoryBarrier]); image_memory_barriers: &[vk::ImageMemoryBarrier]);
``` ```
### Strongly typed handles
Each Vulkan handle type is exposed as a newtyped struct for improved type safety. Null handles can be constructed with
`T::null()`, and handles may be freely converted to and from `u64` with `Handle::from_raw` and `Handle::as_raw` for
interop with non-Ash Vulkan code.
### Default implementation for all types ### Default implementation for all types
```Rust ```Rust
// No need to manually set the structure type // No need to manually set the structure type
@ -71,7 +77,11 @@ let pipeline_vertex_input_state_create_info = vk::PipelineVertexInputStateCreate
.vertex_binding_descriptions(&Vertex::binding_descriptions()) .vertex_binding_descriptions(&Vertex::binding_descriptions())
.vertex_attribute_descriptions(&Vertex::attribute_descriptions()).build(); .vertex_attribute_descriptions(&Vertex::attribute_descriptions()).build();
``` ```
*Note*: No validation is done, the lifetimes only have to live as long as the builder object. It is the responsibility of the user to make sure that the pointers are valid.
Builders implement `Deref` targeting their corresponding Vulkan struct, so references to builders can be passed directly
to Vulkan functions. This is encouraged as doing so allows Rust to check the lifetimes of captured objects are valid,
whereas calling `build` discards lifetime information, making inadvertent use-after-free errors more likely.
### Flags and constants as associated constants ### Flags and constants as associated constants
```Rust ```Rust
@ -95,12 +105,6 @@ println!("Display: {}", flag);
// Display: COLOR_ATTACHMENT_READ | COLOR_ATTACHMENT_WRITE // Display: COLOR_ATTACHMENT_READ | COLOR_ATTACHMENT_WRITE
``` ```
### Interop
Vulkan objects inside Ash can be constructed from raw values with `Object::from:raw`. Useful if you need to interact with a C library.
```Rust
PipelineBindPoint::from_raw(bindpoint);
```
### Function pointer loading ### Function pointer loading
Ash also takes care of loading the function pointers. Function pointers are split into 3 categories. Ash also takes care of loading the function pointers. Function pointers are split into 3 categories.