Avoid writing out of range data over valid data in CVTT decompress methods when decompressing small mip levels #90912
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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

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:
After:
