Skip to content

Commit de960cc

Browse files
authored
Handle TooManyAttachments in wgpu-core (#6076)
1 parent 9619a43 commit de960cc

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

wgpu-core/src/command/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ pub enum CommandEncoderError {
595595
InvalidTimestampWritesQuerySetId(id::QuerySetId),
596596
#[error("Attachment TextureViewId {0:?} is invalid")]
597597
InvalidAttachmentId(id::TextureViewId),
598+
#[error(transparent)]
599+
InvalidColorAttachment(#[from] ColorAttachmentError),
598600
#[error("Resolve attachment TextureViewId {0:?} is invalid")]
599601
InvalidResolveTargetId(id::TextureViewId),
600602
#[error("Depth stencil attachment TextureViewId {0:?} is invalid")]

wgpu-core/src/command/render.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,21 @@ impl Global {
13421342
hub: &crate::hub::Hub<A>,
13431343
desc: &RenderPassDescriptor<'_>,
13441344
arc_desc: &mut ArcRenderPassDescriptor<A>,
1345+
device: &Device<A>,
13451346
) -> Result<(), CommandEncoderError> {
13461347
let query_sets = hub.query_sets.read();
13471348
let texture_views = hub.texture_views.read();
13481349

1350+
let max_color_attachments = device.limits.max_color_attachments as usize;
1351+
if desc.color_attachments.len() > max_color_attachments {
1352+
return Err(CommandEncoderError::InvalidColorAttachment(
1353+
ColorAttachmentError::TooMany {
1354+
given: desc.color_attachments.len(),
1355+
limit: max_color_attachments,
1356+
},
1357+
));
1358+
}
1359+
13491360
for color_attachment in desc.color_attachments.iter() {
13501361
if let Some(RenderPassColorAttachment {
13511362
view: view_id,
@@ -1447,7 +1458,7 @@ impl Global {
14471458
Err(e) => return make_err(e, arc_desc),
14481459
};
14491460

1450-
let err = fill_arc_desc(hub, desc, &mut arc_desc).err();
1461+
let err = fill_arc_desc(hub, desc, &mut arc_desc, &cmd_buf.device).err();
14511462

14521463
(RenderPass::new(Some(cmd_buf), arc_desc), err)
14531464
}

wgpu/src/backend/wgpu_core.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,15 +1923,6 @@ impl crate::Context for ContextWgpuCore {
19231923
encoder_data: &Self::CommandEncoderData,
19241924
desc: &crate::RenderPassDescriptor<'_>,
19251925
) -> (Self::RenderPassId, Self::RenderPassData) {
1926-
if desc.color_attachments.len() > wgc::MAX_COLOR_ATTACHMENTS {
1927-
self.handle_error_fatal(
1928-
wgc::command::ColorAttachmentError::TooMany {
1929-
given: desc.color_attachments.len(),
1930-
limit: wgc::MAX_COLOR_ATTACHMENTS,
1931-
},
1932-
"CommandEncoder::begin_render_pass",
1933-
);
1934-
}
19351926
let colors = desc
19361927
.color_attachments
19371928
.iter()
@@ -1943,7 +1934,7 @@ impl crate::Context for ContextWgpuCore {
19431934
channel: map_pass_channel(Some(&at.ops)),
19441935
})
19451936
})
1946-
.collect::<ArrayVec<_, { wgc::MAX_COLOR_ATTACHMENTS }>>();
1937+
.collect::<Vec<_>>();
19471938

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

0 commit comments

Comments
 (0)