Skip to content

Data format descriptor#4

Merged
Ralith merged 17 commits intoBVE-Reborn:trunkfrom
superdump:data-format-descriptor
Feb 3, 2022
Merged

Data format descriptor#4
Ralith merged 17 commits intoBVE-Reborn:trunkfrom
superdump:data-format-descriptor

Conversation

@superdump
Copy link
Copy Markdown
Contributor

Checklist

  • cargo clippy reports no issues
  • cargo doc reports no issues
  • cargo deny issues have been fixed or added to deny.toml
  • cargo test shows all tests passing
  • human-readable change descriptions added to the changelog under the "Unreleased" heading.
    • If the change does not affect the user (or is a process change), preface the change with "Internal:"
    • Add credit to yourself for each change: Added new functionality @githubname.

Description

Add support for parsing Data Format Descriptor sections from KTX2 files.

This is functionally the same but perhaps an Unsupported variant should be
added to the enums for the catch all?
@superdump
Copy link
Copy Markdown
Contributor Author

To appease clippy I had to change some 0 | _ => SomeType::Unspecified to just _ => as it rightly points out that the _ matches anything else anyway. I had left it as 0 | _ as some kind of documentation. 0 is explicitly in the spec as an 'unspecified' type, presumably so it can be used for custom data without breaking things for other people as ids get standardised. However, as ids get standardised, they won't be in the enums. It feels wrong that a constructor function would return a Result so perhaps adding an Unsupported to the enums and mapping 0 to Unspecified as per the spec, and anything that the crate doesn't know about to Unsupported. However, it would be a shame to break/block user code just because it is an unknown type by the crate. Maybe instead adding an Unknown(pub u32) or whatever is a better option...? Mmm, I like that last option.

Copy link
Copy Markdown
Contributor

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Out of curiosity, what's your use case for this data?

@superdump
Copy link
Copy Markdown
Contributor Author

Thanks for working on this! Out of curiosity, what's your use case for this data?

tl;dr so I can load supercompressed and compressed textures from KTX2 files.

I pulled in the ktx2 crate to bevy to try to add support for some compressed texture formats (also ddsfile). As I was hooking things up and trying to get something working, I noticed that the sample I had was supercompressed and had no format. I looked at the spec and it seemed like parsing the Data Format Descriptor was necessary to figure out the format of the contained data. Indeed after implementing this I was able to understand that the textures contained in the sample that I had were UASTC format, which I think need additional transcoding to formats that can be directly sampled by a GPU like BC*/ASTC/ETC2.

So, my goal is support for KTX2 as a container primarily for compressed textures, with or without mipmaps, and perhaps also supporting cubemaps, even if long-term bevy has a different and custom asset metadata format to be able to configure whatever the engine needs.

The asset pipeline is the next priority in bevy I think, but it’s good to have good support for glTF 2.0, and KTX2/DDS out of the box.

@Ralith
Copy link
Copy Markdown
Contributor

Ralith commented Jan 23, 2022

I noticed that the sample I had was supercompressed and had no format

Interesting, didn't realize that was at all common. That makes this a pretty key feature!

Note that while 0 means Unspecified, and ironically is defined in the
specification with a particular meaning, because pseudo_enum uses NonZeroU32,
it cannot represent 0. As such, I chose to make the members Option<T> and have
None mean Unspecified.
@superdump superdump force-pushed the data-format-descriptor branch from 0f7a3b4 to 4ff2308 Compare January 25, 2022 18:06
Fallible parsing returning ParseError
Separate out DataFormatDescriptorHeader. Remove size member. Derive Eq +
PartialEq. Add constant for DFD header for Basic variant. Remove
data_format_descriptor_type method.
Copy link
Copy Markdown
Contributor

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Thanks, this is looking good! Just a couple nits left.

Copy link
Copy Markdown
Contributor

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for all your work!

@superdump
Copy link
Copy Markdown
Contributor Author

LGTM, thanks for all your work!

Thanks for all the review! :) It’s for sure a better PR because of it.

@Ralith Ralith merged commit b7ab91d into BVE-Reborn:trunk Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants