diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c9f02ed0e..c1f263ce94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ the same every time it is rendered, we now warn if it is missing. - Fix panics that occur when using `as_hal` functions when the hal generic type does not match the hub being looked up in by @i509VCB [#2871](https://github.com/gfx-rs/wgpu/pull/2871) - Add some validation in map_async by @nical in [#2876](https://github.com/gfx-rs/wgpu/pull/2876) - Fix bugs when mapping/unmapping zero-sized buffers and ranges by @nical in [#2877](https://github.com/gfx-rs/wgpu/pull/2877) +- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913) #### DX12 - `DownlevelCapabilities::default()` now returns the `ANISOTROPIC_FILTERING` flag set to true so DX12 lists `ANISOTROPIC_FILTERING` as true again by @cwfitzgerald in [#2851](https://github.com/gfx-rs/wgpu/pull/2851) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index bc3553f0bb..fb32d8580a 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -2469,6 +2469,16 @@ impl Device { ArrayVec::::new(); let mut shader_binding_sizes = FastHashMap::default(); + let num_attachments = desc.fragment.as_ref().map(|f| f.targets.len()).unwrap_or(0); + if num_attachments > hal::MAX_COLOR_ATTACHMENTS { + return Err( + pipeline::CreateRenderPipelineError::TooManyColorAttachments { + given: num_attachments as u32, + limit: hal::MAX_COLOR_ATTACHMENTS as u32, + }, + ); + } + let color_targets = desc .fragment .as_ref() diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index ca30e56a2e..e235ca4706 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -323,6 +323,8 @@ pub enum CreateRenderPipelineError { DepthStencilState(#[from] DepthStencilStateError), #[error("invalid sample count {0}")] InvalidSampleCount(u32), + #[error("the number of color attachments {given} exceeds the limit {limit}")] + TooManyColorAttachments { given: u32, limit: u32 }, #[error("the number of vertex buffers {given} exceeds the limit {limit}")] TooManyVertexBuffers { given: u32, limit: u32 }, #[error("the total number of vertex attributes {given} exceeds the limit {limit}")]