Skip to content

Commit 0620d39

Browse files
committed
doc: missing docs for util module
1 parent 8519a1a commit 0620d39

11 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/util/address.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
1+
//! Wrappers around device addresses
2+
13
use std::ffi::c_void;
24

35
use ash::vk;
46

57
use crate::util::to_vk::AsVulkanType;
68

9+
/// Either a `VkDeviceAddress` or a mutable host pointer
710
#[derive(Copy, Clone)]
811
#[repr(C)]
912
pub enum DeviceOrHostAddress {
13+
/// Device pointer
1014
Device(vk::DeviceAddress),
15+
/// Mutable host pointer
1116
Host(*mut c_void),
1217
}
1318

19+
/// Either a `VkDeviceAddress` or an immutable host pointer
1420
#[derive(Copy, Clone)]
1521
#[repr(C)]
1622
pub enum DeviceOrHostAddressConst {
23+
/// Device pointer
1724
Device(vk::DeviceAddress),
25+
/// Immutable host pointer
1826
Host(*const c_void),
1927
}
2028

2129
impl DeviceOrHostAddress {
30+
/// Create a null pointer on the device
2231
pub fn null_device() -> Self {
2332
Self::Device(vk::DeviceAddress::default())
2433
}
2534

35+
/// Create a null pointer on the host
2636
pub fn null_host() -> Self {
2737
Self::Host(std::ptr::null_mut())
2838
}
2939
}
3040

3141
impl DeviceOrHostAddressConst {
42+
/// Create a null pointer on the device
3243
pub fn null_device() -> Self {
3344
Self::Device(vk::DeviceAddress::default())
3445
}
3546

47+
/// Create a null pointer on the host
3648
pub fn null_host() -> Self {
3749
Self::Host(std::ptr::null())
3850
}

src/util/align.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
//! Utilities for aligning memory
2+
13
use std::ops::{Add, Rem, Sub};
24

5+
/// Align a size to a required alignment. Does not align the base address.
36
pub fn align<T: Add<T, Output=U> + Sub<T, Output=T> + Rem<T, Output=T> + Copy, U>(value: T, alignment: T) -> U {
47
let unaligned_size = value % alignment;
58
let padding = alignment - unaligned_size;

src/util/byte_size.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utility to get the byte size of objects
2+
13
use std::mem::size_of;
24

35
use ash::vk;

src/util/cache.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Generic implementation of a resource cache
2+
13
use std::collections::{hash_map, HashMap};
24
use std::hash::Hash;
35

src/util/deferred_delete.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Deferred deletion queue
2+
13
#[derive(Debug)]
24
struct Item<T> {
35
_value: T,

src/util/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Various utilities
2+
13
pub mod byte_size;
24
pub mod deferred_delete;
35
pub mod upload;

src/util/pnext.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
//! Utilities for dealing with generic pNext chains
2+
13
use std::ffi::c_void;
24

35
use ash::vk;
46

7+
/// A typed element in the pNext chain
58
pub enum PNext {
69
WriteDescriptorSetAccelerationStructure(vk::WriteDescriptorSetAccelerationStructureKHR)
710
}
@@ -11,6 +14,7 @@ fn as_void_ptr<T>(value: &T) -> *const c_void {
1114
}
1215

1316
impl PNext {
17+
/// Get a raw pointer to insert into the Vulkan pNext chain
1418
pub fn as_ptr(&self) -> *const c_void {
1519
match self {
1620
PNext::WriteDescriptorSetAccelerationStructure(value) => { as_void_ptr(value) }

src/util/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! String utilities for dealing with FFI strings
2+
13
use std::ffi::{c_char, CStr, CString};
24

35
/// Wraps a c string into a string, or an empty string if the provided c string was null.

src/util/to_vk.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
//! Utility traits to convert objects into their corresponding vulkan types
2+
3+
/// Convert an object into a vulkan type
14
pub trait IntoVulkanType {
25
type Output;
36

7+
/// Consume self and return a vulkan type
48
fn into_vulkan(self) -> Self::Output;
59
}
610

11+
/// Get a reference to the object, as a vulkan type
712
pub trait AsVulkanType {
813
type Output;
914

15+
/// Return a vulkan type that lives as long as self
1016
fn as_vulkan(&self) -> Self::Output;
1117
}

src/util/transform.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Wrapper around `VkTransformMatrixKHR` for easy usage
2+
13
use ash::vk;
24

35
use crate::util::to_vk::IntoVulkanType;
@@ -8,6 +10,7 @@ use crate::util::to_vk::IntoVulkanType;
810
pub struct TransformMatrix(vk::TransformMatrixKHR);
911

1012
impl TransformMatrix {
13+
/// Create an identity matrix
1114
pub fn identity() -> Self {
1215
Self(vk::TransformMatrixKHR {
1316
matrix: [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],

0 commit comments

Comments
 (0)