Skip to content

Commit

Permalink
Vulkan: Use mip levels for drawing when they are static.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Nov 23, 2023
1 parent 6e5f4b4 commit f7813a9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
59 changes: 57 additions & 2 deletions Source/gs/GSH_Vulkan/GSH_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,11 @@ void CGSH_Vulkan::SetRenderingContext(uint64 primReg)

uint32 fbWriteMask = ~frame.nMask;

uint32 texBufPtr = tex0.GetBufPtr();
uint32 texBufWidth = tex0.GetBufWidth();
uint32 texWidth = tex0.GetWidth();
uint32 texHeight = tex0.GetHeight();

if(prim.nTexture)
{
bool minLinear = false;
Expand Down Expand Up @@ -790,6 +795,57 @@ void CGSH_Vulkan::SetRenderingContext(uint64 primReg)
{
minLinear = magLinear;
}
else
{
//Check if the game uses mipmaps as a kind of texture array
//In this case, we can use the proper mip level instead of mip level 0.
bool mipNearest =
(tex1.nMinFilter == MIN_FILTER_NEAREST_MIP_NEAREST) ||
(tex1.nMinFilter == MIN_FILTER_LINEAR_MIP_NEAREST);
if(mipNearest && tex1.nLODMethod == LOD_CALC_STATIC)
{
auto miptbp1 = make_convertible<MIPTBP1>(m_nReg[GS_REG_MIPTBP1_1 + context]);
auto miptbp2 = make_convertible<MIPTBP2>(m_nReg[GS_REG_MIPTBP2_1 + context]);

int k = trunc(tex1.GetK());
int level = std::clamp<int>(k, 0, tex1.nMaxMip);
texWidth >>= level;
texHeight >>= level;
switch(level)
{
default:
assert(false);
[[fallthrough]];
case 0:
//We already have proper texture settings
break;
case 1:
texBufPtr = miptbp1.GetTbp1();
texBufWidth = miptbp1.GetTbw1();
break;
case 2:
texBufPtr = miptbp1.GetTbp2();
texBufWidth = miptbp1.GetTbw2();
break;
case 3:
texBufPtr = miptbp1.GetTbp3();
texBufWidth = miptbp1.GetTbw3();
break;
case 4:
texBufPtr = miptbp2.GetTbp4();
texBufWidth = miptbp2.GetTbw4();
break;
case 5:
texBufPtr = miptbp2.GetTbp5();
texBufWidth = miptbp2.GetTbw5();
break;
case 6:
texBufPtr = miptbp2.GetTbp6();
texBufWidth = miptbp2.GetTbw6();
break;
}
}
}

pipelineCaps.textureUseLinearFiltering = (minLinear && magLinear);
}
Expand Down Expand Up @@ -894,8 +950,7 @@ void CGSH_Vulkan::SetRenderingContext(uint64 primReg)
m_draw->SetPipelineCaps(pipelineCaps);
m_draw->SetFramebufferParams(frame.GetBasePtr(), frame.GetWidth(), fbWriteMask);
m_draw->SetDepthbufferParams(zbuf.GetBasePtr(), frame.GetWidth());
m_draw->SetTextureParams(tex0.GetBufPtr(), tex0.GetBufWidth(),
tex0.GetWidth(), tex0.GetHeight(), tex0.nCSA * 0x10);
m_draw->SetTextureParams(texBufPtr, texBufWidth, texWidth, texHeight, tex0.nCSA * 0x10);
m_draw->SetTextureAlphaParams(texA.nTA0, texA.nTA1);
m_draw->SetTextureClampParams(
clamp.GetMinU(), clamp.GetMinV(),
Expand Down
6 changes: 6 additions & 0 deletions Source/gs/GSHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,12 @@ class CGSHandler
REGISTERWRITEBUFFER_SUBMIT_THRESHOLD = 0x100
};

enum LOD_CALC
{
LOD_CALC_DYNAMIC = 0,
LOD_CALC_STATIC = 1,
};

enum MAG_FILTER
{
MAG_FILTER_NEAREST = 0,
Expand Down

0 comments on commit f7813a9

Please sign in to comment.