xemu
xemu copied to clipboard
nv2a: Fix pixel center offset problem
This addresses the difference in pixel center between OpenGL and the DirectX 8 approach used by the hardware.
Note that the resultant behavior still does not fully match the hardware, where screen-space pixel coordinates below (x + 0.5625) => x, but it is close enough to fix issues with surface-target rendering. Test HW results With this patch, xemu will produce correct output for the render-target but will not fully match the geometry-based test output.
Fixes #725 Fixes #57
This appears to resolve shadow issues in 5451001a, but only at 1x scaling. On 2x or above, the behavior is the same as master.
Debated between posting here or in the issue, but this seems to be related to the code change so I opted to put it here.
This removes the edge bloom (top and left) present in Fable: The Lost Chapters. :+1:
Progression: artifacts on borders have disappeared for splinter cell double agent and chaos theory with this PR on native scaling:
Splinter cell 1 has been fixed, no more greenish bar on the right side
Still need to fix this at higher render scales, and I just found that it doesn't quite work correctly on M1 (at 0.5 there is already a red bar along the left side, though not along the top) so there may be some device/GL dependency to work through as well.
Also fixes Counter Strike
The current state of this PR also causes some corruption in certain games like Splinter Cell:Double Agent when combined with #879 (which unmasks the issue by allowing compounding errors).
In the pgraph test for #879, I see that there's a yellow column along the right hand side of the texture after it is drawn the second time. I suspect that this happens in games as well, leading textures that go through multiple phases of compositing to be smeared (this is exactly what @revix-0 has reported in SC:DA w/ this fix).
Here is a screenshot from xemu,
and this is the same screenshot zoomed in to look at the right column
Removing this PR and running #879 alone results in correct output.
It looks like there is differing behavior between cases where we are rendering to the framebuffer versus to a texture.
When rendering direct to the framebuffer, it appears to be correct that we should adjust the coordinate by flooring the (screenspace) output of the xbox vertex shader + 0.5625 to match hardware rounding behavior.
When rendering to a texture, it seems like even without this PR (and with any offset values I've tried) there is texture smearing, which makes me think that it's related to the way xemu handles render targets (it looks like it's being filtered rather than faithfully copied).
Here is an illustration of the problem. This screen is the result of compositing the left hand side of a texture on top of itself (leaving the right hand side as the initial value, a hand-defined checkerboard pattern that I've verified is correct by dumping the memory passed to glTexImage2D in pgraph_upload_surface_data
).
Whenever xemu does compositing, it does a partial pixel shift, despite the s2t_rndr being set up with correct coordinates and even if I force GL_NEAREST filtering. I'm not yet sure where the failure is coming from, but this is probably the root cause of the texture corruption that can be seen in combination with #879.
A note on debugging this: Unfortunately renderdoc seems to fail to capture interim states for some of the textures. If I take the hand-initialized texture and just render it to the standard color surface I can look at the input texture in renderdoc and confirm that it is as expected (a crisp checkerboard).
If I add a self-modifying step (input texture renders to a surface pointing at the same memory address), renderdoc ends up showing the final modification as the input stage, so it becomes very confusing as to whether the input texture was corrupted somehow (doesn't seem likely given the above check) or if renderdoc ends up updating its view of the texture after xemu updates it post-render. This step also corrupts the input (in renderdoc) for the test draw that is not self modifying it.
E.g.,
- Create texture manually
- Draw texture to normal color buffer. If you stop here and run in renderdoc, the input texture will be exactly as expected
- Draw texture to a surface at the same address as the texture (on HW this would literally render into itself). If you examine the input texture for this phase in renderdoc, it'll show the final (corrupted) output. If you examine the input texture for step 2 in renderdoc, it'll also show the corrupted output, indicating a problem with renderdoc's resolution (it seems to only correctly track the final state).
With nsight it's a bit more clear:
- When creating the initial texture from the surface, the result is correct (no smearing).
- When doing the first draw (rendering into the surface target) the smearing is introduced.
So I think we can rule out the s2t_rndr, but I'm still left wondering why we don't get consistently shifted results (e.g., if I don't render back into the surface at the same hwaddr as the texture, I get a pixel-aligned image).
It looks like the way xemu handles the WINDOW_CLIP commands may be incorrect, which also contributes to this problem (and may explain uninitialized data along the outer edges of surfaces)
WINDOW_CLIP
differences do not explain the behavior.
I have a fix that gets a pixel perfect match in my test case, but still breaks SC:DA (it does a bunch of downscaling + jitter to do lighting effects and with this fix the resultant overlay is misaligned compared to the plain framebuffer).
can you rebase this with master please so i can do more testing
@RyzenDew - it should've already been automatically mergable, but rebased anyway
fable is looking good but npc's weird outline is still a bit off just glad the white bits are gone
Note: The current state of this PR breaks the highlight texture generation in NFS MW (#890) where the low res version of the color buffer appears to suffer from a pixel offset issue. Applying this PR causes the output to be completely black.
Fixes Deus Ex Invisible War
@abaire This break the tiger wood 2005 as well as avatar the last air bender
https://user-images.githubusercontent.com/71127352/171655676-757e8c37-12df-4a16-87e1-74535386030e.mp4
Also Fixes C.A.T: Cyber Attack Team and Nobunaga no Yabou Ranseiki #598
This cause major z-fighting issues on most of the games I tested
Fixed Commandos Strike Force
Before
After
Also fixes Peter Jackson's King Kong The Official Game of the Movie
Before
After
And the Character Shadow
Before
After
Also fixes the Character Shadow in beat down
Before
After
Also Fixes Curse: The Eye of Isis Character Shadow
Before
After
Also Fixes Aeon Flux Character Shadow and screen border, but causes terrible z-fighting
Before
After
Fixes Crime Life: Gang Wars Character Shadow
Before
After
Fixes the text in AirForce Delta Storm
Before
After
Fixes Strike Force Bowling Character Shadow
Before
After
Fixes Without Warning Shadows