Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise Vulkan/DX12/GL max_color_attachment_bytes_per_sample Limit #6866

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849).
#### Vulkan

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

#### D3D12

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

### Examples

Expand Down
7 changes: 2 additions & 5 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ pub fn validate_color_attachment_bytes_per_sample(
attachment_formats: impl Iterator<Item = Option<wgt::TextureFormat>>,
limit: u32,
) -> Result<(), u32> {
let mut total_bytes_per_sample = 0;
let mut total_bytes_per_sample: u32 = 0;
for format in attachment_formats {
let Some(format) = format else {
continue;
Expand All @@ -1304,10 +1304,7 @@ pub fn validate_color_attachment_bytes_per_sample(
let byte_cost = format.target_pixel_byte_cost().unwrap();
let alignment = format.target_component_alignment().unwrap();

let rem = total_bytes_per_sample % alignment;
if rem != 0 {
total_bytes_per_sample += alignment - rem;
}
total_bytes_per_sample = total_bytes_per_sample.next_multiple_of(alignment);
total_bytes_per_sample += byte_cost;
}

Expand Down
5 changes: 2 additions & 3 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,8 @@ impl super::Adapter {

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

Some(crate::ExposedAdapter {
adapter: super::Adapter {
Expand Down
5 changes: 3 additions & 2 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,9 @@ impl super::Adapter {
.min(crate::MAX_COLOR_ATTACHMENTS as i32) as u32
};

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

let limits = wgt::Limits {
max_texture_dimension_1d: max_texture_size,
Expand Down
9 changes: 7 additions & 2 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,13 @@ impl PhysicalDeviceProperties {

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

wgt::Limits {
max_texture_dimension_1d: limits.max_image_dimension1_d,
Expand Down
11 changes: 10 additions & 1 deletion wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,10 @@ pub struct Limits {
/// The maximum allowed number of color attachments.
pub max_color_attachments: u32,
/// The maximum number of bytes necessary to hold one sample (pixel or subpixel) of render
/// pipeline output data, across all color attachments.
/// pipeline output data, across all color attachments as described by [`TextureFormat::target_pixel_byte_cost`]
/// and [`TextureFormat::target_component_alignment`]. Defaults to 32. Higher is "better".
///
/// ⚠️ `Rgba8Unorm`/`Rgba8Snorm`/`Bgra8Unorm`/`Bgra8Snorm` are deceptively 8 bytes per sample. ⚠️
pub max_color_attachment_bytes_per_sample: u32,
/// Maximum number of bytes used for workgroup memory in a compute entry point. Defaults to
/// 16384. Higher is "better".
Expand Down Expand Up @@ -3775,6 +3778,9 @@ impl TextureFormat {
}
}

/// The largest number that can be returned by [`Self::target_pixel_byte_cost`].
pub const MAX_TARGET_PIXEL_BYTE_COST: u32 = 16;

/// The number of bytes occupied per pixel in a color attachment
/// <https://gpuweb.github.io/gpuweb/#render-target-pixel-byte-cost>
#[must_use]
Expand All @@ -3800,11 +3806,13 @@ impl TextureFormat {
| Self::R32Uint
| Self::R32Sint
| Self::R32Float => Some(4),
// Despite being 4 bytes per pixel, these are 8 bytes per pixel in the table
Self::Rgba8Unorm
| Self::Rgba8UnormSrgb
| Self::Rgba8Snorm
| Self::Bgra8Unorm
| Self::Bgra8UnormSrgb
// ---
| Self::Rgba16Uint
| Self::Rgba16Sint
| Self::Rgba16Unorm
Expand All @@ -3817,6 +3825,7 @@ impl TextureFormat {
| Self::Rgb10a2Unorm
| Self::Rg11b10Ufloat => Some(8),
Self::Rgba32Uint | Self::Rgba32Sint | Self::Rgba32Float => Some(16),
// ⚠️ If you add formats with larger sizes, make sure you change `MAX_TARGET_PIXEL_BYTE_COST`` ⚠️
Self::Stencil8
| Self::Depth16Unorm
| Self::Depth24Plus
Expand Down
Loading