From 989dbcc76d04edabcfe99e2f54dd778d86b62818 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Tue, 10 May 2022 06:40:45 -0700 Subject: [PATCH] nv2a: Match HW behavior when setting window clip --- hw/xbox/nv2a/pgraph.c | 15 ++++++++++----- hw/xbox/nv2a/psh.c | 10 ++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hw/xbox/nv2a/pgraph.c b/hw/xbox/nv2a/pgraph.c index e877ad4962..22811f54d6 100644 --- a/hw/xbox/nv2a/pgraph.c +++ b/hw/xbox/nv2a/pgraph.c @@ -1507,13 +1507,17 @@ DEF_METHOD(NV097, SET_WINDOW_CLIP_TYPE) DEF_METHOD_INC(NV097, SET_WINDOW_CLIP_HORIZONTAL) { int slot = (method - NV097_SET_WINDOW_CLIP_HORIZONTAL) / 4; - pg->regs[NV_PGRAPH_WINDOWCLIPX0 + slot * 4] = parameter; + for (; slot < 8; ++slot) { + pg->regs[NV_PGRAPH_WINDOWCLIPX0 + slot * 4] = parameter; + } } DEF_METHOD_INC(NV097, SET_WINDOW_CLIP_VERTICAL) { int slot = (method - NV097_SET_WINDOW_CLIP_VERTICAL) / 4; - pg->regs[NV_PGRAPH_WINDOWCLIPY0 + slot * 4] = parameter; + for (; slot < 8; ++slot) { + pg->regs[NV_PGRAPH_WINDOWCLIPY0 + slot * 4] = parameter; + } } DEF_METHOD(NV097, SET_ALPHA_TEST_ENABLE) @@ -4075,6 +4079,7 @@ static void pgraph_shader_update_constants(PGRAPHState *pg, } /* Clipping regions */ + int max_gl_height = pg->surface_binding_dim.height - 1; for (i = 0; i < 8; i++) { uint32_t x = pg->regs[NV_PGRAPH_WINDOWCLIPX0 + i * 4]; unsigned int x_min = GET_MASK(x, NV_PGRAPH_WINDOWCLIPX0_XMIN); @@ -4086,9 +4091,9 @@ static void pgraph_shader_update_constants(PGRAPHState *pg, pgraph_apply_anti_aliasing_factor(pg, &x_max, &y_max); /* Translate for the GL viewport origin */ - unsigned int y_min_xlat = MAX(pg->surface_binding_dim.height - y_max - 1, 0); - unsigned int y_max_xlat = MIN(pg->surface_binding_dim.height - y_min - 1, - pg->surface_binding_dim.height); + unsigned int y_min_xlat = MAX(max_gl_height - (int)y_max, 0); + unsigned int y_max_xlat = MIN(max_gl_height - (int)y_min, max_gl_height); + pgraph_apply_scaling_factor(pg, &x_min, &y_min_xlat); pgraph_apply_scaling_factor(pg, &x_max, &y_max_xlat); diff --git a/hw/xbox/nv2a/psh.c b/hw/xbox/nv2a/psh.c index bb70ee1cb9..9a7b1de649 100644 --- a/hw/xbox/nv2a/psh.c +++ b/hw/xbox/nv2a/psh.c @@ -652,10 +652,12 @@ static MString* psh_convert(struct PixelShader *ps) if (!ps->state.window_clip_exclusive) { mstring_append(clip, "bool clipContained = false;\n"); } - mstring_append(clip, "for (int i = 0; i < 8; i++) {\n" - " bvec4 clipTest = bvec4(lessThan(gl_FragCoord.xy-0.5, vec2(clipRegion[i].xy)),\n" - " greaterThan(gl_FragCoord.xy-0.5, vec2(clipRegion[i].zw)));\n" - " if (!any(clipTest)) {\n"); + mstring_append(clip, "vec2 coord = gl_FragCoord.xy - 0.5;\n" + "for (int i = 0; i < 8; i++) {\n" + " bool outside = any(bvec4(\n" + " lessThan(coord, vec2(clipRegion[i].xy)),\n" + " greaterThan(coord, vec2(clipRegion[i].zw))));\n" + " if (!outside) {\n"); if (ps->state.window_clip_exclusive) { mstring_append(clip, " discard;\n"); } else {