Skip to content

Commit

Permalink
Handle TooManyAttachments in wgpu-core (#6076)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagudev committed Aug 5, 2024
1 parent 9619a43 commit de960cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ pub enum CommandEncoderError {
InvalidTimestampWritesQuerySetId(id::QuerySetId),
#[error("Attachment TextureViewId {0:?} is invalid")]
InvalidAttachmentId(id::TextureViewId),
#[error(transparent)]
InvalidColorAttachment(#[from] ColorAttachmentError),
#[error("Resolve attachment TextureViewId {0:?} is invalid")]
InvalidResolveTargetId(id::TextureViewId),
#[error("Depth stencil attachment TextureViewId {0:?} is invalid")]
Expand Down
13 changes: 12 additions & 1 deletion wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,10 +1342,21 @@ impl Global {
hub: &crate::hub::Hub<A>,
desc: &RenderPassDescriptor<'_>,
arc_desc: &mut ArcRenderPassDescriptor<A>,
device: &Device<A>,
) -> Result<(), CommandEncoderError> {
let query_sets = hub.query_sets.read();
let texture_views = hub.texture_views.read();

let max_color_attachments = device.limits.max_color_attachments as usize;
if desc.color_attachments.len() > max_color_attachments {
return Err(CommandEncoderError::InvalidColorAttachment(
ColorAttachmentError::TooMany {
given: desc.color_attachments.len(),
limit: max_color_attachments,
},
));
}

for color_attachment in desc.color_attachments.iter() {
if let Some(RenderPassColorAttachment {
view: view_id,
Expand Down Expand Up @@ -1447,7 +1458,7 @@ impl Global {
Err(e) => return make_err(e, arc_desc),
};

let err = fill_arc_desc(hub, desc, &mut arc_desc).err();
let err = fill_arc_desc(hub, desc, &mut arc_desc, &cmd_buf.device).err();

(RenderPass::new(Some(cmd_buf), arc_desc), err)
}
Expand Down
11 changes: 1 addition & 10 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,15 +1923,6 @@ impl crate::Context for ContextWgpuCore {
encoder_data: &Self::CommandEncoderData,
desc: &crate::RenderPassDescriptor<'_>,
) -> (Self::RenderPassId, Self::RenderPassData) {
if desc.color_attachments.len() > wgc::MAX_COLOR_ATTACHMENTS {
self.handle_error_fatal(
wgc::command::ColorAttachmentError::TooMany {
given: desc.color_attachments.len(),
limit: wgc::MAX_COLOR_ATTACHMENTS,
},
"CommandEncoder::begin_render_pass",
);
}
let colors = desc
.color_attachments
.iter()
Expand All @@ -1943,7 +1934,7 @@ impl crate::Context for ContextWgpuCore {
channel: map_pass_channel(Some(&at.ops)),
})
})
.collect::<ArrayVec<_, { wgc::MAX_COLOR_ATTACHMENTS }>>();
.collect::<Vec<_>>();

let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| {
wgc::command::RenderPassDepthStencilAttachment {
Expand Down

0 comments on commit de960cc

Please sign in to comment.