Skip to content

Commit

Permalink
hal/gles: compressed ETC2 texture support
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jun 30, 2021
1 parent a6ed424 commit 037e317
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 128 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ default-members = ["wgpu", "player", "wgpu-hal", "wgpu-info"]
[patch."https://github.com/zakarumych/gpu-alloc"]
#gpu-alloc = { path = "../gpu-alloc/gpu-alloc" }

[patch."https://github.com/grovesNL/glow"]
glow = { git = "https://github.com/kvark/glow", branch = "bind_vb" }

[patch.crates-io]
#web-sys = { path = "../wasm-bindgen/crates/web-sys" }
#js-sys = { path = "../wasm-bindgen/crates/js-sys" }
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl NumericType {
Tf::Bc4RUnorm | Tf::Bc4RSnorm | Tf::EacRUnorm | Tf::EacRSnorm => {
(NumericDimension::Scalar, Sk::Float)
}
Tf::Bc5RgUnorm | Tf::Bc5RgSnorm | Tf::EtcRgUnorm | Tf::EtcRgSnorm => {
Tf::Bc5RgUnorm | Tf::Bc5RgSnorm | Tf::EacRgUnorm | Tf::EacRgSnorm => {
(NumericDimension::Vector(Vs::Bi), Sk::Float)
}
Tf::Bc6hRgbUfloat | Tf::Bc6hRgbSfloat | Tf::Etc2RgbUnorm | Tf::Etc2RgbUnormSrgb => {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
[lib]

[features]
default = []
default = ["gles"]
metal = ["naga/msl-out", "block", "foreign-types"]
vulkan = ["naga/spv-out", "ash", "gpu-alloc", "gpu-descriptor", "libloading", "inplace_it", "renderdoc-sys"]
gles = ["naga/glsl-out", "glow", "egl", "libloading"]
Expand Down
6 changes: 3 additions & 3 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl super::Adapter {
naga::back::glsl::Version::Embedded(value)
};

let mut features = wgt::Features::empty();
let mut features = wgt::Features::empty() | wgt::Features::TEXTURE_COMPRESSION_ETC2;
features.set(
wgt::Features::DEPTH_CLAMPING,
extensions.contains("GL_EXT_depth_clamp"),
Expand Down Expand Up @@ -394,8 +394,8 @@ impl crate::Adapter<super::Api> for super::Adapter {
| Tf::Etc2RgbA1UnormSrgb
| Tf::EacRUnorm
| Tf::EacRSnorm
| Tf::EtcRgUnorm
| Tf::EtcRgSnorm
| Tf::EacRgUnorm
| Tf::EacRgSnorm
| Tf::Astc4x4RgbaUnorm
| Tf::Astc4x4RgbaUnormSrgb
| Tf::Astc5x4RgbaUnorm
Expand Down
24 changes: 2 additions & 22 deletions wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,24 +294,14 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
) where
T: Iterator<Item = crate::BufferTextureCopy>,
{
let format_info = dst.format.describe();
assert_eq!(
format_info.block_dimensions,
(1, 1),
"Compressed texture copies are TODO"
);
let (dst_raw, dst_target) = dst.inner.as_native();
for copy in regions {
self.cmd_buffer.commands.push(C::CopyBufferToTexture {
src: src.raw,
src_target: src.target,
dst: dst_raw,
dst_target,
dst_info: super::TextureCopyInfo {
external_format: dst.format_desc.external,
data_type: dst.format_desc.data_type,
texel_size: format_info.block_size,
},
dst_format: dst.format,
copy,
})
}
Expand All @@ -326,22 +316,12 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
) where
T: Iterator<Item = crate::BufferTextureCopy>,
{
let format_info = src.format.describe();
assert_eq!(
format_info.block_dimensions,
(1, 1),
"Compressed texture copies are TODO"
);
let (src_raw, src_target) = src.inner.as_native();
for copy in regions {
self.cmd_buffer.commands.push(C::CopyTextureToBuffer {
src: src_raw,
src_target,
src_info: super::TextureCopyInfo {
external_format: src.format_desc.external,
data_type: src.format_desc.data_type,
texel_size: format_info.block_size,
},
src_format: src.format,
dst: dst.raw,
dst_target: dst.target,
copy,
Expand Down
28 changes: 18 additions & 10 deletions wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,24 @@ impl super::AdapterShared {
| Tf::Bc6hRgbSfloat
| Tf::Bc6hRgbUfloat
| Tf::Bc7RgbaUnorm
| Tf::Bc7RgbaUnormSrgb
| Tf::Etc2RgbUnorm
| Tf::Etc2RgbUnormSrgb
| Tf::Etc2RgbA1Unorm
| Tf::Etc2RgbA1UnormSrgb
| Tf::EacRUnorm
| Tf::EacRSnorm
| Tf::EtcRgUnorm
| Tf::EtcRgSnorm
| Tf::Astc4x4RgbaUnorm
| Tf::Bc7RgbaUnormSrgb => unimplemented!(),
Tf::Etc2RgbUnorm => (glow::COMPRESSED_RGB8_ETC2, glow::RGB, 0),
Tf::Etc2RgbUnormSrgb => (glow::COMPRESSED_SRGB8_ETC2, glow::RGB, 0),
Tf::Etc2RgbA1Unorm => (
glow::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
glow::RGBA,
0,
),
Tf::Etc2RgbA1UnormSrgb => (
glow::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
glow::RGBA,
0,
),
Tf::EacRUnorm => (glow::COMPRESSED_R11_EAC, glow::RED, 0),
Tf::EacRSnorm => (glow::COMPRESSED_SIGNED_R11_EAC, glow::RED, 0),
Tf::EacRgUnorm => (glow::COMPRESSED_RG11_EAC, glow::RG, 0),
Tf::EacRgSnorm => (glow::COMPRESSED_SIGNED_RG11_EAC, glow::RG, 0),
Tf::Astc4x4RgbaUnorm
| Tf::Astc4x4RgbaUnormSrgb
| Tf::Astc5x4RgbaUnorm
| Tf::Astc5x4RgbaUnormSrgb
Expand Down
11 changes: 2 additions & 9 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,6 @@ impl Fence {
}
}

#[derive(Debug)]
struct TextureCopyInfo {
external_format: u32,
data_type: u32,
texel_size: u8,
}

#[derive(Clone, Debug, PartialEq)]
struct StencilOps {
pass: u32,
Expand Down Expand Up @@ -535,13 +528,13 @@ enum Command {
src_target: BindTarget,
dst: glow::Texture,
dst_target: BindTarget,
dst_info: TextureCopyInfo,
dst_format: wgt::TextureFormat,
copy: crate::BufferTextureCopy,
},
CopyTextureToBuffer {
src: glow::Texture,
src_target: BindTarget,
src_info: TextureCopyInfo,
src_format: wgt::TextureFormat,
dst: glow::Buffer,
dst_target: BindTarget,
copy: crate::BufferTextureCopy,
Expand Down
Loading

0 comments on commit 037e317

Please sign in to comment.