nv2a: Scale Z by full depth range in inverse viewport transform

This commit is contained in:
Matt Borgerson 2023-10-21 16:46:41 -07:00 committed by mborgerson
parent d6e5342f89
commit 5fa08d20d6
1 changed files with 18 additions and 13 deletions

View File

@ -28,6 +28,9 @@
#include "ui/xemu-settings.h" #include "ui/xemu-settings.h"
#include "qemu/fast-hash.h" #include "qemu/fast-hash.h"
const float f16_max = 511.9375f;
const float f24_max = 1.0E30;
static NV2AState *g_nv2a; static NV2AState *g_nv2a;
GloContext *g_nv2a_context_render; GloContext *g_nv2a_context_render;
GloContext *g_nv2a_context_display; GloContext *g_nv2a_context_display;
@ -3493,10 +3496,6 @@ DEF_METHOD(NV097, CLEAR_SURFACE)
GLint gl_clear_stencil; GLint gl_clear_stencil;
GLfloat gl_clear_depth; GLfloat gl_clear_depth;
/* FIXME: Put these in some lookup table */
const float f16_max = 511.9375f;
const float f24_max = 1.0E30;
switch(pg->surface_shape.zeta_format) { switch(pg->surface_shape.zeta_format) {
case NV097_SET_SURFACE_FORMAT_ZETA_Z16: { case NV097_SET_SURFACE_FORMAT_ZETA_Z16: {
uint16_t z = clear_zstencil & 0xFFFF; uint16_t z = clear_zstencil & 0xFFFF;
@ -4180,8 +4179,18 @@ static void pgraph_shader_update_constants(PGRAPHState *pg,
*(float*)&pg->regs[NV_PGRAPH_FOGPARAM1]); *(float*)&pg->regs[NV_PGRAPH_FOGPARAM1]);
} }
float zclip_max = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMAX]; /* FIXME: Handle NV_PGRAPH_ZCLIPMIN, NV_PGRAPH_ZCLIPMAX */
float zclip_min = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMIN]; float zmax;
switch (pg->surface_shape.zeta_format) {
case NV097_SET_SURFACE_FORMAT_ZETA_Z16:
zmax = pg->surface_shape.z_format ? f16_max : (float)0xFFFF;
break;
case NV097_SET_SURFACE_FORMAT_ZETA_Z24S8:
zmax = pg->surface_shape.z_format ? f24_max : (float)0xFFFFFF;
break;
default:
assert(0);
}
if (fixed_function) { if (fixed_function) {
/* update lighting constants */ /* update lighting constants */
@ -4238,19 +4247,15 @@ static void pgraph_shader_update_constants(PGRAPHState *pg,
float m11 = 0.5 * (pg->surface_binding_dim.width/aa_width); float m11 = 0.5 * (pg->surface_binding_dim.width/aa_width);
float m22 = -0.5 * (pg->surface_binding_dim.height/aa_height); float m22 = -0.5 * (pg->surface_binding_dim.height/aa_height);
float m33 = zclip_max - zclip_min; float m33 = zmax;
float m41 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][0]; float m41 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][0];
float m42 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][1]; float m42 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][1];
float m43 = zclip_min;
if (m33 == 0.0) {
m33 = 1.0;
}
float invViewport[16] = { float invViewport[16] = {
1.0/m11, 0, 0, 0, 1.0/m11, 0, 0, 0,
0, 1.0/m22, 0, 0, 0, 1.0/m22, 0, 0,
0, 0, 1.0/m33, 0, 0, 0, 1.0/m33, 0,
-1.0+m41/m11, 1.0+m42/m22, -m43/m33, 1.0 -1.0+m41/m11, 1.0+m42/m22, 0, 1.0
}; };
if (binding->inv_viewport_loc != -1) { if (binding->inv_viewport_loc != -1) {
@ -4284,7 +4289,7 @@ static void pgraph_shader_update_constants(PGRAPHState *pg,
} }
if (binding->clip_range_loc != -1) { if (binding->clip_range_loc != -1) {
glUniform2f(binding->clip_range_loc, zclip_min, zclip_max); glUniform2f(binding->clip_range_loc, 0, zmax);
} }
/* Clipping regions */ /* Clipping regions */