fix(shader): BDA lookup functions are not inlined #174

Merged
STL1te merged 1 commit from upstream-pr/174 into main 2026-09-30 18:12:05 +00:00
STL1te commented 2026-09-30 07:33:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by STL1te on 2026-09-30T07:33:39Z.


What

DefineBdaLookup emits get_bda_pointer, probe_bda_pointer and get_bda_write_pointer as ordinary SPIR-V functions. NVIDIA's compiler inlines every call of them, each with its binary-search loop over the BDA table, and then spends minutes on shaders with a few hundred guest memory accesses: a ray-tracing compute shader with 496 lookup calls (~88% of them from scalar loads through GPU-selected V#s, one probe plus four byte lookups per dword, twice for the wave64 halves) took 104 s to create as a pipeline. Its compile time tracks the number of inlined OpConvertUToPtr sites and loops, not the size of the module.

The functions are now declared with FunctionControlDontInlineMask. Nothing else changes: same SPIR-V otherwise, same lookups, same fault reporting.

Pipeline creation with the driver's disk cache defeated (a fresh generator word per module), NVIDIA RTX PRO 6000 Blackwell:

Shader SPIR-V words Inlined DontInline
RT compute, 496 lookups 280,168 104.4 s 4.8 s
compute, 530 lookups 95,698 86.3 s 1.5 s
compute 39,959 6.0 s 0.45 s
compute 40,640 6.6 s 0.48 s
pixel 69,179 5.7 s 1.1 s
pixel 90,491 4.1 s 0.74 s
pixel 92,459 4.0 s 0.69 s

The same shader structured by #134 (278,626 words) goes from 103.8 s to 4.84 s with this change, so the two are independent.

Tested

Windows 11 Pro, MinGW-w64 GCC, NVIDIA RTX PRO 6000 Blackwell.

  • A retail title: the menu renders 3,311 frames in 120 s against 3,325 without the change (noise); a loading sequence takes the same wall time and the same GPU dispatch time in both builds, so the calls cost nothing measurable at run time.
  • spirv-val clean on the modules above; the recompiled SPIR-V differs from the previous build only in the function control word of the three lookup functions.
  • ctest passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: nothing
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4687397308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/174). Originally posted by [STL1te](https://github.com/STL1te) on 2026-09-30T07:33:39Z. --- ### What `DefineBdaLookup` emits `get_bda_pointer`, `probe_bda_pointer` and `get_bda_write_pointer` as ordinary SPIR-V functions. NVIDIA's compiler inlines every call of them, each with its binary-search loop over the BDA table, and then spends minutes on shaders with a few hundred guest memory accesses: a ray-tracing compute shader with 496 lookup calls (~88% of them from scalar loads through GPU-selected V#s, one probe plus four byte lookups per dword, twice for the wave64 halves) took 104 s to create as a pipeline. Its compile time tracks the number of inlined `OpConvertUToPtr` sites and loops, not the size of the module. The functions are now declared with `FunctionControlDontInlineMask`. Nothing else changes: same SPIR-V otherwise, same lookups, same fault reporting. Pipeline creation with the driver's disk cache defeated (a fresh generator word per module), NVIDIA RTX PRO 6000 Blackwell: | Shader | SPIR-V words | Inlined | DontInline | |---|---|---|---| | RT compute, 496 lookups | 280,168 | 104.4 s | 4.8 s | | compute, 530 lookups | 95,698 | 86.3 s | 1.5 s | | compute | 39,959 | 6.0 s | 0.45 s | | compute | 40,640 | 6.6 s | 0.48 s | | pixel | 69,179 | 5.7 s | 1.1 s | | pixel | 90,491 | 4.1 s | 0.74 s | | pixel | 92,459 | 4.0 s | 0.69 s | The same shader structured by #134 (278,626 words) goes from 103.8 s to 4.84 s with this change, so the two are independent. ### Tested Windows 11 Pro, MinGW-w64 GCC, NVIDIA RTX PRO 6000 Blackwell. - A retail title: the menu renders 3,311 frames in 120 s against 3,325 without the change (noise); a loading sequence takes the same wall time and the same GPU dispatch time in both builds, so the calls cost nothing measurable at run time. - `spirv-val` clean on the modules above; the recompiled SPIR-V differs from the previous build only in the function control word of the three lookup functions. - `ctest` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: nothing - [x] AI-assisted: yes
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
boykopovar/AnyPS5!174
No description provided.