Skip to content

Commit

Permalink
Add MULTISAMPLE_X16 texture format feature flag where supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Feb 3, 2023
1 parent 41de797 commit 4aaabf9
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
3 changes: 2 additions & 1 deletion wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,8 @@ impl<A: HalApi> Device<A> {
if !format_features.flags.intersects(
wgt::TextureFormatFeatureFlags::MULTISAMPLE_X4
| wgt::TextureFormatFeatureFlags::MULTISAMPLE_X2
| wgt::TextureFormatFeatureFlags::MULTISAMPLE_X8,
| wgt::TextureFormatFeatureFlags::MULTISAMPLE_X8
| wgt::TextureFormatFeatureFlags::MULTISAMPLE_X16,
) {
return Err(CreateTextureError::InvalidMultisampledFormat(desc.format));
}
Expand Down
4 changes: 4 additions & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ impl<A: HalApi> Adapter<A> {
wgt::TextureFormatFeatureFlags::MULTISAMPLE_X8,
caps.contains(Tfc::MULTISAMPLE_X8),
);
flags.set(
wgt::TextureFormatFeatureFlags::MULTISAMPLE_X16,
caps.contains(Tfc::MULTISAMPLE_X16),
);

flags.set(
wgt::TextureFormatFeatureFlags::MULTISAMPLE_RESOLVE,
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
set_sample_count(2, Tfc::MULTISAMPLE_X2);
set_sample_count(4, Tfc::MULTISAMPLE_X4);
set_sample_count(8, Tfc::MULTISAMPLE_X8);
set_sample_count(16, Tfc::MULTISAMPLE_X16);

caps
}
Expand Down
7 changes: 6 additions & 1 deletion wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,12 @@ impl crate::Adapter<super::Api> for super::Adapter {
.lock()
.get_parameter_i32(glow::MAX_SAMPLES)
};
if max_samples >= 8 {
if max_samples >= 16 {
Tfc::MULTISAMPLE_X2
| Tfc::MULTISAMPLE_X4
| Tfc::MULTISAMPLE_X8
| Tfc::MULTISAMPLE_X16
} else if max_samples >= 8 {
Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4 | Tfc::MULTISAMPLE_X8
} else if max_samples >= 4 {
Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4
Expand Down
8 changes: 5 additions & 3 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,16 @@ bitflags!(
const MULTISAMPLE_X4 = 1 << 10;
/// Format can be multisampled by x8.
const MULTISAMPLE_X8 = 1 << 11;
/// Format can be multisampled by x16.
const MULTISAMPLE_X16 = 1 << 12;

/// Format can be used for render pass resolve targets.
const MULTISAMPLE_RESOLVE = 1 << 12;
const MULTISAMPLE_RESOLVE = 1 << 13;

/// Format can be copied from.
const COPY_SRC = 1 << 13;
const COPY_SRC = 1 << 14;
/// Format can be copied to.
const COPY_DST = 1 << 14;
const COPY_DST = 1 << 15;
}
);

Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ impl super::PrivateCapabilities {
if device.supports_texture_sample_count(8) {
sample_count_mask |= crate::TextureFormatCapabilities::MULTISAMPLE_X8;
}
if device.supports_texture_sample_count(16) {
sample_count_mask |= crate::TextureFormatCapabilities::MULTISAMPLE_X16;
}

let rw_texture_tier = if version.at_least((10, 13), (11, 0)) {
device.read_write_texture_support()
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,10 @@ impl crate::Adapter<super::Api> for super::Adapter {
Tfc::MULTISAMPLE_X8,
sample_flags.contains(vk::SampleCountFlags::TYPE_8),
);
flags.set(
Tfc::MULTISAMPLE_X16,
sample_flags.contains(vk::SampleCountFlags::TYPE_16),
);

flags
}
Expand Down
11 changes: 7 additions & 4 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1716,17 +1716,19 @@ bitflags::bitflags! {
const MULTISAMPLE_X4 = 1 << 2 ;
/// Allows [`TextureDescriptor::sample_count`] to be `8`.
const MULTISAMPLE_X8 = 1 << 3 ;
/// Allows [`TextureDescriptor::sample_count`] to be `16`.
const MULTISAMPLE_X16 = 1 << 4;
/// Allows a texture of this format to back a view passed as `resolve_target`
/// to a render pass for an automatic driver-implemented resolve.
const MULTISAMPLE_RESOLVE = 1 << 4;
const MULTISAMPLE_RESOLVE = 1 << 5;
/// When used as a STORAGE texture, then a texture with this format can be bound with
/// [`StorageTextureAccess::ReadOnly`] or [`StorageTextureAccess::ReadWrite`].
const STORAGE_READ_WRITE = 1 << 5;
const STORAGE_READ_WRITE = 1 << 6;
/// When used as a STORAGE texture, then a texture with this format can be written to with atomics.
// TODO: No access flag exposed as of writing
const STORAGE_ATOMICS = 1 << 6;
const STORAGE_ATOMICS = 1 << 7;
/// If not present, the texture can't be blended into the render target.
const BLENDABLE = 1 << 7;
const BLENDABLE = 1 << 8;
}
}

Expand All @@ -1742,6 +1744,7 @@ impl TextureFormatFeatureFlags {
2 => self.contains(tfsc::MULTISAMPLE_X2),
4 => self.contains(tfsc::MULTISAMPLE_X4),
8 => self.contains(tfsc::MULTISAMPLE_X8),
16 => self.contains(tfsc::MULTISAMPLE_X16),
_ => false,
}
}
Expand Down
4 changes: 3 additions & 1 deletion wgpu/examples/msaa-line/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ impl framework::Example for Example {
let sample_flags = _adapter.get_texture_format_features(config.format).flags;

let max_sample_count = {
if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X8) {
if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X16) {
16
} else if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X8) {
8
} else if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X4) {
4
Expand Down

0 comments on commit 4aaabf9

Please sign in to comment.