Skip to content

Commit

Permalink
pvr: allow blending for opaque polys of list continuations
Browse files Browse the repository at this point in the history
Fixes Crackin'DJ invisible background animation and Monkey Ball grey map
background.
  • Loading branch information
flyinghead committed Jan 23, 2024
1 parent 70a69cf commit 88fd264
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 56 deletions.
17 changes: 17 additions & 0 deletions core/hw/pvr/ta_vtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,15 @@ static void ta_parse_vdrc(TA_context* ctx, bool primRestart)
break;
}

// Disable blending for opaque polys of the first pass
if (pass == 0)
{
for (PolyParam& pp : vd_rc.global_param_op) {
pp.tsp.DstInstr = 0;
pp.tsp.SrcInstr = 1;
}
}

bool empty_pass = vd_rc.global_param_op.size() == (pass == 0 ? 0u : (int)vd_rc.render_passes.back().op_count)
&& vd_rc.global_param_pt.size() == (pass == 0 ? 0u : (int)vd_rc.render_passes.back().pt_count)
&& vd_rc.global_param_tr.size() == (pass == 0 ? 0u : (int)vd_rc.render_passes.back().tr_count);
Expand Down Expand Up @@ -1284,6 +1293,14 @@ static void ta_parse_naomi2(TA_context* ctx, bool primRestart)
for (RenderPass& pass : ctx->rend.render_passes)
{
parseRenderPass(pass, previousPass, ctx->rend, primRestart);
// Disable blending for opaque polys of the first pass
if (&pass == &ctx->rend.render_passes[0])
{
for (PolyParam& pp : ctx->rend.global_param_op) {
pp.tsp.DstInstr = 0;
pp.tsp.SrcInstr = 1;
}
}
previousPass = pass;
}

Expand Down
5 changes: 1 addition & 4 deletions core/rend/dx11/dx11_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,7 @@ void DX11Renderer::setRenderState(const PolyParam *gp)
}

// Apparently punch-through polys support blending, or at least some combinations
if (Type == ListType_Translucent || Type == ListType_Punch_Through)
deviceContext->OMSetBlendState(blendStates.getState(true, gp->tsp.SrcInstr, gp->tsp.DstInstr), nullptr, 0xffffffff);
else
deviceContext->OMSetBlendState(blendStates.getState(false, gp->tsp.SrcInstr, gp->tsp.DstInstr), nullptr, 0xffffffff);
deviceContext->OMSetBlendState(blendStates.getState(true, gp->tsp.SrcInstr, gp->tsp.DstInstr), nullptr, 0xffffffff);

setCullMode(gp->isp.CullMode);

Expand Down
8 changes: 2 additions & 6 deletions core/rend/dx11/oit/dx11_oitrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,9 @@ struct DX11OITRenderer : public DX11Renderer
}

if (pass == DX11OITShaders::Color)
{
// Apparently punch-through polys support blending, or at least some combinations
if (Type == ListType_Translucent || Type == ListType_Punch_Through)
deviceContext->OMSetBlendState(blendStates.getState(true, gp->tsp.SrcInstr, gp->tsp.DstInstr), nullptr, 0xffffffff);
else
deviceContext->OMSetBlendState(blendStates.getState(false, gp->tsp.SrcInstr, gp->tsp.DstInstr), nullptr, 0xffffffff);
}
deviceContext->OMSetBlendState(blendStates.getState(true, gp->tsp.SrcInstr, gp->tsp.DstInstr), nullptr, 0xffffffff);

if (useTexture)
{
for (int i = 0; i < 2; i++)
Expand Down
10 changes: 3 additions & 7 deletions core/rend/dx9/d3d_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,8 @@ void D3DRenderer::setGPState(const PolyParam *gp)
}

// Apparently punch-through polys support blending, or at least some combinations
if (Type == ListType_Translucent || Type == ListType_Punch_Through)
{
devCache.SetRenderState(D3DRS_SRCBLEND, SrcBlendGL[gp->tsp.SrcInstr]);
devCache.SetRenderState(D3DRS_DESTBLEND, DstBlendGL[gp->tsp.DstInstr]);
}
devCache.SetRenderState(D3DRS_SRCBLEND, SrcBlendGL[gp->tsp.SrcInstr]);
devCache.SetRenderState(D3DRS_DESTBLEND, DstBlendGL[gp->tsp.DstInstr]);

devCache.SetRenderState(D3DRS_CULLMODE, CullMode[gp->isp.CullMode]);

Expand Down Expand Up @@ -768,11 +765,10 @@ void D3DRenderer::drawStrips()
{
devCache.SetRenderState(D3DRS_STENCILENABLE, FALSE);
}
devCache.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
devCache.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

drawList<ListType_Opaque, false>(pvrrc.global_param_op, previous_pass.op_count, op_count);

devCache.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
devCache.SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
devCache.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
devCache.SetRenderState(D3DRS_ALPHAREF, PT_ALPHA_REF & 0xFF);
Expand Down
2 changes: 1 addition & 1 deletion core/rend/gl4/gldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void SetGPState(const PolyParam* gp)
gl4ShaderUniforms.tcw1 = gp->tcw1;
gl4ShaderUniforms.Set(CurrentShader);

if (pass == Pass::Color && (Type == ListType_Translucent || Type == ListType_Punch_Through))
if (pass == Pass::Color)
{
glcache.Enable(GL_BLEND);
glcache.BlendFunc(SrcBlendGL[gp->tsp.SrcInstr], DstBlendGL[gp->tsp.DstInstr]);
Expand Down
10 changes: 3 additions & 7 deletions core/rend/gles/gldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,9 @@ void SetGPState(const PolyParam* gp,u32 cflip=0)
}

// Apparently punch-through polys support blending, or at least some combinations
if (Type == ListType_Translucent || Type == ListType_Punch_Through)
{
glcache.Enable(GL_BLEND);
glcache.BlendFunc(SrcBlendGL[gp->tsp.SrcInstr],DstBlendGL[gp->tsp.DstInstr]);
}
else
glcache.Disable(GL_BLEND);
// Opaque polygons support blending in list continuations (wild guess)
glcache.Enable(GL_BLEND);
glcache.BlendFunc(SrcBlendGL[gp->tsp.SrcInstr],DstBlendGL[gp->tsp.DstInstr]);

//set cull mode !
//cflip is required when exploding triangles for triangle sorting
Expand Down
2 changes: 1 addition & 1 deletion core/rend/vulkan/oit/oit_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void OITPipelineManager::CreatePipeline(u32 listType, bool autosort, const PolyP
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState;
vk::ColorComponentFlags colorComponentFlags(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA);
// Apparently punch-through polys support blending, or at least some combinations
if (listType == ListType_Punch_Through || (listType == ListType_Translucent && pass == Pass::Color))
if (listType == ListType_Punch_Through || pass == Pass::Color)
{
u32 src = pp.tsp.SrcInstr;
u32 dst = pp.tsp.DstInstr;
Expand Down
43 changes: 13 additions & 30 deletions core/rend/vulkan/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,38 +342,21 @@ void PipelineManager::CreatePipeline(u32 listType, bool sortTriangles, const Pol

// Color flags and blending
vk::ColorComponentFlags colorComponentFlags(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA);
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState;
// Apparently punch-through polys support blending, or at least some combinations
if (listType == ListType_Translucent || listType == ListType_Punch_Through)
// Opaque polygons support blending in list continuations (wild guess)
u32 src = pp.tsp.SrcInstr;
u32 dst = pp.tsp.DstInstr;
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState
{
u32 src = pp.tsp.SrcInstr;
u32 dst = pp.tsp.DstInstr;
pipelineColorBlendAttachmentState =
{
true, // blendEnable
getBlendFactor(src, true), // srcColorBlendFactor
getBlendFactor(dst, false), // dstColorBlendFactor
vk::BlendOp::eAdd, // colorBlendOp
getBlendFactor(src, true), // srcAlphaBlendFactor
getBlendFactor(dst, false), // dstAlphaBlendFactor
vk::BlendOp::eAdd, // alphaBlendOp
colorComponentFlags // colorWriteMask
};
}
else
{
pipelineColorBlendAttachmentState =
{
false, // blendEnable
vk::BlendFactor::eZero, // srcColorBlendFactor
vk::BlendFactor::eZero, // dstColorBlendFactor
vk::BlendOp::eAdd, // colorBlendOp
vk::BlendFactor::eZero, // srcAlphaBlendFactor
vk::BlendFactor::eZero, // dstAlphaBlendFactor
vk::BlendOp::eAdd, // alphaBlendOp
colorComponentFlags // colorWriteMask
};
}
true, // blendEnable
getBlendFactor(src, true), // srcColorBlendFactor
getBlendFactor(dst, false), // dstColorBlendFactor
vk::BlendOp::eAdd, // colorBlendOp
getBlendFactor(src, true), // srcAlphaBlendFactor
getBlendFactor(dst, false), // dstAlphaBlendFactor
vk::BlendOp::eAdd, // alphaBlendOp
colorComponentFlags // colorWriteMask
};

vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo
(
Expand Down

0 comments on commit 88fd264

Please sign in to comment.