Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
55e7beb
D3D12.X: a draw does not wait for a graphics pipeline still being built
isaacwingate Nov 24, 2026
03ceddb
kernelx: physical pages as section slices that can be mapped at many …
adiologydev Nov 25, 2026
51ee197
D3D12.X: add depth+UAV color twins and format-aliased placed texture …
raylitebull Nov 25, 2026
6602a70
kernelx: catch CPU writes to the views of physical pages, page by page
adiologydev Nov 25, 2026
d660e30
kernelx: views of physical pages stay open across a write that cannot…
adiologydev Nov 25, 2026
d91c0cc
local: #2080c
ivall Nov 25, 2026
f025e8e
local: #2107c
ivall Nov 25, 2026
c294340
local: #1803c
ivall Nov 25, 2026
a8146d7
local: #2092
ivall Nov 25, 2026
dae8b4a
local: two-pass heap addresses
ivall Nov 25, 2026
9b4742e
local: #541
ivall Nov 25, 2026
54ef7f3
local: #2126
ivall Nov 25, 2026
c800900
local: precompile chains, place timers
ivall Nov 25, 2026
92f3342
local: build cap, chain blob names
ivall Nov 25, 2026
f30ca3f
kernelx: XCL_PAGE_ALIAS=1 shows a physical page at every address it i…
adiologydev Nov 25, 2026
4f34c8d
kernelx: queue CopyPageMappingsBatchX records the physical page each …
Xeltax Nov 24, 2026
31fe59c
kernelx: the page-mapping method's decoding apart from its record
adiologydev Nov 25, 2026
64ad64c
kernelx: with XCL_PAGE_ALIAS=1 the queue's page mappings show real pages
adiologydev Nov 25, 2026
9ae786c
D3D12.X: stand-ins of pipelines not built yet share the driver's pipe…
ivall Nov 25, 2026
6c8d787
D3D12.X: a split dispatch runs in slabs that share a bounded scratch
ivall Nov 25, 2026
6ec402b
Recompiler: v_readfirstlane in a pixel shader reads a live lane first
madaraXor Nov 25, 2026
b3a85e3
local: #1592 with labels of pieces and passes
ivall Nov 25, 2026
ac3901d
Merge commit 'refs/pr/929' into world6
ivall Nov 25, 2026
80e394f
local: #2308 (with #1055, #2293, #2294, #2307)
ivall Nov 25, 2026
efc6ad7
local: #2305
ivall Nov 25, 2026
b540aeb
local: #1798 (also mesh), wanted draws
ivall Nov 25, 2026
6e906b7
local: loop budget experiment
ivall Nov 25, 2026
9c09d8e
local: buffers of the GPU view (XCL_GPU_VIEW_BUFFERS)
ivall Nov 25, 2026
89d9f35
local: title_bytes reads alias spaces safely
ivall Nov 25, 2026
d1fc32e
Recompiler: whole-wave reductions of wave32 VS / PS count every live …
ivall Nov 25, 2026
7baeb8d
D3D12.X: an indirect dispatch runs no garbage group counts
ivall Nov 25, 2026
01b901c
local: #1989
ivall Nov 25, 2026
edf78f0
D3D12.X: the scratch of split dispatches is bounded over all recordings
ivall Nov 25, 2026
35ba0d6
Merge branch 'world12' into world14
ivall Nov 25, 2026
98be478
local: #1989's test keeps its vtable across Reset
ivall Nov 25, 2026
051e7c6
local: main merged
ivall Nov 25, 2026
2e6c865
local: #615 over the pipelined presenter (a set of SRVs per present i…
ivall Nov 25, 2026
0e06c5e
kernelx: XMemMapPhysicalPagesScatter with no page array unmaps
notdxbi Nov 24, 2026
03e90ae
local: the merged presenter builds
ivall Nov 25, 2026
294539c
local: an unmap with no page array also with XCL_PAGE_ALIAS=1
ivall Nov 25, 2026
a044274
DirectStorage: read a physical-page list again when its request runs
mgrein Nov 24, 2026
e8623e9
local: #1405 also with XCL_PAGE_ALIAS=1
ivall Nov 25, 2026
2af4c65
D3D12.X: XCL_TEXTURE_LEVEL_PAGES=1 gives a sampled texture's levels t…
imnicho Nov 25, 2026
31b4c5c
local: XCL_PSO_MAX_CACHED=1
ivall Nov 25, 2026
77b416f
D3D12.X: the two-pass record buffer is shared by the recordings
ivall Nov 25, 2026
03a3094
local: census of committed resources
ivall Nov 25, 2026
9211159
D3D12.X: the two-pass record buffer is shared while one queue gets th…
ivall Nov 25, 2026
045db31
local: the activity thread asks for a removed device
ivall Nov 25, 2026
6acf8dd
local: XCL_PSO_SKIP_FILE
ivall Nov 25, 2026
e6aca81
D3D12.X: XCL_GPU_CULPRIT names the dispatches a stalled queue has not…
IvyNotFound Nov 24, 2026
82fe7f4
local: indirect group limit from the environment
ivall Nov 25, 2026
27002f4
local: XCL_SKIP_MESH
ivall Nov 25, 2026
559c4d3
local: culprit markers for mesh draws
ivall Nov 25, 2026
ea9401c
D3D12.X: a vertex or index buffer view at address 0 is a null view
ivall Nov 25, 2026
36ba176
local: what the GPU view mirror refuses
ivall Nov 25, 2026
bd4584d
local: XCL_LOOP_FILE, past the caches
ivall Nov 25, 2026
c7a18d8
Revert "local: XCL_LOOP_FILE, past the caches"
ivall Nov 25, 2026
04e0f1c
Merge origin/main (bd2ac507) into amd-dev
raylitebull Nov 25, 2026
7294c83
D3D12.X: label indirect argument passes and fix root UAV bindings
raylitebull Nov 25, 2026
3cda5be
D3D12.X: match 16-bit depth twin steps bit-for-bit in R24G8 sync
raylitebull Nov 25, 2026
b2a2fec
D3D12.X: sync format-aliased writers on enhanced barriers and map res…
raylitebull Nov 25, 2026
f09fc6f
D3D12.X: resolve GPU-view buffers directly to contiguous UMA backing
raylitebull Nov 25, 2026
74c47aa
Merge origin/main (3ceb5507) into amd-dev
raylitebull Nov 25, 2026
cf93147
kernelx: batch contiguous sparse-window commits in physical-page mapping
raylitebull Nov 25, 2026
40f499a
DirectStorage: defer half-full auto-submit for heap page-array batches
raylitebull Nov 25, 2026
8b0db35
Recompiler: ignore non-source SRC0 on VOP3 v_interp_* literal scan
raylitebull Nov 25, 2026
85a9480
Recompiler: emit global UAV fence on s_barrier in UAV-writing or glc …
raylitebull Nov 25, 2026
f44e17b
Recompiler: prefer live lanes in Direct DXIL PS v_readfirstlane and w…
raylitebull Nov 25, 2026
5b3f0a4
Direct DXIL: fold Countbits of constants (AMD folds Bfrev(Countbits(K…
Diskuss Nov 25, 2026
324193c
Recompiler: console pixel shaders tested depth-first keep early depth
0xkn0wh3r3 Nov 25, 2026
b6df9a7
Recompiler: the compact form's larger tables on every GPU again
Royalflamejlh Nov 25, 2026
f4a2cd8
D3D12.X: a pipeline is forgotten before its address is free
veyn-sudo Nov 25, 2026
a1ab351
D3D12.X: harden PresentX compositor and single-plane sub-rect scaling
Decodere Nov 25, 2026
32f0967
D3D12.X: serialize AMD driver PSO calls, honor DispatchX 0x20, gate B…
raylitebull Nov 25, 2026
857cf13
Merge origin/main (3f277701) into amd-dev
raylitebull Nov 25, 2026
b124884
D3D12.X: make AMD_DRIVER_PSO_LOCK opt-in via XCL_AMD_SERIAL_PSO=1
raylitebull Nov 25, 2026
e2b75a4
Merge origin/main (2898511a) into amd-dev
raylitebull Nov 25, 2026
cd7e64e
D3D12.X: a create that fails on a lost device keeps the driver's blob
Digit4w Nov 25, 2026
5730337
D3D12.X: batch vram tile-mapping fence signals into before_execute
raylitebull Nov 25, 2026
70e600d
Recompiler: guard 32-bit raw-buffer OOB wraparound in Direct DXIL
raylitebull Nov 25, 2026
354efa2
Recompiler: honour emit and cut ops on geometry s_sendmsg MSG_GS_DONE
raylitebull Nov 25, 2026
2c33f9f
Recompiler: fix Direct DXIL live double-ext scan and movrel VGPR range
raylitebull Nov 25, 2026
fcb17c9
D3D12.X: bind shared view heap before console ClearUnorderedAccessView*
raylitebull Nov 25, 2026
e74b7c2
D3D12.X: evict unmapped and stale GPU-view mirror tiles in sparse win…
raylitebull Nov 25, 2026
3058ce8
D3D12.X: skip mapping uncommitted graphics-reservation texture pages
raylitebull Nov 25, 2026
ac2938d
D3D12.X: state-diff ABI bindings, keep indirect scratch state, skip m…
raylitebull Nov 25, 2026
593e9cd
D3D12.X: map exhausted hosted view-heap slots to null slot 0 (#2380)
raylitebull Nov 25, 2026
b1a142c
D3D12.X: retain RTV resource under RTVS lock in note_execute (#2381)
raylitebull Nov 25, 2026
bc12d07
D3D12.X: build split ExecuteIndirect whole PSO off the title thread (…
raylitebull Nov 25, 2026
613fd4a
D3D12.X: fold compute dispatches over 65,535 groups in X into Y (#1428)
raylitebull Nov 25, 2026
3b6d008
D3D12.X: ping-pong indirect scratch and dedup arg-order barriers
raylitebull Nov 25, 2026
1286a94
D3D12.X: index dirty title textures by src range and single-read hash…
raylitebull Nov 25, 2026
bcf3e77
D3D12.X: reuse persistent detile worker pool in title_textures
raylitebull Nov 25, 2026
5c83847
D3D12.X: use RwLock for hot read-mostly PSO and UMA lookup tables
raylitebull Nov 25, 2026
d40d027
D3D12.X: recycle released reserved sampled textures by desc and state
raylitebull Nov 25, 2026
9ff793f
D3D12.X: batch busy late_release holds and widen RwLock tables
raylitebull Nov 25, 2026
6bc17a9
D3D12.X: per-draw mirror sync copies without readable() VirtualQuery
raylitebull Nov 25, 2026
d501290
D3D12.X: pack sub-64 KiB sampled textures into 4 KiB-aligned VRAM heaps
raylitebull Nov 25, 2026
f4b0706
Recompiler: fold constant CFG terminators and recompute live DXIL flags
raylitebull Nov 25, 2026
865b238
Recompiler: add branchless direct-DXIL heap-window reads (#2427)
raylitebull Nov 25, 2026
9c4a921
Recompiler: enable compute dispatch splitting for native Wave64 [64,1,1]
raylitebull Nov 25, 2026
7ea5231
D3D12.X: count only spawned threads in DetilePool::new
raylitebull Nov 25, 2026
b9f9184
Merge origin/main (72b59b50) into amd-dev
raylitebull Nov 25, 2026
bb7027c
Recompiler: prioritize wanted DXC compiles and reserve worker headroom
ChalanaGimhanaX Nov 25, 2026
3f64538
Recompiler: an empty DXC blob reads as no bytes (#2413)
crastinator Nov 25, 2026
e654d80
D3D12.X: a null ppv validation call does not crash console #14 (#2401)
GustavoEllwanger Nov 25, 2026
8484858
Tests: update test struct literals and Pages::bind calls after integr…
raylitebull Nov 25, 2026
9cb36c1
D3D12.X: hoist indirect arg clamps into batched prelude command list
raylitebull Nov 25, 2026
5ce71b6
D3D12.X: fall back to smaller dispatch-chain slabs on scratch OOM
raylitebull Nov 25, 2026
062c252
Merge origin/main (06055a7a) into amd-dev
raylitebull Nov 25, 2026
ba41b03
Recompiler: enable scalar reload CSE for direct DXIL vertex and pixel…
emusynths Nov 25, 2026
3806dba
dxil: emit InnerCoverage, ShadingRate, MeshDerivatives, and 64UAVs fl…
Decodere Nov 25, 2026
f02c0fc
D3D12.X: strip console-only root-signature flags in D3D12SerializeRoo…
Decodere Nov 25, 2026
aabb15c
D3D12.X: resolve GPU-view root descriptors to UMA before sparse mirror
raylitebull Nov 25, 2026
119c89b
Recompiler: make HLSL heap memory windows branchless via MEM_HEAP_NULL
raylitebull Nov 25, 2026
3227e36
Recompiler: default XCL_HEAP_FLAT on, extend to VS/PS, fix GS heap in…
raylitebull Nov 25, 2026
6ea50d1
Recompiler: emit branchless root-UAV loads in Direct DXIL
raylitebull Nov 25, 2026
0e19dc1
D3D12.X: guard zero UMA window VAs for branchless root-UAV loads (#2368)
raylitebull Nov 25, 2026
f7aaee8
D3D12.X: tier PSO gating, prioritize MS PSOs, keep >=512 KiB compute …
raylitebull Nov 25, 2026
dd42f94
Merge origin/main (889ef3e8) into amd-dev
raylitebull Nov 25, 2026
3370915
D3D12.X: skip redundant format-alias copies when source is unchanged
raylitebull Nov 25, 2026
7cd4bdc
Merge origin/main (6d051da5) into amd-dev
raylitebull Nov 25, 2026
c465ba6
D3D12.X: retry uploads after lazy mip mapping failures
raylitebull Nov 25, 2026
bafa2b2
D3D12.X: per-draw mirror sync copies only pages the title wrote
raylitebull Nov 25, 2026
28ec004
D3D12.X: clear LAST_CONTENT on unmap/remap and guard present RTV trac…
raylitebull Nov 25, 2026
8cb8d93
D3D12.X: quarantine unpinned sparse tiles and avoid STATE lock in pla…
raylitebull Nov 25, 2026
ddc8a67
D3D12.X: bind console_list heaps before root sig and fix ClearUAV handle
raylitebull Nov 25, 2026
5d488d7
Merge origin/main (e0d93c84) into amd-dev
raylitebull Nov 25, 2026
1306734
Merge origin/main (6d12f58a) into amd-dev
raylitebull Nov 25, 2026
5568d65
D3D12.X: fix make_scaled_args_buffer hang via backing retention and h…
raylitebull Nov 25, 2026
71c14d1
D3D12.X: clear dispatch_chain SHARED scratch and rotate DRED marks on…
raylitebull Nov 25, 2026
372a433
HLE: fix xg_xs vtable length, invalid-offset sentinel, and Z modes
raylitebull Nov 25, 2026
032c661
GPU: optimize GFX10 2D detile and tile with block slabs and contiguou…
raylitebull Nov 25, 2026
c3ed184
D3D12.X: hash only written pages of title textures (#2484)
raylitebull Nov 25, 2026
1dcfde8
D3D12.X: gate tiny <4 KiB GetCachedBlob stubs as cold compiles
raylitebull Nov 25, 2026
a87b439
D3D12.X: wire memory-mapped ID3D12PipelineLibrary1 persistence (#2001)
raylitebull Nov 25, 2026
5aeb661
D3D12.X: never skip non-RT producer compute PSOs and throttle under l…
raylitebull Nov 25, 2026
7745354
D3D12.X: run indirect split compute via chain and cap scratch atomically
raylitebull Nov 25, 2026
e6e13bc
D3D12.X: defer sparse UpdateTileMappings(NULL) behind title queues
raylitebull Nov 25, 2026
ca38495
D3D12.X: fence-gate VRAM tile unmaps, cooling, and late_release
raylitebull Nov 25, 2026
202f649
D3D12.X: the GPU wait watchdog does not miss the wake of an armed wait
tiagonleal Nov 25, 2026
fb81714
D3D12.X: register split segment allocators and gate/cache whole-form …
raylitebull Nov 25, 2026
378cc2a
D3D12.X: the same root signature set again keeps the root arguments
tiagonleal Nov 25, 2026
a080eb6
D3D12.X: a same-list write drops a later wait only when its value mee…
tiagonleal Nov 25, 2026
e54df0f
D3D12.X: forget a command signature's root-changing kind when its add…
tiagonleal Nov 25, 2026
1f6588b
D3D12.X: isolate >=900 KiB giant compiles, skip heavy preload, fix in…
raylitebull Nov 25, 2026
b36de34
D3D12.X: gate RT companion compute shader 95cc13288a27a96e under XCL_…
raylitebull Nov 25, 2026
7582db3
D3D12.X: serialize ID3D12PipelineLibrary1 calls and guard null descs
raylitebull Nov 25, 2026
b71981d
D3D12.X: defer >=256 KiB graphics/MS PSOs, lower HEAVY_CODE to 16 KiB…
raylitebull Nov 25, 2026
8d3c69c
D3D12.X: fence-quarantine released shared descriptor ranges
raylitebull Nov 25, 2026
f3c05d0
D3D12.X: add commit-reserve floor and early unwatched texture recheck
raylitebull Nov 25, 2026
80032a6
D3D12.X: fix null UAV fallback and MSAA/typeless companion SRVs
ChalanaGimhanaX Nov 25, 2026
c3e73a7
D3D12.X: place shader io (u0) in VRAM and hoist preludes per segment
raylitebull Nov 25, 2026
a747b31
D3D12.X: split pipeline library into immutable read handle and async …
raylitebull Nov 25, 2026
6fd9784
Merge origin/main (e1d84b7d) into amd-dev
raylitebull Nov 25, 2026
69060d8
D3D12.X: read back 256x256 float ocean heightmap textures to console …
raylitebull Nov 25, 2026
4dfade6
Shaders: warm memory-mapped ID3D12PipelineLibrary1 (.plib) in offline…
raylitebull Nov 25, 2026
44960c4
D3D12.X: pool <=8 MiB upload staging buffers and reclaim idle staging
raylitebull Nov 25, 2026
f968bfb
D3D12.X: add sky-following stand-in ambient and reflection clamp
raylitebull Nov 25, 2026
fd1ed90
D3D12.X: break sparse::STATE <-> kernelx::AWAY deadlock in gpu_view
raylitebull Nov 25, 2026
6d7dcbb
D3D12.X: read non-UMA title_bytes safely via read_committed
raylitebull Nov 25, 2026
f42c5e2
d3d12x: fix prelude/VRAM-io lifetime, snapshot RTV/DSV, expand water
raylitebull Nov 25, 2026
123ef32
D3D12.X: default XCL_RT_GATE to hold without compiling and cap preloa…
raylitebull Nov 25, 2026
2af0155
D3D12.X: back unresolved outside-UMA GPU-writable buffers in sparse VRAM
raylitebull Nov 25, 2026
1b31962
D3D12.X: pool exclusive ID3D12PipelineLibrary1 read handles to fix co…
raylitebull Nov 25, 2026
60d67a1
Shaders: respect XCL_RT_GATE=hold, log slow compiles, and serialize >…
raylitebull Nov 25, 2026
9d398bf
d3d12x,kernelx: lock-free descriptor copies, PSO bind cache, priority…
raylitebull Nov 25, 2026
dece6dd
D3D12.X: keep GPU-owned and GPU-aliased VRAM textures fully mapped
raylitebull Nov 25, 2026
95e1602
D3D12.X: read DRED ObjectNameW/pObject and name VRAM/sparse resources
raylitebull Nov 25, 2026
993b749
d3d12x: inline indirect-guard batching, RT bind dedup, root VA cache,…
raylitebull Nov 25, 2026
aa5dbf7
D3D12.X: a dispatch put off to the submit waits there until it is built
grahamster2 Nov 25, 2026
04e0b95
KernelX / D3D12.X: fix VirtualFree AWAY/home-reuse bugs and post-uplo…
raylitebull Nov 25, 2026
ecf25c0
D3D12.X: use RwLock for recording-thread PSO/layout/texture lookups
raylitebull Nov 25, 2026
8549b14
d3d12x: unlock sparse Map readback waits and adapt #2548/#2549/#2550
raylitebull Nov 25, 2026
df242ef
Merge origin/main (08db8020) into amd-dev
raylitebull Nov 25, 2026
ce90490
D3D12.X: submit title texture uploads asynchronously on direct title …
raylitebull Nov 25, 2026
9f02a3b
DXIL: guard null/out-of-window BVH nodes and all-zero Box32 children
raylitebull Nov 25, 2026
46aecbf
DXIL: shrink emitted shaders 4.5x-5.4x via abbrevs, compact micro-blo…
raylitebull Nov 25, 2026
61121fe
DirectStorage: wake waiters from ordered completion events (#1833)
razormontana Nov 25, 2026
6e9787c
Recompiler: direct PS compares skip the per-quad mask where no helper…
Kalmarv Nov 25, 2026
b5fc71d
Recompiler: a PS reads float16 attributes packed two per dword per half
MacieGx Nov 25, 2026
110d725
Recompiler: VS / mesh exports unpack float16 params packed two per dword
MacieGx Nov 25, 2026
b67375b
Recompiler: scratch SADDR 0x7F addresses the offset alone (ST form)
oni-swr Nov 25, 2026
4ae5668
Recompiler: lower 32-bit VALU add/sub with carry without i64 in direc…
ramon-victor Nov 25, 2026
71fccb1
DXIL: narrow post-DCE rawBufferLoad masks to highest extracted component
raylitebull Nov 25, 2026
bf02341
D3D12.X: create sparse readback jobs with DIRECT list type to match s…
raylitebull Nov 25, 2026
b96e7eb
d3d12x: create ReadbackJob command list as DIRECT to match sparse queue
raylitebull Nov 25, 2026
02ca14f
d3d12x: indirect draw caps, sharded bind state, stack io, and bitset …
raylitebull Nov 25, 2026
0b2df48
d3d12x: close inline guard batch on draws and Enhanced/UAV barriers
raylitebull Nov 26, 2026
1471472
KernelX: floor title thread priorities and restore fine timer on exit
raylitebull Nov 25, 2026
cb8eb0e
D3D12.X: add 12s per-frame pipeline wait window per kind and prioriti…
raylitebull Nov 26, 2026
806eee3
D3D12.X: skip AMD stub .pso disk cache (#2577) and evict retired text…
raylitebull Nov 26, 2026
e4b66e5
D3D12.X / KernelX: lazy-commit alloc_vram_only sparse buffers on CPU …
raylitebull Nov 26, 2026
6a0bb5b
D3D12.X: enforce wall-clock frame wait windows, bound deferred segmen…
raylitebull Nov 26, 2026
281d8f0
DXIL: fix compact SGPR liveness for RMW/CMOV SALU and Wave32 masks
real-alponzo Nov 26, 2026
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ A gamepad is recommended ([Controls](#controls)). The game folder is never modif
| **kernelx** | ✅ | title memory (budget from MicrosoftGame.Config, physical pages), threads on the PC's processors, modules, OS / console info | unit + end-to-end tests |
| **Memory** | ✅ | title graphics memory shared by CPU and GPU without copies, up to 16 GB (4 GiB windows) | GPU tests: loads, stores and atomics across windows |
| **File system** | ✅ | console paths (`GAME:`, `G:`, `D:` …) → the game folder; writes go to an overlay, the game folder is never modified; the console's drives: `S:\` (persistent local storage) and `T:\` (temp) in the title's data folder; free disk space answered for console paths | end-to-end: the test title's folder stays byte-identical; PLS and free space through the real call path |
| **DirectStorage** | ✅ | the console's DirectStorage queues: file and memory sources, zlib, and BCPack – the console's texture compression – for BC1, BC3, BC4, BC5, BC6H and BC7 (BC2 and the hardware swizzle are refused) | unit tests on synthetic streams; retail BCPack chunks of all six modes byte-identical with a reference decoder (`XCL_SAMPLE_BCPACK`) |
| **DirectStorage** | ✅ | the console's DirectStorage queues: file and memory sources, queued event notifications, zlib, and BCPack – the console's texture compression – for BC1, BC3, BC4, BC5, BC6H and BC7 (BC2 and the hardware swizzle are refused) | unit tests on synthetic streams; retail BCPack chunks of all six modes byte-identical with a reference decoder (`XCL_SAMPLE_BCPACK`) |

</details>

Expand Down
75 changes: 71 additions & 4 deletions crates/xcl/src/gpu/dxil/bitreader_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A test-only reader for the bitstream [`super::bitstream::BitWriter`]
//! produces (unabbreviated records only), used to check record layouts
//! that the validator and disassembler do not distinguish (e.g. atomic
//! ordering codes the LLVM reader maps leniently).
//! produces (both unabbreviated records and `DEFINE_ABBREV` abbreviated records),
//! used to check record layouts that the validator and disassembler do not
//! distinguish (e.g. atomic ordering codes the LLVM reader maps leniently).

use super::module::{BinOp, Module, RmwOp};

Expand All @@ -12,6 +12,15 @@ pub(super) struct Block {
pub blocks: Vec<Block>,
}

#[derive(Clone, Debug)]
enum AbOp {
Literal(u64),
Fixed(u32),
Vbr(u32),
ArrayFixed(u32),
ArrayVbr(u32),
}

impl Block {
/// Depth-first search for the first block with `id`.
pub fn find(&self, id: u32) -> Option<&Block> {
Expand Down Expand Up @@ -57,6 +66,7 @@ impl Reader<'_> {
}
fn block(&mut self, id: u32, width: u32, end_bit: Option<usize>) -> Block {
let mut blk = Block { id, ..Default::default() };
let mut abbrevs: Vec<Vec<AbOp>> = Vec::new();
loop {
if end_bit.is_none() && self.pos + width as usize > self.b.len() * 8 {
return blk;
Expand All @@ -77,13 +87,70 @@ impl Reader<'_> {
let end = self.pos + words * 32;
blk.blocks.push(self.block(sub, w, Some(end)));
}
2 => {
let n = self.vbr(5);
let mut ops = Vec::new();
let mut i = 0;
while i < n {
if self.fixed(1) == 1 {
ops.push(AbOp::Literal(self.vbr(8)));
i += 1;
} else {
match self.fixed(3) {
1 => {
ops.push(AbOp::Fixed(self.vbr(5) as u32));
i += 1;
}
2 => {
ops.push(AbOp::Vbr(self.vbr(5) as u32));
i += 1;
}
3 => {
assert_eq!(self.fixed(1), 0, "array element must be encoded");
match self.fixed(3) {
1 => ops.push(AbOp::ArrayFixed(self.vbr(5) as u32)),
2 => ops.push(AbOp::ArrayVbr(self.vbr(5) as u32)),
e => panic!("unsupported array elem encoding {e}"),
}
i += 2;
}
e => panic!("unsupported abbrev encoding {e}"),
}
}
}
abbrevs.push(ops);
}
3 => {
let code = self.vbr(6) as u32;
let n = self.vbr(6);
let ops = (0..n).map(|_| self.vbr(6)).collect();
blk.records.push((code, ops));
}
a => panic!("unexpected abbreviation id {a}"),
a => {
let ab = abbrevs.get((a - 4) as usize).unwrap_or_else(|| panic!("unknown abbreviation id {a}"));
let mut vals = Vec::new();
for op in ab {
match *op {
AbOp::Literal(v) => vals.push(v),
AbOp::Fixed(w) => vals.push(self.fixed(w)),
AbOp::Vbr(w) => vals.push(self.vbr(w)),
AbOp::ArrayFixed(w) => {
let len = self.vbr(6);
for _ in 0..len {
vals.push(self.fixed(w));
}
}
AbOp::ArrayVbr(w) => {
let len = self.vbr(6);
for _ in 0..len {
vals.push(self.vbr(w));
}
}
}
}
let code = vals[0] as u32;
blk.records.push((code, vals[1..].to_vec()));
}
}
}
}
Expand Down
141 changes: 128 additions & 13 deletions crates/xcl/src/gpu/dxil/bitstream.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
//! LLVM bitstream writer: fixed and VBR fields, nested blocks with
//! back-patched lengths, and unabbreviated records.
//!
//! DXIL accepts the plain bitstream container without any abbreviations,
//! which keeps the writer small; size is not a concern for shader modules
//! (the driver re-encodes them anyway).
//! back-patched lengths, unabbreviated records, and LLVM `DEFINE_ABBREV`
//! abbreviations for compact DXIL encoding.

/// Bit-level writer, little-endian within 32-bit words as LLVM defines.
pub struct BitWriter {
out: Vec<u8>,
acc: u64,
nbits: u32,
/// Open blocks: (byte offset of the length word, outer abbreviation width).
blocks: Vec<(usize, u32)>,
/// Open blocks: (byte offset of the length word, outer abbreviation width, next abbrev id).
blocks: Vec<(usize, u32, u32)>,
width: u32,
}

/// Abbreviation width used for every block we open (IDs 0..3 need 2 bits).
/// Abbreviation operand encoding for LLVM `DEFINE_ABBREV` records.
#[derive(Clone, Copy, Debug)]
pub enum AbbrevOp {
Literal(u64),
Fixed(u32),
Vbr(u32),
/// Trailing array of fixed-width operands (LLVM `Array` + `Fixed(w)` pair).
ArrayFixed(u32),
/// Trailing array of VBR-encoded operands (LLVM `Array` + `VBR(w)` pair).
ArrayVbr(u32),
}

/// Abbreviation width used for every block opened via [`BitWriter::enter_block`] (IDs 0..7).
pub const ABBREV_WIDTH: u32 = 3;

impl Default for BitWriter {
Expand All @@ -31,7 +40,7 @@ impl BitWriter {

pub fn emit(&mut self, value: u64, width: u32) {
debug_assert!(width <= 32);
debug_assert!(width == 64 || value >> width == 0, "value {value:#x} does not fit {width} bits");
debug_assert!(width == 64 || width == 32 || value >> width == 0, "value {value:#x} does not fit {width} bits");
self.acc |= value << self.nbits;
self.nbits += width;
while self.nbits >= 8 {
Expand Down Expand Up @@ -60,25 +69,114 @@ impl BitWriter {
}

pub fn enter_block(&mut self, id: u32) {
self.enter_block_with_width(id, ABBREV_WIDTH);
}

pub fn enter_block_with_width(&mut self, id: u32, abbrev_width: u32) {
self.emit(1, self.width); // ENTER_SUBBLOCK
self.vbr(id as u64, 8);
self.vbr(ABBREV_WIDTH as u64, 4);
self.vbr(abbrev_width as u64, 4);
self.align32();
let at = self.out.len();
self.out.extend_from_slice(&[0; 4]);
self.blocks.push((at, self.width));
self.width = ABBREV_WIDTH;
self.blocks.push((at, self.width, 4));
self.width = abbrev_width;
}

pub fn end_block(&mut self) {
self.emit(0, self.width); // END_BLOCK
self.align32();
let (at, outer) = self.blocks.pop().expect("end_block without enter_block");
let (at, outer, _) = self.blocks.pop().expect("end_block without enter_block");
let words = ((self.out.len() - at - 4) / 4) as u32;
self.out[at..at + 4].copy_from_slice(&words.to_le_bytes());
self.width = outer;
}

/// Define a block-local abbreviation (`DEFINE_ABBREV = 2`) and return its ID (`>= 4`).
pub fn define_abbrev(&mut self, ops: &[AbbrevOp]) -> u32 {
let id = {
let top = self.blocks.last_mut().expect("define_abbrev outside block");
let id = top.2;
top.2 += 1;
id
};
debug_assert!((id as u64) < (1u64 << self.width), "abbrev id {id} exceeds width {}", self.width);
let num_ops: u64 = ops.iter().map(|o| if matches!(o, AbbrevOp::ArrayFixed(_) | AbbrevOp::ArrayVbr(_)) { 2 } else { 1 }).sum();
self.emit(2, self.width); // DEFINE_ABBREV
self.vbr(num_ops, 5);
for &op in ops {
match op {
AbbrevOp::Literal(v) => {
self.emit(1, 1);
self.vbr(v, 8);
}
AbbrevOp::Fixed(w) => {
self.emit(0, 1);
self.emit(1, 3);
self.vbr(w as u64, 5);
}
AbbrevOp::Vbr(w) => {
self.emit(0, 1);
self.emit(2, 3);
self.vbr(w as u64, 5);
}
AbbrevOp::ArrayFixed(w) => {
self.emit(0, 1);
self.emit(3, 3); // Array
self.emit(0, 1);
self.emit(1, 3); // Fixed element
self.vbr(w as u64, 5);
}
AbbrevOp::ArrayVbr(w) => {
self.emit(0, 1);
self.emit(3, 3); // Array
self.emit(0, 1);
self.emit(2, 3); // VBR element
self.vbr(w as u64, 5);
}
}
}
id
}

/// Emit an abbreviated record defined by [`Self::define_abbrev`]. `values` supplies only the
/// non-literal operands in order; if `ops` ends with `ArrayFixed`/`ArrayVbr`, remaining items
/// in `values` form the array payload.
pub fn emit_abbrev(&mut self, id: u32, ops: &[AbbrevOp], values: &[u64]) {
self.emit(id as u64, self.width);
let mut idx = 0usize;
for &op in ops {
match op {
AbbrevOp::Literal(_) => {}
AbbrevOp::Fixed(w) => {
self.emit(values[idx], w);
idx += 1;
}
AbbrevOp::Vbr(w) => {
self.vbr(values[idx], w);
idx += 1;
}
AbbrevOp::ArrayFixed(w) => {
let rest = &values[idx..];
self.vbr(rest.len() as u64, 6);
for &v in rest {
self.emit(v, w);
}
idx = values.len();
}
AbbrevOp::ArrayVbr(w) => {
let rest = &values[idx..];
self.vbr(rest.len() as u64, 6);
for &v in rest {
self.vbr(v, w);
}
idx = values.len();
}
}
}
debug_assert_eq!(idx, values.len());
}

/// An unabbreviated record.
pub fn record(&mut self, code: u32, ops: &[u64]) {
self.emit(3, self.width); // UNABBREV_RECORD
Expand Down Expand Up @@ -152,4 +250,21 @@ mod tests {
assert_eq!(signed(-3), 7);
assert_eq!(signed(i64::MIN), 1);
}

#[test]
fn define_abbrev_round_trips_fixed_vbr_and_arrays() {
const AB: &[AbbrevOp] = &[AbbrevOp::Literal(22), AbbrevOp::ArrayFixed(32)];
let mut w = BitWriter::new();
for b in [b'B', b'C', 0xC0, 0xDE] {
w.emit(b as u64, 8);
}
w.enter_block_with_width(11, 3);
let id = w.define_abbrev(AB);
assert_eq!(id, 4);
w.emit_abbrev(id, AB, &[0x1234_5678, 0xDEAD_BEEF]);
w.end_block();
let bc = w.finish();
assert_eq!(&bc[..4], b"BC\xC0\xDE");
assert_eq!(bc.len() % 4, 0);
}
}
Loading
Loading