Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use SmallVec for command buffer allocations #2071

Merged
merged 1 commit into from
Oct 31, 2022
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
Use SmallVec for command buffer allocations
  • Loading branch information
marc0246 committed Oct 31, 2022
commit 27ed184bdd91d964a8cf6cec5ecb0983bf7de435
13 changes: 6 additions & 7 deletions vulkano/src/command_buffer/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ use crate::{
OomError,
};
use crossbeam_queue::ArrayQueue;
use smallvec::SmallVec;
use smallvec::{IntoIter, SmallVec};
use std::{
cell::{Cell, UnsafeCell},
error::Error,
fmt::Display,
marker::PhantomData,
mem::ManuallyDrop,
sync::Arc,
vec::IntoIter,
};
use thread_local::ThreadLocal;

Expand Down Expand Up @@ -204,7 +203,7 @@ impl StandardCommandBufferAllocator {
}

unsafe impl CommandBufferAllocator for StandardCommandBufferAllocator {
type Iter = IntoIter<StandardCommandBufferBuilderAlloc>;
type Iter = IntoIter<[StandardCommandBufferBuilderAlloc; 1]>;

type Builder = StandardCommandBufferBuilderAlloc;

Expand Down Expand Up @@ -276,7 +275,7 @@ unsafe impl CommandBufferAllocator for StandardCommandBufferAllocator {
}

unsafe impl CommandBufferAllocator for Arc<StandardCommandBufferAllocator> {
type Iter = IntoIter<StandardCommandBufferBuilderAlloc>;
type Iter = IntoIter<[StandardCommandBufferBuilderAlloc; 1]>;

type Builder = StandardCommandBufferBuilderAlloc;

Expand Down Expand Up @@ -418,15 +417,15 @@ impl Pool {
self: &Arc<Self>,
level: CommandBufferLevel,
command_buffer_count: u32,
) -> Option<IntoIter<StandardCommandBufferBuilderAlloc>> {
) -> Option<IntoIter<[StandardCommandBufferBuilderAlloc; 1]>> {
let command_buffer_count = command_buffer_count as usize;

match level {
CommandBufferLevel::Primary => {
if let Some(pool) = &self.inner.primary_pool {
let count = self.inner.primary_allocations.get();
if count + command_buffer_count <= pool.capacity() {
let mut output = Vec::with_capacity(command_buffer_count);
let mut output = SmallVec::<[_; 1]>::with_capacity(command_buffer_count);
for _ in 0..command_buffer_count {
output.push(StandardCommandBufferBuilderAlloc {
inner: StandardCommandBufferAlloc {
Expand Down Expand Up @@ -462,7 +461,7 @@ impl Pool {
if let Some(pool) = &self.inner.secondary_pool {
let count = self.inner.secondary_allocations.get();
if count + command_buffer_count <= pool.capacity() {
let mut output = Vec::with_capacity(command_buffer_count);
let mut output = SmallVec::<[_; 1]>::with_capacity(command_buffer_count);
for _ in 0..command_buffer_count {
output.push(StandardCommandBufferBuilderAlloc {
inner: StandardCommandBufferAlloc {
Expand Down