Skip to content

Commit 1fa944d

Browse files
authored
Merge branch 'master' into unsafe_ops_in_unsafe_fn
2 parents d6587cd + 3c82a4c commit 1fa944d

File tree

17 files changed

+215
-72
lines changed

17 files changed

+215
-72
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Bottom level categories:
5050
- New downlevel feature `UNRESTRICTED_INDEX_BUFFER` to indicate support for using `INDEX` together with other non-copy/map usages (unsupported on WebGL). By @Wumpf in [#3157](https://github.com/gfx-rs/wgpu/pull/3157)
5151

5252
#### WebGPU
53+
5354
- Implement `queue_validate_write_buffer` by @jinleili in [#3098](https://github.com/gfx-rs/wgpu/pull/3098)
5455

5556
#### GLES
@@ -64,12 +65,17 @@ Bottom level categories:
6465
- Add the `"wgsl"` feature, to enable WGSL shaders in `wgpu-core` and `wgpu`. Enabled by default in `wgpu`. By @daxpedda in [#2890](https://github.com/gfx-rs/wgpu/pull/2890).
6566
- Implement `Clone` for `ShaderSource` and `ShaderModuleDescriptor` in `wgpu`. By @daxpedda in [#3086](https://github.com/gfx-rs/wgpu/pull/3086).
6667
- Add `get_default_config` for `Surface` to simplify user creation of `SurfaceConfiguration`. By @jinleili in [#3034](https://github.com/gfx-rs/wgpu/pull/3034)
68+
- Native adapters can now use MSAA x2 and x8 if it's supported , previously only x1 and x4 were supported . By @39ali in [3140](https://github.com/gfx-rs/wgpu/pull/3140)
6769

6870
#### GLES
6971

7072
- Surfaces support now `TextureFormat::Rgba8Unorm` and (non-web only) `TextureFormat::Bgra8Unorm`. By @Wumpf in [#3070](https://github.com/gfx-rs/wgpu/pull/3070)
7173
- Support alpha to coverage. By @Wumpf in [#3156](https://github.com/gfx-rs/wgpu/pull/3156)
7274

75+
#### WebGPU
76+
77+
- Add `MULTISAMPLE_X2`, `MULTISAMPLE_X4` and `MULTISAMPLE_X8` to `TextureFormatFeatureFlags`. By @39ali in [3140](https://github.com/gfx-rs/wgpu/pull/3140)
78+
7379
### Bug Fixes
7480

7581
#### General
@@ -81,6 +87,7 @@ Bottom level categories:
8187
- Fix an integer overflow in `queue_write_texture` by @nical in (#3146)[https://github.com/gfx-rs/wgpu/pull/3146]
8288

8389
#### WebGPU
90+
8491
- Use `log` instead of `println` in hello example by @JolifantoBambla in [#2858](https://github.com/gfx-rs/wgpu/pull/2858)
8592

8693
#### GLES
@@ -95,6 +102,7 @@ Bottom level categories:
95102
By @jimblandy in [#3171](https://github.com/gfx-rs/wgpu/pull/3171)
96103

97104
### Examples
105+
98106
- Log adapter info in hello example on wasm target by @JolifantoBambla in [#2858](https://github.com/gfx-rs/wgpu/pull/2858)
99107

100108
### Testing/Internal
@@ -204,6 +212,7 @@ both `raw_window_handle::HasRawWindowHandle` and `raw_window_handle::HasRawDispl
204212
- Report Apple M2 gpu as integrated. By @i509VCB [#3036](https://github.com/gfx-rs/wgpu/pull/3036)
205213

206214
#### WebGPU
215+
207216
- When called in a web worker, `Context::init()` now uses `web_sys::WorkerGlobalContext` to create a `wgpu::Instance` instead of trying to access the unavailable `web_sys::Window` by @JolifantoBambla in [#2858](https://github.com/gfx-rs/wgpu/pull/2858)
208217

209218
### Changes
@@ -360,6 +369,7 @@ Added items to the public API
360369
- Update present_mode docs as most of them don't automatically fall back to Fifo anymore. by @Elabajaba in [#2855](https://github.com/gfx-rs/wgpu/pull/2855)
361370

362371
#### Hal
372+
363373
- Document safety requirements for `Adapter::from_external` in gles hal by @i509VCB in [#2863](https://github.com/gfx-rs/wgpu/pull/2863)
364374
- Make `AdapterContext` a publicly accessible type in the gles hal by @i509VCB in [#2870](https://github.com/gfx-rs/wgpu/pull/2870)
365375

wgpu-core/src/command/render.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,6 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
732732
expected: sample_count,
733733
});
734734
}
735-
if sample_count != 1 && sample_count != 4 {
736-
return Err(RenderPassErrorInner::InvalidSampleCount(sample_count));
737-
}
738735
attachment_type_name = type_name;
739736
Ok(())
740737
};

wgpu-core/src/device/mod.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,12 +811,23 @@ impl<A: HalApi> Device<A> {
811811
return Err(CreateTextureError::MultisampledNotRenderAttachment);
812812
}
813813

814+
if !format_features.flags.intersects(
815+
wgt::TextureFormatFeatureFlags::MULTISAMPLE_X4
816+
| wgt::TextureFormatFeatureFlags::MULTISAMPLE_X2
817+
| wgt::TextureFormatFeatureFlags::MULTISAMPLE_X8,
818+
) {
819+
return Err(CreateTextureError::InvalidMultisampledFormat(desc.format));
820+
}
821+
814822
if !format_features
815823
.flags
816-
.contains(wgt::TextureFormatFeatureFlags::MULTISAMPLE)
824+
.sample_count_supported(desc.sample_count)
817825
{
818-
return Err(CreateTextureError::InvalidMultisampledFormat(desc.format));
819-
}
826+
return Err(CreateTextureError::InvalidSampleCount(
827+
desc.sample_count,
828+
desc.format,
829+
));
830+
};
820831
}
821832

822833
let mips = desc.mip_level_count;
@@ -2665,7 +2676,9 @@ impl<A: HalApi> Device<A> {
26652676
break Some(pipeline::ColorStateError::FormatNotColor(cs.format));
26662677
}
26672678
if desc.multisample.count > 1
2668-
&& !format_features.flags.contains(Tfff::MULTISAMPLE)
2679+
&& !format_features
2680+
.flags
2681+
.sample_count_supported(desc.multisample.count)
26692682
{
26702683
break Some(pipeline::ColorStateError::FormatNotMultisampled(cs.format));
26712684
}
@@ -2699,7 +2712,10 @@ impl<A: HalApi> Device<A> {
26992712
ds.format,
27002713
));
27012714
}
2702-
if desc.multisample.count > 1 && !format_features.flags.contains(Tfff::MULTISAMPLE)
2715+
if desc.multisample.count > 1
2716+
&& !format_features
2717+
.flags
2718+
.sample_count_supported(desc.multisample.count)
27032719
{
27042720
break Some(pipeline::DepthStencilStateError::FormatNotMultisampled(
27052721
ds.format,

wgpu-core/src/instance.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,18 @@ impl<A: HalApi> Adapter<A> {
268268
);
269269

270270
flags.set(
271-
wgt::TextureFormatFeatureFlags::MULTISAMPLE,
272-
caps.contains(Tfc::MULTISAMPLE),
271+
wgt::TextureFormatFeatureFlags::MULTISAMPLE_X2,
272+
caps.contains(Tfc::MULTISAMPLE_X2),
273273
);
274+
flags.set(
275+
wgt::TextureFormatFeatureFlags::MULTISAMPLE_X4,
276+
caps.contains(Tfc::MULTISAMPLE_X4),
277+
);
278+
flags.set(
279+
wgt::TextureFormatFeatureFlags::MULTISAMPLE_X8,
280+
caps.contains(Tfc::MULTISAMPLE_X8),
281+
);
282+
274283
flags.set(
275284
wgt::TextureFormatFeatureFlags::MULTISAMPLE_RESOLVE,
276285
caps.contains(Tfc::MULTISAMPLE_RESOLVE),

wgpu-core/src/present.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
184184
hal_usage: conv::map_texture_usage(config.usage, config.format.into()),
185185
format_features: wgt::TextureFormatFeatures {
186186
allowed_usages: wgt::TextureUsages::RENDER_ATTACHMENT,
187-
flags: wgt::TextureFormatFeatureFlags::MULTISAMPLE
187+
flags: wgt::TextureFormatFeatureFlags::MULTISAMPLE_X4
188188
| wgt::TextureFormatFeatureFlags::MULTISAMPLE_RESOLVE,
189189
},
190190
initialization_status: TextureInitTracker::new(1, 1),

wgpu-core/src/resource.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ pub enum CreateTextureError {
517517
MultisampledNotRenderAttachment,
518518
#[error("Texture format {0:?} can't be used due to missing features.")]
519519
MissingFeatures(wgt::TextureFormat, #[source] MissingFeatures),
520+
#[error("Sample count {0} is not supported by format {1:?} on this device. It may be supported by your adapter through the TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature.")]
521+
InvalidSampleCount(u32, wgt::TextureFormat),
520522
}
521523

522524
impl<A: hal::Api> Resource for Texture<A> {

wgpu-hal/src/dx12/adapter.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,37 @@ impl crate::Adapter<super::Api> for super::Adapter {
446446
| d3d12::D3D12_FORMAT_SUPPORT1_DEPTH_STENCIL)
447447
!= 0
448448
&& data.Support1 & d3d12::D3D12_FORMAT_SUPPORT1_MULTISAMPLE_RENDERTARGET == 0;
449-
caps.set(Tfc::MULTISAMPLE, !no_msaa_load && !no_msaa_target);
449+
450450
caps.set(
451451
Tfc::MULTISAMPLE_RESOLVE,
452452
data.Support1 & d3d12::D3D12_FORMAT_SUPPORT1_MULTISAMPLE_RESOLVE != 0,
453453
);
454454

455+
let mut ms_levels = d3d12::D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS {
456+
Format: raw_format,
457+
SampleCount: 0,
458+
Flags: d3d12::D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE,
459+
NumQualityLevels: 0,
460+
};
461+
462+
let mut set_sample_count = |sc: u32, tfc: Tfc| {
463+
ms_levels.SampleCount = sc;
464+
465+
if self.device.CheckFeatureSupport(
466+
d3d12::D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS,
467+
<*mut _>::cast(&mut ms_levels),
468+
mem::size_of::<d3d12::D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS>() as _,
469+
) == winerror::S_OK
470+
&& ms_levels.NumQualityLevels != 0
471+
{
472+
caps.set(tfc, !no_msaa_load && !no_msaa_target);
473+
}
474+
};
475+
476+
set_sample_count(2, Tfc::MULTISAMPLE_X2);
477+
set_sample_count(4, Tfc::MULTISAMPLE_X4);
478+
set_sample_count(8, Tfc::MULTISAMPLE_X8);
479+
455480
caps
456481
}
457482

wgpu-hal/src/empty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl crate::Adapter<Api> for Context {
8989
) -> crate::TextureFormatCapabilities {
9090
crate::TextureFormatCapabilities::empty()
9191
}
92+
9293
unsafe fn surface_capabilities(&self, surface: &Context) -> Option<crate::SurfaceCapabilities> {
9394
None
9495
}

wgpu-hal/src/gles/adapter.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl super::Adapter {
196196

197197
(vendor, renderer)
198198
};
199+
199200
let version = unsafe { gl.get_parameter_string(glow::VERSION) };
200201

201202
log::info!("Vendor: {}", vendor);
@@ -664,17 +665,32 @@ impl crate::Adapter<super::Api> for super::Adapter {
664665
use crate::TextureFormatCapabilities as Tfc;
665666
use wgt::TextureFormat as Tf;
666667

668+
let sample_count = {
669+
let max_samples = self
670+
.shared
671+
.context
672+
.lock()
673+
.get_parameter_i32(glow::MAX_SAMPLES);
674+
if max_samples >= 8 {
675+
Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4 | Tfc::MULTISAMPLE_X8
676+
} else if max_samples >= 4 {
677+
Tfc::MULTISAMPLE_X2 | Tfc::MULTISAMPLE_X4
678+
} else {
679+
Tfc::MULTISAMPLE_X2
680+
}
681+
};
682+
667683
// Base types are pulled from the table in the OpenGLES 3.0 spec in section 3.8.
668684
//
669685
// The storage types are based on table 8.26, in section
670686
// "TEXTURE IMAGE LOADS AND STORES" of OpenGLES-3.2 spec.
671687
let empty = Tfc::empty();
672688
let base = Tfc::COPY_SRC | Tfc::COPY_DST;
673689
let unfilterable = base | Tfc::SAMPLED;
674-
let depth = base | Tfc::SAMPLED | Tfc::MULTISAMPLE | Tfc::DEPTH_STENCIL_ATTACHMENT;
690+
let depth = base | Tfc::SAMPLED | sample_count | Tfc::DEPTH_STENCIL_ATTACHMENT;
675691
let filterable = unfilterable | Tfc::SAMPLED_LINEAR;
676692
let renderable =
677-
unfilterable | Tfc::COLOR_ATTACHMENT | Tfc::MULTISAMPLE | Tfc::MULTISAMPLE_RESOLVE;
693+
unfilterable | Tfc::COLOR_ATTACHMENT | sample_count | Tfc::MULTISAMPLE_RESOLVE;
678694
let filterable_renderable = filterable | renderable | Tfc::COLOR_ATTACHMENT_BLEND;
679695
let storage = base | Tfc::STORAGE | Tfc::STORAGE_READ_WRITE;
680696

wgpu-hal/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,20 @@ bitflags!(
583583
/// Format can be used as depth-stencil and input attachment.
584584
const DEPTH_STENCIL_ATTACHMENT = 1 << 8;
585585

586-
/// Format can be multisampled.
587-
const MULTISAMPLE = 1 << 9;
586+
/// Format can be multisampled by x2.
587+
const MULTISAMPLE_X2 = 1 << 9;
588+
/// Format can be multisampled by x4.
589+
const MULTISAMPLE_X4 = 1 << 10;
590+
/// Format can be multisampled by x8.
591+
const MULTISAMPLE_X8 = 1 << 11;
592+
588593
/// Format can be used for render pass resolve targets.
589-
const MULTISAMPLE_RESOLVE = 1 << 10;
594+
const MULTISAMPLE_RESOLVE = 1 << 12;
590595

591596
/// Format can be copied from.
592-
const COPY_SRC = 1 << 11;
597+
const COPY_SRC = 1 << 13;
593598
/// Format can be copied to.
594-
const COPY_DST = 1 << 12;
599+
const COPY_DST = 1 << 14;
595600
}
596601
);
597602

0 commit comments

Comments
 (0)