TtpfReader: BC6H/BC7 BCPack block rebuilders and strict-mode lower-mip fallback (ASSET-315) #23
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/breadbbbb--rpf9-explorer!23
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/23/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tedin7 on GitHub · 2026-11-22 23:16 UTC · original
tedin7:asset-315→main· +1365 −22 · 13 files · 1 commits · closed without mergingClaimed in the Leonida coordination issue as: ASSET-315 (https://github.com/ItsNotRexed/Leonida/issues/3918#issuecomment-7087083876)
What and why
TtpfReadercould not decode BCPack codec 6 (BC6H) and codec 7 (BC7) chunks, which Leonida's pure-Pythontools/bcpack.pyalready reads. This ports the two block rebuilders and keeps the lower-mip fallback (Leonidadocs/textures.md, "Next step" 1).Core/BcpackBc6h.cs,Core/BcpackBc7.cs: ports of_bc6h_blocksand_bc7_check/_bc7_rebuild/_bc7_blocks(strict and provisional behaviour, same limits, same provisional labels).Core/BcpackBptcTables.csholds the public D3D11/Khronos partition and anchor tables and the BC7 lane-15 signature permutation (same values astools/bcpack_tables_bptc.py).history=Nonecase of the Python tool). A block whose delta reaches before the start of the chunk reads that history: strict mode refuses the chunk (BcpackProvisionalException), provisional mode decodes it against an all-zero history while at mostmax(2, blocks / 1024)blocks depend on it. Chunks whose delta chains stay inside the chunk decode exactly. Per the Leonida notes, real chunks almost all read built-in history, so on real pools strict mode will mostly still refuse BC6H/BC7 until external history tables are wired in (the separate "Next step" 2). I could not check that here: there is no game data.BcpackDecoder: codecs 6 and 7 are enabled; the class ispartialandDecodeZigZag/LooseUnknownBlockLimitareinternalso the rebuilders can share them.TtpfReader: because BC6H/BC7 chunks now count as decodable at index time, a mip whose chunk strict mode refuses is handled when the texture is read:CreateDdsdrops that mip and every larger mip and exports from the next smaller one (the DDS header and size follow), andDecodeTexturePreview/DecodeTexturePixelsuse the next smaller mip. This also covers BC1/BC3/BC4/BC5 chunks that need unconfirmed history, which used to fail the whole export. Provisional mode does not fall back. If every mip is refused,CreateDdsthrows theBcpackProvisionalException.Behaviour changes to be aware of: BC6H/BC7 textures are now listed as exportable with their full mip count instead of "lower-mip-only", and when the fallback applies the DDS is shorter than the
DdsSizelisted in the catalog (ArchiveReadershows the listed size but does not check the length). Making the listing exact would need a decode pass at index time, which I did not want to add toInspect.Not in this PR: the
Patterns[2]fix (Core/TtpfReader.cs:70) and the external--historytables.Tested
Environment: Linux, .NET SDK 8.0 (
/root/.dotnet), no Windows, no GPU, no game data.dotnet build Core/RpfPreview.Core.csproj -c Release -m:2: 0 warnings, 0 errors (TreatWarningsAsErrorsis on).dotnet run -c Release --project Tools/BcpackBptcCheck: 776 checks, 0 failed.fixtures.jsonholds 204 synthetic BCPack BC6H/BC7 chunks built from random lane symbols with the encoder in Leonida'stests/test_bcpack.py(all 14 BC6H modes, all 285 BC7 signatures, in-chunk delta chains up to 300 blocks, history reads, inferred signatures, anchor and p-bit failures). For each chunk and each of strict/provisional mode, the output oftools/bcpack.py(bytes, provisional labels, or failure kind) was recorded and the C# result must match exactly.make_fixtures.py --leonida <checkout>regenerates the file (fixed seed, about 5 minutes).SyntheticPool.cs: one 64x64 BC7 texture, 4 mips, one raw chunk with the small mips and one BCPack chunk with mip 0) checks the fallback end to end: a clean chunk exports 4 mips with the reference blocks; a chunk that reads built-in history exports 3 mips in strict mode (same small mips as the clean export), 4 mips withallowProvisional, and the preview picks the 32x32 mip.Appproject (Windows only, not built), andTools/IndexBuilder(unchanged API, not run).Checklist
Tools/BcpackBptcCheck(theTests/folder is git-ignored in this repo).Prepared with the help of an AI coding agent; reviewed and tested as above.
@ -120,0 +123,4 @@try { return WriteDds(input, source, native, first, end, cache, cancellationToken, allowProvisional, ref reading); }// Strict mode refuses a BCPack chunk that needs unconfirmed or unknown built-in history. The mip it// belongs to and every larger mip are dropped and the export starts at the next smaller mip.catch (BcpackProvisionalException) when (!allowProvisional && reading + 1 < end) { first = reading + 1; }@breadbbbb on GitHub · 2026-11-23 01:14 UTC · original
[P1] Preserve a readable top mip when smaller mips are refused
The fallback only moves first toward smaller mip levels. A pool with a valid raw 64x64 top mip and an unknown-history BC7 chunk for mips 1 through 3 previously exported a 64x64 one-mip DDS (4,244 bytes). With this PR, Inspect selects all four mips; CreateDds then fails on mip 1, retries mips 2 and 3, and finally throws BcpackProvisionalException, even though mip 0 is still readable. This is a regression from the current top-only export. Select a valid contiguous mip window, including a top-only window when lower levels cannot be decoded, instead of always discarding every larger mip after a refusal.
@ -120,0 +130,4 @@private static byte[] WriteDds(FileStream input, Index source, Native native, int first, int end, Dictionary<int, byte[]> cache,CancellationToken cancellationToken, bool allowProvisional, ref int reading){var t = native.Info with { BaseMipLevel = first, Mips = end - first }; var layout = native.Layout!;@breadbbbb on GitHub · 2026-11-23 01:14 UTC · original
[P2] Expose the effective mip window to export callers
Changing BaseMipLevel/Mips only on this local copy leaves the catalog and every consumer with the original shape. The supplied history-refusal fixture lists 64x64, four mips, base level 0 and 5,588 DDS bytes, but CreateDds returns 32x32, three mips and 1,492 bytes. Running Leonida rpf9dump against this PR reproduces a manifest with Mips=4 and BaseMipLevel=0 alongside that three-mip DDS; the app also labels the original export dimensions and mip count. Return the resolved export metadata and update consumers, or keep fallback an explicit operation whose changed dimensions are reported, rather than silently changing the existing byte-only export contract.
@breadbbbb on GitHub · 2026-11-23 01:14 UTC · original · requested changes
Checked
87acdd5. The 776 supplied checks, 816 additional bounded-input checks, and App/IndexBuilder builds pass, but two export regressions need fixing before merge. A valid top-only export can now be lost when the smaller mips require unknown history, and a successful fallback can leave the catalog and Leonida manifest describing a different mip window from the returned DDS. Both are reproduced; see the inline comments. Native BC6H/BC7 pool parity was not verified because the original game archives are unavailable.The description explicitly identifies these rebuilders as ports of Leonida functions. Please also document source attribution and the applicable licensing/permission for those ports when revising this; Leonida publishes a GPLv3 license:
github.com/ItsNotRexed/Leonida@aa2988cc55/LICENSE. This provenance question is separate from the reproduced technical regressions.@tedin7 on GitHub · 2026-11-23 01:26 UTC · original
Thanks for the careful review and the reproductions. Both regressions are real; I will fix them (keep a readable top-only window when lower mips are refused, and return the effective mip window so the catalog, the app and Leonida's manifest describe the DDS that was actually written) once the provenance question below is settled, since it decides whether these files can go in at all.
On provenance, plainly:
Core/BcpackBc6h.csandCore/BcpackBc7.csare my C# ports of functions in Leonida'stools/bcpack.py(_bc6h_blocks,_bc7_check,_bc7_rebuild,_bc7_blocks), which other Leonida contributors wrote and which are published under GPL-3.0. A port is a derivative work, so these files have to stay under GPL-3.0 with attribution to Leonida; I cannot offer them under other terms.Core/BcpackBptcTables.csholds the public D3D11/Khronos BPTC partition and anchor tables plus the BC7 lane-15 permutation taken from Leonida'stools/bcpack_tables_bptc.py, so I would treat it the same way.rpf9-explorer has no license file today, so the question is yours: are you willing to take these files under GPL-3.0 (a header with the Leonida source, commit and license in each file, and a note in the README; it would also make the app as distributed GPL-3.0)? If yes, I will add that together with the two fixes. If not, I will close this PR, and the Leonida side (#4074) will be withdrawn too. Either answer is fine.
@breadbbbb on GitHub · 2026-11-23 02:51 UTC · original
Thanks for clarifying the provenance and confirming both export regressions.
The decision is to decline these GPL-3.0 ports and keep rpf9-explorer's current licensing position unchanged. We are not adopting GPL-3.0 for the application through this PR. Closing this proposal without merging, as you offered.
A future proposal would need compatible distribution terms and fixes for the two reproduced export regressions. Thank you for the contribution and the clear explanation.
Pull request closed