Add raw copy dependencies for incompatible textures #181

Merged
LotP merged 1 commit from avan/Ryubing:fix/incompatible-texture-raw-copy into master 2026-08-24 20:45:01 +00:00
Contributor

Trails in the Sky 1st uses texture descriptors with different formats and dimensions that map to the same region of guest GPU memory. For example, the game interprets the same underlying data as both an R32Uint 2x1 texture and an R32G32Float 1x1 texture. Both textures have an 8-byte logical payload, but their texel formats and dimensions are different.

Ryubing cannot represent these two descriptors as normally compatible texture views, so it creates separate host texture objects for them. Since these host textures represent the same guest memory, a modification made to one of them should become visible to the other before the other texture is read. However, the existing synchronization mechanism does not fully handle this situation.

The game uses this pattern for its exposure or brightness history. A compute shader first writes the updated exposure data to the R32G32Float 1x1 host texture. A later operation then reads the raw bits of the same data through the R32Uint 2x1 host texture. The original Ryubing implementation did not synchronize the contents of these two separate host textures. As a result, the reading texture received stale zero values, which caused the shader to calculate an incorrectly low exposure value and made the rendered image appear too dark.

TextureGroup already has a guest-memory synchronization mechanism for incompatible overlaps. When _flushIncompatibleOverlaps is enabled, the most recent texture contents are written back to guest memory, after which the other texture reloads the data. However, this mechanism was primarily enabled through IsFormatHostIncompatible, which checks whether an individual texture format can be correctly supported by the host GPU.

In this case, both R32Uint and R32G32Float are individually supported by the host GPU. Therefore, IsFormatHostIncompatible does not enable this synchronization path. The issue is not that either format is unsupported. The issue is that two individually supported aliases, represented by separate host textures, do not maintain coherent contents.

In theory, the latest contents could be flushed to guest memory immediately after every GPU write to a host texture, allowing other textures that map to the same guest memory to reload the updated data. However, doing so could frequently trigger expensive operations such as GPU waits, data readbacks, guest texture layout conversions, and memory-tracking updates. This would be particularly costly for textures that are updated every frame or during every compute dispatch.

For this reason, the fix does not require an immediate flush after every write. Instead, it extends Ryubing's existing TextureDependency and TextureGroupHandle mechanisms. When two fully incompatible textures map to exactly the same guest memory and satisfy a strict set of raw-copy requirements, the program creates a raw-copy dependency between them.

When the source texture is modified, the target texture is only marked as requiring a raw copy. The latest logical raw bytes are copied from the source only when the target texture is actually about to be used. This keeps the contents of the separate host texture aliases coherent while avoiding unnecessary round trips through guest memory.

https://github.com/Ryubing/Issues/issues/459

Trails in the Sky 1st uses texture descriptors with different formats and dimensions that map to the same region of guest GPU memory. For example, the game interprets the same underlying data as both an R32Uint 2x1 texture and an R32G32Float 1x1 texture. Both textures have an 8-byte logical payload, but their texel formats and dimensions are different. Ryubing cannot represent these two descriptors as normally compatible texture views, so it creates separate host texture objects for them. Since these host textures represent the same guest memory, a modification made to one of them should become visible to the other before the other texture is read. However, the existing synchronization mechanism does not fully handle this situation. The game uses this pattern for its exposure or brightness history. A compute shader first writes the updated exposure data to the R32G32Float 1x1 host texture. A later operation then reads the raw bits of the same data through the R32Uint 2x1 host texture. The original Ryubing implementation did not synchronize the contents of these two separate host textures. As a result, the reading texture received stale zero values, which caused the shader to calculate an incorrectly low exposure value and made the rendered image appear too dark. TextureGroup already has a guest-memory synchronization mechanism for incompatible overlaps. When _flushIncompatibleOverlaps is enabled, the most recent texture contents are written back to guest memory, after which the other texture reloads the data. However, this mechanism was primarily enabled through IsFormatHostIncompatible, which checks whether an individual texture format can be correctly supported by the host GPU. In this case, both R32Uint and R32G32Float are individually supported by the host GPU. Therefore, IsFormatHostIncompatible does not enable this synchronization path. The issue is not that either format is unsupported. The issue is that two individually supported aliases, represented by separate host textures, do not maintain coherent contents. In theory, the latest contents could be flushed to guest memory immediately after every GPU write to a host texture, allowing other textures that map to the same guest memory to reload the updated data. However, doing so could frequently trigger expensive operations such as GPU waits, data readbacks, guest texture layout conversions, and memory-tracking updates. This would be particularly costly for textures that are updated every frame or during every compute dispatch. For this reason, the fix does not require an immediate flush after every write. Instead, it extends Ryubing's existing TextureDependency and TextureGroupHandle mechanisms. When two fully incompatible textures map to exactly the same guest memory and satisfy a strict set of raw-copy requirements, the program creates a raw-copy dependency between them. When the source texture is modified, the target texture is only marked as requiring a raw copy. The latest logical raw bytes are copied from the source only when the target texture is actually about to be used. This keeps the contents of the separate host texture aliases coherent while avoiding unnecessary round trips through guest memory. https://github.com/Ryubing/Issues/issues/459
Member

Trails in the Sky: 1st Chapter plays as it should with this PR, at least from my testing. Previously, only the unpublished full bindless rendering branch fixed the darkening this game suffered from. This is a much more targeted solution.

Trails in the Sky: 1st Chapter plays as it should with this PR, at least from my testing. Previously, only the unpublished full bindless rendering branch fixed the darkening this game suffered from. This is a much more targeted solution.
LotP force-pushed fix/incompatible-texture-raw-copy from ddcd743079
All checks were successful
Pull Request Triage / triage (pull_request_target) Successful in 19s
Build PR / linux-arm64 (Release) (pull_request) Successful in 5m0s
Build PR / linux-x64 (Release) (pull_request) Successful in 8m31s
Build PR / win-arm64 (Release) (pull_request) Successful in 8m18s
Build PR / win-x64 (Release) (pull_request) Successful in 5m4s
Build PR / macOS Universal (Release) (pull_request) Successful in 9m53s
to 326bfc59e1
All checks were successful
Build PR / linux-arm64 (Release) (pull_request) Successful in 3m29s
Build PR / linux-x64 (Release) (pull_request) Successful in 6m30s
Build PR / win-x64 (Release) (pull_request) Successful in 5m33s
Build PR / win-arm64 (Release) (pull_request) Successful in 5m50s
Build PR / macOS Universal (Release) (pull_request) Successful in 4m32s
2026-08-24 17:58:21 +00:00
Compare
LotP force-pushed fix/incompatible-texture-raw-copy from 326bfc59e1
All checks were successful
Build PR / linux-arm64 (Release) (pull_request) Successful in 3m29s
Build PR / linux-x64 (Release) (pull_request) Successful in 6m30s
Build PR / win-x64 (Release) (pull_request) Successful in 5m33s
Build PR / win-arm64 (Release) (pull_request) Successful in 5m50s
Build PR / macOS Universal (Release) (pull_request) Successful in 4m32s
to 6f9f85013c
All checks were successful
Build PR / linux-arm64 (Release) (pull_request) Successful in 2m56s
Build PR / win-arm64 (Release) (pull_request) Successful in 5m27s
Build PR / linux-x64 (Release) (pull_request) Successful in 7m28s
Build PR / win-x64 (Release) (pull_request) Successful in 4m35s
Build PR / macOS Universal (Release) (pull_request) Successful in 3m55s
2026-08-24 20:29:39 +00:00
Compare
LotP merged commit 368a71c1b2 into master 2026-08-24 20:45:01 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
projects/Ryubing!181
No description provided.