Add clean-room BCPack decoder (BC1/BC3/BC4/BC5) to TtpfReader #7

Manually merged
github merged 1 commit from gh-pr/7/head into gh-pr/7/base 2026-11-26 19:04:40 +00:00
Owner

@⁠sombraSoft on GitHub · 2026-11-22 02:54 UTC · original
feat/ttpf-bcpack-decoder → main · +1836 −31 · 7 files · 1 commits · merged 2026-11-22 09:48 UTC

Summary

Adds a clean-room C# Xbox Series DirectStorage BCPack decoder for BC1, BC3, BC4, and BC5 (DSTORAGE_BCPACK_MODE codecs 1, 3, 4, 5) and integrates it into TtpfReader while keeping BCPack textures strictly read-only.

  • New Core/BcpackTables.cs & Core/BcpackDecoder.cs:
    • Implements the 12/16-lane 16-bit interleaved rANS entropy decoder (8-byte/cycle prefetch scheduling, 160 banded exponential probability models, virtual-zero flush handling, exact L = 1 << 24 home-state verification) and block rebuilders for BC1, BC3, BC4, and BC5.
    • Derived clean-room from public specifications (US Patent 11,234,023, Khronos Data Format Specification, public microsoft/silicon-rans MDU tables); codec-level constants only, zero game assets.
    • Strict mode (allowProvisional: false) is the default: chunks referencing unconfirmed/provisional built-in history entries throw BcpackProvisionalException (NotSupportedException), corrupt bitstreams throw InvalidDataException, and unsupported codecs (BC2, BC6H, BC7) throw NotSupportedException naming the codec.
  • Core/TtpfReader.cs:
    • Decodes BCPack BC1/BC3/BC4/BC5 chunks in DecodeChunk and includes them in ReadIndex mip availability and LegacyTopOnlyName.
    • Adds binary/source-compatible allowProvisional overloads on CreateDds, DecodeTexturePixels, and DecodeTexturePreview (default overloads remain strict allowProvisional: false).
    • Reports the actual unsupported codec(s) in Limitation (e.g. BC7, BC6H) instead of a generic BCPack message.
    • Enforces SupportsNativeReplacement = false and marks read-only in PreviewNote whenever any used chunk is BCPack-compressed.
  • Core/Rds5TextureWriter.cs:
    • Filters unaffected neighbor verification samples with !n.UsesBcpack so pure-zlib replacements never fail if a small unaffected neighbor uses a provisional BCPack chunk.
  • Core/ArchiveReader.cs, README.md, README.txt:
    • Updates RDS5/TTPF capability text to note BC1/BC3/BC4/BC5 BCPack decode support and BC6H/BC7 remaining unavailable.

Verification

  • Disclosure: AI-assisted implementation and review. Tested locally on Windows with NVIDIA GeForce RTX 3060 Ti (driver 621.24), .NET 10.0.401 SDK (.NET 8 / .NET 10 targets).
  • Release builds (0 warnings, 0 errors):
    • dotnet build Core/RpfPreview.Core.csproj -c Release
    • dotnet build App/RpfPreview.App.csproj -c Release
    • dotnet build Tools/IndexBuilder/IndexBuilder.csproj -c Release
    • Downstream compatibility build against Leonida tools/rpf9dump (TreatWarningsAsErrors=true)
  • Synthetic public-API smoke tests (asset-free, run locally outside repo):
    • 8 passed, 0 failed: all 160 probability tables, 12/16-lane rANS round-trips, multi-fragment flushes, corrupt/truncated/bounds negative controls, BC2/BC6H/BC7 rejection, strict vs provisional BC1/BC3/BC4/BC5 history behavior, end-to-end synthetic RDS5/ETPF634 TtpfReader/DdsTextureReader tests, and Rds5TextureWriter replacement with a provisional BCPack smallest neighbor.
  • Full 57-pool retail corpus (357,115 descriptors, 103,170 BC1/BC3/BC4/BC5 chunks):
    • TtpfReader.Inspect (1.81s):
      • Exported: 356,363 / 357,115 (Full mip chain: 353,845 [99.08%], Partial: 2,518)
      • Skipped: 752 — 100% unsupported BCPack (742 BC7, 10 BC6H; 0 layout or format skips)
      • Multi-slice exported: 127 2D arrays, 567 cubemaps, 3 volumes
      • SupportsNativeReplacement: 78,629 (0 BCPack textures marked replaceable)
    • Full chunk decode sweep (103,170 chunks, 14.37 GiB decoded in 76.07s, 0 structural/other errors):
      • Strict-clean (allowProvisional: false): 101,440 chunks (98.32%) — covering 354,991 / 356,363 exported textures (99.41% of all catalog entries).
      • Strict-provisional: 1,730 chunks (1,296 BC1, 27 BC3, 77 BC4, 330 BC5) across 1,372 textures (1,329 decode with allowProvisional: true; 43 touch unfitted BC4 history and remain refused).
    • Byte-for-byte SHA-256 parity against ItsNotRexed/Leonida tools/bcpack.py on 565 chunks (120 BC1 + all 35 BC3 + all 77 BC4 + all 333 BC5):
      • Strict mode: 565/565 matched, 0 mismatches
      • Provisional mode: 565/565 matched, 0 mismatches (490 byte-exact decoded payloads + 75 identical unfitted BC4 rejections)
**@⁠sombraSoft** on GitHub · 2026-11-22 02:54 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/7) `feat/ttpf-bcpack-decoder` → `main` · +1836 −31 · 7 files · 1 commits · merged 2026-11-22 09:48 UTC ## Summary Adds a clean-room C# Xbox Series DirectStorage BCPack decoder for **BC1, BC3, BC4, and BC5** (`DSTORAGE_BCPACK_MODE` codecs `1, 3, 4, 5`) and integrates it into `TtpfReader` while keeping BCPack textures strictly read-only. - **New `Core/BcpackTables.cs` & `Core/BcpackDecoder.cs`**: - Implements the 12/16-lane 16-bit interleaved rANS entropy decoder (8-byte/cycle prefetch scheduling, 160 banded exponential probability models, virtual-zero flush handling, exact `L = 1 << 24` home-state verification) and block rebuilders for BC1, BC3, BC4, and BC5. - Derived clean-room from public specifications (US Patent 11,234,023, Khronos Data Format Specification, public `microsoft/silicon-rans` MDU tables); codec-level constants only, zero game assets. - Strict mode (`allowProvisional: false`) is the default: chunks referencing unconfirmed/provisional built-in history entries throw `BcpackProvisionalException` (`NotSupportedException`), corrupt bitstreams throw `InvalidDataException`, and unsupported codecs (`BC2`, `BC6H`, `BC7`) throw `NotSupportedException` naming the codec. - **`Core/TtpfReader.cs`**: - Decodes BCPack BC1/BC3/BC4/BC5 chunks in `DecodeChunk` and includes them in `ReadIndex` mip availability and `LegacyTopOnlyName`. - Adds binary/source-compatible `allowProvisional` overloads on `CreateDds`, `DecodeTexturePixels`, and `DecodeTexturePreview` (default overloads remain strict `allowProvisional: false`). - Reports the actual unsupported codec(s) in `Limitation` (e.g. `BC7`, `BC6H`) instead of a generic BCPack message. - Enforces `SupportsNativeReplacement = false` and marks read-only in `PreviewNote` whenever any used chunk is BCPack-compressed. - **`Core/Rds5TextureWriter.cs`**: - Filters unaffected neighbor verification samples with `!n.UsesBcpack` so pure-zlib replacements never fail if a small unaffected neighbor uses a provisional BCPack chunk. - **`Core/ArchiveReader.cs`, `README.md`, `README.txt`**: - Updates RDS5/TTPF capability text to note BC1/BC3/BC4/BC5 BCPack decode support and BC6H/BC7 remaining unavailable. ## Verification - **Disclosure:** AI-assisted implementation and review. Tested locally on Windows with `NVIDIA GeForce RTX 3060 Ti` (driver `621.24`), `.NET 10.0.401` SDK (`.NET 8` / `.NET 10` targets). - **Release builds (0 warnings, 0 errors):** - `dotnet build Core/RpfPreview.Core.csproj -c Release` - `dotnet build App/RpfPreview.App.csproj -c Release` - `dotnet build Tools/IndexBuilder/IndexBuilder.csproj -c Release` - Downstream compatibility build against Leonida `tools/rpf9dump` (`TreatWarningsAsErrors=true`) - **Synthetic public-API smoke tests (asset-free, run locally outside repo):** - `8 passed, 0 failed`: all 160 probability tables, 12/16-lane rANS round-trips, multi-fragment flushes, corrupt/truncated/bounds negative controls, BC2/BC6H/BC7 rejection, strict vs provisional BC1/BC3/BC4/BC5 history behavior, end-to-end synthetic RDS5/ETPF634 `TtpfReader`/`DdsTextureReader` tests, and `Rds5TextureWriter` replacement with a provisional BCPack smallest neighbor. - **Full 57-pool retail corpus (`357,115` descriptors, `103,170` BC1/BC3/BC4/BC5 chunks):** - `TtpfReader.Inspect` (`1.81s`): - Exported: **356,363 / 357,115** (Full mip chain: **353,845** [99.08%], Partial: **2,518**) - Skipped: **752** — 100% unsupported BCPack (`742` BC7, `10` BC6H; `0` layout or format skips) - Multi-slice exported: **127** 2D arrays, **567** cubemaps, **3** volumes - `SupportsNativeReplacement`: **78,629** (`0` BCPack textures marked replaceable) - Full chunk decode sweep (**103,170** chunks, `14.37 GiB` decoded in `76.07s`, **0** structural/other errors): - Strict-clean (`allowProvisional: false`): **101,440** chunks (`98.32%`) — covering **354,991 / 356,363** exported textures (`99.41%` of all catalog entries). - Strict-provisional: **1,730** chunks (`1,296` BC1, `27` BC3, `77` BC4, `330` BC5) across **1,372** textures (`1,329` decode with `allowProvisional: true`; `43` touch unfitted BC4 history and remain refused). - **Byte-for-byte SHA-256 parity** against `ItsNotRexed/Leonida` `tools/bcpack.py` on **565** chunks (`120` BC1 + all `35` BC3 + all `77` BC4 + all `333` BC5): - Strict mode: **565/565 matched, 0 mismatches** - Provisional mode: **565/565 matched, 0 mismatches** (`490` byte-exact decoded payloads + `75` identical unfitted BC4 rejections)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:04:37 +00:00
github manually merged commit f0616e1abd into gh-pr/7/base 2026-11-26 19:04:40 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.