Don't check the index format for non-indexed calls

This commit is contained in:
Dzmitry Malyshau 2021-02-06 10:47:48 -05:00
parent 3ebe198911
commit d0dcb105f5
2 changed files with 24 additions and 18 deletions

View File

@ -336,7 +336,7 @@ struct State {
} }
impl State { impl State {
fn is_ready(&self) -> Result<(), DrawError> { fn is_ready(&self, indexed: bool) -> Result<(), DrawError> {
// Determine how many vertex buffers have already been bound // Determine how many vertex buffers have already been bound
let bound_buffers = self.vertex.inputs.iter().take_while(|v| v.bound).count() as u32; let bound_buffers = self.vertex.inputs.iter().take_while(|v| v.bound).count() as u32;
// Compare with the needed quantity // Compare with the needed quantity
@ -359,6 +359,7 @@ impl State {
if self.blend_color == OptionalState::Required { if self.blend_color == OptionalState::Required {
return Err(DrawError::MissingBlendColor); return Err(DrawError::MissingBlendColor);
} }
if indexed {
// Pipeline expects an index buffer // Pipeline expects an index buffer
if let Some(pipeline_index_format) = self.index.pipeline_format { if let Some(pipeline_index_format) = self.index.pipeline_format {
// We have a buffer bound // We have a buffer bound
@ -372,6 +373,7 @@ impl State {
}); });
} }
} }
}
Ok(()) Ok(())
} }
@ -1489,12 +1491,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
first_vertex, first_vertex,
first_instance, first_instance,
} => { } => {
let indexed = false;
let scope = PassErrorScope::Draw { let scope = PassErrorScope::Draw {
indexed: false, indexed,
indirect: false, indirect: false,
pipeline: state.pipeline.last_state, pipeline: state.pipeline.last_state,
}; };
state.is_ready().map_pass_err(scope)?; state.is_ready(indexed).map_pass_err(scope)?;
let last_vertex = first_vertex + vertex_count; let last_vertex = first_vertex + vertex_count;
let vertex_limit = state.vertex.vertex_limit; let vertex_limit = state.vertex.vertex_limit;
if last_vertex > vertex_limit { if last_vertex > vertex_limit {
@ -1530,12 +1534,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
base_vertex, base_vertex,
first_instance, first_instance,
} => { } => {
let indexed = true;
let scope = PassErrorScope::Draw { let scope = PassErrorScope::Draw {
indexed: true, indexed,
indirect: false, indirect: false,
pipeline: state.pipeline.last_state, pipeline: state.pipeline.last_state,
}; };
state.is_ready().map_pass_err(scope)?; state.is_ready(indexed).map_pass_err(scope)?;
//TODO: validate that base_vertex + max_index() is within the provided range //TODO: validate that base_vertex + max_index() is within the provided range
let last_index = first_index + index_count; let last_index = first_index + index_count;
@ -1577,7 +1582,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
indirect: true, indirect: true,
pipeline: state.pipeline.last_state, pipeline: state.pipeline.last_state,
}; };
state.is_ready().map_pass_err(scope)?; state.is_ready(indexed).map_pass_err(scope)?;
let stride = match indexed { let stride = match indexed {
false => mem::size_of::<wgt::DrawIndirectArgs>(), false => mem::size_of::<wgt::DrawIndirectArgs>(),
@ -1662,7 +1667,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
indirect: true, indirect: true,
pipeline: state.pipeline.last_state, pipeline: state.pipeline.last_state,
}; };
state.is_ready().map_pass_err(scope)?; state.is_ready(indexed).map_pass_err(scope)?;
let stride = match indexed { let stride = match indexed {
false => mem::size_of::<wgt::DrawIndirectArgs>(), false => mem::size_of::<wgt::DrawIndirectArgs>(),

View File

@ -867,7 +867,8 @@ impl Default for PolygonMode {
pub struct PrimitiveState { pub struct PrimitiveState {
/// The primitive topology used to interpret vertices. /// The primitive topology used to interpret vertices.
pub topology: PrimitiveTopology, pub topology: PrimitiveTopology,
/// The format of index buffers for strip topologies. Should be left `None` for non-strip. /// When drawing strip topologies with indices, this is the required format for the index buffer.
/// This has no effect on non-indexed or non-strip draws.
#[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))]
pub strip_index_format: Option<IndexFormat>, pub strip_index_format: Option<IndexFormat>,
/// The face to consider the front for the purpose of culling and stencil operations. /// The face to consider the front for the purpose of culling and stencil operations.