Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion HANDOFF.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ The EXE (+ EOSSDK) imports 31 functions from console libraries: MFPlat `MFResetD
name @0x40), RetrieveErrorRecord 0x290, Query 0x1C. A worker thread per queue runs the submitted requests in order:
file reads through the VFS (as the title's own CreateFileW), memory copies, zlib (miniz_oxide); a status entry gets
the first failure since the previous one, a signal sets the D3D12 fence from the CPU; a half-full queue submits by
itself. BCPack (and other console formats) are refused; the unlisted interface slots are logged E_NOTIMPL. The test
itself. BCPack BC1/BC3/BC4/BC5/BC6H/BC7 are unpacked by `hle/bcpack` (parity test with `XCL_SAMPLE_BCPACK`);
BC2 and the swizzle are refused; the unlisted interface slots are logged E_NOTIMPL. The test
title reads the start of its own exe through it and waits on the fence. Not yet: cancelling submitted requests,
multi-stage (intermediate-size) decompression, destinations that are not plain memory.
- **Texture layout library (`xg_xs.dll`, `hle/xg.rs`)** – Fortnite imports `XGCreateTextureComputer`. XCL's own GFX10
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ the adapter (no GPU / DXC / wave64 / mesh shaders) passes too, but prints `SKIPP
those skips fail. Tests on real game data are opt-in through
environment variables pointing at your own files – `XCL_SAMPLE_RPF` (shader pack),
`XCL_SAMPLE_DLLS` (the game's console DLLs), `XCL_SAMPLE_TTPF` (texture archive),
`XCL_SAMPLE_BK2` (a movie), `XCL_SAMPLE_BVH4`, `XCL_SAMPLE_AWC` (a sound) – described in `HANDOFF.md`; without them those
`XCL_SAMPLE_BCPACK` (BCPack chunks with their blocks), `XCL_SAMPLE_BK2` (a movie), `XCL_SAMPLE_BVH4`, `XCL_SAMPLE_AWC` (a sound) – described in `HANDOFF.md`; without them those
tests pass without running anything (`scripts/test.ps1` lists the ones not set). No game data is
part of the repository.

Expand Down
1 change: 1 addition & 0 deletions THIRD_PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ carry a note in their header about its origin and the date of changes (GPL-2.0
| [FFmpeg](https://ffmpeg.org/) | LGPL-2.1+ | XMA1/XMA2 decoder and tables (`crates/xcl/src/hle/xma2/`) – after `libavcodec/wmaprodec.c`, `wmaprodata.h`, `wma.c`, `sinewin_tablegen.h`, `libavutil/float_dsp.c`, `tx_template.c` | port to safe Rust with annotation |
| [AMD Machine-Readable GPU ISA](https://gpuopen.com/machine-readable-isa/) | MIT | `crates/xcl/src/gpu/rdna2_spec.rs` (generated by `scripts/gen_rdna2.py`) | encoding and instruction tables |
| [AMD addrlib](https://gitlab.freedesktop.org/mesa/mesa/-/tree/main/src/amd/addrlib) (Mesa) | MIT | `crates/xcl/src/gpu/tiling_tables.rs` (generated by `scripts/gen_tiling.py` from `gfx10SwizzlePattern.h`); GFX10 mip chain / mip tail layout in `gpu/tiling.rs` (after `Gfx10Lib::ComputeSurfaceInfoMacroTiled`) | swizzle tables; layout logic ported with annotation |
| [VIctory](https://github.com/Marvisak/VIctory) | GPL-3.0 | `crates/xcl/src/hle/bcpack/`: port of its `victory-formats/src/bcpack.rs`, and `tables.rs` generated by `scripts/gen_bcpack_victory_tables.py` from its `bcpack-tables.bin` (the format's constant tables) | port to Rust; tables |
| [LLVM](https://github.com/llvm/llvm-project) | Apache-2.0 WITH LLVM-exception | `tests/data/llvm-amdgpu/*` (test data, not part of the program); GFX10 buffer format values (`UfmtSymbolicGFX10`) in `gpu/recomp/emit.rs` | test vectors; hardware facts |
| [WinDurango](https://github.com/WinDurango/WinDurango) | LGPL-3.0 | no code; d3d12_x.dll export numbers (facts) in `crates/xcl/data/stubdb.toml` | reference only |
| [libHttpClient](https://github.com/microsoft/libHttpClient) | MIT | no code; XTaskQueue/XAsync contract | specification |
Expand Down
70 changes: 70 additions & 0 deletions crates/xcl/src/hle/bcpack/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//! BCPack: the DirectStorage stage between zlib and swizzle that unpacks console BCn blocks.
//! A stream has no header; 12 or 16 rANS lanes share one byte stream and rebuild into blocks.
//! Decodes BC1, BC3, BC4, BC5, BC6H and BC7 from the format's constant tables (`tables.rs`);
//! BC2 has no lane layout.
//! Port of VIctory's `victory-formats/src/bcpack.rs`; tables generated from its
//! `bcpack-tables.bin` by `scripts/gen_bcpack_victory_tables.py`.

mod tables;
mod victory;

/// Why a stream does not unpack.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
/// no decoder for this mode
Unsupported,
/// the output is not a whole number of blocks
OutputSize,
/// the stream is truncated, malformed, or ends in a bad lane state
Decode(&'static str),
}

impl Error {
/// The kind of failure, without its numbers.
pub fn kind(&self) -> &'static str {
match self {
Error::Unsupported => "unsupported",
Error::OutputSize => "output size",
Error::Decode(_) => "decode",
}
}
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Error::Unsupported => write!(f, "no decoder for this mode"),
Error::OutputSize => write!(f, "the output size is not a whole number of blocks"),
Error::Decode(why) => write!(f, "{why}"),
}
}
}

/// The bytes of one block of `mode`.
pub fn block_size(mode: u8) -> Option<usize> {
Some(match mode {
1 | 4 => 8,
3 | 5 | 6 | 7 => 16,
_ => return None,
})
}

/// Whether [`decode`] unpacks `mode`.
pub fn can_decode(mode: u8) -> bool {
block_size(mode).is_some()
}

/// Unpack a stream of `mode` to its `out_len` bytes of BCn blocks.
pub fn decode(mode: u8, src: &[u8], out_len: usize) -> Result<Vec<u8>, Error> {
let block = block_size(mode).ok_or(Error::Unsupported)?;
if out_len == 0 || out_len % block != 0 {
return Err(Error::OutputSize);
}
let mut out = vec![0u8; out_len];
victory::decode(mode, src, &mut out, victory::Tables::builtin())
.map_err(|e| Error::Decode(e.0))?;
Ok(out)
}

#[cfg(test)]
mod tests;
Loading
Loading