mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-30 17:53:42 +01:00
Restructure the sprite detection, no longer require Smart 2D texture filtering to apply
This commit is contained in:
1 parent
3ba732d26f
commit
cf9c0c5c84
5 files changed
+107
-66
No files matched your search
@@ -86,8 +86,8 @@ void Compatibility::Load(const std::string &gameID) {
|
||||
}
|
||||
|
||||
void Compatibility::Clear() {
|
||||
memset(&flags_, 0, sizeof(flags_));
|
||||
memset(&vrCompat_, 0, sizeof(vrCompat_));
|
||||
flags_ = {};
|
||||
vrCompat_ = {};
|
||||
activeList_.clear();
|
||||
filesLoaded_.clear();
|
||||
}
|
||||
|
||||
@@ -539,16 +539,15 @@ bool DrawEngineCommon::TestBoundingBoxFast(const float *cullMatrix, const void *
|
||||
|
||||
// 2D bounding box test against scissor. No indexing yet.
|
||||
// Only supports non-indexed draws with float positions. TODO: Add more float formats.
|
||||
bool DrawEngineCommon::TestBoundingBoxThrough(const void *vdata, int vertexCount, const VertexDecoder *dec, u32 vertType, int *bytesRead) {
|
||||
// Grab temp buffer space from large offsets in decoded_. Not exactly safe for large draws.
|
||||
if (vertexCount > 16) {
|
||||
bool DrawEngineCommon::TestBoundingBoxThrough(GEPrimitiveType prim, const void *vdata, const void *idata, int vertexCount, const VertexDecoder *dec, u32 vertType, int *bytesRead, ClipInfoFlags *flags) {
|
||||
// Although this may lead to drawing that shouldn't happen, the viewport is more complex on VR.
|
||||
// Let's always say objects are within bounds.
|
||||
if (gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Although this may lead to drawing that shouldn't happen, the viewport is more complex on VR.
|
||||
// Let's always say objects are within bounds.
|
||||
if (gstate_c.Use(GPU_USE_VIRTUAL_REALITY))
|
||||
return true;
|
||||
// For through mode, we only check FlatZ.
|
||||
*flags |= ClipInfoFlags::Valid;
|
||||
|
||||
const int stride = dec->VertexSize();
|
||||
const int posOffset = dec->posoff;
|
||||
@@ -564,37 +563,76 @@ bool DrawEngineCommon::TestBoundingBoxThrough(const void *vdata, int vertexCount
|
||||
const float right = gstate.getScissorX2() + 1;
|
||||
const float bottom = gstate.getScissorY2() + 1;
|
||||
|
||||
switch (vertType & GE_VTYPE_POS_MASK) {
|
||||
case GE_VTYPE_POS_FLOAT:
|
||||
{
|
||||
// TODO: This can be SIMD'd, with some trickery.
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
const float *pos = (const float*)((const u8 *)vdata + stride * i + posOffset);
|
||||
const float x = pos[0];
|
||||
const float y = pos[1];
|
||||
if (x >= left) {
|
||||
allOutsideLeft = false;
|
||||
}
|
||||
if (x <= right) {
|
||||
allOutsideRight = false;
|
||||
}
|
||||
if (y >= top) {
|
||||
allOutsideTop = false;
|
||||
}
|
||||
if (y <= bottom) {
|
||||
allOutsideBottom = false;
|
||||
}
|
||||
float minZ = FLT_MAX;
|
||||
float maxZ = -FLT_MAX;
|
||||
|
||||
IndexConverter conv(vertType, idata);
|
||||
// TODO: This can be SIMD'd, with some trickery.
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
int index = conv(i);
|
||||
|
||||
float x, y, z;
|
||||
switch (vertType & GE_VTYPE_POS_MASK) {
|
||||
case GE_VTYPE_POS_FLOAT:
|
||||
{
|
||||
const float *pos = (const float*)((const u8 *)vdata + stride * index + posOffset);
|
||||
x = pos[0];
|
||||
y = pos[1];
|
||||
z = pos[2];
|
||||
}
|
||||
if (allOutsideLeft || allOutsideTop || allOutsideRight || allOutsideBottom) {
|
||||
break;
|
||||
case GE_VTYPE_POS_8BIT:
|
||||
{
|
||||
// Through mode doesn't really support 8-bit though.
|
||||
const u8 *pos8 = (const u8 *)vdata + stride * index + posOffset;
|
||||
x = pos8[0];
|
||||
y = pos8[1];
|
||||
z = pos8[2];
|
||||
break;
|
||||
}
|
||||
case GE_VTYPE_POS_16BIT:
|
||||
{
|
||||
const s16 *pos16 = (const s16 *)((const u8 *)vdata + stride * index + posOffset);
|
||||
x = pos16[0];
|
||||
y = pos16[1];
|
||||
z = (u16)pos16[2];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (x >= left) {
|
||||
allOutsideLeft = false;
|
||||
}
|
||||
if (x <= right) {
|
||||
allOutsideRight = false;
|
||||
}
|
||||
if (y >= top) {
|
||||
allOutsideTop = false;
|
||||
}
|
||||
if (y <= bottom) {
|
||||
allOutsideBottom = false;
|
||||
}
|
||||
|
||||
// If prim is rectangles, we only update minZ and maxZ for every second vertex,
|
||||
// since the Z for the whole rect is taken from the 2nd.
|
||||
if (prim != GE_PRIM_RECTANGLES || (i & 1) == 1) {
|
||||
if (z < minZ) {
|
||||
minZ = z;
|
||||
}
|
||||
if (z > maxZ) {
|
||||
maxZ = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
// Shouldn't end up here with the checks outside this function.
|
||||
_dbg_assert_(false);
|
||||
return true;
|
||||
if (allOutsideLeft || allOutsideTop || allOutsideRight || allOutsideBottom) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (minZ == maxZ) {
|
||||
*flags |= ClipInfoFlags::FlatZ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrawEngineCommon::EstimateThroughPrimSafeSize(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, const VertexDecoder *dec, u32 vertType, int *safeWidth, int *safeHeight) {
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
// This is a less accurate version of TestBoundingBox, but faster. Can have more false positives.
|
||||
// Doesn't support indexing.
|
||||
bool TestBoundingBoxFast(const float *cullMatrix, const void *vdata, const void *idata, int vertexCount, const VertexDecoder *dec, u32 vertType, ClipInfoFlags *clipInfoFlags);
|
||||
bool TestBoundingBoxThrough(const void *vdata, int vertexCount, const VertexDecoder *dec, u32 vertType, int *bytesRead);
|
||||
bool TestBoundingBoxThrough(GEPrimitiveType prim, const void *vdata, const void *idata, int vertexCount, const VertexDecoder *dec, u32 vertType, int *bytesRead, ClipInfoFlags *flags);
|
||||
bool EstimateThroughPrimSafeSize(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, const VertexDecoder *dec, u32 vertType, int *safeWidth, int *safeHeight);
|
||||
|
||||
void FlushPartialDecode() {
|
||||
|
||||
@@ -594,7 +594,7 @@ static void ClipTrianglesAgainstNearPlane(
|
||||
}
|
||||
|
||||
// Note: This modifies the U/V coordinates of transformed.
|
||||
static void ApplySpriteBorderFix(TransformedVertex *transformed, const u16 *quad, float uScale, float vScale, float spriteBorderFix) {
|
||||
static void ApplySpriteBorderFixTriangles(TransformedVertex *transformed, const u16 *quad, float uScale, float vScale, float spriteBorderFix) {
|
||||
const float invUScale = 1.0f / uScale;
|
||||
const float invVScale = 1.0f / vScale;
|
||||
|
||||
@@ -797,8 +797,13 @@ static SoftwareTransformAction ProjectClipAndExpand(SoftwareTransformParams &par
|
||||
|
||||
// Let's go look for pixel mapping.
|
||||
const bool flat = ((u32)params.clipInfoFlags & ((u32)(ClipInfoFlags::Valid | ClipInfoFlags::FlatZ))) == (u32)(ClipInfoFlags::Valid | ClipInfoFlags::FlatZ);
|
||||
const bool lookForPixelMapping = throughmode || flat;
|
||||
if (lookForPixelMapping && g_Config.bSmart2DTexFiltering && !gstate_c.textureIsVideo) {
|
||||
const bool lookForPixelMapping = flat && gstate.isMagnifyFilteringEnabled();
|
||||
|
||||
// TODO: We should probably take uv scale into account?
|
||||
const float uScale = gstate_c.curTextureWidth;
|
||||
const float vScale = gstate_c.curTextureHeight;
|
||||
bool pixelMapped = true;
|
||||
if (lookForPixelMapping && !gstate_c.textureIsVideo) {
|
||||
// We check some common cases for pixel mapping.
|
||||
//
|
||||
// It's enough to check UV deltas vs pos deltas between vertex pairs:
|
||||
@@ -807,43 +812,41 @@ static SoftwareTransformAction ProjectClipAndExpand(SoftwareTransformParams &par
|
||||
// so the operations are exact.
|
||||
//
|
||||
// Additionally, we check for sprite lists. These are used for example in GTA.
|
||||
const float spriteBorderFix = PSP_CoreParameter().compat.flags().SpriteBorderFix; // if != 0.0, apply border fix.
|
||||
bool pixelMapped = true;
|
||||
const u16 *indsIn = (const u16 *)inds;
|
||||
const float uScale = gstate_c.curTextureWidth;
|
||||
const float vScale = gstate_c.curTextureHeight;
|
||||
|
||||
// This assumes that we have a list of two-triangle sprites. If not the position checks will fail anyway.
|
||||
bool firstTriangleInQuad = true;
|
||||
for (int t = 0; t < vertexCount; t += 3) {
|
||||
struct { int a; int b; } pairs[] = {{0, 1}, {1, 2}, {2, 0}};
|
||||
for (int i = 0; i < ARRAY_SIZE(pairs); i++) {
|
||||
int a = indsIn[t + pairs[i].a];
|
||||
int b = indsIn[t + pairs[i].b];
|
||||
float du = fabsf((transformed[a].u - transformed[b].u) * uScale);
|
||||
float dv = fabsf((transformed[a].v - transformed[b].v) * vScale);
|
||||
float dx = fabsf(transformed[a].x - transformed[b].x);
|
||||
float dy = fabsf(transformed[a].y - transformed[b].y);
|
||||
const int a = indsIn[t + pairs[i].a];
|
||||
const int b = indsIn[t + pairs[i].b];
|
||||
const float du = fabsf((transformed[a].u - transformed[b].u) * uScale);
|
||||
const float dv = fabsf((transformed[a].v - transformed[b].v) * vScale);
|
||||
const float dx = fabsf(transformed[a].x - transformed[b].x);
|
||||
const float dy = fabsf(transformed[a].y - transformed[b].y);
|
||||
if (du != dx || dv != dy) {
|
||||
pixelMapped = false;
|
||||
}
|
||||
}
|
||||
if (!pixelMapped && spriteBorderFix == 0.0f) {
|
||||
if (!pixelMapped) {
|
||||
// Early out. Later add an early out for sprite border fix too.
|
||||
break;
|
||||
}
|
||||
|
||||
if (!firstTriangleInQuad && spriteBorderFix != 1.0f) {
|
||||
// The previous triangle started three vertices ago. Now, let's do some disgustingly hacky checks,
|
||||
// to identify the type of sprite (if any) and move the UV coordinates inwards a bit.
|
||||
const u16 *quad = indsIn + t - 3;
|
||||
ApplySpriteBorderFix(transformed, quad, uScale, vScale, spriteBorderFix);
|
||||
}
|
||||
firstTriangleInQuad = !firstTriangleInQuad;
|
||||
}
|
||||
result->pixelMapped = pixelMapped;
|
||||
}
|
||||
|
||||
// Apply the sprite border fix, but only if pixel mapping was not detected!
|
||||
const float spriteBorderFix = PSP_CoreParameter().compat.flags().SpriteBorderFix; // if != 0.0, apply border fix.
|
||||
if (spriteBorderFix != 0.0f && flat) {
|
||||
// This assumes that we have a list of two-triangle sprites. If not the position checks will fail anyway.
|
||||
const u16 *indsIn = (const u16 *)inds;
|
||||
for (int t = 0; t < vertexCount - 5; t += 6) {
|
||||
// The previous triangle started three vertices ago. Now, let's do some disgustingly hacky checks,
|
||||
// to identify the type of sprite (if any) and move the UV coordinates inwards a bit.
|
||||
const u16 *quad = indsIn + t;
|
||||
ApplySpriteBorderFixTriangles(transformed, quad, uScale, vScale, spriteBorderFix);
|
||||
}
|
||||
}
|
||||
|
||||
if (!throughmode) {
|
||||
// Culling and clipping needs to be done here, it doesn't happen in the shader in the case of software transform.
|
||||
// However, fast culling should already have taken care of the Z<-W and Z>W culling, but we check for it on a per-triangle
|
||||
|
||||
+5
-5
@@ -997,10 +997,12 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) {
|
||||
}
|
||||
}
|
||||
|
||||
// Through mode early-out for simple float 2D draws, like in Fate Extra CCC (very beneficial there due to avoiding texture loads)
|
||||
if ((vertexType & (GE_VTYPE_THROUGH_MASK | GE_VTYPE_POS_MASK | GE_VTYPE_IDX_MASK)) == (GE_VTYPE_THROUGH_MASK | GE_VTYPE_POS_FLOAT | GE_VTYPE_IDX_NONE)) {
|
||||
// Through mode early-out. Very beneficial for Fate Extra CCC (very beneficial there due to avoiding texture loads)
|
||||
// Also we take the opportunity to check for flat draws, where we can detect sprites (to fix filter artifacts).
|
||||
ClipInfoFlags flags{};
|
||||
if (gstate.isModeThrough()) {
|
||||
int bytesRead = 0;
|
||||
if (!drawEngineCommon_->TestBoundingBoxThrough(verts, count, decoder, vertexType, &bytesRead)) {
|
||||
if (!drawEngineCommon_->TestBoundingBoxThrough(prim, verts, inds, count, decoder, vertexType, &bytesRead, &flags)) {
|
||||
gpuStats.perFrame.numCulledDraws++;
|
||||
int cycles = vertexCost_ * count;
|
||||
gpuStats.perFrame.vertexGPUCycles += cycles;
|
||||
@@ -1024,8 +1026,6 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) {
|
||||
|
||||
#endif
|
||||
|
||||
ClipInfoFlags flags{};
|
||||
|
||||
// If certain conditions are true, do frustum culling.
|
||||
bool passCulling = PASSES_CULLING;
|
||||
if (!passCulling) {
|
||||
|
||||
Reference in new issue
Block a user