Skip to content

Commit 703ee30

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 168aba0 commit 703ee30

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
// extended from spec
403407
#[webidl(rename = "texture-format-16-bit-norm")]
@@ -486,7 +490,8 @@ pub fn feature_names_to_features(
486490
GPUFeatureName::Float32Filterable => Features::FLOAT32_FILTERABLE,
487491
GPUFeatureName::DualSourceBlending => Features::DUAL_SOURCE_BLENDING,
488492
GPUFeatureName::Subgroups => Features::SUBGROUP,
489-
GPUFeatureName::TextureFormat16BitNorm => Features::TEXTURE_FORMAT_16BIT_NORM,
493+
GPUFeatureName::TextureFormatsTier1 => Features::TEXTURE_FORMATS_TIER1,
494+
GPUFeatureName::TextureFormatsTier2 => Features::TEXTURE_FORMATS_TIER2,
490495
GPUFeatureName::TextureCompressionAstcHdr => Features::TEXTURE_COMPRESSION_ASTC_HDR,
491496
GPUFeatureName::TextureAdapterSpecificFormatFeatures => Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
492497
GPUFeatureName::PipelineStatisticsQuery => Features::PIPELINE_STATISTICS_QUERY,
@@ -578,6 +583,9 @@ pub fn features_to_feature_names(
578583
if features.contains(wgpu_types::Features::SUBGROUP) {
579584
return_features.insert(Subgroups);
580585
}
586+
if features.contains(wgpu_types::Features::TEXTURE_FORMATS_TIER1) {
587+
return_features.insert(TextureFormatsTier1);
588+
}
581589

582590
// extended from spec
583591

wgpu-core/src/device/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub fn create_validator(
454454
);
455455
caps.set(
456456
Caps::STORAGE_TEXTURE_16BIT_NORM_FORMATS,
457-
features.contains(wgt::Features::TEXTURE_FORMAT_16BIT_NORM),
457+
features.contains(wgt::Features::TEXTURE_FORMATS_TIER1),
458458
);
459459
caps.set(Caps::MULTIVIEW, features.contains(wgt::Features::MULTIVIEW));
460460
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
@@ -1024,7 +1024,7 @@ impl super::PrivateCapabilities {
10241024
| F::IMMEDIATES
10251025
| F::POLYGON_MODE_LINE
10261026
| F::CLEAR_TEXTURE
1027-
| F::TEXTURE_FORMAT_16BIT_NORM
1027+
| F::TEXTURE_FORMATS_TIER1
10281028
| F::SHADER_F16
10291029
| F::DEPTH32FLOAT_STENCIL8
10301030
| F::BGRA8UNORM_STORAGE

wgpu-types/src/features.rs

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

7878
#[doc(hidden)]
7979
pub const WEBGPU_FEATURE_IMMEDIATES: u64 = 1 << 15;
80+
81+
#[doc(hidden)]
82+
pub const WEBGPU_FEATURE_TEXTURE_FORMATS_TIER1: u64 = 1 << 15;
83+
84+
#[doc(hidden)]
85+
pub const WEBGPU_FEATURE_TEXTURE_FORMATS_TIER2: u64 = 1 << 16;
8086
}
8187

8288
macro_rules! bitflags_array_impl {
@@ -590,20 +596,11 @@ bitflags_array! {
590596
// ? const 32BIT_FORMAT_MULTISAMPLE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
591597
// ? const 32BIT_FORMAT_RESOLVE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
592598
// ? const TEXTURE_COMPRESSION_ASTC_HDR = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3856)
593-
// TEXTURE_FORMAT_16BIT_NORM & TEXTURE_COMPRESSION_ASTC_HDR will most likely become web features as well
599+
// TEXTURE_COMPRESSION_ASTC_HDR will most likely become web features as well
594600
// TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES might not be necessary if we have all the texture features implemented
595601

596602
// Texture Formats:
597603

598-
/// Enables normalized `16-bit` texture formats.
599-
///
600-
/// Supported platforms:
601-
/// - Vulkan
602-
/// - DX12
603-
/// - Metal
604-
///
605-
/// This is a native only feature.
606-
const TEXTURE_FORMAT_16BIT_NORM = 1 << 1;
607604
/// Enables ASTC HDR family of compressed textures.
608605
///
609606
/// Compressed textures sacrifice some quality in exchange for significantly reduced
@@ -1544,6 +1541,99 @@ bitflags_array! {
15441541
/// This is a web and native feature.
15451542
const DUAL_SOURCE_BLENDING = WEBGPU_FEATURE_DUAL_SOURCE_BLENDING;
15461543

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

0 commit comments

Comments
 (0)