softjit: Add tests for compile success.

This commit is contained in:
Unknown W. Brackets 2022-01-29 18:34:14 -08:00
parent e266eb78ad
commit 0d93200faf
7 changed files with 110 additions and 2 deletions

View file

@ -2318,6 +2318,7 @@ if(UNITTEST)
unittest/TestArm64Emitter.cpp
unittest/TestX64Emitter.cpp
unittest/TestVertexJit.cpp
unittest/TestSoftwareGPUJit.cpp
unittest/TestThreadManager.cpp
unittest/JitHarness.cpp
Core/MIPS/ARM/ArmRegCache.cpp

View file

@ -253,6 +253,8 @@ std::string DescribePixelFuncID(const PixelFuncID &id) {
}
if (id.AlphaTestFunc() != GE_COMP_ALWAYS) {
if (id.clearMode)
desc = "INVALID:" + desc;
switch (id.AlphaTestFunc()) {
case GE_COMP_NEVER: desc += "ANever"; break;
case GE_COMP_ALWAYS: break;
@ -266,9 +268,13 @@ std::string DescribePixelFuncID(const PixelFuncID &id) {
if (id.hasAlphaTestMask)
desc += "Msk";
desc += StringFromFormat("%02X:", id.alphaTestRef);
} else if (id.hasAlphaTestMask || id.alphaTestRef != 0) {
desc = "INVALID:" + desc;
}
if (id.DepthTestFunc() != GE_COMP_ALWAYS) {
if (id.clearMode)
desc = "INVALID:" + desc;
switch (id.DepthTestFunc()) {
case GE_COMP_NEVER: desc += "ZNever:"; break;
case GE_COMP_ALWAYS: break;
@ -300,6 +306,8 @@ std::string DescribePixelFuncID(const PixelFuncID &id) {
if (id.hasStencilTestMask)
desc += "Msk";
desc += StringFromFormat("%02X:", id.stencilTestRef);
} else if (id.hasStencilTestMask || id.stencilTestRef != 0 || id.stencilTestFunc != 0) {
desc = "INVALID:" + desc;
}
switch (id.SFail()) {
@ -326,8 +334,14 @@ std::string DescribePixelFuncID(const PixelFuncID &id) {
case GE_STENCILOP_INCR: desc += "ZTstTInc:"; break;
case GE_STENCILOP_DECR: desc += "ZTstTDec:"; break;
}
if (!id.stencilTest || id.clearMode) {
if (id.sFail != 0 || id.zFail != 0 || id.zPass != 0)
desc = "INVALID:" + desc;
}
if (id.alphaBlend) {
if (id.clearMode)
desc = "INVALID:" + desc;
switch (id.AlphaBlendEq()) {
case GE_BLENDMODE_MUL_AND_ADD: desc += "BlendAdd<"; break;
case GE_BLENDMODE_MUL_AND_SUBTRACT: desc += "BlendSub<"; break;
@ -366,15 +380,21 @@ std::string DescribePixelFuncID(const PixelFuncID &id) {
case PixelBlendFactor::ZERO: desc += "0>:"; break;
case PixelBlendFactor::ONE: desc += "1>:"; break;
}
} else if (id.alphaBlendEq != 0 || id.alphaBlendSrc != 0 || id.alphaBlendDst != 0) {
desc = "INVALID:" + desc;
}
if (id.applyLogicOp)
desc += "Logic:";
else if (id.clearMode)
desc = "INVALID:" + desc;
if (id.applyFog)
desc += "Fog:";
else if (id.clearMode)
desc = "INVALID:" + desc;
if (desc.empty())
return desc;
return "INVALID";
desc.resize(desc.size() - 1);
return desc;
}

View file

@ -738,8 +738,9 @@ ifeq ($(UNITTEST),1)
LOCAL_SRC_FILES := \
$(SRC)/unittest/JitHarness.cpp \
$(SRC)/unittest/TestShaderGenerators.cpp \
$(SRC)/unittest/TestVertexJit.cpp \
$(SRC)/unittest/TestSoftwareGPUJit.cpp \
$(SRC)/unittest/TestThreadManager.cpp \
$(SRC)/unittest/TestVertexJit.cpp \
$(TESTARMEMITTER_FILE) \
$(SRC)/unittest/UnitTest.cpp

View file

@ -0,0 +1,82 @@
// Copyright (c) 2022- 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 "Common/Data/Random/Rng.h"
#include "Common/StringUtils.h"
#include "Core/Config.h"
#include "GPU/Software/DrawPixel.h"
#include "GPU/Software/Sampler.h"
#include "GPU/Software/SoftGpu.h"
static bool TestPixelJit() {
using namespace Rasterizer;
PixelJitCache *cache = new PixelJitCache();
GMRng rng;
int successes = 0;
int count = 3000;
bool header = false;
u32 *fb_data = new u32[512 * 2];
u16 *zb_data = new u16[512 * 2];
fb.as32 = fb_data;
depthbuf.as16 = zb_data;
for (int i = 0; i < count; ) {
PixelFuncID id;
memset(&id, 0, sizeof(id));
id.fullKey = (uint64_t)rng.R32() | ((uint64_t)rng.R32() << 32);
std::string desc = DescribePixelFuncID(id);
if (startsWith(desc, "INVALID"))
continue;
i++;
SingleFunc func = cache->GetSingle(id);
SingleFunc genericFunc = cache->GenericSingle(id);
if (func != genericFunc) {
successes++;
} else {
if (!header)
printf("Failed funcs:\n");
header = true;
printf(" * %s\n", desc.c_str());
}
// Try running it to make sure it doesn't trivially crash.
func(0, 0, 1000, 255, ToVec4IntArg(Math3D::Vec4<int>(127, 127, 127, 127)), id);
}
if (successes < count)
printf("PixelFunc success: %d / %d\n", successes, count);
delete [] fb_data;
delete [] zb_data;
delete cache;
return successes == count && !HitAnyAsserts();
}
bool TestSoftwareGPUJit() {
g_Config.bSoftwareRenderingJit = true;
ResetHitAnyAsserts();
if (!TestPixelJit()) {
return false;
}
return true;
}

View file

@ -754,6 +754,7 @@ bool TestArmEmitter();
bool TestArm64Emitter();
bool TestX64Emitter();
bool TestShaderGenerators();
bool TestSoftwareGPUJit();
bool TestThreadManager();
TestItem availableTests[] = {
@ -779,6 +780,7 @@ TestItem availableTests[] = {
TEST_ITEM(CLZ),
TEST_ITEM(MemMap),
TEST_ITEM(ShaderGenerators),
TEST_ITEM(SoftwareGPUJit),
TEST_ITEM(Path),
TEST_ITEM(AndroidContentURI),
TEST_ITEM(ThreadManager),

View file

@ -383,6 +383,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="TestShaderGenerators.cpp" />
<ClCompile Include="TestSoftwareGPUJit.cpp" />
<ClCompile Include="TestThreadManager.cpp" />
<ClCompile Include="TestVertexJit.cpp" />
<ClCompile Include="UnitTest.cpp" />

View file

@ -13,6 +13,7 @@
</ClCompile>
<ClCompile Include="TestShaderGenerators.cpp" />
<ClCompile Include="TestThreadManager.cpp" />
<ClCompile Include="TestSoftwareGPUJit.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="JitHarness.h" />