Skip to content

Commit 422d539

Browse files
Add missing maxColorAttachmentBytesPerSample validation for render passes (#8697)
1 parent f558612 commit 422d539

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ By @cwfitzgerald in [#8609](https://github.com/gfx-rs/wgpu/pull/8609).
195195
- Corrected documentation of the minimum alignment of the _end_ of a mapped range of a buffer (it is 4, not 8). By @kpreid in [#8450](https://github.com/gfx-rs/wgpu/pull/8450).
196196
- `util::StagingBelt` now takes a `Device` when it is created instead of when it is used. By @kpreid in [#8462](https://github.com/gfx-rs/wgpu/pull/8462).
197197
- `wgpu_hal::vulkan::Texture` API changes to handle externally-created textures and memory more flexibly. By @s-ol in [#8512](https://github.com/gfx-rs/wgpu/pull/8512), [#8521](https://github.com/gfx-rs/wgpu/pull/8521).
198+
- Render passes are now validated against the `maxColorAttachmentBytesPerSample` limit. By @andyleiserson in [#8697](https://github.com/gfx-rs/wgpu/pull/8697).
198199

199200
#### Metal
200201

cts_runner/test.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ webgpu:api,validation,queue,buffer_mapped:copyTextureToBuffer:*
129129
webgpu:api,validation,queue,buffer_mapped:map_command_recording_order:*
130130
webgpu:api,validation,queue,submit:command_buffer,*
131131
webgpu:api,validation,render_pass,render_pass_descriptor:attachments,*
132-
webgpu:api,validation,render_pass,render_pass_descriptor:color_attachments,depthSlice,*
132+
webgpu:api,validation,render_pass,render_pass_descriptor:color_attachments,*
133133
webgpu:api,validation,render_pass,render_pass_descriptor:resolveTarget,*
134134
webgpu:api,validation,render_pass,resolve:resolve_attachment:*
135135
webgpu:api,validation,resource_usages,buffer,in_pass_encoder:*

wgpu-core/src/command/render.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use crate::{
4444
ParentDevice, QuerySet, Texture, TextureView, TextureViewNotRenderableReason,
4545
},
4646
track::{ResourceUsageCompatibilityError, Tracker, UsageScope},
47-
Label,
47+
validation, Label,
4848
};
4949

5050
#[cfg(feature = "serde")]
@@ -1277,6 +1277,15 @@ impl RenderPassInfo {
12771277
));
12781278
}
12791279

1280+
validation::validate_color_attachment_bytes_per_sample(
1281+
color_attachments
1282+
.iter()
1283+
.flatten()
1284+
.map(|at| at.view.desc.format),
1285+
device.limits.max_color_attachment_bytes_per_sample,
1286+
)
1287+
.map_err(RenderPassErrorInner::ColorAttachment)?;
1288+
12801289
fn check_attachment_overlap(
12811290
attachment_set: &mut crate::FastHashSet<(crate::track::TrackerIndex, u32, u32)>,
12821291
view: &TextureView,

wgpu-core/src/device/resource.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::{
5252
snatch::{SnatchGuard, SnatchLock, Snatchable},
5353
timestamp_normalization::TIMESTAMP_NORMALIZATION_BUFFER_USES,
5454
track::{BindGroupStates, DeviceTracker, TrackerIndexAllocators, UsageScope, UsageScopePool},
55-
validation::{self, validate_color_attachment_bytes_per_sample},
55+
validation,
5656
weak_vec::WeakVec,
5757
FastHashMap, LabelHelpers, OnceCellOrLock,
5858
};
@@ -4134,15 +4134,11 @@ impl Device {
41344134
}
41354135
}
41364136

4137-
let limit = self.limits.max_color_attachment_bytes_per_sample;
4138-
let formats = color_targets
4139-
.iter()
4140-
.map(|cs| cs.as_ref().map(|cs| cs.format));
4141-
if let Err(total) = validate_color_attachment_bytes_per_sample(formats, limit) {
4142-
return Err(pipeline::CreateRenderPipelineError::ColorAttachment(
4143-
command::ColorAttachmentError::TooManyBytesPerSample { total, limit },
4144-
));
4145-
}
4137+
validation::validate_color_attachment_bytes_per_sample(
4138+
color_targets.iter().flatten().map(|cs| cs.format),
4139+
self.limits.max_color_attachment_bytes_per_sample,
4140+
)
4141+
.map_err(pipeline::CreateRenderPipelineError::ColorAttachment)?;
41464142

41474143
if let Some(ds) = depth_stencil_state {
41484144
target_specified = true;

wgpu-core/src/validation.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,17 +1411,17 @@ impl Interface {
14111411
}
14121412
}
14131413

1414-
// https://gpuweb.github.io/gpuweb/#abstract-opdef-calculating-color-attachment-bytes-per-sample
1414+
/// Validate a list of color attachment formats against `maxColorAttachmentBytesPerSample`.
1415+
///
1416+
/// The color attachments can be from a render pass descriptor or a pipeline descriptor.
1417+
///
1418+
/// Implements <https://gpuweb.github.io/gpuweb/#abstract-opdef-calculating-color-attachment-bytes-per-sample>.
14151419
pub fn validate_color_attachment_bytes_per_sample(
1416-
attachment_formats: impl Iterator<Item = Option<wgt::TextureFormat>>,
1420+
attachment_formats: impl IntoIterator<Item = wgt::TextureFormat>,
14171421
limit: u32,
1418-
) -> Result<(), u32> {
1422+
) -> Result<(), crate::command::ColorAttachmentError> {
14191423
let mut total_bytes_per_sample: u32 = 0;
14201424
for format in attachment_formats {
1421-
let Some(format) = format else {
1422-
continue;
1423-
};
1424-
14251425
let byte_cost = format.target_pixel_byte_cost().unwrap();
14261426
let alignment = format.target_component_alignment().unwrap();
14271427

@@ -1430,7 +1430,12 @@ pub fn validate_color_attachment_bytes_per_sample(
14301430
}
14311431

14321432
if total_bytes_per_sample > limit {
1433-
return Err(total_bytes_per_sample);
1433+
return Err(
1434+
crate::command::ColorAttachmentError::TooManyBytesPerSample {
1435+
total: total_bytes_per_sample,
1436+
limit,
1437+
},
1438+
);
14341439
}
14351440

14361441
Ok(())

0 commit comments

Comments
 (0)