diff --git a/GPU/GPUState.h b/GPU/GPUState.h index e91be6d1ab..c6fb03c4d3 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -298,9 +298,7 @@ struct GPUgstate { bool isTextureAlphaUsed() const { return (texfunc & 0x100) != 0; } GETextureFormat getTextureFormat() const { return static_cast(texformat & 0xF); } bool isTextureFormatIndexed() const { return (texformat & 4) != 0; } // GE_TFMT_CLUT4 - GE_TFMT_CLUT32 are 0b1xx. - int getTextureEnvColR() const { return texenvcolor&0xFF; } - int getTextureEnvColG() const { return (texenvcolor>>8)&0xFF; } - int getTextureEnvColB() const { return (texenvcolor>>16)&0xFF; } + int getTextureEnvColRGB() const { return texenvcolor & 0x00FFFFFF; } u32 getClutAddress() const { return (clutaddr & 0x00FFFFF0) | ((clutaddrupper << 8) & 0x0F000000); } int getClutLoadBytes() const { return (loadclut & 0x3F) * 32; } int getClutLoadBlocks() const { return (loadclut & 0x3F); } diff --git a/GPU/Software/FuncId.cpp b/GPU/Software/FuncId.cpp index 276e4f0820..3ee0d68655 100644 --- a/GPU/Software/FuncId.cpp +++ b/GPU/Software/FuncId.cpp @@ -427,6 +427,9 @@ void ComputeSamplerID(SamplerID *id_out) { if (id.texFunc > GE_TEXFUNC_ADD) id.texFunc = GE_TEXFUNC_ADD; + if (id.texFunc == GE_TEXFUNC_BLEND) + id.cached.texBlendColor = gstate.getTextureEnvColRGB(); + *id_out = id; } diff --git a/GPU/Software/FuncId.h b/GPU/Software/FuncId.h index b505e88412..6c372a0c4f 100644 --- a/GPU/Software/FuncId.h +++ b/GPU/Software/FuncId.h @@ -171,6 +171,7 @@ struct SamplerID { uint16_t w; uint16_t h; } sizes[8]; + uint32_t texBlendColor; } cached; union { diff --git a/GPU/Software/Sampler.cpp b/GPU/Software/Sampler.cpp index bc997f7bf0..f346aa9759 100644 --- a/GPU/Software/Sampler.cpp +++ b/GPU/Software/Sampler.cpp @@ -509,7 +509,7 @@ Vec4IntResult SOFTRAST_CALL GetTextureFunctionOutput(Vec4IntArg prim_color_in, V case GE_TEXFUNC_BLEND: { const Vec3 const255(255, 255, 255); - const Vec3 texenv(gstate.getTextureEnvColR(), gstate.getTextureEnvColG(), gstate.getTextureEnvColB()); + const Vec3 texenv = Vec3::FromRGB(samplerID.cached.texBlendColor); // Unlike the others (and even alpha), this one simply always rounds up. const Vec3 roundup = Vec3::AssignToAll(255); diff --git a/GPU/Software/SamplerX86.cpp b/GPU/Software/SamplerX86.cpp index c7d6388eeb..cf650c0d67 100644 --- a/GPU/Software/SamplerX86.cpp +++ b/GPU/Software/SamplerX86.cpp @@ -1649,19 +1649,19 @@ bool SamplerJitCache::Jit_ApplyTextureFunc(const SamplerID &id) { // We divide later. } - X64Reg gstateReg = GetGState(); + X64Reg idReg = GetSamplerID(); X64Reg texEnvReg = regCache_.Alloc(RegCache::VEC_TEMP1); if (cpu_info.bSSE4_1) { - PMOVZXBW(texEnvReg, MDisp(gstateReg, offsetof(GPUgstate, texenvcolor))); + PMOVZXBW(texEnvReg, MDisp(idReg, offsetof(SamplerID, cached.texBlendColor))); } else { - MOVD_xmm(texEnvReg, MDisp(gstateReg, offsetof(GPUgstate, texenvcolor))); + MOVD_xmm(texEnvReg, MDisp(idReg, offsetof(SamplerID, cached.texBlendColor))); X64Reg zeroReg = GetZeroVec(); PUNPCKLBW(texEnvReg, R(zeroReg)); regCache_.Unlock(zeroReg, RegCache::VEC_ZERO); } PMULLW(resultReg, R(texEnvReg)); regCache_.Release(texEnvReg, RegCache::VEC_TEMP1); - regCache_.Unlock(gstateReg, RegCache::GEN_GSTATE); + UnlockSamplerID(idReg); // Add in the prim color side and divide. PADDW(resultReg, R(tempReg));