mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
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:
@ -52,13 +52,8 @@ void Shutdown()
|
||||
|
||||
static void SaveTexture(const std::string& filename, u32 texmap, s32 mip)
|
||||
{
|
||||
FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
|
||||
u8 subTexmap = texmap & 3;
|
||||
|
||||
TexImage0& ti0 = texUnit.texImage0[subTexmap];
|
||||
|
||||
u32 width = ti0.width + 1;
|
||||
u32 height = ti0.height + 1;
|
||||
u32 width = bpmem.tex.GetUnit(texmap).texImage0.width + 1;
|
||||
u32 height = bpmem.tex.GetUnit(texmap).texImage0.height + 1;
|
||||
|
||||
auto data = std::make_unique<u8[]>(width * height * 4);
|
||||
|
||||
@ -80,10 +75,7 @@ void GetTextureRGBA(u8* dst, u32 texmap, s32 mip, u32 width, u32 height)
|
||||
|
||||
static s32 GetMaxTextureLod(u32 texmap)
|
||||
{
|
||||
FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
|
||||
u8 subTexmap = texmap & 3;
|
||||
|
||||
u8 maxLod = texUnit.texMode1[subTexmap].max_lod;
|
||||
u8 maxLod = bpmem.tex.GetUnit(texmap).texMode1.max_lod;
|
||||
u8 mip = maxLod >> 4;
|
||||
u8 fract = maxLod & 0xf;
|
||||
|
||||
|
@ -163,13 +163,12 @@ static void InitSlope(Slope* slope, float f1, float f2, float f3, float DX31, fl
|
||||
|
||||
static inline void CalculateLOD(s32* lodp, bool* linear, u32 texmap, u32 texcoord)
|
||||
{
|
||||
const FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
|
||||
const u8 subTexmap = texmap & 3;
|
||||
auto texUnit = bpmem.tex.GetUnit(texmap);
|
||||
|
||||
// LOD calculation requires data from the texture mode for bias, etc.
|
||||
// it does not seem to use the actual texture size
|
||||
const TexMode0& tm0 = texUnit.texMode0[subTexmap];
|
||||
const TexMode1& tm1 = texUnit.texMode1[subTexmap];
|
||||
const TexMode0& tm0 = texUnit.texMode0;
|
||||
const TexMode1& tm1 = texUnit.texMode1;
|
||||
|
||||
float sDelta, tDelta;
|
||||
if (tm0.diag_lod == LODType::Diagonal)
|
||||
|
@ -74,8 +74,8 @@ void Sample(s32 s, s32 t, s32 lod, bool linear, u8 texmap, u8* sample)
|
||||
bool mipLinear = false;
|
||||
|
||||
#if (ALLOW_MIPMAP)
|
||||
const FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
|
||||
const TexMode0& tm0 = texUnit.texMode0[texmap & 3];
|
||||
auto texUnit = bpmem.tex.GetUnit(texmap);
|
||||
const TexMode0& tm0 = texUnit.texMode0;
|
||||
|
||||
const s32 lodFract = lod & 0xf;
|
||||
|
||||
@ -115,26 +115,25 @@ void Sample(s32 s, s32 t, s32 lod, bool linear, u8 texmap, u8* sample)
|
||||
|
||||
void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8* sample)
|
||||
{
|
||||
const FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
|
||||
const u8 subTexmap = texmap & 3;
|
||||
auto texUnit = bpmem.tex.GetUnit(texmap);
|
||||
|
||||
const TexMode0& tm0 = texUnit.texMode0[subTexmap];
|
||||
const TexImage0& ti0 = texUnit.texImage0[subTexmap];
|
||||
const TexTLUT& texTlut = texUnit.texTlut[subTexmap];
|
||||
const TexMode0& tm0 = texUnit.texMode0;
|
||||
const TexImage0& ti0 = texUnit.texImage0;
|
||||
const TexTLUT& texTlut = texUnit.texTlut;
|
||||
const TextureFormat texfmt = ti0.format;
|
||||
const TLUTFormat tlutfmt = texTlut.tlut_format;
|
||||
|
||||
const u8* imageSrc;
|
||||
const u8* imageSrcOdd = nullptr;
|
||||
if (texUnit.texImage1[subTexmap].cache_manually_managed)
|
||||
if (texUnit.texImage1.cache_manually_managed)
|
||||
{
|
||||
imageSrc = &texMem[texUnit.texImage1[subTexmap].tmem_even * TMEM_LINE_SIZE];
|
||||
imageSrc = &texMem[texUnit.texImage1.tmem_even * TMEM_LINE_SIZE];
|
||||
if (texfmt == TextureFormat::RGBA8)
|
||||
imageSrcOdd = &texMem[texUnit.texImage2[subTexmap].tmem_odd * TMEM_LINE_SIZE];
|
||||
imageSrcOdd = &texMem[texUnit.texImage2.tmem_odd * TMEM_LINE_SIZE];
|
||||
}
|
||||
else
|
||||
{
|
||||
const u32 imageBase = texUnit.texImage3[subTexmap].image_base << 5;
|
||||
const u32 imageBase = texUnit.texImage3.image_base << 5;
|
||||
imageSrc = Memory::GetPointer(imageBase);
|
||||
}
|
||||
|
||||
@ -198,7 +197,7 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8* sample)
|
||||
WrapCoord(&imageSPlus1, tm0.wrap_s, image_width_minus_1 + 1);
|
||||
WrapCoord(&imageTPlus1, tm0.wrap_t, image_height_minus_1 + 1);
|
||||
|
||||
if (!(texfmt == TextureFormat::RGBA8 && texUnit.texImage1[subTexmap].cache_manually_managed))
|
||||
if (!(texfmt == TextureFormat::RGBA8 && texUnit.texImage1.cache_manually_managed))
|
||||
{
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageS, imageT, image_width_minus_1, texfmt,
|
||||
tlut, tlutfmt);
|
||||
@ -250,7 +249,7 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8* sample)
|
||||
WrapCoord(&imageS, tm0.wrap_s, image_width_minus_1 + 1);
|
||||
WrapCoord(&imageT, tm0.wrap_t, image_height_minus_1 + 1);
|
||||
|
||||
if (!(texfmt == TextureFormat::RGBA8 && texUnit.texImage1[subTexmap].cache_manually_managed))
|
||||
if (!(texfmt == TextureFormat::RGBA8 && texUnit.texImage1.cache_manually_managed))
|
||||
TexDecoder_DecodeTexel(sample, imageSrc, imageS, imageT, image_width_minus_1, texfmt, tlut,
|
||||
tlutfmt);
|
||||
else
|
||||
|
Reference in New Issue
Block a user