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

Error on --format R8G8B8A8_SRGB (v4.3.0-alpha3) #751

Closed
donmccurdy opened this issue Aug 21, 2023 · 6 comments
Closed

Error on --format R8G8B8A8_SRGB (v4.3.0-alpha3) #751

donmccurdy opened this issue Aug 21, 2023 · 6 comments

Comments

@donmccurdy
Copy link
Contributor

donmccurdy commented Aug 21, 2023

I'm creating some PNG textures, and want to encode them as RGBA32. Commonly authoring tools will omit the alpha channel in the PNG, but I need that channel to be present in the encoded KTX2 data, so we get RGBA32 and not RGB32. Here's what I tried:

# (A)
ktx create --format R8G8B8A8_SRGB \
  --zstd 18 --assign-oetf srgb --assign-primaries bt709 --generate-mipmap \
  rgb8.png rgba8.ktx2

# (B)
ktx create --format R8G8B8A8_SRGB --input-swizzle rgb1 \
  --zstd 18 --assign-oetf srgb --assign-primaries bt709 --generate-mipmap \
  rgb8.png rgba8.ktx2

For both, I see this error:

ktx create fatal: rgb8.png: Input file channel count 3 is less than the required 4 for VK_FORMAT_R8G8B8A8_SRGB.

My workaround for now is to use imagemagick to put an alpha channel into the source file, but ideally this could be done in the ktx CLI directly. I'm not sure whether the --input-swizzle flag should be required here or not.

Imagemagick:

convert rgb8.png png32:rgba8.png

Source image:

2d_rgb8.png.zip

@donmccurdy donmccurdy changed the title Error on --format R8G8B8A8_SRGB --input-swizzle rgb1 (v4.3.0-alpha3) Error on --format R8G8B8A8_SRGB (v4.3.0-alpha3) Aug 21, 2023
@MarkCallow
Copy link
Collaborator

IINM --input-swizzle rgb1 should add the alpha channel. @aqnuep please confirm.

@aqnuep
Copy link
Collaborator

aqnuep commented Aug 21, 2023

IINM --input-swizzle rgb1 should add the alpha channel. @aqnuep please confirm.

No, that won't work. The current version of the KTX Tools has been designed to require the input content to match the output format in terms of component count and bit-depth (8bpp or 16bpp normalized data can come from PNG, while 16/32-bit float or integer data can come from EXR), thus unfortunately this is not currently supported.

If support for having different component counts in inputs vs outputs is necessary (e.g. for the create and extract command) then that could be added as a feature request, as it would need a somewhat wider set of image transformations. Just adding such swizzling wouldn't be too difficult though.

@lexaknyazev, FYI.

@MarkCallow
Copy link
Collaborator

Given that Metal (and therefore MoltenVK) does not support RGB textures being able to add an opaque alpha channel without needing to use an external tool seems an important feature to me.

@aqnuep
Copy link
Collaborator

aqnuep commented Aug 21, 2023

I don't disagree with that, in fact it's not specific to Metal, many desktop GPUs do not support RGB, only RGBA. I'm just stating that such functionality was not part of the original set of requirements as there was a 1-to-1 mapping from input image formats to output texture formats.

@aqnuep
Copy link
Collaborator

aqnuep commented Aug 21, 2023

In any case, I'll put together a PR for supporting this (with and without an explicit input swizzle parameter).

@aqnuep
Copy link
Collaborator

aqnuep commented Aug 21, 2023

I've created PR #755 to add support for this. Also added about 100 test cases covering the added new functionality (see CTS PR KhronosGroup/KTX-Software-CTS#3).

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

No branches or pull requests

3 participants