Commit Graph

38 Commits

Author SHA1 Message Date
Matt Borgerson c3a8b9569f nv2a: Simplify surface clip to scissor size calculation 2025-03-17 14:48:47 -07:00
Logan Stromberg 860bccb722
nv2a: Fix surface clip to scissor origin 2025-03-17 14:32:40 -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 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
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 58c1daf594 nv2a/vk: Report dirty if no pipeline is bound 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 974b2be87a nv2a/vk: Add command buffer region debug markers 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 ca42f0f2df nv2a/vk: Clear in separate renderpass for now 2024-12-31 01:37:05 -07:00
Matt Borgerson 31db8d04b0 nv2a/vk: Ensure queries do not include clears 2024-12-31 01:37:05 -07:00
Matt Borgerson 2f910eeacf nv2a/vk: Fixup unaligned attribute data in inline buffer 2024-12-31 01:37:05 -07:00
Matt Borgerson 3096f2a9c8 nv2a/vk: Always bind fragment shader in draw pipeline 2024-12-31 01:37:05 -07:00
Matt Borgerson a2b994d80d nv2a/vk: Only bind clear fragment shader on partial color clear 2024-12-31 01:37:05 -07:00
Matt Borgerson 6ba917fed9 nv2a/vk: Fix clear scissor ymin 2024-12-31 01:37:05 -07:00
Matt Borgerson 605605d0da nv2a/vk: Fix scissor overflow 2024-12-31 01:37:05 -07:00
Matt Borgerson 5a6b8a14da nv2a/vk: Only clear stencil on images with stencil aspect 2024-12-31 01:37:05 -07:00
Matt Borgerson e20a2b15b3 nv2a/vk: Don't release textures until after draw completes 2024-12-31 01:37:05 -07:00
Matt Borgerson 1fec4947b6 nv2a/vk: Ensure clear rect never extends beyond surface 2024-12-31 01:37:05 -07:00
Matt Borgerson 374eada8ef nv2a/vk: Ensure pg->clearing set before pgraph_vk_surface_update 2024-12-31 01:37:05 -07:00
Matt Borgerson fc803fe375 nv2a/vk: Omit pipeline fragment shader when no color binding 2024-12-31 01:37:05 -07:00
Matt Borgerson dd3bb50f11 nv2a/vk: Tighten renderpass dependencies 2024-12-31 01:37:05 -07:00
Matt Borgerson 177dcc7559 nv2a/vk: Clear render_passes on finalization 2024-12-31 01:37:05 -07:00
Matt Borgerson c41853a3f3 nv2a/vk: Finish when queue is empty 2024-12-31 01:37:05 -07:00
Matt Borgerson da1e72a39a nv2a/vk: Use additional descriptor sets in compute ops 2024-12-31 01:37:05 -07:00
Matt Borgerson 7b37a94438 nv2a/vk: Finalize, simplify render passes 2024-12-31 01:37:05 -07:00
Matt Borgerson a80cfc8573 nv2a/vk: Don't call vkCmdBindVertexBuffers if 0 bindings 2024-12-31 01:37:05 -07:00
Matt Borgerson b0e3d00a5d nv2a/vk: Drop fragment shader when only depth attachment is cleared 2024-12-31 01:37:05 -07:00
Matt Borgerson 126a51724b nv2a/vk: Finalize clear shaders 2024-12-31 01:37:05 -07:00
Matt Borgerson 89db9590f7 nv2a/vk: Flush vertex ram buffer, insert barrier 2024-12-31 01:37:05 -07:00
Matt Borgerson 9ab8549a4e nv2a/vk: Insert barrier after staging buffer copies 2024-12-31 01:37:05 -07:00
Matt Borgerson 1a57d4ae94 nv2a/vk: Fix finish queue submission semaphore wait stage 2024-12-31 01:37:05 -07:00
Matt Borgerson 0169caadd0 nv2a/vk: Fallback to UBO if maxPushConstantsSize is insufficient 2024-12-31 01:37:05 -07:00
Matt Borgerson 1973ed7f58 n2va/vk: Drop debug message 2024-12-31 01:37:05 -07:00
Matt Borgerson a5385803db nv2a: Add Vulkan renderer 2024-12-31 01:37:05 -07:00