mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
softgpu: Add func to calculate pixel func ID.
This normalizes some things, and eventually can be used for a jit key.
This commit is contained in:
parent
20c3c8f291
commit
953200c995
10 changed files with 222 additions and 36 deletions
|
@ -1580,6 +1580,8 @@ set(GPU_SOURCES
|
|||
GPU/Math3D.h
|
||||
GPU/Software/Clipper.cpp
|
||||
GPU/Software/Clipper.h
|
||||
GPU/Software/FuncId.cpp
|
||||
GPU/Software/FuncId.h
|
||||
GPU/Software/Lighting.cpp
|
||||
GPU/Software/Lighting.h
|
||||
GPU/Software/Rasterizer.cpp
|
||||
|
|
|
@ -454,6 +454,7 @@
|
|||
<ClInclude Include="Math3D.h" />
|
||||
<ClInclude Include="Software\Clipper.h" />
|
||||
<ClInclude Include="Software\Lighting.h" />
|
||||
<ClInclude Include="Software\FuncId.h" />
|
||||
<ClInclude Include="Software\Rasterizer.h" />
|
||||
<ClInclude Include="Software\RasterizerRectangle.h" />
|
||||
<ClInclude Include="Software\Sampler.h" />
|
||||
|
@ -629,6 +630,7 @@
|
|||
<ClCompile Include="Math3D.cpp" />
|
||||
<ClCompile Include="Software\Clipper.cpp" />
|
||||
<ClCompile Include="Software\Lighting.cpp" />
|
||||
<ClCompile Include="Software\FuncId.cpp" />
|
||||
<ClCompile Include="Software\Rasterizer.cpp" />
|
||||
<ClCompile Include="Software\RasterizerRectangle.cpp" />
|
||||
<ClCompile Include="Software\Sampler.cpp" />
|
||||
|
|
|
@ -264,6 +264,9 @@
|
|||
<ClInclude Include="Common\ReinterpretFramebuffer.h">
|
||||
<Filter>Common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Software\FuncId.h">
|
||||
<Filter>Software</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Math3D.cpp">
|
||||
|
@ -530,5 +533,8 @@
|
|||
<ClCompile Include="Common\ReinterpretFramebuffer.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Software\FuncId.cpp">
|
||||
<Filter>Software</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
77
GPU/Software/FuncId.cpp
Normal file
77
GPU/Software/FuncId.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
// 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/.
|
||||
|
||||
#include "GPU/Software/FuncId.h"
|
||||
#include "GPU/GPUState.h"
|
||||
|
||||
void ComputePixelFuncID(PixelFuncID *id) {
|
||||
id->fullKey = 0;
|
||||
|
||||
// TODO: Could this be minz > 0x0000 || maxz < 0xFFFF? Maybe unsafe, depending on verts...
|
||||
id->applyDepthRange = !gstate.isModeThrough();
|
||||
// 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) {
|
||||
id->colorClear = gstate.isClearModeColorMask();
|
||||
id->stencilClear = gstate.isClearModeAlphaMask();
|
||||
id->depthClear = gstate.isClearModeDepthMask();
|
||||
} 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();
|
||||
|
||||
if (id->stencilTest) {
|
||||
id->stencilTestFunc = gstate.getStencilTestFunction();
|
||||
id->stencilTestRef = gstate.getStencilTestRef() & gstate.getStencilTestMask();
|
||||
id->hasStencilTestMask = gstate.getStencilTestMask() != 0xFF;
|
||||
id->sFail = gstate.getStencilOpSFail();
|
||||
id->zFail = gstate.isDepthTestEnabled() ? gstate.getStencilOpZFail() : GE_STENCILOP_KEEP;
|
||||
id->zPass = gstate.getStencilOpZPass();
|
||||
}
|
||||
|
||||
id->depthTestFunc = gstate.isDepthTestEnabled() ? gstate.getDepthTestFunction() : GE_COMP_ALWAYS;
|
||||
id->alphaTestFunc = gstate.isAlphaTestEnabled() ? gstate.getAlphaTestFunction() : GE_COMP_ALWAYS;
|
||||
if (id->alphaTestFunc != GE_COMP_ALWAYS) {
|
||||
id->alphaTestRef = gstate.getAlphaTestRef() & gstate.getAlphaTestMask();
|
||||
id->hasAlphaTestMask = gstate.getAlphaTestMask() != 0xFF;
|
||||
}
|
||||
|
||||
id->alphaBlend = gstate.isAlphaBlendEnabled();
|
||||
if (id->alphaBlend) {
|
||||
id->alphaBlendEq = gstate.getBlendEq();
|
||||
id->alphaBlendSrc = gstate.getBlendFuncA();
|
||||
id->alphaBlendDst = gstate.getBlendFuncB();
|
||||
}
|
||||
|
||||
id->applyLogicOp = gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_COPY;
|
||||
id->applyFog = gstate.isFogEnabled() && !gstate.isModeThrough();
|
||||
}
|
||||
}
|
128
GPU/Software/FuncId.h
Normal file
128
GPU/Software/FuncId.h
Normal file
|
@ -0,0 +1,128 @@
|
|||
// 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/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include "GPU/ge_constants.h"
|
||||
|
||||
struct PixelFuncID {
|
||||
PixelFuncID() {
|
||||
}
|
||||
|
||||
union {
|
||||
uint64_t fullKey{};
|
||||
struct {
|
||||
bool clearMode : 1;
|
||||
union {
|
||||
bool colorTest : 1;
|
||||
bool colorClear : 1;
|
||||
};
|
||||
union {
|
||||
bool stencilTest : 1;
|
||||
bool stencilClear : 1;
|
||||
};
|
||||
union {
|
||||
bool depthWrite : 1;
|
||||
bool depthClear : 1;
|
||||
};
|
||||
bool applyDepthRange : 1;
|
||||
// If alpha testing is disabled, set to GE_COMP_ALWAYS.
|
||||
GEComparison alphaTestFunc : 3;
|
||||
// If depth testing is disabled, set to GE_COMP_ALWAYS.
|
||||
GEComparison depthTestFunc : 3;
|
||||
GEComparison stencilTestFunc : 3;
|
||||
GEBufferFormat fbFormat : 2;
|
||||
// 16 bits before alphaTestRef.
|
||||
uint8_t alphaTestRef : 8;
|
||||
uint8_t stencilTestRef : 8;
|
||||
// 32 bits before alphaBlend.
|
||||
bool alphaBlend : 1;
|
||||
GEBlendMode alphaBlendEq : 3;
|
||||
GEBlendSrcFactor alphaBlendSrc : 4;
|
||||
GEBlendDstFactor alphaBlendDst : 4;
|
||||
// Meaning: alphaTestMask != 0xFF
|
||||
bool hasAlphaTestMask : 1;
|
||||
// Meaning: stencilTestMask != 0xFF
|
||||
bool hasStencilTestMask : 1;
|
||||
bool dithering : 1;
|
||||
bool applyLogicOp : 1;
|
||||
// 48 bits before applyFog.
|
||||
bool applyFog : 1;
|
||||
// Meaning: fb_stride == 512 && z_stride == 512
|
||||
bool useStandardStride : 1;
|
||||
// Meaning: maskRGB != 0 || maskA != 0
|
||||
bool applyColorWriteMask : 1;
|
||||
GEStencilOp sFail : 3;
|
||||
GEStencilOp zFail : 3;
|
||||
GEStencilOp zPass : 3;
|
||||
// 60 bits, 4 free.
|
||||
};
|
||||
};
|
||||
|
||||
bool operator == (const PixelFuncID &other) const {
|
||||
return fullKey == other.fullKey;
|
||||
}
|
||||
};
|
||||
|
||||
struct SamplerID {
|
||||
SamplerID() : fullKey(0) {
|
||||
}
|
||||
|
||||
union {
|
||||
uint32_t fullKey;
|
||||
struct {
|
||||
uint8_t texfmt : 4;
|
||||
uint8_t clutfmt : 2;
|
||||
uint8_t : 2;
|
||||
bool swizzle : 1;
|
||||
bool useSharedClut : 1;
|
||||
bool hasClutMask : 1;
|
||||
bool hasClutShift : 1;
|
||||
bool hasClutOffset : 1;
|
||||
bool hasInvalidPtr : 1;
|
||||
bool linear : 1;
|
||||
};
|
||||
};
|
||||
|
||||
bool operator == (const SamplerID &other) const {
|
||||
return fullKey == other.fullKey;
|
||||
}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<PixelFuncID> {
|
||||
std::size_t operator()(const PixelFuncID &k) const {
|
||||
return hash<uint64_t>()(k.fullKey);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<SamplerID> {
|
||||
std::size_t operator()(const SamplerID &k) const {
|
||||
return hash<uint32_t>()(k.fullKey);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
void ComputePixelFuncID(PixelFuncID *id);
|
|
@ -32,42 +32,7 @@
|
|||
#include "Common/FakeEmitter.h"
|
||||
#endif
|
||||
#include "GPU/Math3D.h"
|
||||
|
||||
struct SamplerID {
|
||||
SamplerID() : fullKey(0) {
|
||||
}
|
||||
|
||||
union {
|
||||
u32 fullKey;
|
||||
struct {
|
||||
uint8_t texfmt : 4;
|
||||
uint8_t clutfmt : 2;
|
||||
uint8_t : 2;
|
||||
bool swizzle : 1;
|
||||
bool useSharedClut : 1;
|
||||
bool hasClutMask : 1;
|
||||
bool hasClutShift : 1;
|
||||
bool hasClutOffset : 1;
|
||||
bool hasInvalidPtr : 1;
|
||||
bool linear : 1;
|
||||
};
|
||||
};
|
||||
|
||||
bool operator == (const SamplerID &other) const {
|
||||
return fullKey == other.fullKey;
|
||||
}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<SamplerID> {
|
||||
std::size_t operator()(const SamplerID &k) const {
|
||||
return hash<u32>()(k.fullKey);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
#include "GPU/Software/FuncId.h"
|
||||
|
||||
namespace Sampler {
|
||||
|
||||
|
|
|
@ -426,6 +426,7 @@
|
|||
<ClInclude Include="..\..\GPU\GPUState.h" />
|
||||
<ClInclude Include="..\..\GPU\Math3D.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Clipper.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\FuncId.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Lighting.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Rasterizer.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\RasterizerRectangle.h" />
|
||||
|
@ -484,6 +485,7 @@
|
|||
<ClCompile Include="..\..\GPU\GPUState.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Math3D.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Clipper.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\FuncId.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Lighting.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Rasterizer.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\RasterizerRectangle.cpp" />
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
<ClCompile Include="..\..\GPU\GPUState.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Math3D.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Clipper.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\FuncId.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Lighting.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Rasterizer.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Sampler.cpp" />
|
||||
|
@ -102,6 +103,7 @@
|
|||
<ClInclude Include="..\..\GPU\GPUState.h" />
|
||||
<ClInclude Include="..\..\GPU\Math3D.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Clipper.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\FuncId.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Lighting.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Rasterizer.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Sampler.h" />
|
||||
|
|
|
@ -358,6 +358,7 @@ EXEC_AND_LIB_FILES := \
|
|||
$(SRC)/GPU/GLES/FragmentTestCacheGLES.cpp.arm \
|
||||
$(SRC)/GPU/GLES/TextureScalerGLES.cpp \
|
||||
$(SRC)/GPU/Software/Clipper.cpp \
|
||||
$(SRC)/GPU/Software/FuncId.cpp \
|
||||
$(SRC)/GPU/Software/Lighting.cpp \
|
||||
$(SRC)/GPU/Software/Rasterizer.cpp.arm \
|
||||
$(SRC)/GPU/Software/RasterizerRectangle.cpp.arm \
|
||||
|
|
|
@ -348,6 +348,7 @@ SOURCES_CXX += \
|
|||
$(GPUDIR)/GPUState.cpp \
|
||||
$(GPUDIR)/Math3D.cpp \
|
||||
$(GPUDIR)/Software/Clipper.cpp \
|
||||
$(GPUDIR)/Software/FuncId.cpp \
|
||||
$(GPUDIR)/Software/Lighting.cpp \
|
||||
$(GPUDIR)/Software/Rasterizer.cpp \
|
||||
$(GPUDIR)/Software/RasterizerRectangle.cpp \
|
||||
|
|
Loading…
Add table
Reference in a new issue