shader: run GTA V's ray tracing dispatches #1258
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1258
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1258/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@TheCruZ on GitHub · 2026-10-08 20:54 UTC · original
pr/gtav-ray-tracing-dispatches→main· +1282 −127 · 27 files · 2 commits · closed without mergingDepends on #1257 (bindless T# tables). This branch contains that PR's commit; only the last commit,
shader: run GTA V's ray tracing dispatches, belongs to this PR.Summary
Lets Grand Theft Auto V (PPSA04263) run its ray tracing compute shaders instead of failing on them:
0xfa8b1616fddc203b,0x6db33a2bcb077bc3,0xca313cf56ef25496and0x651da332bc4a3f98in Fidelity mode and0xedc5bdc9a5687671in Performance RT mode. Without them, ray-traced reflections and shadows are missing and Franklin's house had dark, wrong indirect lighting in Fidelity.Problem
With BVH intersections and GPU-selected scalar loads supported upstream, two things still stopped these shaders:
S_BUFFER_LOAD_DWORDX8at(material >> 4) << 5). Its SGPRs are reused for other data, so the T# words also reach Phis of those other register lifetimes, and the bindless table plan (which requires the T# reads to feed only image descriptors) was rejected.0xedc5bdc9a5687671also queries the size of a material table texture (IMAGE_GET_RESINFO), andImageQueryDimensionshad no table path.Change
entry = key & mask, slot lookup in the flattened SRT) moves intoImageTableElement, shared by sampling and byImageQueryDimensions, which now queries the selected table element; materialization acceptsImageQueryDimensionson table images.Testing
resource_tracking_tests: newTestIndirectScalarReads,TestGpuDependentAddressReads,TestBindlessImageTableQueryandTestBindlessImageTableSharedRegisterscases; passes.shader_recompiler_compute_tests: newScalarLoadsGpuSelectedDescriptorsGPU case (--indirect-buffer-only);--indirect-buffer-onlyand the default run pass.resource_materialization_tests,memory_tracker_tests,page_manager_tests,shader_cfg_testsandvirtual_memory_allocation_testspass.AI usage
AI (Claude Opus 5.5) was used to investigate the issue and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my GTA V fork, i will be bringing PRs here after test them enough.
@coderabbitai[bot] on GitHub · 2026-10-08 21:01 UTC · original · edited 2026-10-08 21:41 UTC
📝 Walkthrough
Walkthrough
The change adds bindless image-table support across resource tracking, materialization, SPIR-V emission, and host renderer descriptor binding. It also adds speculative texture lookup, image and backing-store epochs, backing-readability checks, and scoped soft-exit exceptions. Vulkan feature configuration and sampled-image descriptor-pool capacity are updated. Tests cover image-table tracking and materialization, dimension queries, shared register uses, and GPU-selected scalar descriptor reads.
Suggested reviewers:
nmzik,senaxxPriority: ➖ Normal
Change: Feature
Merge Risk: 🟡 Moderate · up to
d634aBindless texture tables enable GTA V ray-traced effects. However, a failed guest-memory write while a table texture is being resolved can crash the emulator instead of falling back to a null image. Very large tables can also exceed descriptor capacity. Fix the crash path before merging.
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 15.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 100 functions across 22 files. (3 skipped: 2 unsupported, 1 too large.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -14,0 +30,4 @@throw SoftExitError(fmt::format("{} ({}:{})", text, file, line));}}@coderabbitai[bot] on GitHub · 2026-10-08 21:01 UTC · original · edited 2026-10-08 21:15 UTC
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29348
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7163
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 28870
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 20011
Do not let the soft-exit path call
noexceptWriteBacking.ResolveTableTextureenablesSoftExitScopebeforeResolveTexture. That path callsFindImageSpeculative, which inserts an image and then callsMaterializeColorClear.MaterializeColorClearcan callLibKernel::Memory::WriteBacking. If the write fails,WriteBackingcallsEXIT;ThrowIfSoftthrowsSoftExitError, butWriteBackingisnoexcept, so the process terminates beforeResolveTableTexturecan catch the error.Remove
noexceptfromWriteBackingso this failure reaches the existing soft-exit handler.🐛 Suggested fix
FindImageImplalso publishes the inserted image beforeMaterializeColorClearruns. If materialization raises a caughtSoftExitError, the image remains cached although materialization did not complete. Roll back speculative inserts, or publish the entry only after materialization succeeds. The lock is released before materialization, so this is a cache-state issue rather than a leaked lock.✅ Confirmed as addressed by @TheCruZ
@ -510,0 +514,4 @@supported_features2.features.shaderSampledImageArrayDynamicIndexing != VK_TRUE) {LOGF("WARNING: non-uniform sampled image indexing is not supported; bindless image ""tables will not work\n");}@coderabbitai[bot] on GitHub · 2026-10-08 21:01 UTC · original · edited 2026-10-08 21:14 UTC
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
The device can be created without non-uniform indexing, and table shaders then use undeclared features.
This change copies the device's reported support into
features12. Device creation therefore no longer fails whenshaderSampledImageArrayNonUniformIndexingis unsupported. Device selection still rejects such a device, becauseVulkanFindPhysicalDevicechecks this feature as required. A selected device therefore always has support, and the new fallback branch is unreachable. IfshaderSampledImageArrayDynamicIndexingis unsupported, however, the emitter still requiresSampledImageArrayDynamicIndexingfor table bindings. Pipeline creation then fails, and the only signal is the warning in the log. AddshaderSampledImageArrayDynamicIndexingto the device-selection checks, or disable the bindless table path when the feature is missing.@ -457,0 +495,4 @@const auto entry_mask = indirect.table_mask >> 5u;const auto entries = std::min<uint64_t>({size > indirect.table_offset ? (size - indirect.table_offset) / 32u : 0u,uint64_t {entry_mask} + 1u, MaxIndirectDescriptorProbes});@coderabbitai[bot] on GitHub · 2026-10-08 21:01 UTC · original · edited 2026-10-08 21:41 UTC
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21290
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 13585
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14379
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14088
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14088
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11387
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11387
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 18716
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 18716
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12008
Reject full-size image tables before materialization.
With
table_mask == UINT32_MAX, this path can read 65,536 entries. If those entries are distinct and valid, the initial null slot increasesfound->slots.size()to 65,537, andImageTableCapacityrounds that value to 131,072. The descriptor pool reserves only 65,536 sampled-image descriptors. The allocation can therefore fail.MaxElementsdoes not prevent this.FindTableResolutionclears an already oversized cache only on a later lookup.🐛 Suggested fix
📝 Committable suggestion
✅ Confirmed as addressed by @TheCruZ
@coderabbitai[bot] on GitHub · 2026-10-08 21:01 UTC · original · reviewed
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
206e0dbe-bcad-4f91-8adf-cd87651dc95e📥 Commits
Reviewing files that changed from the base of the PR and between
2f4b8a335dand d634aea1aa95c58af70c3dc0c4df76a26853c4f5.📒 Files selected for processing (25)
CMakeLists.txtsrc/common/assert.cppsrc/common/assert.hsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/pipeline/descriptorHeap.cppsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/descriptors.hsrc/graphics/host_gpu/renderer/render.hsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/ir/ResourceSnapshot.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/BindingLayout.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppsrc/kernel/memory.cppsrc/kernel/memory.hsrc/kernel/memoryAddressSpace.inctests/ResourceTrackingTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@ -14,0 +30,4 @@throw SoftExitError(fmt::format("{} ({}:{})", text, file, line));}}@TheCruZ on GitHub · 2026-10-08 21:14 UTC · original
Fixed in f78d0ab (the #1257 commit this PR is based on; this branch is rebased on it as 772e21c):
WriteBackingis no longernoexcept, so its failure under the soft-exit scope reachesResolveTableTextureand binds a null image instead of terminating. As for the inserted image: I'm not rolling it back. Its clear failed because the guest backing is gone, and before this change that case terminated the emulator; the image stays an ordinary cache entry that the next unmap/overlap handling removes.@ -510,0 +514,4 @@supported_features2.features.shaderSampledImageArrayDynamicIndexing != VK_TRUE) {LOGF("WARNING: non-uniform sampled image indexing is not supported; bindless image ""tables will not work\n");}@TheCruZ on GitHub · 2026-10-08 21:14 UTC · original
I'm leaving device selection as is. Making
shaderSampledImageArrayDynamicIndexinga hard requirement would refuse devices that run every title without bindless tables; every desktop Vulkan 1.2 driver I know of reports it. When it is missing, only the table shaders fail, and the log line names the missing feature.@ -457,0 +495,4 @@const auto entry_mask = indirect.table_mask >> 5u;const auto entries = std::min<uint64_t>({size > indirect.table_offset ? (size - indirect.table_offset) / 32u : 0u,uint64_t {entry_mask} + 1u, MaxIndirectDescriptorProbes});@TheCruZ on GitHub · 2026-10-08 21:14 UTC · original
Addressed in f78d0ab: a table that would need more sampled images than the pool provides (such as 65537 slots rounded to 131072) now stops at layout creation with a message giving the counts and limits, instead of failing the descriptor set allocation. In practice the slots are the distinct valid T#s of the table (about 9800 in GTA V's 65536-entry heap).
@ -510,0 +514,4 @@supported_features2.features.shaderSampledImageArrayDynamicIndexing != VK_TRUE) {LOGF("WARNING: non-uniform sampled image indexing is not supported; bindless image ""tables will not work\n");}@coderabbitai[bot] on GitHub · 2026-10-08 21:15 UTC · original
@TheCruZ, thanks for the guidance. MakingshaderSampledImageArrayDynamicIndexingmandatory would reject devices that can run titles without bindless tables. I accept your decision to keep device selection unchanged and allow only table shaders to fail when the feature is unavailable.✏️ Learnings added
You are interacting with an AI system.
@ -14,0 +30,4 @@throw SoftExitError(fmt::format("{} ({}:{})", text, file, line));}}@coderabbitai[bot] on GitHub · 2026-10-08 21:15 UTC · original
@TheCruZThanks for the fix and the clarification. RemovingnoexceptfromWriteBackingaddresses the termination issue.I accept your decision to retain the inserted image for the existing unmap/overlap handling. I withdraw the rollback recommendation.
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@ -457,0 +495,4 @@const auto entry_mask = indirect.table_mask >> 5u;const auto entries = std::min<uint64_t>({size > indirect.table_offset ? (size - indirect.table_offset) / 32u : 0u,uint64_t {entry_mask} + 1u, MaxIndirectDescriptorProbes});@coderabbitai[bot] on GitHub · 2026-10-08 21:15 UTC · original
🧩 Analysis chain
🏁 Script executed:
Length of output: 25452
@TheCruZ, verified inf78d0ab.CreateDescriptorLayoutnow checks sampled-image counts against the descriptor-pool limit and the device’s per-set and per-stage limits. It reports the counts and limits before creating an oversized layout.This addresses the allocation failure without rejecting a 65,536-entry table whose deduplicated slots fit the limits. Thanks for the clarification.
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@ -457,0 +495,4 @@const auto entry_mask = indirect.table_mask >> 5u;const auto entries = std::min<uint64_t>({size > indirect.table_offset ? (size - indirect.table_offset) / 32u : 0u,uint64_t {entry_mask} + 1u, MaxIndirectDescriptorProbes});@TheCruZ on GitHub · 2026-10-08 21:41 UTC · original
Follow-up: the descriptor pool now holds 262144 sampled images (#1257,
4d0b7f2a), so a table that grows to 131072 entries still fits.@ -457,0 +495,4 @@const auto entry_mask = indirect.table_mask >> 5u;const auto entries = std::min<uint64_t>({size > indirect.table_offset ? (size - indirect.table_offset) / 32u : 0u,uint64_t {entry_mask} + 1u, MaxIndirectDescriptorProbes});@coderabbitai[bot] on GitHub · 2026-10-08 21:42 UTC · original
@TheCruZ, thanks for the clarification. A rounded capacity of 131,072 sampled-image descriptors fits the 262,144-descriptor pool in#1257(4d0b7f2a). The pool-overflow concern no longer applies to this case. The device’s per-set and per-stage limits still apply.🧠 Learnings used
✅ Review thread resolved.
You are interacting with an AI system.
Pull request closed