Skip to content

nv2a: Fix blend tests #1901

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

Draft
wants to merge 3 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
2 changes: 1 addition & 1 deletion hw/xbox/nv2a/pgraph/gl/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ static const GLenum pgraph_blend_equation_gl_map[] = {
GL_FUNC_ADD,
GL_MIN,
GL_MAX,
GL_FUNC_REVERSE_SUBTRACT,
GL_FUNC_ADD,
GL_FUNC_REVERSE_SUBTRACT,
};

/* FIXME
Expand Down
25 changes: 17 additions & 8 deletions hw/xbox/nv2a/pgraph/gl/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,6 @@ void pgraph_gl_draw_begin(NV2AState *d)

if (pgraph_reg_r(pg, NV_PGRAPH_BLEND) & NV_PGRAPH_BLEND_EN) {
glEnable(GL_BLEND);
uint32_t sfactor = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND),
NV_PGRAPH_BLEND_SFACTOR);
uint32_t dfactor = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND),
NV_PGRAPH_BLEND_DFACTOR);
assert(sfactor < ARRAY_SIZE(pgraph_blend_factor_gl_map));
assert(dfactor < ARRAY_SIZE(pgraph_blend_factor_gl_map));
glBlendFunc(pgraph_blend_factor_gl_map[sfactor],
pgraph_blend_factor_gl_map[dfactor]);

uint32_t equation = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND),
NV_PGRAPH_BLEND_EQN);
Expand All @@ -187,6 +179,23 @@ void pgraph_gl_draw_begin(NV2AState *d)
pgraph_argb_pack32_to_rgba_float(blend_color, gl_blend_color);
glBlendColor(gl_blend_color[0], gl_blend_color[1], gl_blend_color[2],
gl_blend_color[3]);
uint32_t sfactor = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND),
NV_PGRAPH_BLEND_SFACTOR);
uint32_t dfactor = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND),
NV_PGRAPH_BLEND_DFACTOR);
assert(sfactor < ARRAY_SIZE(pgraph_blend_factor_gl_map));
assert(dfactor < ARRAY_SIZE(pgraph_blend_factor_gl_map));

if (equation < 5) {
glBlendFunc(pgraph_blend_factor_gl_map[sfactor],
pgraph_blend_factor_gl_map[dfactor]);
} else {
glBlendFuncSeparate(pgraph_blend_factor_gl_map[3],
pgraph_blend_factor_gl_map[1],
pgraph_blend_factor_gl_map[sfactor],
pgraph_blend_factor_gl_map[dfactor]);
}

} else {
glDisable(GL_BLEND);
}
Expand Down
2 changes: 1 addition & 1 deletion hw/xbox/nv2a/pgraph/vk/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ static const VkBlendOp pgraph_blend_equation_vk_map[] = {
VK_BLEND_OP_ADD,
VK_BLEND_OP_MIN,
VK_BLEND_OP_MAX,
VK_BLEND_OP_REVERSE_SUBTRACT,
VK_BLEND_OP_ADD,
VK_BLEND_OP_REVERSE_SUBTRACT,
};

/* FIXME
Expand Down
42 changes: 27 additions & 15 deletions hw/xbox/nv2a/pgraph/vk/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,21 +909,6 @@ static void create_pipeline(PGRAPHState *pg)
if (pgraph_reg_r(pg, NV_PGRAPH_BLEND) & NV_PGRAPH_BLEND_EN) {
color_blend_attachment.blendEnable = VK_TRUE;

uint32_t sfactor =
GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND), NV_PGRAPH_BLEND_SFACTOR);
uint32_t dfactor =
GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND), NV_PGRAPH_BLEND_DFACTOR);
assert(sfactor < ARRAY_SIZE(pgraph_blend_factor_vk_map));
assert(dfactor < ARRAY_SIZE(pgraph_blend_factor_vk_map));
color_blend_attachment.srcColorBlendFactor =
pgraph_blend_factor_vk_map[sfactor];
color_blend_attachment.dstColorBlendFactor =
pgraph_blend_factor_vk_map[dfactor];
color_blend_attachment.srcAlphaBlendFactor =
pgraph_blend_factor_vk_map[sfactor];
color_blend_attachment.dstAlphaBlendFactor =
pgraph_blend_factor_vk_map[dfactor];

uint32_t equation =
GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND), NV_PGRAPH_BLEND_EQN);
assert(equation < ARRAY_SIZE(pgraph_blend_equation_vk_map));
Expand All @@ -935,6 +920,33 @@ static void create_pipeline(PGRAPHState *pg)

uint32_t blend_color = pgraph_reg_r(pg, NV_PGRAPH_BLENDCOLOR);
pgraph_argb_pack32_to_rgba_float(blend_color, blend_constant);

uint32_t sfactor = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND),
NV_PGRAPH_BLEND_SFACTOR);
uint32_t dfactor = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_BLEND),
NV_PGRAPH_BLEND_DFACTOR);
assert(sfactor < ARRAY_SIZE(pgraph_blend_factor_vk_map));
assert(dfactor < ARRAY_SIZE(pgraph_blend_factor_vk_map));

if (equation < 5) {
color_blend_attachment.srcColorBlendFactor =
pgraph_blend_factor_vk_map[sfactor];
color_blend_attachment.dstColorBlendFactor =
pgraph_blend_factor_vk_map[dfactor];
color_blend_attachment.srcAlphaBlendFactor =
pgraph_blend_factor_vk_map[sfactor];
color_blend_attachment.dstAlphaBlendFactor =
pgraph_blend_factor_vk_map[dfactor];
} else {
color_blend_attachment.srcColorBlendFactor =
pgraph_blend_factor_vk_map[3];
color_blend_attachment.dstColorBlendFactor =
pgraph_blend_factor_vk_map[1];
color_blend_attachment.srcAlphaBlendFactor =
pgraph_blend_factor_vk_map[sfactor];
color_blend_attachment.dstAlphaBlendFactor =
pgraph_blend_factor_vk_map[dfactor];
}
}

VkPipelineColorBlendStateCreateInfo color_blending = {
Expand Down