softgpu: Move texenv color into sampler state.

This commit is contained in:
Unknown W. Brackets 2022-01-15 17:52:40 -08:00
parent ad3635c82a
commit c0e85e6170
5 changed files with 10 additions and 8 deletions

View file

@ -298,9 +298,7 @@ struct GPUgstate {
bool isTextureAlphaUsed() const { return (texfunc & 0x100) != 0; } bool isTextureAlphaUsed() const { return (texfunc & 0x100) != 0; }
GETextureFormat getTextureFormat() const { return static_cast<GETextureFormat>(texformat & 0xF); } GETextureFormat getTextureFormat() const { return static_cast<GETextureFormat>(texformat & 0xF); }
bool isTextureFormatIndexed() const { return (texformat & 4) != 0; } // GE_TFMT_CLUT4 - GE_TFMT_CLUT32 are 0b1xx. bool isTextureFormatIndexed() const { return (texformat & 4) != 0; } // GE_TFMT_CLUT4 - GE_TFMT_CLUT32 are 0b1xx.
int getTextureEnvColR() const { return texenvcolor&0xFF; } int getTextureEnvColRGB() const { return texenvcolor & 0x00FFFFFF; }
int getTextureEnvColG() const { return (texenvcolor>>8)&0xFF; }
int getTextureEnvColB() const { return (texenvcolor>>16)&0xFF; }
u32 getClutAddress() const { return (clutaddr & 0x00FFFFF0) | ((clutaddrupper << 8) & 0x0F000000); } u32 getClutAddress() const { return (clutaddr & 0x00FFFFF0) | ((clutaddrupper << 8) & 0x0F000000); }
int getClutLoadBytes() const { return (loadclut & 0x3F) * 32; } int getClutLoadBytes() const { return (loadclut & 0x3F) * 32; }
int getClutLoadBlocks() const { return (loadclut & 0x3F); } int getClutLoadBlocks() const { return (loadclut & 0x3F); }

View file

@ -427,6 +427,9 @@ void ComputeSamplerID(SamplerID *id_out) {
if (id.texFunc > GE_TEXFUNC_ADD) if (id.texFunc > GE_TEXFUNC_ADD)
id.texFunc = GE_TEXFUNC_ADD; id.texFunc = GE_TEXFUNC_ADD;
if (id.texFunc == GE_TEXFUNC_BLEND)
id.cached.texBlendColor = gstate.getTextureEnvColRGB();
*id_out = id; *id_out = id;
} }

View file

@ -171,6 +171,7 @@ struct SamplerID {
uint16_t w; uint16_t w;
uint16_t h; uint16_t h;
} sizes[8]; } sizes[8];
uint32_t texBlendColor;
} cached; } cached;
union { union {

View file

@ -509,7 +509,7 @@ Vec4IntResult SOFTRAST_CALL GetTextureFunctionOutput(Vec4IntArg prim_color_in, V
case GE_TEXFUNC_BLEND: case GE_TEXFUNC_BLEND:
{ {
const Vec3<int> const255(255, 255, 255); const Vec3<int> const255(255, 255, 255);
const Vec3<int> texenv(gstate.getTextureEnvColR(), gstate.getTextureEnvColG(), gstate.getTextureEnvColB()); const Vec3<int> texenv = Vec3<int>::FromRGB(samplerID.cached.texBlendColor);
// Unlike the others (and even alpha), this one simply always rounds up. // Unlike the others (and even alpha), this one simply always rounds up.
const Vec3<int> roundup = Vec3<int>::AssignToAll(255); const Vec3<int> roundup = Vec3<int>::AssignToAll(255);

View file

@ -1649,19 +1649,19 @@ bool SamplerJitCache::Jit_ApplyTextureFunc(const SamplerID &id) {
// We divide later. // We divide later.
} }
X64Reg gstateReg = GetGState(); X64Reg idReg = GetSamplerID();
X64Reg texEnvReg = regCache_.Alloc(RegCache::VEC_TEMP1); X64Reg texEnvReg = regCache_.Alloc(RegCache::VEC_TEMP1);
if (cpu_info.bSSE4_1) { if (cpu_info.bSSE4_1) {
PMOVZXBW(texEnvReg, MDisp(gstateReg, offsetof(GPUgstate, texenvcolor))); PMOVZXBW(texEnvReg, MDisp(idReg, offsetof(SamplerID, cached.texBlendColor)));
} else { } else {
MOVD_xmm(texEnvReg, MDisp(gstateReg, offsetof(GPUgstate, texenvcolor))); MOVD_xmm(texEnvReg, MDisp(idReg, offsetof(SamplerID, cached.texBlendColor)));
X64Reg zeroReg = GetZeroVec(); X64Reg zeroReg = GetZeroVec();
PUNPCKLBW(texEnvReg, R(zeroReg)); PUNPCKLBW(texEnvReg, R(zeroReg));
regCache_.Unlock(zeroReg, RegCache::VEC_ZERO); regCache_.Unlock(zeroReg, RegCache::VEC_ZERO);
} }
PMULLW(resultReg, R(texEnvReg)); PMULLW(resultReg, R(texEnvReg));
regCache_.Release(texEnvReg, RegCache::VEC_TEMP1); regCache_.Release(texEnvReg, RegCache::VEC_TEMP1);
regCache_.Unlock(gstateReg, RegCache::GEN_GSTATE); UnlockSamplerID(idReg);
// Add in the prim color side and divide. // Add in the prim color side and divide.
PADDW(resultReg, R(tempReg)); PADDW(resultReg, R(tempReg));