Skip to content

Commit 36b15a0

Browse files
committed
Add BGRA8UNORM_STORAGE extension
1 parent 316312b commit 36b15a0

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

deno_webgpu/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
186186
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC) {
187187
return_features.push("texture-compression-astc");
188188
}
189+
if features.contains(wgpu_types::Features::BGRA8UNORM_STORAGE) {
190+
return_features.push("bgra8unorm-storage");
191+
}
189192

190193
// extended from spec
191194

@@ -404,6 +407,10 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
404407
wgpu_types::Features::TEXTURE_COMPRESSION_ASTC,
405408
required_features.0.contains("texture-compression-astc"),
406409
);
410+
features.set(
411+
wgpu_types::Features::BGRA8UNORM_STORAGE,
412+
required_features.0.contains("bgra8unorm-storage"),
413+
);
407414

408415
// extended from spec
409416

wgpu-core/src/device/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,11 @@ impl<A: HalApi> Device<A> {
32403240
if using_device_features || downlevel {
32413241
Ok(adapter.get_texture_format_features(format))
32423242
} else {
3243-
Ok(format.guaranteed_format_features())
3243+
let mut features = format.guaranteed_format_features();
3244+
if self.features.contains(wgt::Features::BGRA8UNORM_STORAGE) {
3245+
features.allowed_usages |= wgt::TextureUsages::STORAGE_BINDING;
3246+
}
3247+
Ok(features)
32443248
}
32453249
}
32463250

wgpu-hal/src/dx12/adapter.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::{
44
};
55
use std::{mem, ptr, sync::Arc, thread};
66
use winapi::{
7-
shared::{dxgi, dxgi1_2, minwindef::DWORD, windef, winerror},
7+
shared::{
8+
dxgi, dxgi1_2, dxgiformat::DXGI_FORMAT_B8G8R8A8_UNORM, minwindef::DWORD, windef, winerror,
9+
},
810
um::{d3d12 as d3d12_ty, d3d12sdklayers, winuser},
911
};
1012

@@ -243,6 +245,27 @@ impl super::Adapter {
243245
shader_model_support.HighestShaderModel >= d3d12_ty::D3D_SHADER_MODEL_5_1,
244246
);
245247

248+
let bgra8unorm_storage_supported = {
249+
let mut bgra8unorm_info: d3d12_ty::D3D12_FEATURE_DATA_FORMAT_SUPPORT =
250+
unsafe { mem::zeroed() };
251+
bgra8unorm_info.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
252+
let hr = unsafe {
253+
device.CheckFeatureSupport(
254+
d3d12_ty::D3D12_FEATURE_FORMAT_SUPPORT,
255+
&mut bgra8unorm_info as *mut _ as *mut _,
256+
mem::size_of::<d3d12_ty::D3D12_FEATURE_DATA_FORMAT_SUPPORT>() as _,
257+
)
258+
};
259+
hr == 0
260+
&& (bgra8unorm_info.Support1
261+
& d3d12_ty::D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW
262+
!= 0)
263+
};
264+
features.set(
265+
wgt::Features::BGRA8UNORM_STORAGE,
266+
bgra8unorm_storage_supported,
267+
);
268+
246269
// TODO: Determine if IPresentationManager is supported
247270
let presentation_timer = auxil::dxgi::time::PresentationTimer::new_dxgi();
248271

wgpu-hal/src/metal/adapter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ impl super::PrivateCapabilities {
765765
| F::TEXTURE_FORMAT_16BIT_NORM
766766
| F::SHADER_F16
767767
| F::DEPTH32FLOAT_STENCIL8
768-
| F::MULTI_DRAW_INDIRECT;
768+
| F::MULTI_DRAW_INDIRECT
769+
| F::BGRA8UNORM_STORAGE;
769770

770771
features.set(F::TEXTURE_COMPRESSION_ASTC, self.format_astc);
771772
features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr);

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ impl PhysicalDeviceFeatures {
526526

527527
features.set(F::DEPTH32FLOAT_STENCIL8, texture_d32_s8);
528528

529+
let bgra8unorm_storage = supports_format(
530+
instance,
531+
phd,
532+
vk::Format::B8G8R8A8_UNORM,
533+
vk::ImageTiling::OPTIMAL,
534+
vk::FormatFeatureFlags::STORAGE_IMAGE,
535+
);
536+
features.set(F::BGRA8UNORM_STORAGE, bgra8unorm_storage);
537+
529538
(features, dl_flags)
530539
}
531540

wgpu-types/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,19 @@ bitflags::bitflags! {
287287
//
288288
// ? const FORMATS_TIER_1 = 1 << 14; (https://github.com/gpuweb/gpuweb/issues/3837)
289289
// ? const RW_STORAGE_TEXTURE_TIER_1 = 1 << 15; (https://github.com/gpuweb/gpuweb/issues/3838)
290-
// TODO const BGRA8UNORM_STORAGE = 1 << 16;
290+
291+
/// Allows the [`wgpu::TextureUsages::STORAGE_BINDING`] usage on textures with format [`TextureFormat::Bgra8unorm`]
292+
///
293+
/// Note: this is not supported in naga yet.
294+
///
295+
/// Supported Platforms:
296+
/// - Vulkan
297+
/// - DX12
298+
/// - Metal
299+
///
300+
/// This is a web and native feature.
301+
const BGRA8UNORM_STORAGE = 1 << 16;
302+
291303
// ? const NORM16_FILTERABLE = 1 << 17; (https://github.com/gpuweb/gpuweb/issues/3839)
292304
// ? const NORM16_RESOLVE = 1 << 18; (https://github.com/gpuweb/gpuweb/issues/3839)
293305
// TODO const FLOAT32_FILTERABLE = 1 << 19;

wgpu/src/backend/web.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ const FEATURES_MAPPING: [(wgt::Features, web_sys::GpuFeatureName); 8] = [
583583
wgt::Features::SHADER_F16,
584584
web_sys::GpuFeatureName::ShaderF16,
585585
),
586+
(
587+
wgt::Features::BGRA8UNORM_STORAGE,
588+
web_sys::GpuFeatureName::Bgra8unormStorage,
589+
),
586590
];
587591

588592
fn map_wgt_features(supported_features: web_sys::GpuSupportedFeatures) -> wgt::Features {

0 commit comments

Comments
 (0)