Skip to content

shader: extend mesh heap and scalar memory proofs (Part of #3703) - #3835

Merged
R0Y00 merged 4 commits into
R0Y00:mainfrom
timbot103:shader/mesh-heap-provenance-smem
Dec 3, 2026
Merged

R0Y00 merged 4 commits into
R0Y00:mainfrom
timbot103:shader/mesh-heap-provenance-smem

Conversation

@timbot103

Copy link
Copy Markdown
Contributor

Extends mesh resource-heap root-constant provenance beyond #3719 ("mesh heap slot lacks masked root constant provenance", 544 programs) and lowers verified root-SRV / fixed-table s_load_dword* scalar memory forms ("mesh scalar memory needs a verified guest root mapping: s_load_dwordx4", 77 programs) in src/gfx1013_direct_mesh.inl.

Part of #3703. Refs #3641, #3719.
(Opened as Draft per #3514 until an active review slot frees.)

Summary

  • src/gfx1013_direct_mesh.inl:
    • Extended heap-slot root provenance: Propagates RootBits (((root >> shift) & mask) + base) through v_bfe_u32 / s_bfe_u32, v_and_b32 / s_and_b32 (both operand orders), v_lshrrev_b32 / s_lshr_b32, v_lshlrev_b32 / s_lshl_b32, v_add_nc_u32 / s_add_{u32,i32}, v_or_b32 / s_or_b32 (disjoint bit add), s_mul_i32, v_readfirstlane_b32 (at full EXEC), s_cselect_b32 / v_cndmask_b32 (identical proofs on both inputs), and CFG phi joins (matching proofs on both edges). Allows 4- and 8-dword typed heap fetches to fold aligned immediate byte offsets into MeshHeapRead::base.
    • Root-SRV & fixed-table scalar loads: Accepts s_load_dword* from verified Symbol::Type::root_address pairs (with matching high half) at immediate or proven constant SGPR offsets, and s_load_dwordx4 from declared root descriptor tables at aligned constant SGPR offsets validated against the table's descriptor ranges. Keeps GPU buffer words ineligible for CPU root-constant selectors and refuses unproven/unaligned/out-of-range offsets.
  • tests/native_mesh_heap_provenance_smem_check.py + tests/cmake/native_mesh_heap_provenance_smem.cmake:
    • native_mesh_heap_provenance_smem_ir (runs in pr CTest preset): 18 accepted cases verified against selector reports and DXIL + 27 fail-closed refusal controls.

Verification

Host: Windows 11 (10.0.26200.9974), MSVC C++20 /W4 (zero warnings in edited lines). Base origin/main f365f125.

  • ctest --preset pr --no-tests=error -R "^native_mesh_heap_provenance_smem_ir$": 1/1 passed (18 positive + 27 refusals).
  • Debug (dev) & Release (release): 3/3 passed in both configs (native_mesh_heap_provenance_smem_ir, native_direct_mesh, native_direct_container).
  • tests/bidi_controls_check.py, tests/docs_links_check.py, git diff --check origin/main..HEAD: all clean.

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5feae82d (draft) by reading the diff; not built or run.

Verdict: approve. Each new RootBits step keeps ((root >> shift) & mask) + base exact, and the new scalar loads go through the existing bounded root and table paths. No MUST.

  • SHOULD Run a before/after m86 census on f365f125 for the real gain on the 544 + 77. Clearing provenance can expose the next wall, and v_readfirstlane_b32 now forwards a root-derived source as-is under full EXEC (gfx1013_direct_mesh.inl:2455), so the census would also show any changed refusal. Follow-up is fine.
  • Checked, no finding:
    • Operand order (:235): v_lshrrev/v_lshlrev take the shift from src[0], v_bfe_u32 its width from src[2], and shift amounts use the low 5 bits.
    • Shifts, extracts and masks refuse a non-zero base. OR counts as ADD only with no base and no shared mask bits. ADD requires a masked selector, and add_slot_base (:229) keeps mask + base within the slot range. A scaled value accepts only a 32-byte-aligned ADD or OR.
    • s_cselect/v_cndmask and phi joins carry a proof only when both inputs have identical bits, so the selected value equals either one. Proofs come only from entry constants: loaded words are never added.
    • Root s_load_dword* (:1736): the high half must match, and the folded constant offset then reaches the shared root path, which refuses spans over 64 KB and passes the span to root_buffer_handle. A fixed-table s_load_dwordx4 needs a 32-byte-aligned slot inside a declared range, with APPEND offsets resolved in order (:1762).
    • A heap fetch with an immediate offset adds immediate >> 5 slots to the selector and moves the symbolic word offsets back by the same bytes, so the descriptor words stay relative to the fetched record.

Tests: native_mesh_heap_provenance_smem_ir (18 cases, 27 refusals) is in the pr filter.

@lukaslw-lab lukaslw-lab left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review on 70d66873 (rebased on 5770f14e: vector_exec and uniform_alu_source from main).

Verdict: approve.

Census, same capture and method as before (6,685 distinct mesh programs), main 5770f14e vs this head:

Programs
Translate, main / with this PR 1,047 / 1,047
Lost / gained / first refusal moved 0 / 0 / 0

Same as the earlier head. The range-diff against my reviewed head contains only main's renames. The heap-slot refusal is the first refusal of many programs here, but none of them moves.

Update: the first run was on a main that refused 257 programs early (my #3707, #3892; fixed by #3893). I reran main 5770f14e and this head, both with that fix: 0 moved, 0 lost, 0 gained. 544 programs stop first at the heap-slot refusal there, and none of them moves.

AI-assisted.

# Conflicts:
#	src/gfx1013_direct_mesh.inl
The full Texture1D descriptor path on main rebuilt only the mask from the root constant. Share selector lowering with typed buffer loads so the DXIL slot and the reported selector agree for shifted fields and immediate displacements.
@timbot103

Copy link
Copy Markdown
Contributor Author

Merged main (67862ee4) into this branch; the reviewed commit 70d66873 is unchanged.

  • The conflict was in gfx1013_direct_mesh.inl. The resolution keeps this PR's root-proven slot displacements together with main's opaque GPU-selected texture descriptors.
  • 1095b0d4 makes the Texture1D consumer apply the shift and displacement recorded in the manifest. A new IR control caught the mismatch.

Tests, Windows 11 26200 with RTX 5080 and WARP. The mesh filter was native_direct_mesh|native_direct_container|native_mesh_ plus this PR's own tests. Every branch passed a full Debug build of every target, including the C++17 native_compute_pack_refusal_check.

  • Debug passed 16/16. Release passed 13/16, and the PR preset passed 1/1.
  • The Release failures are the existing asynchronous WARP allocation fixtures (accepted=1 refused=0). They also fail on a clean 67862ee4, and every one of them passed with X2W_SYNC_MESH_REQUESTS=1.

All six mesh PRs (#3832, #3835, #3838, #3842, #3843 and #3846) were also merged together onto 67862ee4. That combined tree passed 47/47 in Debug and 47/47 in Release, plus 8/8 under the PR preset. All 15 pairs merge cleanly.

The shared graphics decoder can admit DLC and GLC for read-only scalar loads. Exercise a reserved bit in the address word so the refusal control checks unsupported addressing under either decoder policy.
@timbot103

Copy link
Copy Markdown
Contributor Author

705d91ab makes this PR independent of #3833.

#3833 allows DLC/GLC cache-policy bits on read-only scalar loads in the shared decoder, and mesh lowering uses that decoder. With both PRs merged, this PR's root-glc-dlc refusal control therefore compiled. Accepting those bits on a read-only load is correct, so the control, not the compiler, was out of date.

The control now uses a reserved SMEM address bit, which is refused with or without #3833, so it still checks that unsupported addressing fails closed.

Tests on main c42b7ce3, with and without #3833 merged:

  • native_mesh_heap_provenance_smem_ir passes in Debug and Release.
  • The mesh filter passed 14/14 in Debug and 11/14 in Release.
  • The 3 Release failures are the existing asynchronous WARP allocation fixtures. They also fail on clean main and pass with X2W_SYNC_MESH_REQUESTS=1.

The RTX 5080 checks pass.

@timbot103
timbot103 marked this pull request as ready for review December 3, 2026 01:14
@timbot103

Copy link
Copy Markdown
Contributor Author

Marked Ready for review now that the previous batch (#3832, #3838, #3839, #3844, #3847) has merged. This keeps us within 5 non-draft PRs per #3514. The branch merges cleanly into current main, and CI is green at this head.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently reviewed 705d91a. At joins the selector survives only when its reaching root and every selector field agree. The byte displacement is folded into the selector once, and the encoded offset and table range are checked before publishing. Built compile_dxil on MSVC Debug and ran ctest --preset dev --no-tests=error -j 1 --output-on-failure -R "^(native_mesh_heap_provenance_smem_ir|native_direct_mesh)$": 2/2 passed. Removing the immediate alignment test made unaligned-heap-immediate translate and failed the fixture. The restored head passed again. This is compiler IR/selector verification.

@R0Y00
R0Y00 merged commit be5f201 into R0Y00:main Dec 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants