Skip to content

Commit

Permalink
nv2a: Match HW behavior when setting window clip
Browse files Browse the repository at this point in the history
  • Loading branch information
abaire authored and mborgerson committed May 10, 2022
1 parent 6f3470a commit 989dbcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 10 additions & 5 deletions hw/xbox/nv2a/pgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions hw/xbox/nv2a/psh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 989dbcc

Please sign in to comment.