Skip to content

Incorrect bit packing in GPU-encoded BC7 #67

Description

@elasota

https://github.com/Microsoft/DirectXTex/blob/master/DirectXTex/Shaders/BC7Encode.hlsl

In block_package1, when fixup index is 6:

block.w = (get_color_index(15) << 29) | (get_color_index(14) << 26) | (get_color_index(13) << 23) |
(get_color_index(12) << 20) | (get_color_index(11) << 17) | (get_color_index(10) << 14) |
(get_color_index(9) << 11) | (get_color_index(8) << 8) |
(get_color_index(7) << 6) | (get_color_index(6) << 4) | get_color_index(5);

Indexes 6 and 7 are shifted 1 bit higher than they should be. 6 and 7 should be 2 bits apart, and all others 3 bits apart, but index 5 is given 4 bits and index 7 is given 2.

Activity

  1. walbourn commented on Jan 2, 2018

    @walbourn
    Collaborator

    Thanks for the report. I'll take a look now that I'm back in the office.

  2. walbourn commented on Jan 9, 2018

    @walbourn
    Collaborator

    Does this look like the correct fix to you?

    block.w = (get_color_index(15) << 29) | (get_color_index(14) << 26) |  ( get_color_index(13) << 23) |
    (get_color_index(12) << 20) | (get_color_index(11) << 17) | (get_color_index(10) << 14) |
    (get_color_index(9) << 11) | (get_color_index(8) << 8) | 
    (get_color_index(7) << 5) | (get_color_index(6) << 3) | | get_color_index(5);
    
  3. elasota commented on Jan 10, 2018

    @elasota
    ContributorAuthor

    Yeah that looks right.

  4. walbourn commented on Jan 10, 2018

    @walbourn
    Collaborator

    Do you have a test image that uses this particular codepath you can share?

  5. elasota commented on Jan 11, 2018

    @elasota
    ContributorAuthor

    defect

    ^ Encode this image with texconv -f BC7_UNORM -m 1 -y defect.png

    The first byte of the output block (offset 148 in the DDS) is 0xbe, a.k.a. mode 1 partition 47.

    The middle 2 pixels in the second row should be the same in the encoded result because they're in the same subset and have the same input value, but they wind up being different because the bits are in the wrong place.

  6. walbourn commented on Jan 17, 2018

    @walbourn
    Collaborator

    Awesome. Thanks for the specific repro...

  7. walbourn commented on Jan 17, 2018

    @walbourn
    Collaborator

    Fixed in this commit

  8. walbourn commented on Feb 9, 2018

    @walbourn
    Collaborator

    Fixed in the February 2018 release

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions