Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebGL] Add a downlevel capability for rendering to floating point textures #2729

Merged
6 changes: 5 additions & 1 deletion wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ impl<A: HalApi> Adapter<A> {
) -> wgt::TextureFormatFeatures {
use hal::TextureFormatCapabilities as Tfc;

let caps = unsafe { self.raw.adapter.texture_format_capabilities(format) };
let caps = unsafe {
self.raw
.adapter
.texture_format_capabilities(format, &self.raw.capabilities)
};
let mut allowed_usages = format.describe().guaranteed_format_features.allowed_usages;

allowed_usages.set(
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx11/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
capabilities: &crate::Capabilities,
expenses marked this conversation as resolved.
Show resolved Hide resolved
) -> crate::TextureFormatCapabilities {
todo!()
}
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
_capabilities: &crate::Capabilities,
) -> crate::TextureFormatCapabilities {
use crate::TextureFormatCapabilities as Tfc;

Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl crate::Adapter<Api> for Context {
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
capabilities: &crate::Capabilities,
) -> crate::TextureFormatCapabilities {
crate::TextureFormatCapabilities::empty()
}
Expand Down
30 changes: 23 additions & 7 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ impl super::Adapter {
wgt::DownlevelFlags::ANISOTROPIC_FILTERING,
extensions.contains("EXT_texture_filter_anisotropic"),
);
downlevel_flags.set(
wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT,
extensions.contains("EXT_color_buffer_float"),
);

let mut features = wgt::Features::empty()
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES
Expand Down Expand Up @@ -603,6 +607,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
capabilities: &crate::Capabilities,
) -> crate::TextureFormatCapabilities {
use crate::TextureFormatCapabilities as Tfc;
use wgt::TextureFormat as Tf;
Expand All @@ -619,6 +624,17 @@ impl crate::Adapter<super::Api> for super::Adapter {
unfilterable | Tfc::COLOR_ATTACHMENT | Tfc::MULTISAMPLE | Tfc::MULTISAMPLE_RESOLVE;
let filterable_renderable = filterable | renderable | Tfc::COLOR_ATTACHMENT_BLEND;
let storage = Tfc::STORAGE | Tfc::STORAGE_READ_WRITE;

let float_renderable = if capabilities
.downlevel
.flags
.contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT)
{
Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND
} else {
Tfc::empty()
};

match format {
Tf::R8Unorm => filterable_renderable,
Tf::R8Snorm => filterable,
Expand All @@ -628,37 +644,37 @@ impl crate::Adapter<super::Api> for super::Adapter {
Tf::R16Sint => renderable,
Tf::R16Unorm => empty,
Tf::R16Snorm => empty,
Tf::R16Float => filterable,
Tf::R16Float => filterable | float_renderable,
Tf::Rg8Unorm => filterable_renderable,
Tf::Rg8Snorm => filterable,
Tf::Rg8Uint => renderable,
Tf::Rg8Sint => renderable,
Tf::R32Uint => renderable | storage,
Tf::R32Sint => renderable | storage,
Tf::R32Float => unfilterable | storage,
Tf::R32Float => unfilterable | storage | float_renderable,
Tf::Rg16Uint => renderable,
Tf::Rg16Sint => renderable,
Tf::Rg16Unorm => empty,
Tf::Rg16Snorm => empty,
Tf::Rg16Float => filterable,
Tf::Rg16Float => filterable | float_renderable,
Tf::Rgba8Unorm | Tf::Rgba8UnormSrgb => filterable_renderable | storage,
Tf::Bgra8Unorm | Tf::Bgra8UnormSrgb => filterable_renderable,
Tf::Rgba8Snorm => filterable,
Tf::Rgba8Uint => renderable | storage,
Tf::Rgba8Sint => renderable | storage,
Tf::Rgb10a2Unorm => filterable_renderable,
Tf::Rg11b10Float => filterable,
Tf::Rg11b10Float => filterable | float_renderable,
Tf::Rg32Uint => renderable,
Tf::Rg32Sint => renderable,
Tf::Rg32Float => unfilterable,
Tf::Rg32Float => unfilterable | float_renderable,
Tf::Rgba16Uint => renderable | storage,
Tf::Rgba16Sint => renderable | storage,
Tf::Rgba16Unorm => empty,
Tf::Rgba16Snorm => empty,
Tf::Rgba16Float => filterable | storage,
Tf::Rgba16Float => filterable | storage | float_renderable,
Tf::Rgba32Uint => renderable | storage,
Tf::Rgba32Sint => renderable | storage,
Tf::Rgba32Float => unfilterable | storage,
Tf::Rgba32Float => unfilterable | storage | float_renderable,
Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub trait Adapter<A: Api>: Send + Sync {
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
capabilities: &Capabilities,
) -> TextureFormatCapabilities;

/// Returns the capabilities of working with a specified surface.
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
_capabilities: &crate::Capabilities,
) -> crate::TextureFormatCapabilities {
use crate::TextureFormatCapabilities as Tfc;
use wgt::TextureFormat as Tf;
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
_capabilities: &crate::Capabilities,
) -> crate::TextureFormatCapabilities {
use crate::TextureFormatCapabilities as Tfc;

Expand Down
3 changes: 3 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ bitflags::bitflags! {
///
/// GLES/WebGL don't support this.
const DEPTH_TEXTURE_AND_BUFFER_COPIES = 1 << 13;

/// Supports rendering to floating-point textures.
const COLOR_ATTACHMENT_FLOAT = 1 << 14;
expenses marked this conversation as resolved.
Show resolved Hide resolved
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down