Skip to content

Commit

Permalink
Add len method to IndexBuffer (vulkano-rs#2342)
Browse files Browse the repository at this point in the history
* ### Additions
- `IndexBuffer::len` method.

* Fixed formatting
  • Loading branch information
TrevorCow authored and hakolao committed Feb 20, 2024
1 parent dadb888 commit 171461c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion vulkano/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ impl BufferState {
gpu_reads: 0,
} => (),
CurrentAccess::Shared { cpu_reads, .. } if *cpu_reads > 0 => {
return Err(AccessConflict::HostRead)
return Err(AccessConflict::HostRead);
}
CurrentAccess::Shared { .. } => return Err(AccessConflict::DeviceRead),
}
Expand Down Expand Up @@ -1014,6 +1014,16 @@ impl IndexBuffer {
IndexBuffer::U32(buffer) => buffer.as_bytes(),
}
}

/// Returns the number of elements in the buffer.
#[inline]
pub fn len(&self) -> DeviceSize {
match self {
IndexBuffer::U8(buffer) => buffer.len(),
IndexBuffer::U16(buffer) => buffer.len(),
IndexBuffer::U32(buffer) => buffer.len(),
}
}
}

impl From<Subbuffer<[u8]>> for IndexBuffer {
Expand Down

0 comments on commit 171461c

Please # to comment.