BPMemory: Refactor/consolidate TexUnit Addressing

Currently the logic for addressing the individual TexUnits is splattered all
across dolphin's codebase, this commit attempts to consolidate it all into a
single place and formalise it using our new TexUnitAddress struct.
This commit is contained in:
Scott Mansell
2021-10-10 08:16:15 +13:00
parent ef0e401708
commit 9fa26624b0
7 changed files with 146 additions and 59 deletions

View File

@ -14,30 +14,29 @@
TextureInfo TextureInfo::FromStage(u32 stage)
{
const FourTexUnits& tex = bpmem.tex[stage >> 2];
const u32 id = stage & 3;
const auto tex = bpmem.tex.GetUnit(stage);
const auto texture_format = tex.texImage0[id].format;
const auto tlut_format = tex.texTlut[id].tlut_format;
const auto texture_format = tex.texImage0.format;
const auto tlut_format = tex.texTlut.tlut_format;
const auto width = tex.texImage0[id].width + 1;
const auto height = tex.texImage0[id].height + 1;
const auto width = tex.texImage0.width + 1;
const auto height = tex.texImage0.height + 1;
const u32 address = (tex.texImage3[id].image_base /* & 0x1FFFFF*/) << 5;
const u32 address = (tex.texImage3.image_base /* & 0x1FFFFF*/) << 5;
const u32 tlutaddr = tex.texTlut[id].tmem_offset << 9;
const u32 tlutaddr = tex.texTlut.tmem_offset << 9;
const u8* tlut_ptr = &texMem[tlutaddr];
std::optional<u32> mip_count;
const bool has_mipmaps = SamplerCommon::AreBpTexMode0MipmapsEnabled(tex.texMode0[id]);
const bool has_mipmaps = SamplerCommon::AreBpTexMode0MipmapsEnabled(tex.texMode0);
if (has_mipmaps)
{
mip_count = (tex.texMode1[id].max_lod + 0xf) / 0x10;
mip_count = (tex.texMode1.max_lod + 0xf) / 0x10;
}
const bool from_tmem = tex.texImage1[id].cache_manually_managed != 0;
const u32 tmem_address_even = from_tmem ? tex.texImage1[id].tmem_even * TMEM_LINE_SIZE : 0;
const u32 tmem_address_odd = from_tmem ? tex.texImage2[id].tmem_odd * TMEM_LINE_SIZE : 0;
const bool from_tmem = tex.texImage1.cache_manually_managed != 0;
const u32 tmem_address_even = from_tmem ? tex.texImage1.tmem_even * TMEM_LINE_SIZE : 0;
const u32 tmem_address_odd = from_tmem ? tex.texImage2.tmem_odd * TMEM_LINE_SIZE : 0;
if (from_tmem)
{