Skip to content

Commit 473792d

Browse files
WIP: feat: recognize TEXTURE_FORMATS_TIER{1,2}
Tier 1 PRs for WebGPU spec.: [`gpuweb`gfx-rs#5213](gpuweb/gpuweb#5213) and [`gpuweb`gfx-rs#5160](gpuweb/gpuweb#5160). Tier 2 PR for WebGPU spec.: [`gpuweb`gfx-rs#5226](gpuweb/gpuweb#5226)
1 parent 373db54 commit 473792d

6 files changed

Lines changed: 137 additions & 14 deletions

File tree

deno_webgpu/adapter.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ impl GPUAdapter {
9393
self.features.get(scope, |scope| {
9494
let features = self.instance.adapter_features(self.id);
9595
// Only expose WebGPU features, not wgpu native-only features
96-
let features = features & wgpu_types::Features::all_webgpu_mask();
96+
let texture_format_tier_features =
97+
wgpu_types::Features::TEXTURE_FORMATS_TIER1
98+
| wgpu_types::Features::TEXTURE_FORMATS_TIER2;
99+
let features = features
100+
& wgpu_types::Features::all_webgpu_mask()
101+
& !texture_format_tier_features;
97102
let features = features_to_feature_names(features);
98103
GPUSupportedFeatures::new(scope, features)
99104
})

deno_webgpu/webidl.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ pub enum GPUFeatureName {
398398
DualSourceBlending,
399399
#[webidl(rename = "subgroups")]
400400
Subgroups,
401+
#[webidl(rename = "texture-formats-tier1")]
402+
TextureFormatsTier1,
403+
#[webidl(rename = "texture-formats-tier2")]
404+
TextureFormatsTier2,
401405

402406
// standard feature, but not default yet in wgpu due to incomplete support
403407
// (and even if enabled in wgpu, doing so may not be appropriate in Deno)
@@ -492,7 +496,8 @@ pub fn feature_names_to_features(
492496
GPUFeatureName::DualSourceBlending => Features::DUAL_SOURCE_BLENDING,
493497
GPUFeatureName::Subgroups => Features::SUBGROUP,
494498
GPUFeatureName::ExternalTexture => Features::EXTERNAL_TEXTURE,
495-
GPUFeatureName::TextureFormat16BitNorm => Features::TEXTURE_FORMAT_16BIT_NORM,
499+
GPUFeatureName::TextureFormatsTier1 => Features::TEXTURE_FORMATS_TIER1,
500+
GPUFeatureName::TextureFormatsTier2 => Features::TEXTURE_FORMATS_TIER2,
496501
GPUFeatureName::TextureCompressionAstcHdr => Features::TEXTURE_COMPRESSION_ASTC_HDR,
497502
GPUFeatureName::TextureAdapterSpecificFormatFeatures => Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
498503
GPUFeatureName::PipelineStatisticsQuery => Features::PIPELINE_STATISTICS_QUERY,
@@ -584,6 +589,9 @@ pub fn features_to_feature_names(
584589
if features.contains(wgpu_types::Features::SUBGROUP) {
585590
return_features.insert(Subgroups);
586591
}
592+
if features.contains(wgpu_types::Features::TEXTURE_FORMATS_TIER1) {
593+
return_features.insert(TextureFormatsTier1);
594+
}
587595

588596
// extended from spec
589597

wgpu-core/src/device/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ pub fn features_to_naga_capabilities(
445445
);
446446
caps.set(
447447
Caps::STORAGE_TEXTURE_16BIT_NORM_FORMATS,
448-
features.contains(wgt::Features::TEXTURE_FORMAT_16BIT_NORM),
448+
features.contains(wgt::Features::TEXTURE_FORMATS_TIER1),
449449
);
450450
caps.set(Caps::MULTIVIEW, features.contains(wgt::Features::MULTIVIEW));
451451
caps.set(

wgpu-core/src/instance.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,26 @@ impl Adapter {
884884
return Err(RequestDeviceError::LimitsExceeded(failed));
885885
}
886886

887+
let texture_formats_tier_features = desc.required_features.intersection(
888+
wgt::Features::TEXTURE_FORMATS_TIER1 | wgt::Features::TEXTURE_FORMATS_TIER2,
889+
);
890+
if desc
891+
.required_features
892+
.intersects(texture_formats_tier_features)
893+
{
894+
log::warn!(
895+
concat!(
896+
"{:?} was requested, and is not yet implemented. ",
897+
"Upstream tracking can be found at ",
898+
"<TODO>",
899+
),
900+
texture_formats_tier_features
901+
);
902+
return Err(RequestDeviceError::UnsupportedFeature(
903+
texture_formats_tier_features,
904+
));
905+
}
906+
887907
let open = unsafe {
888908
self.raw.adapter.open(
889909
desc.required_features,

wgpu-hal/src/metal/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl super::PrivateCapabilities {
10001000
| F::IMMEDIATES
10011001
| F::POLYGON_MODE_LINE
10021002
| F::CLEAR_TEXTURE
1003-
| F::TEXTURE_FORMAT_16BIT_NORM
1003+
| F::TEXTURE_FORMATS_TIER1
10041004
| F::SHADER_F16
10051005
| F::DEPTH32FLOAT_STENCIL8
10061006
| F::BGRA8UNORM_STORAGE

wgpu-types/src/features.rs

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ mod webgpu_impl {
8080

8181
#[doc(hidden)]
8282
pub const WEBGPU_FEATURE_IMMEDIATES: u64 = 1 << 16;
83+
84+
#[doc(hidden)]
85+
pub const WEBGPU_FEATURE_TEXTURE_FORMATS_TIER1: u64 = 1 << 15;
86+
87+
#[doc(hidden)]
88+
pub const WEBGPU_FEATURE_TEXTURE_FORMATS_TIER2: u64 = 1 << 16;
8389
}
8490

8591
macro_rules! bitflags_array_impl {
@@ -592,20 +598,11 @@ bitflags_array! {
592598
// ? const 32BIT_FORMAT_MULTISAMPLE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
593599
// ? const 32BIT_FORMAT_RESOLVE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
594600
// ? const TEXTURE_COMPRESSION_ASTC_HDR = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3856)
595-
// TEXTURE_FORMAT_16BIT_NORM & TEXTURE_COMPRESSION_ASTC_HDR will most likely become web features as well
601+
// TEXTURE_COMPRESSION_ASTC_HDR will most likely become web features as well
596602
// TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES might not be necessary if we have all the texture features implemented
597603

598604
// Texture Formats:
599605

600-
/// Enables normalized `16-bit` texture formats.
601-
///
602-
/// Supported platforms:
603-
/// - Vulkan
604-
/// - DX12
605-
/// - Metal
606-
///
607-
/// This is a native only feature.
608-
const TEXTURE_FORMAT_16BIT_NORM = 1 << 1;
609606
/// Enables ASTC HDR family of compressed textures.
610607
///
611608
/// Compressed textures sacrifice some quality in exchange for significantly reduced
@@ -1552,6 +1549,99 @@ bitflags_array! {
15521549
/// This is a web and native feature.
15531550
const DUAL_SOURCE_BLENDING = WEBGPU_FEATURE_DUAL_SOURCE_BLENDING;
15541551

1552+
/// Implies [`Features::RG11B10UFLOAT_RENDERABLE`]. Adds the following texture format
1553+
/// support (TODO: translate to `rustdoc` links):
1554+
///
1555+
/// - TODO: validate: Enables the following formats with `RENDER_ATTACHMENT`, `blendable`,
1556+
/// `multisampling` capabilities and the `STORAGE_BINDING` capability with `read-only`
1557+
/// and `write-only` storage texture accesses:
1558+
///
1559+
/// - [`R16Unorm`]
1560+
/// - [`R16Snorm`]
1561+
/// - [`Rg16Unorm`]
1562+
/// - [`Rg16Snorm`]
1563+
/// - [`Rgba16Unorm`]
1564+
/// - [`Rgba16Snorm`]
1565+
///
1566+
/// - TODO: validate: Allows the `RENDER_ATTACHMENT`, `blendable`, `multisampling` and
1567+
/// `resolve` capabilities on below texture formats:
1568+
///
1569+
/// - [`R8Snorm`]
1570+
/// - [`Rg8Snorm`]
1571+
/// - [`Rgba8Snorm`]
1572+
///
1573+
/// - TODO: validate: Allows the `read-only` and `write-only` storage texture accesses on
1574+
/// below texture formats:
1575+
///
1576+
/// - [`R8Unorm`]
1577+
/// - [`R8Snorm`]
1578+
/// - [`R8Uint`]
1579+
/// - [`R8Sint`]
1580+
/// - [`Rg8Unorm`]
1581+
/// - [`Rg8Snorm`]
1582+
/// - [`Rg8Uint`]
1583+
/// - [`Rg8Sint`]
1584+
/// - [`R16Uint`]
1585+
/// - [`R16Sint`]
1586+
/// - [`R16Float`]
1587+
/// - [`Rg16Uint`]
1588+
/// - [`Rg16Sint`]
1589+
/// - [`Rg16Float`]
1590+
/// - [`Rgb10A2uint`]
1591+
/// - [`Rgb10A2unorm`]
1592+
/// - [`Rg11B10ufloat`]
1593+
///
1594+
/// [`R16Float`]: super::TextureFormat::R16Float
1595+
/// [`R16Sint`]: super::TextureFormat::R16Sint
1596+
/// [`R16Snorm`]: super::TextureFormat::R16Snorm
1597+
/// [`R16Uint`]: super::TextureFormat::R16Uint
1598+
/// [`R16Unorm`]: super::TextureFormat::R16Unorm
1599+
/// [`R8Sint`]: super::TextureFormat::R8Sint
1600+
/// [`R8Snorm`]: super::TextureFormat::R8Snorm
1601+
/// [`R8Uint`]: super::TextureFormat::R8Uint
1602+
/// [`R8Unorm`]: super::TextureFormat::R8Unorm
1603+
/// [`Rg11B10ufloat`]: super::TextureFormat::Rg11B10ufloat
1604+
/// [`Rg16Float`]: super::TextureFormat::Rg16Float
1605+
/// [`Rg16Sint`]: super::TextureFormat::Rg16Sint
1606+
/// [`Rg16Snorm`]: super::TextureFormat::Rg16Snorm
1607+
/// [`Rg16Uint`]: super::TextureFormat::Rg16Uint
1608+
/// [`Rg16Unorm`]: super::TextureFormat::Rg16Unorm
1609+
/// [`Rg8Sint`]: super::TextureFormat::Rg8Sint
1610+
/// [`Rg8Snorm`]: super::TextureFormat::Rg8Snorm
1611+
/// [`Rg8Snorm`]: super::TextureFormat::Rg8Snorm
1612+
/// [`Rg8Uint`]: super::TextureFormat::Rg8Uint
1613+
/// [`Rg8Unorm`]: super::TextureFormat::Rg8Unorm
1614+
/// [`Rgb10A2uint`]: super::TextureFormat::Rgb10A2uint
1615+
/// [`Rgb10A2unorm`]: super::TextureFormat::Rgb10A2unorm
1616+
/// [`Rgba16Snorm`]: super::TextureFormat::Rgba16Snorm
1617+
/// [`Rgba16Unorm`]: super::TextureFormat::Rgba16Unorm
1618+
/// [`Rgba8Snorm`]: super::TextureFormat::Rgba8Snorm
1619+
///
1620+
/// This is a WebGPU equivalent to requesting [`Features::TEXTURE_FORMAT_16BIT_NORM`].
1621+
/// TODO: Just migrate that feature to this one, maybe?
1622+
const TEXTURE_FORMATS_TIER1 = WEBGPU_FEATURE_TEXTURE_FORMATS_TIER1;
1623+
1624+
/// Implies [`Feature::TEXTURE_FORMATS_TIER1`]. Enables
1625+
/// [`TextureFormatFeatureFlags::STORAGE_READ_WRITE`](super::TextureFormatFeatureFlags::STORAGE_READ_WRITE)
1626+
/// for the various formats listed below.
1627+
///
1628+
/// - [`R8Unorm`](super::TextureFormat::R8Unorm)
1629+
/// - [`R8Uint`](super::TextureFormat::R8Uint)
1630+
/// - [`R8Sint`](super::TextureFormat::R8Sint)
1631+
/// - [`Rgba8Unorm`](super::TextureFormat::Rgba8Unorm)
1632+
/// - [`Rgba8Uint`](super::TextureFormat::Rgba8Uint)
1633+
/// - [`Rgba8Sint`](super::TextureFormat::Rgba8Sint)
1634+
/// - [`R16Uint`](super::TextureFormat::R16Uint)
1635+
/// - [`R16Sint`](super::TextureFormat::R16Sint)
1636+
/// - [`R16Float`](super::TextureFormat::R16Float)
1637+
/// - [`Rgba16Uint`](super::TextureFormat::Rgba16Uint)
1638+
/// - [`Rgba16Sint`](super::TextureFormat::Rgba16Sint)
1639+
/// - [`Rgba16Float`](super::TextureFormat::Rgba16Float)
1640+
/// - [`Rgba32Uint`](super::TextureFormat::Rgba32Uint)
1641+
/// - [`Rgba32Sint`](super::TextureFormat::Rgba32Sint)
1642+
/// - [`Rgba32Float`](super::TextureFormat::Rgba32Float)
1643+
const TEXTURE_FORMATS_TIER2 = WEBGPU_FEATURE_TEXTURE_FORMATS_TIER2;
1644+
15551645
/// Allows the use of immediate data: small, fast bits of memory that can be updated
15561646
/// inside a [`RenderPass`].
15571647
///

0 commit comments

Comments
 (0)