Skip to content

Commit

Permalink
Increase default maximum vertex buffer inputs from 8 to 16
Browse files Browse the repository at this point in the history
Additionally, the input states are now stored in a `SmallVec` to
enable higher limits.

Fixes #558
  • Loading branch information
aloucks committed Apr 8, 2020
1 parent 77d95f5 commit b6ec844
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
use arrayvec::ArrayVec;
use hal::command::CommandBuffer as _;
use peek_poke::{Peek, PeekPoke, Poke};
use smallvec::SmallVec;
use wgt::{
BufferAddress, BufferUsage, Color, DynamicOffset, IndexFormat, InputStepMode, LoadOp,
RenderPassColorAttachmentDescriptorBase, RenderPassDepthStencilAttachmentDescriptorBase,
Expand Down Expand Up @@ -227,7 +228,7 @@ impl VertexBufferState {

#[derive(Debug)]
pub struct VertexState {
inputs: [VertexBufferState; MAX_VERTEX_BUFFERS],
inputs: SmallVec<[VertexBufferState; MAX_VERTEX_BUFFERS]>,
vertex_limit: u32,
instance_limit: u32,
}
Expand Down Expand Up @@ -798,7 +799,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
limit: 0,
},
vertex: VertexState {
inputs: [VertexBufferState::EMPTY; MAX_VERTEX_BUFFERS],
inputs: SmallVec::new(),
vertex_limit: 0,
instance_limit: 0,
},
Expand Down Expand Up @@ -968,7 +969,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
vbs.stride = stride;
vbs.rate = rate;
}
for vbs in state.vertex.inputs[pipeline.vertex_strides.len()..].iter_mut() {
let vertex_strides_len = pipeline.vertex_strides.len();
for vbs in state.vertex.inputs.iter_mut().skip(vertex_strides_len) {
vbs.stride = 0;
vbs.rate = InputStepMode::Vertex;
}
Expand Down Expand Up @@ -1017,6 +1019,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.use_extend(&*buffer_guard, buffer_id, (), BufferUsage::VERTEX)
.unwrap();
assert!(buffer.usage.contains(BufferUsage::VERTEX));
let empty_slots = (1 + slot as usize).saturating_sub(state.vertex.inputs.len());
state
.vertex
.inputs
.extend(iter::repeat(VertexBufferState::EMPTY).take(empty_slots));
state.vertex.inputs[slot as usize].total_size = if size != 0 {
size
} else {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod life;

pub const MAX_COLOR_TARGETS: usize = 4;
pub const MAX_MIP_LEVELS: usize = 16;
pub const MAX_VERTEX_BUFFERS: usize = 8;
pub const MAX_VERTEX_BUFFERS: usize = 16;

pub fn all_buffer_stages() -> hal::pso::PipelineStage {
use hal::pso::PipelineStage as Ps;
Expand Down

0 comments on commit b6ec844

Please sign in to comment.