Skip to content

Commit d0aa3f4

Browse files
authored
Validate the number of color attachments in create_render_pipeline (#2913)
1 parent 537c6be commit d0aa3f4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ the same every time it is rendered, we now warn if it is missing.
8585
- 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)
8686
- Add some validation in map_async by @nical in [#2876](https://github.com/gfx-rs/wgpu/pull/2876)
8787
- Fix bugs when mapping/unmapping zero-sized buffers and ranges by @nical in [#2877](https://github.com/gfx-rs/wgpu/pull/2877)
88+
- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913)
8889

8990
#### DX12
9091
- `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)

wgpu-core/src/device/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,16 @@ impl<A: HalApi> Device<A> {
24692469
ArrayVec::<binding_model::BindEntryMap, { hal::MAX_BIND_GROUPS }>::new();
24702470
let mut shader_binding_sizes = FastHashMap::default();
24712471

2472+
let num_attachments = desc.fragment.as_ref().map(|f| f.targets.len()).unwrap_or(0);
2473+
if num_attachments > hal::MAX_COLOR_ATTACHMENTS {
2474+
return Err(
2475+
pipeline::CreateRenderPipelineError::TooManyColorAttachments {
2476+
given: num_attachments as u32,
2477+
limit: hal::MAX_COLOR_ATTACHMENTS as u32,
2478+
},
2479+
);
2480+
}
2481+
24722482
let color_targets = desc
24732483
.fragment
24742484
.as_ref()

wgpu-core/src/pipeline.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ pub enum CreateRenderPipelineError {
323323
DepthStencilState(#[from] DepthStencilStateError),
324324
#[error("invalid sample count {0}")]
325325
InvalidSampleCount(u32),
326+
#[error("the number of color attachments {given} exceeds the limit {limit}")]
327+
TooManyColorAttachments { given: u32, limit: u32 },
326328
#[error("the number of vertex buffers {given} exceeds the limit {limit}")]
327329
TooManyVertexBuffers { given: u32, limit: u32 },
328330
#[error("the total number of vertex attributes {given} exceeds the limit {limit}")]

0 commit comments

Comments
 (0)