Commit Graph

149 Commits

Author SHA1 Message Date
coldhex 3eb22b6b81 nv2a: Explicit float representation for RCC and vertex shader W range 2025-03-08 14:54:18 -07:00
coldhex 63cb75ce84 nv2a: Fix -0.0 clamping of RCC instruction and vertex shader W-output
Xbox rounds -0.0 to the negative range and 0.0 to the positive range. This
commit also restores RCC instruction clamping to be done on the output of
reciprocal calculation (which current Xemu release does) with fix for the
input=Infinity case.
2025-03-08 14:54:18 -07:00
coldhex 8dc6c90e11 nv2a/vk: Drop unnecessary dirty check for NV_PGRAPH_ZCOMPRESSOCCLUDE
This was used to enable/disable Vulkan depth clamping, but that was
removed in previous commit.
2025-03-08 14:54:18 -07:00
coldhex 854a001063 nv2a: Fix zero-vector input in fixed function vertex shader
If tPosition is a zero-vector, then invViewport matrix had no effect.
Bounding w-coordinate away from zero and infinity must be done before
applying invViewport (which is needed for OpenGL/Vulkan) to emulate
Xbox hardware behaviour properly.
2025-03-08 14:54:18 -07:00
coldhex 798ad30819 nv2a: Perspective-correct interpolation for w-buffering
z_perspective is true implies w-buffering and then the w-coordinate stored
in the depth buffer should also be interpolated in a perspective-correct
way. We do this by calculating w and setting gl_FragDepth in the fragment
shader.

Since enabling polygon offset and setting values using glPolygonOffset
won't have any effect when manually setting gl_FragDepth for w-buffering,
we introduce the depthOffset variable to obtain similar behaviour (but the
glPolygonOffset factor-argument is currently not emulated.) (Note that
glPolygonOffset is OpenGL implementation-dependent and it might be good to
use depthOffset for z-buffering as well, but this is not done here and we
still use OpenGL/Vulkan zbias functionality.)

This also implements depth clipping and clamping in the fragment shader.
If triangles are clipped, the shadows of the small rocks in Halo 2 Beaver
Creek map can have flickering horizontal lines. The shadows are drawn on
the ground in another pass with the same models as for the ground, but for
some reason with depth clamping enabled. The flickering happens if Xemu
clips the ground triangles, but the exact same shadow triangles are depth
clamped, so there are small differences in the coordinates. The shadows
are drawn with depth function GL_EQUAL so there is no tolerance for any
differences. Clipping in the fragment shader solves the problem because
the ground and shadow triangles remain exactly the same regardless of
depth clipping/clamping. For some performance gain, it might be a good
idea to cull triangles by depth in the geometry shader, but this is not
implemented here.

In the programmable vertex shader we always multiply position output by w
because this improves numerical stability in subsequent floating point
computations by modern GPUs. This usually means that the perspective
divide done by the vertex program gets undone.

The magic bounding constants 5.42101e-020 and 1.884467e+019 are replaced
by 5.421011e-20 and 1.8446744e19, i.e. more decimals added. This makes the
32-bit floating point numbers represent exactly 2^(-64) and 2^64 (raw bits
0x1f800000 and 0x5f800000) which seem more likely the correct values
although testing with hardware was not done to this precision.

Testing indicates that the same RCC instruction magic constants are also
applied to both fixed function and programmable vertex shader w-coordinate
output. This bounding replaces the special test for w==0.0 and abs(w)==inf
which used to set vtx_inv_w=1.0 (which did not match Xbox hardware
behaviour.)
2025-03-08 14:54:18 -07:00
Erik Abair f701573d44 nv2a: Use rounded values for alpha testing 2025-03-05 17:12:14 -07:00
Matt Borgerson 7cb7bb68a9 nv2a: Multiversion [un]swizzle to optimize for common bpp 2025-01-26 18:47:46 -07:00
Matt Borgerson eae328dc19 nv2a: Move [un]swizzle_rect to swizzle.h 2025-01-26 18:47:46 -07:00
Matt Borgerson bb5ee6865b nv2a: Drop osdep.h, add stdbool.h to swizzle.c 2025-01-26 18:47:46 -07:00
NZJenkins ae4b5c0695
nv2a: Speed up software swizzling 2025-01-26 14:00:35 -07:00
Matt Borgerson 7eba0d3124 nv2a/gl: Update copyright on recently modified files 2025-01-07 17:37:06 -07:00
Matt Borgerson 510c280b05 nv2a/gl: Unify ShaderBinding and ShaderLruNode 2025-01-07 17:35:06 -07:00
Matt Borgerson 6c389194b6 nv2a/psh: Remove unused arguments in string format 2025-01-07 00:52:51 -07:00
Matt Borgerson d76898f63b nv2a: Fix variable shadowing complaints 2025-01-07 00:52:51 -07:00
Matt Borgerson 57c6d82fa3 nv2a/vk: Simplify debug indent loop to a variable field width format 2025-01-07 00:52:51 -07:00
Matt Borgerson 6ac52147a4 nv2a/psh: Remove function scope variable i, which was being shadowed 2025-01-07 00:52:51 -07:00
Matt Borgerson 3070d6422c mstring: Remove mstring_append_{int,char} 2025-01-07 00:52:51 -07:00
Matt Borgerson 0e50741c28 ui,xbox: Copyright updates on changed files 2025-01-06 23:06:21 -07:00
Matt Borgerson 75ce25c9b5 nv2a: Define DEBUG_NV2A_*=0 ifndef 2025-01-06 23:05:53 -07:00
Matt Borgerson 3106ea97e5 mcpx: Use new bql_[un]lock functions 2025-01-06 23:05:53 -07:00
Matt Borgerson 5cb65d1791 nv2a: Migrate nv2a_get_offsets to new _get_params model 2025-01-06 23:05:53 -07:00
Matt Borgerson 824af3978f meson: Migrate nv2a_vsh_cpu submodule to a subproject 2025-01-02 19:07:25 -07:00
Matt Borgerson 8f478e017a nv2a/psh: Handle 3D textures in BUMPENVMAP[_LUM] modes 2024-12-31 03:17:52 -07:00
Matt Borgerson b6d6a4709d nv2a/gl: Use snake case for line width ranges 2024-12-31 01:37:05 -07:00
Matt Borgerson e67f19d03b nv2a/vk,gl: Fix a couple 64b shift/printing bugs 2024-12-31 01:37:05 -07:00
Matt Borgerson ae3fe91223 nv2a/gl: Rebase line width feature 2024-12-31 01:37:05 -07:00
Matt Borgerson fb7feb7b1f nv2a/vk: Fix missing display surface addr in debug marker 2024-12-31 01:37:05 -07:00
Matt Borgerson 4a09eeb121 nv2a/vk: Use unsigned types for clear scissor calculation for now 2024-12-31 01:37:05 -07:00
Matt Borgerson 1e5cae068a nv2a/vk: Drop unused vertex_buffer_inline field 2024-12-31 01:37:05 -07:00
Matt Borgerson 477d5489ac nv2a/vk: Copy remapped vert data after pre-draw 2024-12-31 01:37:05 -07:00
Matt Borgerson 28c9f5f6ef nv2a/vk: Load 16b float depth textures as unorm to match surface w/a 2024-12-31 01:37:05 -07:00
Matt Borgerson c098b82108 nv2a/vk: VK_CHECK call to vkBindImageMemory 2024-12-31 01:37:05 -07:00
Matt Borgerson 085fb33141 nv2a/vk: Fix external memory handle type on Windows 2024-12-31 01:37:05 -07:00
Matt Borgerson 88835a1019 nv2a/vk,gl: Handle case where pline_offset == 0 2024-12-31 01:37:05 -07:00
Matt Borgerson 58c1daf594 nv2a/vk: Report dirty if no pipeline is bound 2024-12-31 01:37:05 -07:00
Matt Borgerson 8dc3b646a3 nv2a/vk: Move display GL compat after line_offset adjust 2024-12-31 01:37:05 -07:00
Matt Borgerson 7afeda5da0 nv2a/vk: Add regs control_{0,3}, setupraster to shader dirty test 2024-12-31 01:37:05 -07:00
Matt Borgerson 4cd4153937 nv2a/vk: Move reg dirty clear into create_pipeline 2024-12-31 01:37:05 -07:00
Matt Borgerson de1381c932 nv2a/vk: Drop pipeline merge stat 2024-12-31 01:37:05 -07:00
Matt Borgerson 986b18214c nv2a/vk: Drop display update early-out 2024-12-31 01:37:05 -07:00
Matt Borgerson 974b2be87a nv2a/vk: Add command buffer region debug markers 2024-12-31 01:37:05 -07:00
Matt Borgerson c7f82ab79f nv2a/gl: Fix bind_shaders dgroup 2024-12-31 01:37:05 -07:00
Matt Borgerson 580c2e9da4 nv2a/vk: Run full dirty texture check 2024-12-31 01:37:05 -07:00
Matt Borgerson 5527e908b7 nv2a/vk: Process pending surface upload just in time for display 2024-12-31 01:37:05 -07:00
Matt Borgerson e5be3f2714 nv2a/vk: Add missing math.h include 2024-12-31 01:37:05 -07:00
Matt Borgerson d054b366f8 nv2a/vk: Add pvideo support 2024-12-31 01:37:05 -07:00
Matt Borgerson f26b8c32d6 n2va/vk: Key textures on sampler state for now 2024-12-31 01:37:05 -07:00
Matt Borgerson 69b5318cb5 nv2a/vk: Fix create_pipeline debug marker inbalance 2024-12-31 01:37:05 -07:00
Matt Borgerson 9ab1f96911 nv2a/vk: Make pgraph_vk_insert_debug_marker format strings 2024-12-31 01:37:05 -07:00
Matt Borgerson ca42f0f2df nv2a/vk: Clear in separate renderpass for now 2024-12-31 01:37:05 -07:00