From 65e1a7689dd30864229517775008fdd2fb11f955 Mon Sep 17 00:00:00 2001 From: Maik Klein Date: Tue, 12 Dec 2017 12:09:47 +0100 Subject: [PATCH] Update docs for `Align` --- ash/src/util.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ash/src/util.rs b/ash/src/util.rs index ef2cfbc..78e3070 100644 --- a/ash/src/util.rs +++ b/ash/src/util.rs @@ -3,14 +3,13 @@ use std::marker::PhantomData; use std::mem::size_of; use vk; -/// `Align` handles dynamic alignment. x86 aligns on 4 byte boundries but GPUs -/// sometimes have different requirements. For example if the user wants to create -/// a Uniform buffer of a Vec3, `get_buffer_memory_requirements` might return -/// an alignment of 16 bytes. A Vec3 has a size of 12 bytes. The memory layout -/// for a `Vec>` will be contigous, because 4 is a multiple of 12. But Vulkan -/// expects a 4 byte padding in between each Vec3, if the alignment is 16 bytes. -/// `Vec3, 4bytes, Vec3, 4bytes, Vec3...`. Align is able to take a slice -/// that is allocated on 4 bytes boundries, and insert the correct amount of paddings. +/// `Align` handles dynamic alignment. The is useful for dynamic uniform buffers where +/// the alignment might be different. For example a 4x4 f32 matrix has a size of 64 bytes +/// but the min alignment for a dynamic uniform buffer might be 256 bytes. A slice of `&[Mat4x4]` +/// has a memory layout of `[[64 bytes], [64 bytes], [64 bytes]]`, but it might need to have a memory +/// layout of `[[256 bytes], [256 bytes], [256 bytes]]. +/// `Align::copy_from_slice` will copy a slice of `&[T]` directly into the host memory without +/// an additional allocation and with the correct alignment. #[derive(Debug, Clone)] pub struct Align { ptr: *mut vk::c_void,