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

Avoid writing out of range data over valid data in CVTT decompress methods when decompressing small mip levels #90912

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

clayjohn
Copy link
Member

I noticed this while debugging #90873

Bug

When decompressing a BPTC texture, the last column of pixel for all mipmaps from levels 16x16 and lower would be black
image

This results in the last miplevel being totally black since it only has one column.

I can reproduce this bug in 4.3, 4.2, and 4.1. I haven't tested earlier versions.

Problem

The problem comes from how we decompress the image. A block in BPTC is a 4x4 group of pixels. We decompress 8 blocks at a time (this isn't necessary, but it seems like it was done to allow us to trivially parallelize decompression). Which means that we decompress a 32x4 group of pixels at once.

Once you have a mip level with a width smaller than 32 we decrease the number of blocks that we copy over into the input buffer. However, we still process the invalid blocks (they are zeroed out) and we still attempt to copy them over to the final image. Only the last column is affected because the logic for writing pixels greater than width is to write them out at width - 1.

Solution

When calculating the end of the region to write pixels, we take into account the number of blocks that we are processing and we don't read back pixels from blocks that are totally zeroed out. This way we only copy back data from valid blocks

Before:

Screenshot from 2024-04-19 10-22-52

After:
image

@clayjohn clayjohn added bug topic:core topic:rendering cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Apr 19, 2024
@clayjohn clayjohn added this to the 4.3 milestone Apr 19, 2024
@clayjohn clayjohn requested a review from a team as a code owner April 19, 2024 17:31
@fire fire requested a review from lyuma April 19, 2024 19:21
@akien-mga
Copy link
Member

CC @BlueCube3310

Copy link
Contributor

@BlueCube3310 BlueCube3310 left a comment

Choose a reason for hiding this comment

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

LGTM

@akien-mga akien-mga merged commit 8931a3e into godotengine:master Apr 22, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@clayjohn clayjohn deleted the CVTT-decomp branch September 22, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release topic:core topic:rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants