GPU Tiling: enforce tail depth bounds and linear base_xor safety #1624

Open
github-bot wants to merge 1 commit from github-bot/gh-1624 into main AGit
Owner

@⁠slopgobblercobbler on GitHub · 2026-11-24 18:23 UTC · original
slopgobblercobbler:fix/tiling-tail-depth-and-linear-safety → main · +164 −19 · 1 files · 1 commits · open

Summary

Audits 3D thick texture mip-tail depth bounds, linear swizzle mode base XOR masking, and truncated buffer bounds in crates/xcl/src/gpu/tiling.rs:

  1. 3D thick texture mip-tail depth bounds:
    • Computes explicit tail depth limit td in Chain::new_3d (block_d for blk % 3 in (0, 1), and block_d / 2 for blk % 3 == 2).
    • Constrains first_tail level discovery to require d <= td in addition to w <= tw and h <= th. Deep 3D textures (e.g. 8x8x64) now correctly keep levels where depth > td in the main chain, preventing multi-slice collision in the single tail block.
  2. NPOT and zero-dimension edge case protection:
    • Guarded side.max(1) and depth.max(1) in Chain::new and Chain::new_3d.
    • In Layout::offset_z, guarded pitch_blocks = w.max(1).div_ceil(self.block_w) preventing divide-by-zero and row-pitch collapse when width is 0.
  3. Swizzle mode 0 (linear) base_xor safety:
    • Enforced base_xor = 0 when swizzle_mode == 0 in image_layout and image_chain. Linear surfaces do not use GF(2) pipe/bank XOR swizzling; unaligned host base addresses no longer scramble element offsets.
    • In detile_level, clamped base = if t.mode == 0 { 0 } else { t.base_xor & in_blk_mask }, matching offset_z and eliminating block-boundary overruns.
  4. Truncated buffer bounds safety:
    • Safe slice windowing (if let (Some(...), Some(...))) in tile_level, detile_volume, and tile_volume to prevent out-of-bounds panics on truncated or partial buffers.
  5. Unit tests:
    • Added unit tests: npot_bcn_mip_chains_round_trip, thick_3d_tail_depth_bounds, linear_mode_ignores_unaligned_base_xor, offset_z_zero_width_preserves_row_pitch, and short_buffer_bounds_safety.

Changes

  • crates/xcl/src/gpu/tiling.rs:
    • Tail depth boundary constraints for 3D volume textures.
    • Zero-width protection in offset_z.
    • Linear mode base XOR bypassing.
    • Bounds checks for partial/truncated slice windows.
    • Comprehensive unit test suite.

Tested

  • Windows 11 x64, Rust MSVC stable.
  • cargo test -p xcl -- tiling: all passed, 0 failed.
  • Clean diff: zero trailing whitespace, clean rebase on latest upstream/main, GPL-2.0-only compliant, zero retail game data or keys.

Not Tested

  • Real-time 3D volume texture sampling on hardware D3D12 device.

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

**@⁠slopgobblercobbler** on GitHub · 2026-11-24 18:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/1624) `slopgobblercobbler:fix/tiling-tail-depth-and-linear-safety` → `main` · +164 −19 · 1 files · 1 commits · open ## Summary Audits 3D thick texture mip-tail depth bounds, linear swizzle mode base XOR masking, and truncated buffer bounds in `crates/xcl/src/gpu/tiling.rs`: 1. **3D thick texture mip-tail depth bounds**: - Computes explicit tail depth limit `td` in `Chain::new_3d` (`block_d` for `blk % 3 in (0, 1)`, and `block_d / 2` for `blk % 3 == 2`). - Constrains `first_tail` level discovery to require `d <= td` in addition to `w <= tw` and `h <= th`. Deep 3D textures (e.g. 8x8x64) now correctly keep levels where `depth > td` in the main chain, preventing multi-slice collision in the single tail block. 2. **NPOT and zero-dimension edge case protection**: - Guarded `side.max(1)` and `depth.max(1)` in `Chain::new` and `Chain::new_3d`. - In `Layout::offset_z`, guarded `pitch_blocks = w.max(1).div_ceil(self.block_w)` preventing divide-by-zero and row-pitch collapse when width is 0. 3. **Swizzle mode 0 (linear) `base_xor` safety**: - Enforced `base_xor = 0` when `swizzle_mode == 0` in `image_layout` and `image_chain`. Linear surfaces do not use GF(2) pipe/bank XOR swizzling; unaligned host base addresses no longer scramble element offsets. - In `detile_level`, clamped `base = if t.mode == 0 { 0 } else { t.base_xor & in_blk_mask }`, matching `offset_z` and eliminating block-boundary overruns. 4. **Truncated buffer bounds safety**: - Safe slice windowing (`if let (Some(...), Some(...))`) in `tile_level`, `detile_volume`, and `tile_volume` to prevent out-of-bounds panics on truncated or partial buffers. 5. **Unit tests**: - Added unit tests: `npot_bcn_mip_chains_round_trip`, `thick_3d_tail_depth_bounds`, `linear_mode_ignores_unaligned_base_xor`, `offset_z_zero_width_preserves_row_pitch`, and `short_buffer_bounds_safety`. ## Changes - `crates/xcl/src/gpu/tiling.rs`: - Tail depth boundary constraints for 3D volume textures. - Zero-width protection in `offset_z`. - Linear mode base XOR bypassing. - Bounds checks for partial/truncated slice windows. - Comprehensive unit test suite. ## Tested - Windows 11 x64, Rust MSVC stable. - `cargo test -p xcl -- tiling`: all passed, 0 failed. - Clean diff: zero trailing whitespace, clean rebase on latest `upstream/main`, GPL-2.0-only compliant, zero retail game data or keys. ## Not Tested - Real-time 3D volume texture sampling on hardware D3D12 device. ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:49 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:46 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 20:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/1624#issuecomment-7144040932) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠frenziedcoder on GitHub · 2026-11-24 20:55 UTC · original

NVIDIA test report for 134fb5a: the full workspace and a smoke pair on the retail title, next to @⁠DavidM1911's RTX 3060 Ti library run above. Full suite green, the PR's own test passing, and a clean smoke pair (1657 vs 1655 frames).

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head 134fb5a26923446b60902c44c3653c1f98064990, no local changes.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug): 781 passed, 0 failed, 41 ignored; all 19 gpu::tiling tests pass. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Regression run (scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen; XCL_PSO_PRELOAD=0 for both builds, because this machine's preload list holds the program of #1307)

base (9e3831e, this PR's base):

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1655 (PresentX 1655)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14601 MB

this PR:

xcl-smoke v1
commit: 134fb5a26923446b60902c44c3653c1f98064990
gpu: NVIDIA GeForce RTX 5080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1657 (PresentX 1657)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14600 MB

Not tested: the title's 3-D (thick) textures with deep mip tails at the world load (its volume LUTs come later than the start screen); AMD.

AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.

**@⁠frenziedcoder** on GitHub · 2026-11-24 20:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1624#issuecomment-7144246311) **NVIDIA test report for `134fb5a`: the full workspace and a smoke pair on the retail title, next to @⁠DavidM1911's RTX 3060 Ti library run above. Full suite green, the PR's own test passing, and a clean smoke pair (1657 vs 1655 frames).** **Tested** - NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 `stable-x86_64-pc-windows-msvc`, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head `134fb5a26923446b60902c44c3653c1f98064990`, no local changes. - `cargo build --workspace && cargo test --workspace -- --test-threads=4` (debug): **781 passed, 0 failed, 41 ignored**; all 19 `gpu::tiling` tests pass. SKIPPED: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). **Regression run** (`scripts/smoke.ps1 -Seconds 60`, release, the retail title of #505 at its start screen; `XCL_PSO_PRELOAD=0` for both builds, because this machine's preload list holds the program of #1307) base (`9e3831e`, this PR's base): ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 5080 title: RetailTitle seconds: 60 exit: 0x0 frames shown: 1655 (PresentX 1655) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14601 MB ``` this PR: ``` xcl-smoke v1 commit: 134fb5a26923446b60902c44c3653c1f98064990 gpu: NVIDIA GeForce RTX 5080 title: RetailTitle seconds: 60 exit: 0x0 frames shown: 1657 (PresentX 1657) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14600 MB ``` **Not tested:** the title's 3-D (thick) textures with deep mip tails at the world load (its volume LUTs come later than the start screen); AMD. *AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.*
Author
Owner

@⁠throny on GitHub · 2026-11-25 00:15 UTC · original

Two contributors checked independently and found that #1614 solves the same problem (for #1488) in a different way: #1607, group D50. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-25 00:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1624#issuecomment-7148319954) <!-- xcl-1607-hint:D50 --> Two contributors checked independently and found that #1614 solves the same problem (for #1488) in a different way: #1607, group D50. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 05:00 UTC · original

XCL PR #1624 focused Windows verification

Verified head 134fb5a26923446b60902c44c3653c1f98064990 in a clean, detached checkout on STOR-WINLAB. The PR changes only crates/xcl/src/gpu/tiling.rs.

Windows 11 Enterprise Evaluation x64, build 26200. AMD Ryzen 7 3800X and Intel Arc A770 Graphics with driver 32.0.101.9175. DXC 1.9.2609.5. rustc 1.100.0 (0ef1bc386 2026-11-09), x86_64-pc-windows-msvc.

Tested

  • cargo build --workspace completed successfully in the dev profile.
  • cargo test --workspace --no-run compiled the workspace test executables successfully in the test profile.
  • cargo test -p xcl --lib gpu::tiling::tests -- --nocapture with XCL_ADAPTER=NONE_CPU_ONLY finished in 22.05 s. pr1624-focused.log recorded 19 passed, 0 failed, 0 ignored, 0 SKIPPED lines, and 734 filtered out. All commands ran outside the Arc mutex.

The five added tests passed. They checked odd-sized BC1 and BC7 mip-chain round trips, exclusion of oversized-depth mips from a thick 3D tail and round trips across the volume levels, linear RGBA8 offsets from an unaligned base address, row pitch for a zero-width offset calculation, and short source buffers in Layout::tile and Chain::tile_level.

Not tested

Coverage was limited to focused CPU tiling tests and full workspace compilation. The full workspace GPU suite, D3D12 execution, and retail-title smoke runs were omitted.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1624-focused.log and published.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/1624#issuecomment-7153361961) # XCL PR #1624 focused Windows verification Verified head `134fb5a26923446b60902c44c3653c1f98064990` in a clean, detached checkout on STOR-WINLAB. The PR changes only `crates/xcl/src/gpu/tiling.rs`. Windows 11 Enterprise Evaluation x64, build 26200. AMD Ryzen 7 3800X and Intel Arc A770 Graphics with driver 32.0.101.9175. DXC 1.9.2609.5. `rustc 1.100.0 (0ef1bc386 2026-11-09)`, `x86_64-pc-windows-msvc`. **Tested** - `cargo build --workspace` completed successfully in the dev profile. - `cargo test --workspace --no-run` compiled the workspace test executables successfully in the test profile. - `cargo test -p xcl --lib gpu::tiling::tests -- --nocapture` with `XCL_ADAPTER=NONE_CPU_ONLY` finished in 22.05 s. `pr1624-focused.log` recorded 19 passed, 0 failed, 0 ignored, 0 `SKIPPED` lines, and 734 filtered out. All commands ran outside the Arc mutex. The five added tests passed. They checked odd-sized BC1 and BC7 mip-chain round trips, exclusion of oversized-depth mips from a thick 3D tail and round trips across the volume levels, linear RGBA8 offsets from an unaligned base address, row pitch for a zero-width offset calculation, and short source buffers in `Layout::tile` and `Chain::tile_level`. **Not tested** Coverage was limited to focused CPU tiling tests and full workspace compilation. The full workspace GPU suite, D3D12 execution, and retail-title smoke runs were omitted. **AI use** T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1624-focused.log` and published.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/tiling.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1624/head:github-bot/gh-1624'
git switch 'github-bot/gh-1624'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1624'
git switch 'github-bot/gh-1624'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1624'
git switch 'github-bot/gh-1624'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1624'
git switch 'main'
git merge --squash 'github-bot/gh-1624'
git switch 'main'
git merge --ff-only 'github-bot/gh-1624'
git switch 'main'
git merge 'github-bot/gh-1624'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.