Skip to content

rsx: Fix unnormalized texture scale for 3D textures - #19779

Draft
digant73 wants to merge 1 commit into
RPCS3:masterfrom
digant73:fix_kz3_water
Draft

digant73 wants to merge 1 commit into
RPCS3:masterfrom
digant73:fix_kz3_water

Conversation

@digant73

@digant73 digant73 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Analysis and fix made by Opus 5.5. Tested by me.

Fixes the missing waves on water in Killzone 3 and Resistance 2 (#18250), a regression from #10637.
Tested in Killzone 3 and Resistance 2: waves are back.

fixes #18250

image

In upload_texture() the unnormalized coordinate scale was computed before the texture attributes were decoded, so for 3D textures attributes.depth was still 0 and scale.depth became infinite (every lookup sampled the same slice).

Changes (following the review):

  • the is_unnormalized block is moved after the dimension decode and validation, so all dimensions are valid; the registers are decoded only once;
  • the width scale divides by the width captured before the pitch fixup, because the pitch fixup already multiplies scale.width by packed_pitch / pitch; dividing by the fixed-up width would count that correction twice;
  • cubemaps are no longer scaled: their coordinates are a direction, and a non-uniform (1/W, 1/H, 1) scale would rotate it. Hardware behavior for unnormalized cubemaps is not verified.

The texcoord snapping workaround for the grid pattern visible on the waves (see screenshot above) has been removed from this PR. The grid is a separate issue (it was hidden while the depth scale was broken) and will be tracked on its own with hardware tests.

@digant73
digant73 marked this pull request as draft October 8, 2026 23:17

@kd-11 kd-11 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.

This fix stumbles across a real bug but doesn't fix it correctly. The one-liner in texture_cache.h is correct only for 3D textures.

  1. From a graphics programming POV, unnormalized cubemap textures don't really make sense. This needs to be probed if RSX throws or silently fails when trying to do this.
  2. The code section is supposed to force register decodes exactly one time. So the proper fix would have moved the is_unnormalized block below the attribute initialization block and changed initialization to use multiplication instead of assignment.
  3. The texcoord snapping hack is tricky. Note that only NVIDIA cards are affected by the texcoord rounding drift, and we don't even know for sure which generations are affected and which aren't. Tbh I think the hackfix was not the right solution, but that work needs a whole issue and a suite of hardware test scenarios (see #19778 for an example of what that looks like).
    The explanation given at the site doesn't make much sense to me - the texcoord transformation is internal, not visible to the original shader itself.

Textures on RSX have very limited dimensions, so as a start, perform a sweep of all possible values to identify these so-called thin-bands explicitly. There's only 4096 numbers to check which a python script can do trivially. The bias becomes very very tiny (min value = 0.00000244140625, encoded as 0.000002441406195...) and sampling is doing with point sampling. If there are edge cases found, the answer is obviously to simply adjust the subpixel bias until the platform passes.
FLR can be used to sample unnormalized ofc, but FRC cannot (it would always sample 0). Remember that this whole subpixel bias thing only exists for unnormalized (integer coords) textures and nearest sampling.

@digant73

digant73 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

thanks. Hopefully even this currently broken feature will be fixed soon. Consider that the changes in this PR fixed also the ripples on water also in Resistance 2. So probably it impacts also other Insomniac games

Apply the unnormalized coordinate scale after the texture attributes are
decoded, so the depth of 3D textures is known (it was 0, giving an
infinite depth scale). The width scale uses the decoded width captured
before the pitch fixup, which applies its own correction to the scale.
Cubemaps are left unscaled, since their coordinates are a direction.
@digant73 digant73 changed the title [NOT TO BE MERGED] rsx: Fix unnormalized 3D texture depth scale and point-sampled texel … rsx: Fix unnormalized texture scale for 3D textures Dec 3, 2026
@digant73

digant73 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@kd-11 updated following your review:

  • point 2: the is_unnormalized block now runs after the attribute decode/validation, with no second register decode. One detail: the width divides by the width captured before the pitch fixup (decoded_width), since that fixup already applies packed_pitch / pitch to scale.width; using the fixed-up attributes.width would apply the correction twice. Height is not changed by the fixup.
  • point 1: cubemaps are left unscaled for now. Cube coordinates go through the same TEX3D path and _texcoord_xform scales per component, so the previous (1/W, 1/H, 1) would rotate the direction. I have not hwtested unnormalized cubemaps yet.
  • point 3: the texcoord snapping hack is dropped from this PR. With only this fix the waves render again and the grid shows up, as expected; I will open a separate issue for it and look at the dimension sweep / subpixel bias tuning with hardware tests.

@github-actions github-actions Bot added the Beep bop 🤖 Written by AI. label Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Beep bop 🤖 Written by AI. RSX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Killzone 3, Resistance 2: Missing waves on water

3 participants