Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add len method to IndexBuffer #2342

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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