From d0dcb105f55e3cdf95d927929615e138043090cc Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 6 Feb 2021 10:47:48 -0500 Subject: [PATCH] Don't check the index format for non-indexed calls --- wgpu-core/src/command/render.rs | 39 +++++++++++++++++++-------------- wgpu-types/src/lib.rs | 3 ++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index ba73ee7852..36948dfcbc 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -336,7 +336,7 @@ struct 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 let bound_buffers = self.vertex.inputs.iter().take_while(|v| v.bound).count() as u32; // Compare with the needed quantity @@ -359,17 +359,19 @@ impl State { if self.blend_color == OptionalState::Required { return Err(DrawError::MissingBlendColor); } - // Pipeline expects an index buffer - if let Some(pipeline_index_format) = self.index.pipeline_format { - // We have a buffer bound - let buffer_index_format = self.index.format.ok_or(DrawError::MissingIndexBuffer)?; + if indexed { + // Pipeline expects an index buffer + if let Some(pipeline_index_format) = self.index.pipeline_format { + // We have a buffer bound + let buffer_index_format = self.index.format.ok_or(DrawError::MissingIndexBuffer)?; - // The buffers are different formats - if pipeline_index_format != buffer_index_format { - return Err(DrawError::UnmatchedIndexFormats { - pipeline: pipeline_index_format, - buffer: buffer_index_format, - }); + // The buffers are different formats + if pipeline_index_format != buffer_index_format { + return Err(DrawError::UnmatchedIndexFormats { + pipeline: pipeline_index_format, + buffer: buffer_index_format, + }); + } } } Ok(()) @@ -1489,12 +1491,14 @@ impl Global { first_vertex, first_instance, } => { + let indexed = false; let scope = PassErrorScope::Draw { - indexed: false, + indexed, indirect: false, 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 vertex_limit = state.vertex.vertex_limit; if last_vertex > vertex_limit { @@ -1530,12 +1534,13 @@ impl Global { base_vertex, first_instance, } => { + let indexed = true; let scope = PassErrorScope::Draw { - indexed: true, + indexed, indirect: false, 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 let last_index = first_index + index_count; @@ -1577,7 +1582,7 @@ impl Global { indirect: true, pipeline: state.pipeline.last_state, }; - state.is_ready().map_pass_err(scope)?; + state.is_ready(indexed).map_pass_err(scope)?; let stride = match indexed { false => mem::size_of::(), @@ -1662,7 +1667,7 @@ impl Global { indirect: true, pipeline: state.pipeline.last_state, }; - state.is_ready().map_pass_err(scope)?; + state.is_ready(indexed).map_pass_err(scope)?; let stride = match indexed { false => mem::size_of::(), diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 2474456b4b..d83b2e5941 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -867,7 +867,8 @@ impl Default for PolygonMode { pub struct PrimitiveState { /// The primitive topology used to interpret vertices. 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))] pub strip_index_format: Option, /// The face to consider the front for the purpose of culling and stencil operations.