Skip to content

Commit

Permalink
[WebGL] Add a downlevel capability for rendering to floating point te…
Browse files Browse the repository at this point in the history
…xtures (#2729)

* Add a downlevel capability for rendering to floating point textures

* Rename capabilities to _capabilities

* Run cargo fmt

* Pass downlevel_flags to the adapter

* Add wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT to dx11

* Remove downlevel_flags from the adapter and use is_ext_color_buffer_float_supported instead

* Add DownlevelFlags::WEBGPU_TEXTURE_FORMAT_SUPPORT

* Apply suggestions
  • Loading branch information
expenses authored Jun 14, 2022
1 parent 3a193ec commit a880eb9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions wgpu-hal/src/dx11/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl super::Adapter {

if feature_level >= FL11_0 {
downlevel |= wgt::DownlevelFlags::INDIRECT_EXECUTION;
downlevel |= wgt::DownlevelFlags::WEBGPU_TEXTURE_FORMAT_SUPPORT;
features |= wgt::Features::TEXTURE_COMPRESSION_BC;
}

Expand Down
24 changes: 17 additions & 7 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ impl super::Adapter {
extensions.contains("EXT_texture_filter_anisotropic"),
);

let is_ext_color_buffer_float_supported = extensions.contains("EXT_color_buffer_float");

let mut features = wgt::Features::empty()
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES
| wgt::Features::CLEAR_TEXTURE
Expand Down Expand Up @@ -500,6 +502,7 @@ impl super::Adapter {
workarounds,
shading_language_version,
max_texture_size,
is_ext_color_buffer_float_supported,
}),
},
info: Self::make_info(vendor, renderer),
Expand Down Expand Up @@ -619,6 +622,13 @@ 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 self.shared.is_ext_color_buffer_float_supported {
Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND
} else {
Tfc::empty()
};

match format {
Tf::R8Unorm => filterable_renderable,
Tf::R8Snorm => filterable,
Expand All @@ -628,37 +638,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/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ struct AdapterShared {
workarounds: Workarounds,
shading_language_version: naga::back::glsl::Version,
max_texture_size: u32,
is_ext_color_buffer_float_supported: bool,
}

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

/// Supports all the texture usages described in WebGPU. If this isn't supported, you
/// should call `get_texture_format_features` to get how you can use textures of a given format
const WEBGPU_TEXTURE_FORMAT_SUPPORT = 1 << 15;
}
}

Expand Down

0 comments on commit a880eb9

Please sign in to comment.