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

Add support for decompressing ETC2 #100365

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

BlueCube3310
Copy link
Contributor

@BlueCube3310 BlueCube3310 commented Dec 13, 2024

Fixes #25595

TODO:

  • Add editor-only build macros,
  • Add boundary checks for the decompressed buffer,
  • Verify the decompressed data

@fire
Copy link
Member

fire commented Dec 14, 2024

I don't have a setup for etc2 verification right now. I recall these types of PRs require device access.

@BlueCube3310
Copy link
Contributor Author

BlueCube3310 commented Dec 14, 2024

It's possible to test this by enabling 'import as etc2/astc' in the project settings and copying the *.etc2.ctex file from the project's imported directory into the main one

@BlueCube3310 BlueCube3310 marked this pull request as ready for review December 14, 2024 22:04
@BlueCube3310 BlueCube3310 requested review from a team as code owners December 14, 2024 22:04
@BlueCube3310
Copy link
Contributor Author

I've added boundary checks (in a similar way to bcdec), it should function correctly now

@BlueCube3310
Copy link
Contributor Author

BlueCube3310 commented Dec 17, 2024

Here are some etc2 textures for testing purposes:
tex.zip

On hardware that supports etc2, they will be passed directly to the gpu, while on ones that don't they will be decompressed

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally using the textures from tex.zip, it works as expected.

Testing project: test_etc2_load.zip

What's interesting is that the texture type appears to be ETC2, with the memory usage displayed as if the texture was uncompressed RGBA8 (even if the source ETC2 texture is RGB8 without alpha). This is on a NVIDIA GPU where ETC2 textures aren't natively supported:

image

Does this mean the texture is uncompressed to RGBA8 instead of RGB8 even if it has no alpha channel?

Uncompressed RGB8 Uncompressed RGBA8
image image

@BlueCube3310
Copy link
Contributor Author

Does this mean the texture is uncompressed to RGBA8 instead of RGB8 even if it has no alpha channel?

Yes, etcpak (and many more block decompression tools) work this way to simplify the alignment to 4 bytes, though when using Vulkan most devices don't support directly sampling from RGB8 textures anyway, so they still need to be converted to RGBA8

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, assuming the size impact is reasonable.

@@ -1,5 +1,5 @@
def can_build(env, platform):
return env.editor_build
return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should measure the size impact on a template_release build to make sure that the increase in binary size is worth the added feature.

@akien-mga
Copy link
Member

I made some template_release builds with the official build scripts to evaluate the size impact.

-rw-r--r--. 1 akien akien 9450452 Jan 13 21:32 out-master/web/templates/godot.web.template_release.wasm32.zip
-rw-r--r--. 1 akien akien 9453583 Jan 13 21:01 out-pr-100365/web/templates/godot.web.template_release.wasm32.zip

-rwxr-xr-x. 1 akien akien 69352248 Jan 13 21:32 out-master/linux/x86_64/templates/godot.linuxbsd.template_release.x86_64
-rwxr-xr-x. 1 akien akien 69376824 Jan 13 21:01 out-pr-100365/linux/x86_64/templates/godot.linuxbsd.template_release.x86_64

-rwxr-xr-x. 1 akien akien 86819328 Jan 13 21:32 out-master/windows/x86_64/templates/godot.windows.template_release.x86_64.exe
-rwxr-xr-x. 1 akien akien 86844416 Jan 13 21:01 out-pr-100365/windows/x86_64/templates/godot.windows.template_release.x86_64.exe

The size impact seems really minimal:

  • +3 kB for the Web template zip (+0.033%)
  • +24.5 kB for the Linux template (+0.035%)
  • +25 kB for the Windows template (+0.029%)

That seems somewhat surprising, but I suppose we only use very little code in the template so the rest gets optimized out by the linker.

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Jan 13, 2025
@akien-mga akien-mga changed the title Add support for decompressing etc2 Add support for decompressing ETC2 Jan 13, 2025
@akien-mga akien-mga merged commit bee5de6 into godotengine:master Jan 13, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ETC2 decompression for Image::decompress()
5 participants