Handle TooManyAttachments in wgpu-core (#6076)

This commit is contained in:
Samson 2024-08-05 15:45:02 +02:00 committed by GitHub
parent 9619a43849
commit de960ccbba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 11 deletions

View File

@ -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")]

View File

@ -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,
@ -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)
}

View File

@ -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()
@ -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 {