Skip to content

Commit

Permalink
More fixes for ZMinMaxControl tests
Browse files Browse the repository at this point in the history
Partially fixes fixed function, w-buffer, z cull tests
  • Loading branch information
polymetal0 committed Jan 19, 2025
1 parent a3747fa commit ef09148
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
30 changes: 24 additions & 6 deletions hw/xbox/nv2a/pgraph/glsl/vsh-ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,30 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
mstring_append(body, " oPos.z = oPos.z * 2.0 - oPos.w;\n");
}

if (state->z_perspective) {
mstring_append(body,
" if (oPos.w < 0.0) {\n"
" oPos.w = clamp(oPos.w, -1.884467e+019, -5.421011e-20);\n"
" } else {\n"
" oPos.w = clamp(oPos.w, 5.421011e-20, 1.884467e+019);\n"
" }\n");

mstring_append(body, " oPos.z = oPos.w;\n");

mstring_append(body, " if (clipRange.y != clipRange.x) {\n");
if (state->vulkan) {
mstring_append(body,
" oPos.z = (oPos.z - clipRange.z)/(clipRange.w - clipRange.z);\n");
} else {
mstring_append(body,
" oPos.z = (oPos.z - clipRange.z)/(0.5*(clipRange.w - clipRange.z)) - 1;\n");
}
mstring_append(body, " }\n");
if (state->z_perspective) {
mstring_append(body, " oPos.z *= oPos.w;\n");
}
}

/* FIXME: Testing */
if (state->point_params_enable) {
mstring_append_fmt(
Expand All @@ -446,12 +470,6 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
state->surface_scale_factor);
}

mstring_append(body,
" if (oPos.w < 0.0) {\n"
" oPos.w = clamp(oPos.w, -1.884467e+019, -5.421011e-20);\n"
" } else {\n"
" oPos.w = clamp(oPos.w, 5.421011e-20, 1.884467e+019);\n"
" }\n");
}

static void append_skinning_code(MString* str, bool mix,
Expand Down
22 changes: 12 additions & 10 deletions hw/xbox/nv2a/pgraph/glsl/vsh-prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <assert.h>

#include "hw/xbox/nv2a/pgraph/vsh.h"
#include "hw/xbox/nv2a/pgraph/shaders.h"
#include "common.h"
#include "vsh-prog.h"

Expand Down Expand Up @@ -795,13 +796,14 @@ static const char* vsh_header =
"}\n";

void pgraph_gen_vsh_prog_glsl(uint16_t version,
const uint32_t *tokens,
unsigned int length,
bool z_perspective,
bool texture,
bool vulkan,
const ShaderState *state,
MString *header, MString *body)
{
const uint32_t *tokens = (uint32_t *)state->program_data;
unsigned int length = state->program_length;
bool z_perspective = state->z_perspective;
bool texture = state->texture_perspective;
bool vulkan = state->vulkan;

mstring_append(header, vsh_header);

Expand Down Expand Up @@ -860,11 +862,11 @@ void pgraph_gen_vsh_prog_glsl(uint16_t version,

mstring_append(body,
" if (clipRange.y != clipRange.x) {\n");
if (vulkan) {
mstring_append(body, " oPos.z = (oPos.z - clipRange.z)/(clipRange.w - clipRange.z);\n");
} else {
mstring_append(body, " oPos.z = (oPos.z - clipRange.z)/(0.5*(clipRange.w - clipRange.z)) - 1;\n");
}
if (vulkan) {
mstring_append(body, " oPos.z = (oPos.z - clipRange.z)/(clipRange.w - clipRange.z);\n");
} else {
mstring_append(body, " oPos.z = (oPos.z - clipRange.z)/(0.5*(clipRange.w - clipRange.z)) - 1;\n");
}
mstring_append(body,
" }\n"
);
Expand Down
5 changes: 2 additions & 3 deletions hw/xbox/nv2a/pgraph/glsl/vsh-prog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#ifndef HW_XBOX_NV2A_PGRAPH_GLSL_VSH_PROG_H
#define HW_XBOX_NV2A_PGRAPH_GLSL_VSH_PROG_H

void pgraph_gen_vsh_prog_glsl(uint16_t version, const uint32_t *tokens,
unsigned int length, bool z_perspective, bool texture,
bool vulkan, MString *header, MString *body);
void pgraph_gen_vsh_prog_glsl(uint16_t version, const ShaderState *state,
MString *header, MString *body);

#endif
5 changes: 1 addition & 4 deletions hw/xbox/nv2a/pgraph/glsl/vsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ MString *pgraph_gen_vsh_glsl(const ShaderState *state, bool prefix_outputs)
if (state->fixed_function) {
pgraph_gen_vsh_ff_glsl(state, header, body, uniforms);
} else if (state->vertex_program) {
pgraph_gen_vsh_prog_glsl(VSH_VERSION_XVS,
(uint32_t *)state->program_data,
state->program_length, state->z_perspective, state->texture_perspective,
state->vulkan, header, body);
pgraph_gen_vsh_prog_glsl(VSH_VERSION_XVS, state, header, body);
} else {
assert(false);
}
Expand Down

0 comments on commit ef09148

Please sign in to comment.