Skip to content

Two bugs in the C# layer, both reproducible against the current main (f8b5db5).#102

Open
Moayad-Rahhal wants to merge 1 commit into
atteneder:mainfrom
Moayad-Rahhal:fix/orientation-and-square-astc-formats
Open

Two bugs in the C# layer, both reproducible against the current main (f8b5db5).#102
Moayad-Rahhal wants to merge 1 commit into
atteneder:mainfrom
Moayad-Rahhal:fix/orientation-and-square-astc-formats

Conversation

@Moayad-Rahhal
Copy link
Copy Markdown

Bug 1 — Orientation metadata dropped for direct-format paths
KtxTexture.LoadTexture2D copies m_Ktx.orientation to result.orientation only inside the m_Ktx.needsTranscoding branch. The direct-format else branch never sets it, so KTX2 files that don't need transcoding (any direct GPU format, e.g. ASTC_8x8 with KTXorientation: ru) silently lose their orientation. Consumers calling result.orientation.IsYFlipped() get true for files explicitly authored Y-up.

Fix: copy the orientation in the direct-format branch as well.

Bug 2 — GetGraphicsFormat() only maps ASTC_8x8
The switch in KtxNativeInstance.GetGraphicsFormat maps only Astc8X8SrgbBlock/Astc8X8UNormBlock. The other square ASTC variants (Astc4X4, Astc5X5, Astc6X6, Astc10X10, Astc12X12) are listed in the unsupported fall-through, even though Unity's GraphicsFormat enum has all of them. Loading a KTX2 with any of those formats hits the "untested/unsupported format" error.

Fix: add the missing square ASTC cases (sRGB + UNorm) and remove them from the unsupported fall-through.

Reproduction

ktx create --format ASTC_6x6_SRGB_BLOCK --astc-quality medium
--convert-texcoord-origin bottom-left --assign-tf srgb in.png out.ktx2
ktx info out.ktx2 shows KTXorientation: ru.
Load with KtxTexture.LoadFromBytes(...) against current main → LogError "untested/unsupported format" (Bug 2).
With this PR → file loads, and result.orientation.IsYFlipped() correctly returns false (Bug 1).
Tested on Unity 2022.3 in Editor (macOS) and on Android device. Verified end-to-end against ASTC_6x6 and ASTC_8x8 files. Diff is minimal — no behavioral change for previously-working formats.

- KtxTexture.LoadTexture2D: copy m_Ktx.orientation to result.orientation
  in the direct-format branch (was only set in the transcoding branch),
  fixing IsYFlipped() returning true for files explicitly authored Y-up.
- KtxNativeInstance.GetGraphicsFormat: add cases for ASTC_4x4, 5x5, 6x6,
  10x10, 12x12 (sRGB and UNorm) and remove them from the unsupported
  fall-through. Previously only ASTC_8x8 loaded; other square ASTC files
  hit 'untested/unsupported format'.
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.

1 participant