Skip to content

Commit

Permalink
Add BGRA8UNORM_STORAGE extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Apr 2, 2023
1 parent 316312b commit 36b15a0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
7 changes: 7 additions & 0 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC) {
return_features.push("texture-compression-astc");
}
if features.contains(wgpu_types::Features::BGRA8UNORM_STORAGE) {
return_features.push("bgra8unorm-storage");
}

// extended from spec

Expand Down Expand Up @@ -404,6 +407,10 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
wgpu_types::Features::TEXTURE_COMPRESSION_ASTC,
required_features.0.contains("texture-compression-astc"),
);
features.set(
wgpu_types::Features::BGRA8UNORM_STORAGE,
required_features.0.contains("bgra8unorm-storage"),
);

// extended from spec

Expand Down
6 changes: 5 additions & 1 deletion wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,11 @@ impl<A: HalApi> Device<A> {
if using_device_features || downlevel {
Ok(adapter.get_texture_format_features(format))
} else {
Ok(format.guaranteed_format_features())
let mut features = format.guaranteed_format_features();
if self.features.contains(wgt::Features::BGRA8UNORM_STORAGE) {
features.allowed_usages |= wgt::TextureUsages::STORAGE_BINDING;
}
Ok(features)
}
}

Expand Down
25 changes: 24 additions & 1 deletion wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::{
};
use std::{mem, ptr, sync::Arc, thread};
use winapi::{
shared::{dxgi, dxgi1_2, minwindef::DWORD, windef, winerror},
shared::{
dxgi, dxgi1_2, dxgiformat::DXGI_FORMAT_B8G8R8A8_UNORM, minwindef::DWORD, windef, winerror,
},
um::{d3d12 as d3d12_ty, d3d12sdklayers, winuser},
};

Expand Down Expand Up @@ -243,6 +245,27 @@ impl super::Adapter {
shader_model_support.HighestShaderModel >= d3d12_ty::D3D_SHADER_MODEL_5_1,
);

let bgra8unorm_storage_supported = {
let mut bgra8unorm_info: d3d12_ty::D3D12_FEATURE_DATA_FORMAT_SUPPORT =
unsafe { mem::zeroed() };
bgra8unorm_info.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
let hr = unsafe {
device.CheckFeatureSupport(
d3d12_ty::D3D12_FEATURE_FORMAT_SUPPORT,
&mut bgra8unorm_info as *mut _ as *mut _,
mem::size_of::<d3d12_ty::D3D12_FEATURE_DATA_FORMAT_SUPPORT>() as _,
)
};
hr == 0
&& (bgra8unorm_info.Support1
& d3d12_ty::D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW
!= 0)
};
features.set(
wgt::Features::BGRA8UNORM_STORAGE,
bgra8unorm_storage_supported,
);

// TODO: Determine if IPresentationManager is supported
let presentation_timer = auxil::dxgi::time::PresentationTimer::new_dxgi();

Expand Down
3 changes: 2 additions & 1 deletion wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ impl super::PrivateCapabilities {
| F::TEXTURE_FORMAT_16BIT_NORM
| F::SHADER_F16
| F::DEPTH32FLOAT_STENCIL8
| F::MULTI_DRAW_INDIRECT;
| F::MULTI_DRAW_INDIRECT
| F::BGRA8UNORM_STORAGE;

features.set(F::TEXTURE_COMPRESSION_ASTC, self.format_astc);
features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr);
Expand Down
9 changes: 9 additions & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,15 @@ impl PhysicalDeviceFeatures {

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

let bgra8unorm_storage = supports_format(
instance,
phd,
vk::Format::B8G8R8A8_UNORM,
vk::ImageTiling::OPTIMAL,
vk::FormatFeatureFlags::STORAGE_IMAGE,
);
features.set(F::BGRA8UNORM_STORAGE, bgra8unorm_storage);

(features, dl_flags)
}

Expand Down
14 changes: 13 additions & 1 deletion wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,19 @@ bitflags::bitflags! {
//
// ? const FORMATS_TIER_1 = 1 << 14; (https://github.com/gpuweb/gpuweb/issues/3837)
// ? const RW_STORAGE_TEXTURE_TIER_1 = 1 << 15; (https://github.com/gpuweb/gpuweb/issues/3838)
// TODO const BGRA8UNORM_STORAGE = 1 << 16;

/// Allows the [`wgpu::TextureUsages::STORAGE_BINDING`] usage on textures with format [`TextureFormat::Bgra8unorm`]
///
/// Note: this is not supported in naga yet.
///
/// Supported Platforms:
/// - Vulkan
/// - DX12
/// - Metal
///
/// This is a web and native feature.
const BGRA8UNORM_STORAGE = 1 << 16;

// ? const NORM16_FILTERABLE = 1 << 17; (https://github.com/gpuweb/gpuweb/issues/3839)
// ? const NORM16_RESOLVE = 1 << 18; (https://github.com/gpuweb/gpuweb/issues/3839)
// TODO const FLOAT32_FILTERABLE = 1 << 19;
Expand Down
4 changes: 4 additions & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ const FEATURES_MAPPING: [(wgt::Features, web_sys::GpuFeatureName); 8] = [
wgt::Features::SHADER_F16,
web_sys::GpuFeatureName::ShaderF16,
),
(
wgt::Features::BGRA8UNORM_STORAGE,
web_sys::GpuFeatureName::Bgra8unormStorage,
),
];

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

0 comments on commit 36b15a0

Please sign in to comment.