Skip to content

Commit

Permalink
Validate strip_index_format (#2177)
Browse files Browse the repository at this point in the history
The spec mandates that stripIndexFormat is set even when drawIndexed is
not used. (https://www.w3.org/TR/webgpu/#primitive-state)
There is some recent discussion about this though:
gpuweb/gpuweb#2199
  • Loading branch information
Bobo1239 authored Nov 15, 2021
1 parent f25a45f commit 08b9c46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,14 @@ impl<A: HalApi> Device<A> {
);
}

if desc.primitive.strip_index_format.is_none() && desc.primitive.topology.is_strip() {
return Err(
pipeline::CreateRenderPipelineError::NoStripIndexFormatForStripTopology {
topology: desc.primitive.topology,
},
);
}

if desc.primitive.unclipped_depth {
self.require_features(wgt::Features::DEPTH_CLIP_CONTROL)?;
}
Expand Down
2 changes: 2 additions & 0 deletions wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ pub enum CreateRenderPipelineError {
strip_index_format: Option<wgt::IndexFormat>,
topology: wgt::PrimitiveTopology,
},
#[error("strip index format is None while using the strip topology {topology:?}")]
NoStripIndexFormatForStripTopology { topology: wgt::PrimitiveTopology },
#[error("Conservative Rasterization is only supported for wgt::PolygonMode::Fill")]
ConservativeRasterizationNonFillPolygonMode,
#[error(transparent)]
Expand Down
1 change: 1 addition & 0 deletions wgpu/examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl framework::Example for Example {
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
strip_index_format: Some(wgpu::IndexFormat::Uint16),
..wgpu::PrimitiveState::default()
},
depth_stencil: None,
Expand Down
2 changes: 2 additions & 0 deletions wgpu/examples/mipmap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Example {
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
strip_index_format: Some(wgpu::IndexFormat::Uint16),
..Default::default()
},
depth_stencil: None,
Expand Down Expand Up @@ -292,6 +293,7 @@ impl framework::Example for Example {
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
strip_index_format: Some(wgpu::IndexFormat::Uint16),
front_face: wgpu::FrontFace::Ccw,
cull_mode: Some(wgpu::Face::Back),
..Default::default()
Expand Down

0 comments on commit 08b9c46

Please sign in to comment.