Tiling: bounds check tile linear slice and mask base_xor to block size #1373

Open
slopgobblercobbler wants to merge 1 commit from upstream-pr/1383 into main
slopgobblercobbler commented 2026-11-24 15:25:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T15:25:37Z.


Summary

In crates/xcl/src/gpu/tiling.rs:

  1. In offset_z:
    • Guard against zero width when computing pitch_blocks (w.max(1).div_ceil(self.block_w)).
    • Mask base_xor and intra-block xor offset with in_blk_mask = self.block_bytes - 1, ensuring the intra-block offset never overruns the block size regardless of swizzle mode bit patterns.
  2. In tile:
    • Replace unchecked subslice index copy out[o..o + e].copy_from_slice(&linear[s..s + e]) with checked slicing via out.get_mut(o..o + e) and linear.get(s..s + e) to prevent out-of-bounds panics on truncated linear inputs or boundary coordinates.

Changes

  • crates/xcl/src/gpu/tiling.rs:
    • offset_z: apply in_blk_mask to base_xor and intra-block offset; guard w.max(1).
    • tile: bounds-check destination and source subslice access.

Tested

  • Windows 11 x64, Rust 1.85+ stable (MSVC).
  • cargo test -p xcl -- tiling: all tiling tests passed cleanly.
  • Zero trailing whitespace, GPL-2.0-only compliant, zero game data/keys.

Not Tested

  • Full game asset texture de-tiling (synthetic unit tests only).

AI Use

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

<!-- greyfinch-sync:ivall/xcl:issue:5475106851 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1383). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-24T15:25:37Z. --- ## Summary In `crates/xcl/src/gpu/tiling.rs`: 1. In `offset_z`: - Guard against zero width when computing `pitch_blocks` (`w.max(1).div_ceil(self.block_w)`). - Mask `base_xor` and intra-block xor offset with `in_blk_mask = self.block_bytes - 1`, ensuring the intra-block offset never overruns the block size regardless of swizzle mode bit patterns. 2. In `tile`: - Replace unchecked subslice index copy `out[o..o + e].copy_from_slice(&linear[s..s + e])` with checked slicing via `out.get_mut(o..o + e)` and `linear.get(s..s + e)` to prevent out-of-bounds panics on truncated linear inputs or boundary coordinates. ## Changes - `crates/xcl/src/gpu/tiling.rs`: - `offset_z`: apply `in_blk_mask` to `base_xor` and intra-block offset; guard `w.max(1)`. - `tile`: bounds-check destination and source subslice access. ## Tested - Windows 11 x64, Rust 1.85+ stable (MSVC). - `cargo test -p xcl -- tiling`: all tiling tests passed cleanly. - Zero trailing whitespace, GPL-2.0-only compliant, zero game data/keys. ## Not Tested - Full game asset texture de-tiling (synthetic unit tests only). ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
futurepro62 commented 2026-11-24 16:07:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:33:46Z.


Full-suite run, since this PR has no test report yet. Tested exact head 4842033 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 756 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: truncated_directories_are_rejected, import_directory_without_null_terminator_exceeding_size_is_error, delay_import_without_null_terminator_exceeding_size_is_error, export_tables_exceeding_directory_bounds_is_error, thunks_with_out_of_bounds_iat_slot_is_error.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 756 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7136236761 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1383#issuecomment-7136236761). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:33:46Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `4842033` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **756 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `truncated_directories_are_rejected`, `import_directory_without_null_terminator_exceeding_size_is_error`, `delay_import_without_null_terminator_exceeding_size_is_error`, `export_tables_exceeding_directory_bounds_is_error`, `thunks_with_out_of_bounds_iat_slot_is_error`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **756 passed, 0 failed, 41 ignored**, no skips. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-24 17:06:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:49:49Z.


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

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

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7138271318 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1383#issuecomment-7138271318). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T16:49:49Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Toons29 commented 2026-11-25 04:10:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:28:23Z.


Regression run of b58bc3c7 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: b58bc3c7f23770cf43825552dc24462b56f859d7
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14812 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7151946541 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1383#issuecomment-7151946541). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:28:23Z. --- Regression run of `b58bc3c7` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: b58bc3c7f23770cf43825552dc24462b56f859d7 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1632 (PresentX 1632) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14812 MB ``` Against the limits in CONTRIBUTING.md: 101 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
DavidM1911 commented 2026-11-26 05:05:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:03:22Z.


Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

<!-- greyfinch-sync:ivall/xcl:comment:7183139788 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1383#issuecomment-7183139788). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T05:03:22Z. --- Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
github-actions[bot] commented 2026-12-01 02:32:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:32:01Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298718467 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1383#issuecomment-7298718467). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:32:01Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:35:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:35:57Z.


Triage (#1607) – head b58bc3c

#1624 (same author) contains all three hunks of this PR unchanged in gpu/tiling.rs (offset_z's w.max(1) and masked base_xor, the bounds-checked copy in tile) and adds the same guards to Chain's tile / detile paths, zeroes base_xor for linear images in image_layout / image_chain, bounds the thick 3D mip tail by depth, and has tests. This PR has no test.
Recommendation: close (superseded by #1624).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301938047 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1383#issuecomment-7301938047). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:35:57Z. --- **Triage (#1607)** – head b58bc3c #1624 (same author) contains all three hunks of this PR unchanged in `gpu/tiling.rs` (`offset_z`'s `w.max(1)` and masked `base_xor`, the bounds-checked copy in `tile`) and adds the same guards to `Chain`'s tile / detile paths, zeroes `base_xor` for linear images in `image_layout` / `image_chain`, bounds the thick 3D mip tail by depth, and has tests. This PR has no test. Recommendation: close (superseded by #1624). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1383:upstream-pr/1383'
git switch 'upstream-pr/1383'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1383'
git switch 'upstream-pr/1383'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1383'
git switch 'upstream-pr/1383'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1383'
git switch 'main'
git merge --squash 'upstream-pr/1383'
git switch 'main'
git merge --ff-only 'upstream-pr/1383'
git switch 'main'
git merge 'upstream-pr/1383'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1373
No description provided.