Skip to content

Commit a8a62f6

Browse files
fix: validate fragment output locations against max_color_attachments
1 parent 2e2d9b5 commit a8a62f6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

wgpu-core/src/validation.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ pub enum StageError {
313313
MultipleEntryPointsFound,
314314
#[error(transparent)]
315315
InvalidResource(#[from] InvalidResourceError),
316+
#[error(
317+
"Location[{location}] {var}'s index exceeds `max_color_attachments` ({})",
318+
hal::MAX_COLOR_ATTACHMENTS
319+
)]
320+
ColorAttachmentLocationExceedsLimit { location: u32, var: InterfaceVar },
316321
}
317322

318323
impl WebGpuError for StageError {
@@ -334,7 +339,8 @@ impl WebGpuError for StageError {
334339
| Self::TooManyVaryings { .. }
335340
| Self::MissingEntryPoint(..)
336341
| Self::NoEntryPointFound
337-
| Self::MultipleEntryPointsFound => return ErrorType::Validation,
342+
| Self::MultipleEntryPointsFound
343+
| Self::ColorAttachmentLocationExceedsLimit { .. } => return ErrorType::Validation,
338344
};
339345
e.webgpu_error_type()
340346
}
@@ -1317,7 +1323,6 @@ impl Interface {
13171323
}
13181324
}
13191325

1320-
#[expect(clippy::single_match)]
13211326
match shader_stage {
13221327
naga::ShaderStage::Vertex => {
13231328
for output in entry_point.outputs.iter() {
@@ -1352,6 +1357,19 @@ impl Interface {
13521357
}
13531358
}
13541359
}
1360+
naga::ShaderStage::Fragment => {
1361+
for output in &entry_point.outputs {
1362+
let &Varying::Local { location, ref iv } = output else {
1363+
continue;
1364+
};
1365+
if location > self.limits.max_color_attachments {
1366+
return Err(StageError::ColorAttachmentLocationExceedsLimit {
1367+
location,
1368+
var: iv.clone(),
1369+
});
1370+
}
1371+
}
1372+
}
13551373
_ => (),
13561374
}
13571375

@@ -1370,6 +1388,7 @@ impl Interface {
13701388
Varying::BuiltIn(_) => None,
13711389
})
13721390
.collect();
1391+
13731392
Ok(outputs)
13741393
}
13751394

0 commit comments

Comments
 (0)