Skip to content

Commit 4124fbf

Browse files
authored
Raise Vulkan/DX12/GL max_color_attachment_bytes_per_sample Limit (#6866)
1 parent cb6dbb8 commit 4124fbf

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,12 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849).
221221
#### Vulkan
222222

223223
- Allocate descriptors for acceleration structures. By @Vecvec in [#6861](https://github.com/gfx-rs/wgpu/pull/6861).
224+
- `max_color_attachment_bytes_per_sample` is now correctly set to 128. By @cwfitzgerald in [#6866](https://github.com/gfx-rs/wgpu/pull/6866)
224225

225226
#### D3D12
226227

227228
- Fix no longer showing software rasterizer adapters. By @wumpf in [#6843](https://github.com/gfx-rs/wgpu/pull/6843).
229+
- `max_color_attachment_bytes_per_sample` is now correctly set to 128. By @cwfitzgerald in [#6866](https://github.com/gfx-rs/wgpu/pull/6866)
228230

229231
### Examples
230232

wgpu-core/src/validation.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ pub fn validate_color_attachment_bytes_per_sample(
12951295
attachment_formats: impl Iterator<Item = Option<wgt::TextureFormat>>,
12961296
limit: u32,
12971297
) -> Result<(), u32> {
1298-
let mut total_bytes_per_sample = 0;
1298+
let mut total_bytes_per_sample: u32 = 0;
12991299
for format in attachment_formats {
13001300
let Some(format) = format else {
13011301
continue;
@@ -1304,10 +1304,7 @@ pub fn validate_color_attachment_bytes_per_sample(
13041304
let byte_cost = format.target_pixel_byte_cost().unwrap();
13051305
let alignment = format.target_component_alignment().unwrap();
13061306

1307-
let rem = total_bytes_per_sample % alignment;
1308-
if rem != 0 {
1309-
total_bytes_per_sample += alignment - rem;
1310-
}
1307+
total_bytes_per_sample = total_bytes_per_sample.next_multiple_of(alignment);
13111308
total_bytes_per_sample += byte_cost;
13121309
}
13131310

wgpu-hal/src/dx12/adapter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ impl super::Adapter {
425425

426426
// See https://learn.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support
427427
let max_color_attachments = 8;
428-
// TODO: determine this programmatically if possible.
429-
// https://github.com/gpuweb/gpuweb/issues/2965#issuecomment-1361315447
430-
let max_color_attachment_bytes_per_sample = 64;
428+
let max_color_attachment_bytes_per_sample =
429+
max_color_attachments * wgt::TextureFormat::MAX_TARGET_PIXEL_BYTE_COST;
431430

432431
Some(crate::ExposedAdapter {
433432
adapter: super::Adapter {

wgpu-hal/src/gles/adapter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,9 @@ impl super::Adapter {
663663
.min(crate::MAX_COLOR_ATTACHMENTS as i32) as u32
664664
};
665665

666-
// TODO: programmatically determine this.
667-
let max_color_attachment_bytes_per_sample = 32;
666+
// 16 bytes per sample is the maximum size of a color attachment.
667+
let max_color_attachment_bytes_per_sample =
668+
max_color_attachments * wgt::TextureFormat::MAX_TARGET_PIXEL_BYTE_COST;
668669

669670
let limits = wgt::Limits {
670671
max_texture_dimension_1d: max_texture_size,

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,13 @@ impl PhysicalDeviceProperties {
10521052

10531053
// TODO: programmatically determine this, if possible. It's unclear whether we can
10541054
// as of https://github.com/gpuweb/gpuweb/issues/2965#issuecomment-1361315447.
1055-
// We could increase the limit when we aren't on a tiled GPU.
1056-
let max_color_attachment_bytes_per_sample = 32;
1055+
//
1056+
// In theory some tilers may not support this much. We can't tell however, and
1057+
// the driver will throw a DEVICE_REMOVED if it goes too high in usage. This is fine.
1058+
//
1059+
// 16 bytes per sample is the maximum size for a color attachment.
1060+
let max_color_attachment_bytes_per_sample =
1061+
limits.max_color_attachments * wgt::TextureFormat::MAX_TARGET_PIXEL_BYTE_COST;
10571062

10581063
wgt::Limits {
10591064
max_texture_dimension_1d: limits.max_image_dimension1_d,

wgpu-types/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,10 @@ pub struct Limits {
11921192
/// The maximum allowed number of color attachments.
11931193
pub max_color_attachments: u32,
11941194
/// The maximum number of bytes necessary to hold one sample (pixel or subpixel) of render
1195-
/// pipeline output data, across all color attachments.
1195+
/// pipeline output data, across all color attachments as described by [`TextureFormat::target_pixel_byte_cost`]
1196+
/// and [`TextureFormat::target_component_alignment`]. Defaults to 32. Higher is "better".
1197+
///
1198+
/// ⚠️ `Rgba8Unorm`/`Rgba8Snorm`/`Bgra8Unorm`/`Bgra8Snorm` are deceptively 8 bytes per sample. ⚠️
11961199
pub max_color_attachment_bytes_per_sample: u32,
11971200
/// Maximum number of bytes used for workgroup memory in a compute entry point. Defaults to
11981201
/// 16384. Higher is "better".
@@ -3775,6 +3778,9 @@ impl TextureFormat {
37753778
}
37763779
}
37773780

3781+
/// The largest number that can be returned by [`Self::target_pixel_byte_cost`].
3782+
pub const MAX_TARGET_PIXEL_BYTE_COST: u32 = 16;
3783+
37783784
/// The number of bytes occupied per pixel in a color attachment
37793785
/// <https://gpuweb.github.io/gpuweb/#render-target-pixel-byte-cost>
37803786
#[must_use]
@@ -3800,11 +3806,13 @@ impl TextureFormat {
38003806
| Self::R32Uint
38013807
| Self::R32Sint
38023808
| Self::R32Float => Some(4),
3809+
// Despite being 4 bytes per pixel, these are 8 bytes per pixel in the table
38033810
Self::Rgba8Unorm
38043811
| Self::Rgba8UnormSrgb
38053812
| Self::Rgba8Snorm
38063813
| Self::Bgra8Unorm
38073814
| Self::Bgra8UnormSrgb
3815+
// ---
38083816
| Self::Rgba16Uint
38093817
| Self::Rgba16Sint
38103818
| Self::Rgba16Unorm
@@ -3817,6 +3825,7 @@ impl TextureFormat {
38173825
| Self::Rgb10a2Unorm
38183826
| Self::Rg11b10Ufloat => Some(8),
38193827
Self::Rgba32Uint | Self::Rgba32Sint | Self::Rgba32Float => Some(16),
3828+
// ⚠️ If you add formats with larger sizes, make sure you change `MAX_TARGET_PIXEL_BYTE_COST`` ⚠️
38203829
Self::Stencil8
38213830
| Self::Depth16Unorm
38223831
| Self::Depth24Plus

0 commit comments

Comments
 (0)