diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs
index 7290330da..ec600d2c6 100644
--- a/wgpu-core/src/command/mod.rs
+++ b/wgpu-core/src/command/mod.rs
@@ -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")]
diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs
index 5227d075e..8c00e0d30 100644
--- a/wgpu-core/src/command/render.rs
+++ b/wgpu-core/src/command/render.rs
@@ -1342,10 +1342,21 @@ impl Global {
hub: &crate::hub::Hub,
desc: &RenderPassDescriptor<'_>,
arc_desc: &mut ArcRenderPassDescriptor,
+ device: &Device,
) -> 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)
}
diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs
index 780655249..0adf8c3e5 100644
--- a/wgpu/src/backend/wgpu_core.rs
+++ b/wgpu/src/backend/wgpu_core.rs
@@ -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::>();
+ .collect::>();
let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| {
wgc::command::RenderPassDepthStencilAttachment {