Skip to content

Commit

Permalink
Validate the number of color attachments in create_render_pipeline (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nical authored Jul 26, 2022
1 parent 537c6be commit d0aa3f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,16 @@ impl<A: HalApi> Device<A> {
ArrayVec::<binding_model::BindEntryMap, { hal::MAX_BIND_GROUPS }>::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()
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 @@ -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}")]
Expand Down

0 comments on commit d0aa3f4

Please sign in to comment.