2021-11-20 21:11:52 +00:00
|
|
|
// Copyright (c) 2021- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2021-11-26 18:12:54 +00:00
|
|
|
#include "Common/Data/Convert/ColorConv.h"
|
2021-11-21 16:21:59 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2022-01-03 00:52:22 +00:00
|
|
|
#include "Core/MemMap.h"
|
|
|
|
#include "GPU/Common/TextureDecoder.h"
|
2021-11-20 21:11:52 +00:00
|
|
|
#include "GPU/GPUState.h"
|
2022-01-03 00:52:22 +00:00
|
|
|
#include "GPU/Software/FuncId.h"
|
2021-11-20 21:11:52 +00:00
|
|
|
|
2022-01-16 07:12:03 +00:00
|
|
|
static_assert(sizeof(SamplerID) == sizeof(SamplerID::fullKey) + sizeof(SamplerID::cached) + sizeof(SamplerID::pad), "Bad sampler ID size");
|
2021-11-26 18:12:54 +00:00
|
|
|
static_assert(sizeof(PixelFuncID) == sizeof(PixelFuncID::fullKey) + sizeof(PixelFuncID::cached), "Bad pixel func ID size");
|
2021-11-21 17:39:14 +00:00
|
|
|
|
2021-12-02 01:32:18 +00:00
|
|
|
static inline GEComparison OptimizeRefByteCompare(GEComparison func, u8 ref) {
|
|
|
|
// Not equal tests are easier.
|
|
|
|
if (ref == 0 && func == GE_COMP_GREATER)
|
|
|
|
return GE_COMP_NOTEQUAL;
|
|
|
|
if (ref == 0xFF && func == GE_COMP_LESS)
|
|
|
|
return GE_COMP_NOTEQUAL;
|
|
|
|
|
|
|
|
// Sometimes games pointlessly use tests like these.
|
|
|
|
if (ref == 0 && func == GE_COMP_GEQUAL)
|
|
|
|
return GE_COMP_ALWAYS;
|
|
|
|
if (ref == 0xFF && func == GE_COMP_LEQUAL)
|
|
|
|
return GE_COMP_ALWAYS;
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2022-01-02 04:40:28 +00:00
|
|
|
static inline PixelBlendFactor OptimizeAlphaFactor(uint32_t color) {
|
|
|
|
if (color == 0x00000000)
|
|
|
|
return PixelBlendFactor::ZERO;
|
|
|
|
if (color == 0x00FFFFFF)
|
|
|
|
return PixelBlendFactor::ONE;
|
|
|
|
return PixelBlendFactor::FIX;
|
|
|
|
}
|
|
|
|
|
2022-09-18 02:42:41 +00:00
|
|
|
void ComputePixelFuncID(PixelFuncID *id) {
|
2021-11-20 21:11:52 +00:00
|
|
|
id->fullKey = 0;
|
|
|
|
|
|
|
|
// TODO: Could this be minz > 0x0000 || maxz < 0xFFFF? Maybe unsafe, depending on verts...
|
2022-09-18 02:42:41 +00:00
|
|
|
id->applyDepthRange = !gstate.isModeThrough();
|
2021-11-20 21:11:52 +00:00
|
|
|
// Dither happens even in clear mode.
|
|
|
|
id->dithering = gstate.isDitherEnabled();
|
|
|
|
id->fbFormat = gstate.FrameBufFormat();
|
|
|
|
id->useStandardStride = gstate.FrameBufStride() == 512 && gstate.DepthBufStride() == 512;
|
|
|
|
id->applyColorWriteMask = gstate.getColorMask() != 0;
|
|
|
|
|
|
|
|
id->clearMode = gstate.isModeClear();
|
|
|
|
if (id->clearMode) {
|
2021-11-21 17:39:14 +00:00
|
|
|
id->colorTest = gstate.isClearModeColorMask();
|
2021-11-23 23:04:27 +00:00
|
|
|
id->stencilTest = gstate.isClearModeAlphaMask() && gstate.FrameBufFormat() != GE_FORMAT_565;
|
2021-11-21 17:39:14 +00:00
|
|
|
id->depthWrite = gstate.isClearModeDepthMask();
|
2021-11-22 01:52:51 +00:00
|
|
|
id->depthTestFunc = GE_COMP_ALWAYS;
|
|
|
|
id->alphaTestFunc = GE_COMP_ALWAYS;
|
2021-11-20 21:11:52 +00:00
|
|
|
} else {
|
|
|
|
id->colorTest = gstate.isColorTestEnabled() && gstate.getColorTestFunction() != GE_COMP_ALWAYS;
|
|
|
|
if (gstate.isStencilTestEnabled() && gstate.getStencilTestFunction() == GE_COMP_ALWAYS) {
|
|
|
|
// If stencil always passes, force off when we won't write any stencil bits.
|
|
|
|
bool stencilWrite = (gstate.pmska & 0xFF) != 0xFF && gstate.FrameBufFormat() != GE_FORMAT_565;
|
|
|
|
if (gstate.isDepthTestEnabled() && gstate.getDepthTestFunction() != GE_COMP_ALWAYS)
|
|
|
|
id->stencilTest = stencilWrite && (gstate.getStencilOpZPass() != GE_STENCILOP_KEEP || gstate.getStencilOpZFail() != GE_STENCILOP_KEEP);
|
|
|
|
else
|
|
|
|
id->stencilTest = stencilWrite && gstate.getStencilOpZPass() != GE_STENCILOP_KEEP;
|
|
|
|
} else {
|
|
|
|
id->stencilTest = gstate.isStencilTestEnabled();
|
|
|
|
}
|
|
|
|
id->depthWrite = gstate.isDepthTestEnabled() && gstate.isDepthWriteEnabled();
|
2022-09-12 05:11:15 +00:00
|
|
|
id->depthTestFunc = gstate.isDepthTestEnabled() ? gstate.getDepthTestFunction() : GE_COMP_ALWAYS;
|
2021-11-20 21:11:52 +00:00
|
|
|
|
|
|
|
if (id->stencilTest) {
|
|
|
|
id->stencilTestRef = gstate.getStencilTestRef() & gstate.getStencilTestMask();
|
2021-12-02 01:32:18 +00:00
|
|
|
id->stencilTestFunc = OptimizeRefByteCompare(gstate.getStencilTestFunction(), id->stencilTestRef);
|
2021-11-26 05:00:34 +00:00
|
|
|
id->hasStencilTestMask = gstate.getStencilTestMask() != 0xFF && gstate.FrameBufFormat() != GE_FORMAT_565;
|
|
|
|
|
|
|
|
// Stencil can't be written on 565, and any invalid op acts like KEEP, which is 0.
|
|
|
|
if (gstate.FrameBufFormat() != GE_FORMAT_565 && gstate.getStencilOpSFail() <= GE_STENCILOP_DECR)
|
|
|
|
id->sFail = gstate.getStencilOpSFail();
|
|
|
|
if (gstate.FrameBufFormat() != GE_FORMAT_565 && gstate.getStencilOpZFail() <= GE_STENCILOP_DECR)
|
|
|
|
id->zFail = gstate.isDepthTestEnabled() ? gstate.getStencilOpZFail() : GE_STENCILOP_KEEP;
|
|
|
|
if (gstate.FrameBufFormat() != GE_FORMAT_565 && gstate.getStencilOpZPass() <= GE_STENCILOP_DECR)
|
|
|
|
id->zPass = gstate.getStencilOpZPass();
|
2021-11-29 04:24:13 +00:00
|
|
|
|
2021-12-02 05:41:15 +00:00
|
|
|
// Normalize REPLACE 00 to ZERO, especially if using a mask.
|
|
|
|
if (gstate.getStencilTestRef() == 0) {
|
|
|
|
if (id->SFail() == GE_STENCILOP_REPLACE)
|
|
|
|
id->sFail = GE_STENCILOP_ZERO;
|
|
|
|
if (id->ZFail() == GE_STENCILOP_REPLACE)
|
|
|
|
id->zFail = GE_STENCILOP_ZERO;
|
|
|
|
if (id->ZPass() == GE_STENCILOP_REPLACE)
|
|
|
|
id->zPass = GE_STENCILOP_ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For 5551, DECR is also the same as ZERO.
|
|
|
|
if (id->FBFormat() == GE_FORMAT_5551) {
|
|
|
|
if (id->SFail() == GE_STENCILOP_DECR)
|
|
|
|
id->sFail = GE_STENCILOP_ZERO;
|
|
|
|
if (id->ZFail() == GE_STENCILOP_DECR)
|
|
|
|
id->zFail = GE_STENCILOP_ZERO;
|
|
|
|
if (id->ZPass() == GE_STENCILOP_DECR)
|
|
|
|
id->zPass = GE_STENCILOP_ZERO;
|
|
|
|
}
|
|
|
|
|
2022-09-12 01:39:39 +00:00
|
|
|
// And same for sFail if there's no stencil test. Prefer KEEP, though.
|
2022-09-12 05:11:15 +00:00
|
|
|
if (id->StencilTestFunc() == GE_COMP_ALWAYS) {
|
|
|
|
if (id->DepthTestFunc() == GE_COMP_ALWAYS)
|
|
|
|
id->zFail = GE_STENCILOP_KEEP;
|
|
|
|
id->sFail = GE_STENCILOP_KEEP;
|
|
|
|
// Always doesn't need a mask.
|
|
|
|
id->stencilTestRef = gstate.getStencilTestRef();
|
|
|
|
id->hasStencilTestMask = false;
|
|
|
|
|
|
|
|
// Turn off stencil testing if it's doing nothing.
|
|
|
|
if (id->SFail() == GE_STENCILOP_KEEP && id->ZFail() == GE_STENCILOP_KEEP && id->ZPass() == GE_STENCILOP_KEEP) {
|
2021-12-02 05:41:15 +00:00
|
|
|
id->stencilTest = false;
|
2022-09-12 05:11:15 +00:00
|
|
|
id->stencilTestFunc = 0;
|
|
|
|
id->stencilTestRef = 0;
|
|
|
|
}
|
|
|
|
} else if (id->DepthTestFunc() == GE_COMP_ALWAYS) {
|
|
|
|
// Always treat zPass/zFail the same if there's no depth test.
|
|
|
|
id->zFail = id->zPass;
|
2021-12-02 05:41:15 +00:00
|
|
|
}
|
2021-11-20 21:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
id->alphaTestFunc = gstate.isAlphaTestEnabled() ? gstate.getAlphaTestFunction() : GE_COMP_ALWAYS;
|
2021-11-21 17:39:14 +00:00
|
|
|
if (id->AlphaTestFunc() != GE_COMP_ALWAYS) {
|
2021-11-20 21:11:52 +00:00
|
|
|
id->alphaTestRef = gstate.getAlphaTestRef() & gstate.getAlphaTestMask();
|
|
|
|
id->hasAlphaTestMask = gstate.getAlphaTestMask() != 0xFF;
|
2021-11-29 04:24:13 +00:00
|
|
|
// Try to pick a more optimal variant.
|
2021-12-02 01:32:18 +00:00
|
|
|
id->alphaTestFunc = OptimizeRefByteCompare(id->AlphaTestFunc(), id->alphaTestRef);
|
|
|
|
if (id->alphaTestFunc == GE_COMP_ALWAYS) {
|
|
|
|
id->alphaTestRef = 0;
|
|
|
|
id->hasAlphaTestMask = false;
|
|
|
|
}
|
2021-11-20 21:11:52 +00:00
|
|
|
}
|
|
|
|
|
2021-11-26 02:59:32 +00:00
|
|
|
// If invalid (6 or 7), doesn't do any blending, so force off.
|
|
|
|
id->alphaBlend = gstate.isAlphaBlendEnabled() && gstate.getBlendEq() <= 5;
|
2021-11-20 22:52:51 +00:00
|
|
|
// Force it off if the factors are constant and don't blend. Some games use this...
|
|
|
|
if (id->alphaBlend && gstate.getBlendEq() == GE_BLENDMODE_MUL_AND_ADD) {
|
|
|
|
bool srcFixedOne = gstate.getBlendFuncA() == GE_SRCBLEND_FIXA && gstate.getFixA() == 0x00FFFFFF;
|
|
|
|
bool dstFixedZero = gstate.getBlendFuncB() == GE_DSTBLEND_FIXB && gstate.getFixB() == 0x00000000;
|
|
|
|
if (srcFixedOne && dstFixedZero)
|
|
|
|
id->alphaBlend = false;
|
|
|
|
}
|
2022-01-02 04:40:28 +00:00
|
|
|
if (id->alphaBlend)
|
2021-11-20 21:11:52 +00:00
|
|
|
id->alphaBlendEq = gstate.getBlendEq();
|
2022-01-02 04:40:28 +00:00
|
|
|
if (id->alphaBlend && id->alphaBlendEq <= GE_BLENDMODE_MUL_AND_SUBTRACT_REVERSE) {
|
2021-11-20 21:11:52 +00:00
|
|
|
id->alphaBlendSrc = gstate.getBlendFuncA();
|
|
|
|
id->alphaBlendDst = gstate.getBlendFuncB();
|
2022-01-02 04:40:28 +00:00
|
|
|
// Special values.
|
2022-01-24 08:08:33 +00:00
|
|
|
if (id->alphaBlendSrc >= GE_SRCBLEND_FIXA)
|
2022-01-02 04:40:28 +00:00
|
|
|
id->alphaBlendSrc = (uint8_t)OptimizeAlphaFactor(gstate.getFixA());
|
2022-01-24 08:08:33 +00:00
|
|
|
if (id->alphaBlendDst >= GE_DSTBLEND_FIXB)
|
2022-01-02 04:40:28 +00:00
|
|
|
id->alphaBlendDst = (uint8_t)OptimizeAlphaFactor(gstate.getFixB());
|
2021-11-20 21:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
id->applyLogicOp = gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_COPY;
|
2022-09-18 02:42:41 +00:00
|
|
|
id->applyFog = gstate.isFogEnabled() && !gstate.isModeThrough();
|
2022-09-11 04:22:13 +00:00
|
|
|
|
|
|
|
id->earlyZChecks = id->DepthTestFunc() != GE_COMP_ALWAYS;
|
|
|
|
if (id->stencilTest && id->earlyZChecks) {
|
|
|
|
// Can't do them early if stencil might need to write.
|
|
|
|
if (id->SFail() != GE_STENCILOP_KEEP || id->ZFail() != GE_STENCILOP_KEEP)
|
|
|
|
id->earlyZChecks = false;
|
|
|
|
}
|
2021-11-20 21:11:52 +00:00
|
|
|
}
|
2021-11-26 18:12:54 +00:00
|
|
|
|
|
|
|
// Cache some values for later convenience.
|
|
|
|
if (id->dithering) {
|
|
|
|
for (int y = 0; y < 4; ++y) {
|
|
|
|
for (int x = 0; x < 4; ++x)
|
|
|
|
id->cached.ditherMatrix[y * 4 + x] = gstate.getDitherValue(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (id->applyColorWriteMask) {
|
|
|
|
uint32_t mask = gstate.getColorMask();
|
|
|
|
// This flag means stencil clear or stencil test, basically whether writing to stencil.
|
|
|
|
if (!id->stencilTest)
|
|
|
|
mask |= 0xFF000000;
|
|
|
|
|
|
|
|
switch (id->fbFormat) {
|
|
|
|
case GE_FORMAT_565:
|
|
|
|
id->cached.colorWriteMask = RGBA8888ToRGB565(mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_FORMAT_5551:
|
|
|
|
id->cached.colorWriteMask = RGBA8888ToRGBA5551(mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_FORMAT_4444:
|
|
|
|
id->cached.colorWriteMask = RGBA8888ToRGBA4444(mask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_FORMAT_8888:
|
|
|
|
id->cached.colorWriteMask = mask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-01-15 17:38:50 +00:00
|
|
|
if (id->applyFog) {
|
|
|
|
id->cached.fogColor = gstate.fogcolor & 0x00FFFFFF;
|
|
|
|
}
|
2022-01-16 06:31:28 +00:00
|
|
|
if (id->applyLogicOp)
|
|
|
|
id->cached.logicOp = gstate.getLogicOp();
|
2022-01-15 18:32:15 +00:00
|
|
|
id->cached.minz = gstate.getDepthRangeMin();
|
|
|
|
id->cached.maxz = gstate.getDepthRangeMax();
|
2022-01-15 17:58:48 +00:00
|
|
|
id->cached.framebufStride = gstate.FrameBufStride();
|
|
|
|
id->cached.depthbufStride = gstate.DepthBufStride();
|
2022-01-15 19:46:07 +00:00
|
|
|
|
|
|
|
if (id->hasStencilTestMask) {
|
|
|
|
// Without the mask applied, unlike the one in the key.
|
|
|
|
id->cached.stencilRef = gstate.getStencilTestRef();
|
|
|
|
id->cached.stencilTestMask = gstate.getStencilTestMask();
|
|
|
|
}
|
|
|
|
if (id->hasAlphaTestMask)
|
|
|
|
id->cached.alphaTestMask = gstate.getAlphaTestMask();
|
2022-01-15 19:59:08 +00:00
|
|
|
if (!id->clearMode && id->colorTest) {
|
|
|
|
id->cached.colorTestFunc = gstate.getColorTestFunction();
|
|
|
|
id->cached.colorTestMask = gstate.getColorTestMask();
|
|
|
|
id->cached.colorTestRef = gstate.getColorTestRef() & id->cached.colorTestMask;
|
|
|
|
}
|
2022-01-15 20:08:00 +00:00
|
|
|
if (id->alphaBlendSrc == GE_SRCBLEND_FIXA)
|
|
|
|
id->cached.alphaBlendSrc = gstate.getFixA();
|
|
|
|
if (id->alphaBlendDst == GE_DSTBLEND_FIXB)
|
|
|
|
id->cached.alphaBlendDst = gstate.getFixB();
|
2021-11-20 21:11:52 +00:00
|
|
|
}
|
2021-11-21 16:21:59 +00:00
|
|
|
|
|
|
|
std::string DescribePixelFuncID(const PixelFuncID &id) {
|
|
|
|
std::string desc;
|
|
|
|
if (id.clearMode) {
|
|
|
|
desc = "Clear";
|
2021-11-21 17:39:14 +00:00
|
|
|
if (id.ColorClear())
|
2021-11-21 16:21:59 +00:00
|
|
|
desc += "C";
|
2021-11-21 17:39:14 +00:00
|
|
|
if (id.StencilClear())
|
2021-11-21 16:21:59 +00:00
|
|
|
desc += "S";
|
2021-11-21 17:39:14 +00:00
|
|
|
if (id.DepthClear())
|
2021-11-21 16:21:59 +00:00
|
|
|
desc += "D";
|
|
|
|
desc += ":";
|
|
|
|
}
|
|
|
|
if (id.applyDepthRange)
|
|
|
|
desc += "DepthR:";
|
|
|
|
if (id.useStandardStride)
|
|
|
|
desc += "Str512:";
|
|
|
|
if (id.dithering)
|
|
|
|
desc += "Dith:";
|
|
|
|
if (id.applyColorWriteMask)
|
|
|
|
desc += "Msk:";
|
|
|
|
|
2021-11-22 13:57:54 +00:00
|
|
|
switch (id.fbFormat) {
|
2021-11-21 16:21:59 +00:00
|
|
|
case GE_FORMAT_565: desc += "5650:"; break;
|
|
|
|
case GE_FORMAT_5551: desc += "5551:"; break;
|
|
|
|
case GE_FORMAT_4444: desc += "4444:"; break;
|
|
|
|
case GE_FORMAT_8888: desc += "8888:"; break;
|
|
|
|
}
|
|
|
|
|
2021-11-21 17:39:14 +00:00
|
|
|
if (id.AlphaTestFunc() != GE_COMP_ALWAYS) {
|
2022-01-30 02:34:14 +00:00
|
|
|
if (id.clearMode)
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.AlphaTestFunc()) {
|
2021-11-21 16:21:59 +00:00
|
|
|
case GE_COMP_NEVER: desc += "ANever"; break;
|
|
|
|
case GE_COMP_ALWAYS: break;
|
|
|
|
case GE_COMP_EQUAL: desc += "AEQ"; break;
|
|
|
|
case GE_COMP_NOTEQUAL: desc += "ANE"; break;
|
|
|
|
case GE_COMP_LESS: desc += "ALT"; break;
|
|
|
|
case GE_COMP_LEQUAL: desc += "ALE"; break;
|
|
|
|
case GE_COMP_GREATER: desc += "AGT"; break;
|
|
|
|
case GE_COMP_GEQUAL: desc += "AGE"; break;
|
|
|
|
}
|
|
|
|
if (id.hasAlphaTestMask)
|
|
|
|
desc += "Msk";
|
|
|
|
desc += StringFromFormat("%02X:", id.alphaTestRef);
|
2022-01-30 02:34:14 +00:00
|
|
|
} else if (id.hasAlphaTestMask || id.alphaTestRef != 0) {
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 16:21:59 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 04:57:22 +00:00
|
|
|
if (id.earlyZChecks)
|
|
|
|
desc += "ZEarly:";
|
2021-11-21 17:39:14 +00:00
|
|
|
if (id.DepthTestFunc() != GE_COMP_ALWAYS) {
|
2022-01-30 02:34:14 +00:00
|
|
|
if (id.clearMode)
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.DepthTestFunc()) {
|
2021-11-21 16:21:59 +00:00
|
|
|
case GE_COMP_NEVER: desc += "ZNever:"; break;
|
|
|
|
case GE_COMP_ALWAYS: break;
|
|
|
|
case GE_COMP_EQUAL: desc += "ZEQ:"; break;
|
|
|
|
case GE_COMP_NOTEQUAL: desc += "ZNE:"; break;
|
|
|
|
case GE_COMP_LESS: desc += "ZLT:"; break;
|
|
|
|
case GE_COMP_LEQUAL: desc += "ZLE:"; break;
|
|
|
|
case GE_COMP_GREATER: desc += "ZGT:"; break;
|
|
|
|
case GE_COMP_GEQUAL: desc += "ZGE:"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (id.depthWrite && !id.clearMode)
|
|
|
|
desc += "ZWr:";
|
|
|
|
|
|
|
|
if (id.colorTest && !id.clearMode)
|
|
|
|
desc += "CTest:";
|
|
|
|
|
|
|
|
if (id.stencilTest && !id.clearMode) {
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.StencilTestFunc()) {
|
2021-11-21 16:21:59 +00:00
|
|
|
case GE_COMP_NEVER: desc += "SNever"; break;
|
|
|
|
case GE_COMP_ALWAYS: desc += "SAlways"; break;
|
|
|
|
case GE_COMP_EQUAL: desc += "SEQ"; break;
|
|
|
|
case GE_COMP_NOTEQUAL: desc += "SNE"; break;
|
|
|
|
case GE_COMP_LESS: desc += "SLT"; break;
|
|
|
|
case GE_COMP_LEQUAL: desc += "SLE"; break;
|
|
|
|
case GE_COMP_GREATER: desc += "SGT"; break;
|
|
|
|
case GE_COMP_GEQUAL: desc += "SGE"; break;
|
|
|
|
}
|
|
|
|
if (id.hasStencilTestMask)
|
|
|
|
desc += "Msk";
|
2022-09-12 05:11:15 +00:00
|
|
|
if (id.StencilTestFunc() != GE_COMP_ALWAYS || id.DepthTestFunc() != GE_COMP_ALWAYS)
|
|
|
|
desc += StringFromFormat("%02X:", id.stencilTestRef);
|
2022-01-30 02:34:14 +00:00
|
|
|
} else if (id.hasStencilTestMask || id.stencilTestRef != 0 || id.stencilTestFunc != 0) {
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 16:21:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.SFail()) {
|
2021-11-21 16:21:59 +00:00
|
|
|
case GE_STENCILOP_KEEP: break;
|
|
|
|
case GE_STENCILOP_ZERO: desc += "STstF0:"; break;
|
|
|
|
case GE_STENCILOP_REPLACE: desc += "STstFRpl:"; break;
|
|
|
|
case GE_STENCILOP_INVERT: desc += "STstFXor:"; break;
|
|
|
|
case GE_STENCILOP_INCR: desc += "STstFInc:"; break;
|
|
|
|
case GE_STENCILOP_DECR: desc += "STstFDec:"; break;
|
|
|
|
}
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.ZFail()) {
|
2021-11-21 16:21:59 +00:00
|
|
|
case GE_STENCILOP_KEEP: break;
|
|
|
|
case GE_STENCILOP_ZERO: desc += "ZTstF0:"; break;
|
|
|
|
case GE_STENCILOP_REPLACE: desc += "ZTstFRpl:"; break;
|
|
|
|
case GE_STENCILOP_INVERT: desc += "ZTstFXor:"; break;
|
|
|
|
case GE_STENCILOP_INCR: desc += "ZTstFInc:"; break;
|
|
|
|
case GE_STENCILOP_DECR: desc += "ZTstFDec:"; break;
|
|
|
|
}
|
2022-09-12 05:11:15 +00:00
|
|
|
if (id.StencilTestFunc() == GE_COMP_ALWAYS && id.DepthTestFunc() == GE_COMP_ALWAYS) {
|
|
|
|
switch (id.ZPass()) {
|
|
|
|
case GE_STENCILOP_KEEP: break;
|
|
|
|
case GE_STENCILOP_ZERO: desc += "Zero:"; break;
|
|
|
|
case GE_STENCILOP_REPLACE: desc += StringFromFormat("Rpl%02X:", id.stencilTestRef); break;
|
|
|
|
case GE_STENCILOP_INVERT: desc += "Xor:"; break;
|
|
|
|
case GE_STENCILOP_INCR: desc += "Inc:"; break;
|
|
|
|
case GE_STENCILOP_DECR: desc += "Dec:"; break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (id.ZPass()) {
|
|
|
|
case GE_STENCILOP_KEEP: break;
|
|
|
|
case GE_STENCILOP_ZERO: desc += "ZTstT0:"; break;
|
|
|
|
case GE_STENCILOP_REPLACE: desc += "ZTstTRpl:"; break;
|
|
|
|
case GE_STENCILOP_INVERT: desc += "ZTstTXor:"; break;
|
|
|
|
case GE_STENCILOP_INCR: desc += "ZTstTInc:"; break;
|
|
|
|
case GE_STENCILOP_DECR: desc += "ZTstTDec:"; break;
|
|
|
|
}
|
2021-11-21 16:21:59 +00:00
|
|
|
}
|
2022-01-30 02:34:14 +00:00
|
|
|
if (!id.stencilTest || id.clearMode) {
|
|
|
|
if (id.sFail != 0 || id.zFail != 0 || id.zPass != 0)
|
|
|
|
desc = "INVALID:" + desc;
|
|
|
|
}
|
2021-11-21 16:21:59 +00:00
|
|
|
|
|
|
|
if (id.alphaBlend) {
|
2022-01-30 02:34:14 +00:00
|
|
|
if (id.clearMode)
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.AlphaBlendEq()) {
|
2021-11-21 16:21:59 +00:00
|
|
|
case GE_BLENDMODE_MUL_AND_ADD: desc += "BlendAdd<"; break;
|
|
|
|
case GE_BLENDMODE_MUL_AND_SUBTRACT: desc += "BlendSub<"; break;
|
|
|
|
case GE_BLENDMODE_MUL_AND_SUBTRACT_REVERSE: desc += "BlendRSub<"; break;
|
|
|
|
case GE_BLENDMODE_MIN: desc += "BlendMin<"; break;
|
|
|
|
case GE_BLENDMODE_MAX: desc += "BlendMax<"; break;
|
|
|
|
case GE_BLENDMODE_ABSDIFF: desc += "BlendDiff<"; break;
|
|
|
|
}
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.AlphaBlendSrc()) {
|
2022-01-02 04:40:28 +00:00
|
|
|
case PixelBlendFactor::OTHERCOLOR: desc += "DstRGB,"; break;
|
|
|
|
case PixelBlendFactor::INVOTHERCOLOR: desc += "1-DstRGB,"; break;
|
|
|
|
case PixelBlendFactor::SRCALPHA: desc += "SrcA,"; break;
|
|
|
|
case PixelBlendFactor::INVSRCALPHA: desc += "1-SrcA,"; break;
|
|
|
|
case PixelBlendFactor::DSTALPHA: desc += "DstA,"; break;
|
|
|
|
case PixelBlendFactor::INVDSTALPHA: desc += "1-DstA,"; break;
|
|
|
|
case PixelBlendFactor::DOUBLESRCALPHA: desc += "2*SrcA,"; break;
|
|
|
|
case PixelBlendFactor::DOUBLEINVSRCALPHA: desc += "1-2*SrcA,"; break;
|
|
|
|
case PixelBlendFactor::DOUBLEDSTALPHA: desc += "2*DstA,"; break;
|
|
|
|
case PixelBlendFactor::DOUBLEINVDSTALPHA: desc += "1-2*DstA,"; break;
|
|
|
|
case PixelBlendFactor::FIX: desc += "Fix,"; break;
|
|
|
|
case PixelBlendFactor::ZERO: desc += "0,"; break;
|
|
|
|
case PixelBlendFactor::ONE: desc += "1,"; break;
|
2021-11-21 16:21:59 +00:00
|
|
|
}
|
2021-11-21 17:39:14 +00:00
|
|
|
switch (id.AlphaBlendDst()) {
|
2022-01-02 04:40:28 +00:00
|
|
|
case PixelBlendFactor::OTHERCOLOR: desc += "SrcRGB>:"; break;
|
|
|
|
case PixelBlendFactor::INVOTHERCOLOR: desc += "1-SrcRGB>:"; break;
|
|
|
|
case PixelBlendFactor::SRCALPHA: desc += "SrcA>:"; break;
|
|
|
|
case PixelBlendFactor::INVSRCALPHA: desc += "1-SrcA>:"; break;
|
|
|
|
case PixelBlendFactor::DSTALPHA: desc += "DstA>:"; break;
|
|
|
|
case PixelBlendFactor::INVDSTALPHA: desc += "1-DstA>:"; break;
|
|
|
|
case PixelBlendFactor::DOUBLESRCALPHA: desc += "2*SrcA>:"; break;
|
|
|
|
case PixelBlendFactor::DOUBLEINVSRCALPHA: desc += "1-2*SrcA>:"; break;
|
|
|
|
case PixelBlendFactor::DOUBLEDSTALPHA: desc += "2*DstA>:"; break;
|
|
|
|
case PixelBlendFactor::DOUBLEINVDSTALPHA: desc += "1-2*DstA>:"; break;
|
|
|
|
case PixelBlendFactor::FIX: desc += "Fix>:"; break;
|
|
|
|
case PixelBlendFactor::ZERO: desc += "0>:"; break;
|
|
|
|
case PixelBlendFactor::ONE: desc += "1>:"; break;
|
2021-11-21 16:21:59 +00:00
|
|
|
}
|
2022-01-30 02:34:14 +00:00
|
|
|
} else if (id.alphaBlendEq != 0 || id.alphaBlendSrc != 0 || id.alphaBlendDst != 0) {
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 16:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id.applyLogicOp)
|
|
|
|
desc += "Logic:";
|
2022-01-30 02:34:14 +00:00
|
|
|
else if (id.clearMode)
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 16:21:59 +00:00
|
|
|
if (id.applyFog)
|
|
|
|
desc += "Fog:";
|
2022-01-30 02:34:14 +00:00
|
|
|
else if (id.clearMode)
|
|
|
|
desc = "INVALID:" + desc;
|
2021-11-21 16:21:59 +00:00
|
|
|
|
|
|
|
if (desc.empty())
|
2022-01-30 02:34:14 +00:00
|
|
|
return "INVALID";
|
2021-11-21 16:21:59 +00:00
|
|
|
desc.resize(desc.size() - 1);
|
|
|
|
return desc;
|
|
|
|
}
|
2021-12-31 18:23:59 +00:00
|
|
|
|
|
|
|
void ComputeSamplerID(SamplerID *id_out) {
|
|
|
|
SamplerID id{};
|
|
|
|
|
|
|
|
id.useStandardBufw = true;
|
2022-01-03 00:52:22 +00:00
|
|
|
id.overReadSafe = true;
|
2021-12-31 18:23:59 +00:00
|
|
|
int maxLevel = gstate.isMipmapEnabled() ? gstate.getTextureMaxLevel() : 0;
|
2022-02-05 21:04:17 +00:00
|
|
|
GETextureFormat fmt = gstate.getTextureFormat();
|
2021-12-31 18:23:59 +00:00
|
|
|
for (int i = 0; i <= maxLevel; ++i) {
|
2022-01-03 00:52:22 +00:00
|
|
|
uint32_t addr = gstate.getTextureAddress(i);
|
|
|
|
if (!Memory::IsValidAddress(addr))
|
2021-12-31 18:23:59 +00:00
|
|
|
id.hasInvalidPtr = true;
|
2022-01-03 00:52:22 +00:00
|
|
|
|
2022-02-05 21:04:17 +00:00
|
|
|
int bufw = GetTextureBufw(i, addr, fmt);
|
|
|
|
int bitspp = textureBitsPerPixel[fmt];
|
2022-01-03 00:52:22 +00:00
|
|
|
// We use a 16 byte minimum for all small bufws, so allow those as standard.
|
2021-12-31 18:23:59 +00:00
|
|
|
int w = gstate.getTextureWidth(i);
|
2022-01-05 08:11:34 +00:00
|
|
|
if (bitspp == 0 || std::max(w, 128 / bitspp) != bufw)
|
2021-12-31 18:23:59 +00:00
|
|
|
id.useStandardBufw = false;
|
2022-02-05 21:04:17 +00:00
|
|
|
// TODO: Verify 16 bit bufw align handling in DXT.
|
|
|
|
if (fmt >= GE_TFMT_DXT1 && w != bufw)
|
|
|
|
id.useStandardBufw = false;
|
2022-01-03 00:52:22 +00:00
|
|
|
|
|
|
|
int h = gstate.getTextureHeight(i);
|
|
|
|
int bytes = h * (bufw * bitspp) / 8;
|
|
|
|
if (bitspp < 32 && !Memory::IsValidAddress(addr + bytes + (32 - bitspp) / 8))
|
|
|
|
id.overReadSafe = false;
|
2022-01-16 01:22:43 +00:00
|
|
|
|
|
|
|
id.cached.sizes[i].w = w;
|
|
|
|
id.cached.sizes[i].h = h;
|
2021-12-31 18:23:59 +00:00
|
|
|
}
|
2022-01-30 04:31:18 +00:00
|
|
|
// TODO: What specifically happens if these are above 11?
|
2022-01-23 06:41:41 +00:00
|
|
|
id.width0Shift = gstate.texsize[0] & 0xF;
|
|
|
|
id.height0Shift = (gstate.texsize[0] >> 8) & 0xF;
|
2021-12-31 18:23:59 +00:00
|
|
|
id.hasAnyMips = maxLevel != 0;
|
|
|
|
|
2022-02-05 21:04:17 +00:00
|
|
|
id.texfmt = fmt;
|
2021-12-31 18:23:59 +00:00
|
|
|
id.swizzle = gstate.isTextureSwizzled();
|
|
|
|
// Only CLUT4 can use separate CLUTs per mimap.
|
2022-02-05 21:04:17 +00:00
|
|
|
id.useSharedClut = fmt != GE_TFMT_CLUT4 || maxLevel == 0 || !gstate.isMipmapEnabled() || gstate.isClutSharedForMipmaps();
|
2021-12-31 18:23:59 +00:00
|
|
|
if (gstate.isTextureFormatIndexed()) {
|
|
|
|
id.clutfmt = gstate.getClutPaletteFormat();
|
|
|
|
id.hasClutMask = gstate.getClutIndexMask() != 0xFF;
|
|
|
|
id.hasClutShift = gstate.getClutIndexShift() != 0;
|
|
|
|
id.hasClutOffset = gstate.getClutIndexStartPos() != 0;
|
2022-01-16 02:09:09 +00:00
|
|
|
id.cached.clutFormat = gstate.clutformat;
|
2021-12-31 18:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
id.clampS = gstate.isTexCoordClampedS();
|
|
|
|
id.clampT = gstate.isTexCoordClampedT();
|
|
|
|
|
|
|
|
id.useTextureAlpha = gstate.isTextureAlphaUsed();
|
|
|
|
id.useColorDoubling = gstate.isColorDoublingEnabled();
|
|
|
|
id.texFunc = gstate.getTextureFunction();
|
|
|
|
if (id.texFunc > GE_TEXFUNC_ADD)
|
|
|
|
id.texFunc = GE_TEXFUNC_ADD;
|
|
|
|
|
2022-01-16 01:52:40 +00:00
|
|
|
if (id.texFunc == GE_TEXFUNC_BLEND)
|
|
|
|
id.cached.texBlendColor = gstate.getTextureEnvColRGB();
|
|
|
|
|
2021-12-31 18:23:59 +00:00
|
|
|
*id_out = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string DescribeSamplerID(const SamplerID &id) {
|
|
|
|
std::string name;
|
|
|
|
switch (id.TexFmt()) {
|
|
|
|
case GE_TFMT_5650: name = "5650"; break;
|
|
|
|
case GE_TFMT_5551: name = "5551"; break;
|
|
|
|
case GE_TFMT_4444: name = "4444"; break;
|
|
|
|
case GE_TFMT_8888: name = "8888"; break;
|
|
|
|
case GE_TFMT_CLUT4: name = "CLUT4"; break;
|
|
|
|
case GE_TFMT_CLUT8: name = "CLUT8"; break;
|
|
|
|
case GE_TFMT_CLUT16: name = "CLUT16"; break;
|
|
|
|
case GE_TFMT_CLUT32: name = "CLUT32"; break;
|
|
|
|
case GE_TFMT_DXT1: name = "DXT1"; break;
|
|
|
|
case GE_TFMT_DXT3: name = "DXT3"; break;
|
|
|
|
case GE_TFMT_DXT5: name = "DXT5"; break;
|
2022-01-30 04:31:18 +00:00
|
|
|
default: name = "INVALID"; break;
|
2021-12-31 18:23:59 +00:00
|
|
|
}
|
|
|
|
switch (id.ClutFmt()) {
|
|
|
|
case GE_CMODE_16BIT_BGR5650:
|
|
|
|
switch (id.TexFmt()) {
|
|
|
|
case GE_TFMT_CLUT4:
|
|
|
|
case GE_TFMT_CLUT8:
|
|
|
|
case GE_TFMT_CLUT16:
|
|
|
|
case GE_TFMT_CLUT32:
|
|
|
|
name += ":C5650";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Ignore 0 clutfmt when no clut.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GE_CMODE_16BIT_ABGR5551: name += ":C5551"; break;
|
|
|
|
case GE_CMODE_16BIT_ABGR4444: name += ":C4444"; break;
|
|
|
|
case GE_CMODE_32BIT_ABGR8888: name += ":C8888"; break;
|
|
|
|
}
|
|
|
|
if (id.swizzle) {
|
|
|
|
name += ":SWZ";
|
|
|
|
}
|
|
|
|
if (!id.useSharedClut) {
|
|
|
|
name += ":CMIP";
|
|
|
|
}
|
|
|
|
if (id.hasInvalidPtr) {
|
|
|
|
name += ":INV";
|
|
|
|
}
|
|
|
|
if (id.hasClutMask) {
|
|
|
|
name += ":CMASK";
|
|
|
|
}
|
|
|
|
if (id.hasClutShift) {
|
|
|
|
name += ":CSHF";
|
|
|
|
}
|
|
|
|
if (id.hasClutOffset) {
|
|
|
|
name += ":COFF";
|
|
|
|
}
|
|
|
|
if (id.clampS || id.clampT) {
|
|
|
|
name += std::string(":CL") + (id.clampS ? "S" : "") + (id.clampT ? "T" : "");
|
|
|
|
}
|
|
|
|
if (!id.useStandardBufw) {
|
|
|
|
name += ":BUFW";
|
|
|
|
}
|
2022-01-03 00:52:22 +00:00
|
|
|
if (!id.overReadSafe) {
|
|
|
|
name += ":XRD";
|
|
|
|
}
|
|
|
|
if (id.hasAnyMips) {
|
2021-12-31 18:23:59 +00:00
|
|
|
name += ":MIP";
|
|
|
|
}
|
|
|
|
if (id.linear) {
|
|
|
|
name += ":LERP";
|
|
|
|
}
|
2021-12-31 18:35:26 +00:00
|
|
|
if (id.fetch) {
|
|
|
|
name += ":FETCH";
|
|
|
|
}
|
2021-12-31 18:23:59 +00:00
|
|
|
if (id.useTextureAlpha) {
|
|
|
|
name += ":A";
|
|
|
|
}
|
|
|
|
if (id.useColorDoubling) {
|
|
|
|
name += ":DBL";
|
|
|
|
}
|
|
|
|
switch (id.texFunc) {
|
|
|
|
case GE_TEXFUNC_MODULATE:
|
|
|
|
name += ":MOD";
|
|
|
|
break;
|
|
|
|
case GE_TEXFUNC_DECAL:
|
|
|
|
name += ":DECAL";
|
|
|
|
break;
|
|
|
|
case GE_TEXFUNC_BLEND:
|
|
|
|
name += ":BLEND";
|
|
|
|
break;
|
|
|
|
case GE_TEXFUNC_REPLACE:
|
|
|
|
break;
|
|
|
|
case GE_TEXFUNC_ADD:
|
|
|
|
name += ":ADD";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
name += StringFromFormat(":W%dH%d", 1 << id.width0Shift, 1 << id.height0Shift);
|
2022-01-30 04:31:18 +00:00
|
|
|
if (id.width0Shift > 10 || id.height0Shift > 10)
|
|
|
|
name = "INVALID:" + name;
|
2021-12-31 18:23:59 +00:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|