Skip to content

Commit

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

* Fixed formatting
  • Loading branch information
TrevorCow authored Sep 28, 2023
1 parent 56b051c commit c24c7ad
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 c24c7ad

Please sign in to comment.