Skip to content

Commit

Permalink
Refactor GLES's texture_format_capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Jul 6, 2022
1 parent 499e9e6 commit 259991e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
66 changes: 39 additions & 27 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ impl super::Adapter {
context,
private_caps,
workarounds,
features,
shading_language_version,
max_texture_size,
}),
Expand Down Expand Up @@ -639,34 +640,45 @@ impl crate::Adapter<super::Api> for super::Adapter {
// The storage types are based on table 8.26, in section
// "TEXTURE IMAGE LOADS AND STORES" of OpenGLES-3.2 spec.
let empty = Tfc::empty();
let unfilterable = Tfc::SAMPLED;
let depth = Tfc::SAMPLED | Tfc::MULTISAMPLE | Tfc::DEPTH_STENCIL_ATTACHMENT;
let base = Tfc::COPY_SRC | Tfc::COPY_DST;
let unfilterable = base | Tfc::SAMPLED;
let depth = base | Tfc::SAMPLED | Tfc::MULTISAMPLE | Tfc::DEPTH_STENCIL_ATTACHMENT;
let filterable = unfilterable | Tfc::SAMPLED_LINEAR;
let renderable =
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 storage = base | Tfc::STORAGE | Tfc::STORAGE_READ_WRITE;

let half_float_renderable = if self
.shared
.private_caps
.contains(super::PrivateCapabilities::COLOR_BUFFER_HALF_FLOAT)
{
Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND
} else {
Tfc::empty()
let feature_fn = |f, caps| {
if self.shared.features.contains(f) {
caps
} else {
empty
}
};

let float_renderable = if self
.shared
.private_caps
.contains(super::PrivateCapabilities::COLOR_BUFFER_FLOAT)
{
Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND
} else {
Tfc::empty()
let bcn_features = feature_fn(wgt::Features::TEXTURE_COMPRESSION_BC, filterable);
let etc2_features = feature_fn(wgt::Features::TEXTURE_COMPRESSION_ETC2, filterable);
let astc_features = feature_fn(wgt::Features::TEXTURE_COMPRESSION_ASTC_LDR, filterable);

let private_caps_fn = |f, caps| {
if self.shared.private_caps.contains(f) {
caps
} else {
empty
}
};

let half_float_renderable = private_caps_fn(
super::PrivateCapabilities::COLOR_BUFFER_HALF_FLOAT,
Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND,
);

let float_renderable = private_caps_fn(
super::PrivateCapabilities::COLOR_BUFFER_FLOAT,
Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND,
);

match format {
Tf::R8Unorm => filterable_renderable,
Tf::R8Snorm => filterable,
Expand Down Expand Up @@ -712,8 +724,8 @@ impl crate::Adapter<super::Api> for super::Adapter {
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8
| Tf::Depth24UnormStencil8 => depth,
Tf::Rgb9e5Ufloat
| Tf::Bc1RgbaUnorm
Tf::Rgb9e5Ufloat => filterable,
Tf::Bc1RgbaUnorm
| Tf::Bc1RgbaUnormSrgb
| Tf::Bc2RgbaUnorm
| Tf::Bc2RgbaUnormSrgb
Expand All @@ -726,8 +738,8 @@ impl crate::Adapter<super::Api> for super::Adapter {
| Tf::Bc6hRgbSfloat
| Tf::Bc6hRgbUfloat
| Tf::Bc7RgbaUnorm
| Tf::Bc7RgbaUnormSrgb
| Tf::Etc2Rgb8Unorm
| Tf::Bc7RgbaUnormSrgb => bcn_features,
Tf::Etc2Rgb8Unorm
| Tf::Etc2Rgb8UnormSrgb
| Tf::Etc2Rgb8A1Unorm
| Tf::Etc2Rgb8A1UnormSrgb
Expand All @@ -736,15 +748,15 @@ impl crate::Adapter<super::Api> for super::Adapter {
| Tf::EacR11Unorm
| Tf::EacR11Snorm
| Tf::EacRg11Unorm
| Tf::EacRg11Snorm
| Tf::Astc {
| Tf::EacRg11Snorm => etc2_features,
Tf::Astc {
block: _,
channel: AstcChannel::Unorm | AstcChannel::UnormSrgb,
} => filterable,
} => astc_features,
Tf::Astc {
block: _,
channel: AstcChannel::Hdr,
} => empty,
} => Tfc::empty(),
}
}

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 @@ -185,6 +185,7 @@ struct TextureFormatDesc {
struct AdapterShared {
context: AdapterContext,
private_caps: PrivateCapabilities,
features: wgt::Features,
workarounds: Workarounds,
shading_language_version: naga::back::glsl::Version,
max_texture_size: u32,
Expand Down

0 comments on commit 259991e

Please sign in to comment.