Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nv2a: Handle NaN values to be similar to HW #1780

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/build/
/.cache/
/.vscode/
/.vs/
*.pyc
.sdk
.stgit-*
Expand All @@ -22,7 +23,8 @@ GTAGS
*.gcov

build.log
/dist
/dist/
/ccache/
/xemu.ini
/macos-libs/
/macos-pkgs/
Expand Down
32 changes: 23 additions & 9 deletions hw/xbox/nv2a/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,20 @@ GLSL_DEFINE(texMat3, GLSL_C_MAT4(NV_IGRAPH_XF_XFCTX_T3MAT))
i, i);
}
}
mstring_append(header,
"/* Converts the input to vec4, pads with last component */\n"
"vec4 _in(float v) { return vec4(v); }\n"
"vec4 _in(vec2 v) { return v.xyyy; }\n"
"vec4 _in(vec3 v) { return v.xyzz; }\n"
"vec4 _in(vec4 v) { return v.xyzw; }\n"
"#define FixNaN(src, mask) _FixNaN(_in(src)).mask\n"
"vec4 _FixNaN(vec4 src)\n"
"{\n"
" if (any(isnan(src))) {\n"
" return mix(src, vec4(1.0), isnan(src));\n"
" }\n"
" return src;\n"
"}\n");
mstring_append(header, "\n");

MString *body = mstring_from_str("void main() {\n");
Expand Down Expand Up @@ -965,15 +979,15 @@ GLSL_DEFINE(texMat3, GLSL_C_MAT4(NV_IGRAPH_XF_XFCTX_T3MAT))
/* Set outputs */
const char *shade_model_mult = state->smooth_shading ? "vtx_inv_w" : "vtx_inv_w_flat";
mstring_append_fmt(body, "\n"
" vtxD0 = clamp(oD0, 0.0, 1.0) * %s;\n"
" vtxD1 = clamp(oD1, 0.0, 1.0) * %s;\n"
" vtxB0 = clamp(oB0, 0.0, 1.0) * %s;\n"
" vtxB1 = clamp(oB1, 0.0, 1.0) * %s;\n"
" vtxFog = oFog.x * vtx_inv_w;\n"
" vtxT0 = oT0 * vtx_inv_w;\n"
" vtxT1 = oT1 * vtx_inv_w;\n"
" vtxT2 = oT2 * vtx_inv_w;\n"
" vtxT3 = oT3 * vtx_inv_w;\n"
" vtxD0 = clamp(FixNaN(oD0, xyzw), 0.0, 1.0) * %s;\n"
" vtxD1 = clamp(FixNaN(oD1, xyzw), 0.0, 1.0) * %s;\n"
" vtxB0 = clamp(FixNaN(oB0, xyzw), 0.0, 1.0) * %s;\n"
" vtxB1 = clamp(FixNaN(oB1, xyzw), 0.0, 1.0) * %s;\n"
" vtxFog = FixNaN(oFog, x) * vtx_inv_w;\n"
" vtxT0 = FixNaN(oT0, xyzw) * vtx_inv_w;\n"
" vtxT1 = FixNaN(oT1, xyzw) * vtx_inv_w;\n"
" vtxT2 = FixNaN(oT2, xyzw) * vtx_inv_w;\n"
" vtxT3 = FixNaN(oT3, xyzw) * vtx_inv_w;\n"
" gl_Position = oPos;\n"
" gl_PointSize = oPts.x;\n"
" gl_ClipDistance[0] = oPos.z - oPos.w*clipRange.z;\n" // Near
Expand Down
11 changes: 0 additions & 11 deletions hw/xbox/nv2a/vsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,17 +614,6 @@ static const char* vsh_header =
* https://www.opengl.org/registry/specs/NV/vertex_program1_1.txt
*/
"\n"
//QQQ #ifdef NICE_CODE
"/* Converts the input to vec4, pads with last component */\n"
"vec4 _in(float v) { return vec4(v); }\n"
"vec4 _in(vec2 v) { return v.xyyy; }\n"
"vec4 _in(vec3 v) { return v.xyzz; }\n"
"vec4 _in(vec4 v) { return v.xyzw; }\n"
//#else
// "/* Make sure input is always a vec4 */\n"
// "#define _in(v) vec4(v)\n"
//#endif
"\n"
"#define INFINITY (1.0 / 0.0)\n"
"\n"
"#define MOV(dest, mask, src) dest.mask = _MOV(_in(src)).mask\n"
Expand Down