From 08b9c46ec48a72bda6bc014a3ae6bed0e5ab2797 Mon Sep 17 00:00:00 2001 From: Boris-Chengbiao Zhou Date: Mon, 15 Nov 2021 01:03:33 +0100 Subject: [PATCH] Validate strip_index_format (#2177) 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: https://github.com/gpuweb/gpuweb/issues/2199 --- wgpu-core/src/device/mod.rs | 8 ++++++++ wgpu-core/src/pipeline.rs | 2 ++ wgpu/examples/bunnymark/main.rs | 1 + wgpu/examples/mipmap/main.rs | 2 ++ 4 files changed, 13 insertions(+) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index d153515357..c67e925010 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -2211,6 +2211,14 @@ impl Device { ); } + 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)?; } diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 2436f8cf25..bb8df5e6d0 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -309,6 +309,8 @@ pub enum CreateRenderPipelineError { strip_index_format: Option, 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)] diff --git a/wgpu/examples/bunnymark/main.rs b/wgpu/examples/bunnymark/main.rs index f8c1c2b879..b99cc7fdad 100644 --- a/wgpu/examples/bunnymark/main.rs +++ b/wgpu/examples/bunnymark/main.rs @@ -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, diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index f53bbc0ea4..82fd40e62b 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -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, @@ -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()