feat(gles): add support for 16-bit normalized texture formats and color attachments (#9601)

Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
AdrianEddyandAndreas Reich authored and GitHub committed 2026-06-07 09:02:33 +00:00
1 parent c3caf2feb4
commit c003fc45e2
6 files changed
+137 -31

No files matched your search

+1
View File
@@ -144,6 +144,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505).
- Added support for GLSL passthrough. By @inner-daemons in [#9064](https://github.com/gfx-rs/wgpu/pull/9064).
- Implement `Adapter::new_external()` for WebGL2 (just like EGL/WGL) to import an external WebGL2 rendering context, and expose the imported context back through `Adapter::adapter_context()` / `Device::context()`. By @pepperoni505 in [#9438](https://github.com/gfx-rs/wgpu/pull/9438).
- Add `gles::Device::buffer_from_raw` for wrapping an externally-owned GL buffer as a `wgpu_hal::gles::Buffer`. By @AdrianEddy in [#9550](https://github.com/gfx-rs/wgpu/pull/9550).
- Advertise `Features::TEXTURE_FORMAT_16BIT_NORM` on OpenGL, including storage-texture usage where the driver supports it. By @AdrianEddy in [#9601](https://github.com/gfx-rs/wgpu/pull/9601).
#### DX12
+37 -25
View File
@@ -418,32 +418,44 @@ impl<W> Writer<'_, W> {
self.features.request(Features::MULTISAMPLED_TEXTURE_ARRAYS);
}
}
ImageClass::Storage { format, .. } => match format {
StorageFormat::R8Unorm
| StorageFormat::R8Snorm
| StorageFormat::R8Uint
| StorageFormat::R8Sint
| StorageFormat::R16Uint
| StorageFormat::R16Sint
| StorageFormat::R16Float
| StorageFormat::Rg8Unorm
| StorageFormat::Rg8Snorm
| StorageFormat::Rg8Uint
| StorageFormat::Rg8Sint
| StorageFormat::Rg16Uint
| StorageFormat::Rg16Sint
| StorageFormat::Rg16Float
| StorageFormat::Rgb10a2Uint
| StorageFormat::Rgb10a2Unorm
| StorageFormat::Rg11b10Ufloat
| StorageFormat::R64Uint
| StorageFormat::Rg32Uint
| StorageFormat::Rg32Sint
| StorageFormat::Rg32Float => {
self.features.request(Features::FULL_IMAGE_FORMATS)
ImageClass::Storage { format, .. } => {
// Storage images require `image_load_store`; the extension write
// (and the `NV_image_formats` write nested under it) is otherwise
// never emitted on targets that need it.
self.features.request(Features::IMAGE_LOAD_STORE);
match format {
StorageFormat::R8Unorm
| StorageFormat::R8Snorm
| StorageFormat::R8Uint
| StorageFormat::R8Sint
| StorageFormat::R16Uint
| StorageFormat::R16Sint
| StorageFormat::R16Float
| StorageFormat::R16Unorm
| StorageFormat::R16Snorm
| StorageFormat::Rg8Unorm
| StorageFormat::Rg8Snorm
| StorageFormat::Rg8Uint
| StorageFormat::Rg8Sint
| StorageFormat::Rg16Uint
| StorageFormat::Rg16Sint
| StorageFormat::Rg16Float
| StorageFormat::Rg16Unorm
| StorageFormat::Rg16Snorm
| StorageFormat::Rgba16Unorm
| StorageFormat::Rgba16Snorm
| StorageFormat::Rgb10a2Uint
| StorageFormat::Rgb10a2Unorm
| StorageFormat::Rg11b10Ufloat
| StorageFormat::R64Uint
| StorageFormat::Rg32Uint
| StorageFormat::Rg32Sint
| StorageFormat::Rg32Float => {
self.features.request(Features::FULL_IMAGE_FORMATS)
}
_ => {}
}
_ => {}
},
}
ImageClass::Sampled { multi: false, .. }
| ImageClass::Depth { multi: false }
| ImageClass::External => {}
+1
View File
@@ -652,4 +652,5 @@ pub fn supported_capabilities() -> valid::Capabilities {
| Caps::DRAW_INDEX
| Caps::MEMORY_DECORATION_COHERENT
| Caps::MEMORY_DECORATION_VOLATILE
| Caps::STORAGE_TEXTURE_16BIT_NORM_FORMATS
}
+82 -6
View File
@@ -445,12 +445,51 @@ impl super::Adapter {
downlevel_flags.set(wgt::DownlevelFlags::NONBLOCKING_QUERY_RESOLVE, true);
}
// Desktop GL: norm16 is core since GL 3.0/3.1; we minimum-version
// to GL 3.3, so always on. GLES/WebGL2: needs `EXT_texture_norm16`.
let supports_16bit_norm = if es_ver.is_some() {
extensions.contains("GL_EXT_texture_norm16")
|| extensions.contains("EXT_texture_norm16")
} else {
true
};
// SNORM color-rendering is not spec-guaranteed on either path
// (GLES Table 8.13 marks it not-renderable; desktop GL exposes
// it as only "optionally renderable"), so gate it on
// `EXT_render_snorm` for both - matching how `COLOR_BUFFER_FLOAT`
// is probed above.
let supports_16bit_snorm_renderable = supports_16bit_norm
&& (extensions.contains("GL_EXT_render_snorm")
|| extensions.contains("EXT_render_snorm"));
// Storage on norm16. ARB_shader_image_load_store / GL 4.2 Table X.2 and
// NV_image_formats Table 8.27 both list `r16/rg16/rgba16` and the SNORM
// variants as image-unit formats, so one gate covers UNORM and SNORM.
// Paths:
// * Desktop: core in GL 4.2+; on 3.3..=4.1 via `GL_ARB_shader_image_load_store`.
// * GLES/WebGL2: only via `GL_NV_image_formats` - the ES 3.1/3.2 core
// Table 8.27 omits these formats, and `GL_EXT_texture_norm16` does not
// extend Table 8.27 (NV_image_formats itself depends on EXT_texture_norm16
// for the norm16 entries, so an ES driver exposing NV_image_formats
// without EXT_texture_norm16 still wouldn't accept them - the
// `supports_16bit_norm` prerequisite below catches that).
let supports_16bit_norm_storage = supports_16bit_norm
&& if es_ver.is_some() {
extensions.contains("GL_NV_image_formats")
} else {
full_ver.is_some_and(|v| v >= (4, 2))
|| extensions.contains("GL_ARB_shader_image_load_store")
};
let mut features = wgt::Features::empty()
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES
| wgt::Features::CLEAR_TEXTURE
| wgt::Features::IMMEDIATES
| wgt::Features::DEPTH32FLOAT_STENCIL8
| wgt::Features::PASSTHROUGH_SHADERS;
features.set(
wgt::Features::TEXTURE_FORMAT_16BIT_NORM,
supports_16bit_norm,
);
features.set(
wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO,
extensions.contains("GL_EXT_texture_border_clamp")
@@ -675,6 +714,18 @@ impl super::Adapter {
super::PrivateCapabilities::MULTISAMPLED_RENDER_TO_TEXTURE,
extensions.contains("GL_EXT_multisampled_render_to_texture"),
);
private_caps.set(
super::PrivateCapabilities::TEXTURE_FORMAT_NORM16,
supports_16bit_norm,
);
private_caps.set(
super::PrivateCapabilities::TEXTURE_FORMAT_SNORM16_RENDERABLE,
supports_16bit_snorm_renderable,
);
private_caps.set(
super::PrivateCapabilities::TEXTURE_FORMAT_NORM16_STORAGE,
supports_16bit_norm_storage,
);
// GLSL ES 3.10+ / GLSL 4.30+ natively support coherent/volatile qualifiers
// on storage buffers. These were introduced alongside storage buffer support.
@@ -1160,6 +1211,31 @@ impl crate::Adapter for super::Adapter {
let image_atomic = feature_fn(wgt::Features::TEXTURE_ATOMIC, Tfc::STORAGE_ATOMIC);
let image_64_atomic = feature_fn(wgt::Features::TEXTURE_INT64_ATOMIC, Tfc::STORAGE_ATOMIC);
// UNORM gets full filterable+renderable; SNORM splits because
// `EXT_texture_norm16` marks only UNORM as color-renderable.
// Storage rides on a separate cap (desktop GL >= 4.2 core / pre-4.2
// `GL_ARB_shader_image_load_store`, GLES `GL_NV_image_formats`).
let norm16_unorm = private_caps_fn(
super::PrivateCapabilities::TEXTURE_FORMAT_NORM16,
filterable_renderable,
);
let norm16_snorm = if self
.shared
.private_caps
.contains(super::PrivateCapabilities::TEXTURE_FORMAT_SNORM16_RENDERABLE)
{
norm16_unorm
} else {
private_caps_fn(
super::PrivateCapabilities::TEXTURE_FORMAT_NORM16,
filterable,
)
};
let norm16_storage = private_caps_fn(
super::PrivateCapabilities::TEXTURE_FORMAT_NORM16_STORAGE,
storage,
);
match format {
Tf::R8Unorm => filterable_renderable,
Tf::R8Snorm => filterable,
@@ -1167,8 +1243,8 @@ impl crate::Adapter for super::Adapter {
Tf::R8Sint => renderable,
Tf::R16Uint => renderable,
Tf::R16Sint => renderable,
Tf::R16Unorm => empty,
Tf::R16Snorm => empty,
Tf::R16Unorm => norm16_unorm | norm16_storage,
Tf::R16Snorm => norm16_snorm | norm16_storage,
Tf::R16Float => filterable | half_float_renderable,
Tf::Rg8Unorm => filterable_renderable,
Tf::Rg8Snorm => filterable,
@@ -1179,8 +1255,8 @@ impl crate::Adapter for super::Adapter {
Tf::R32Float => unfilterable | storage | float_renderable | texture_float_linear,
Tf::Rg16Uint => renderable,
Tf::Rg16Sint => renderable,
Tf::Rg16Unorm => empty,
Tf::Rg16Snorm => empty,
Tf::Rg16Unorm => norm16_unorm | norm16_storage,
Tf::Rg16Snorm => norm16_snorm | norm16_storage,
Tf::Rg16Float => filterable | half_float_renderable,
Tf::Rgba8Unorm => filterable_renderable | storage,
Tf::Rgba8UnormSrgb => filterable_renderable,
@@ -1197,8 +1273,8 @@ impl crate::Adapter for super::Adapter {
Tf::Rg32Float => unfilterable | float_renderable | texture_float_linear,
Tf::Rgba16Uint => renderable | storage,
Tf::Rgba16Sint => renderable | storage,
Tf::Rgba16Unorm => empty,
Tf::Rgba16Snorm => empty,
Tf::Rgba16Unorm => norm16_unorm | norm16_storage,
Tf::Rgba16Snorm => norm16_snorm | norm16_storage,
Tf::Rgba16Float => filterable | storage | half_float_renderable,
Tf::Rgba32Uint => renderable | storage,
Tf::Rgba32Sint => renderable | storage,
+13
View File
@@ -234,6 +234,19 @@ bitflags::bitflags! {
const FULLY_FEATURED_INSTANCING = 1 << 16;
/// Supports direct multisampled rendering to a texture without needing a resolve texture.
const MULTISAMPLED_RENDER_TO_TEXTURE = 1 << 17;
/// Supports norm16 sized internal formats as filterable sampled
/// textures, with UNORM variants also color-renderable. SNORM
/// renderability is gated on `TEXTURE_FORMAT_SNORM16_RENDERABLE`.
const TEXTURE_FORMAT_NORM16 = 1 << 18;
/// Supports SNORM 16-bit formats as color attachments. Requires
/// `GL_EXT_render_snorm` (in addition to `GL_EXT_texture_norm16`
/// on GLES) - desktop GL alone only "optionally" renders SNORM 16.
const TEXTURE_FORMAT_SNORM16_RENDERABLE = 1 << 19;
/// Supports norm16 sized internal formats as image-load/store targets.
/// Desktop GL >= 4.2 (core image-format list) or pre-4.2 with
/// `GL_ARB_shader_image_load_store`; GLES needs `GL_NV_image_formats`
/// (which itself depends on `GL_EXT_texture_norm16`).
const TEXTURE_FORMAT_NORM16_STORAGE = 1 << 20;
}
}
+3
View File
@@ -641,6 +641,9 @@ bitflags_array! {
/// - Vulkan
/// - DX12
/// - Metal
/// - OpenGL (desktop GL 3.3+ for UNORM; GLES / WebGL2 needs
/// `EXT_texture_norm16`. SNORM color-attachment usage
/// additionally requires `EXT_render_snorm` on both paths.)
///
/// This is a native only feature.
#[name("wgpu-texture-format-16-bit-norm", "texture-format-16-bit-norm")]