mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Add a unit test to mat4 x mat4
This commit is contained in:
1 parent
d8ee52fe23
commit
31dc48c815
3 files changed
+77
-15
No files matched your search
@@ -132,13 +132,6 @@ inline void Uint8x3ToInt4(int i[4], uint32_t u) {
|
||||
i[3] = 0;
|
||||
}
|
||||
|
||||
inline void Uint8x3ToInt4_Alpha(int i[4], uint32_t u, uint8_t alpha) {
|
||||
i[0] = ((u >> 0) & 0xFF);
|
||||
i[1] = ((u >> 8) & 0xFF);
|
||||
i[2] = ((u >> 16) & 0xFF);
|
||||
i[3] = alpha;
|
||||
}
|
||||
|
||||
inline void Uint8x3ToFloat4_Alpha(float f[4], uint32_t u, float alpha) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = ((u >> 8) & 0xFF) * (1.0f / 255.0f);
|
||||
@@ -146,13 +139,6 @@ inline void Uint8x3ToFloat4_Alpha(float f[4], uint32_t u, float alpha) {
|
||||
f[3] = alpha;
|
||||
}
|
||||
|
||||
inline void Uint8x1ToFloat4(float f[4], uint32_t u) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = 0.0f;
|
||||
f[2] = 0.0f;
|
||||
f[3] = 0.0f;
|
||||
}
|
||||
|
||||
// These are just for readability.
|
||||
|
||||
inline void CopyFloat2(float dest[2], const float src[2]) {
|
||||
@@ -206,6 +192,7 @@ inline void CopyMatrix4x4(float dest[16], const float src[16]) {
|
||||
memcpy(dest, src, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
// WARNING: This can quietly "over-load" src by 4 bytes.
|
||||
inline void ExpandFloat24x3ToFloat4(float dest[4], const uint32_t src[3]) {
|
||||
#ifdef _M_SSE
|
||||
__m128i values = _mm_slli_epi32(_mm_loadu_si128((const __m128i *)src), 8);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
|
||||
#include "Common/Math/SIMDHeaders.h"
|
||||
#include "Common/Common.h"
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
#include "Common/Data/Convert/ColorConv.h"
|
||||
#include "Common/File/VFS/VFS.h"
|
||||
#include "Common/File/VFS/DirectoryReader.h"
|
||||
#include "Common/Math/fast/fast_matrix.h"
|
||||
#include "Core/FileSystems/ISOFileSystem.h"
|
||||
#include "Core/MemMap.h"
|
||||
#include "Core/KeyMap.h"
|
||||
@@ -88,6 +89,7 @@
|
||||
#include "Core/MIPS/MIPSVFPUUtils.h"
|
||||
#include "GPU/Common/TextureDecoder.h"
|
||||
#include "GPU/Common/GPUStateUtils.h"
|
||||
#include "GPU/Math3D.h"
|
||||
|
||||
#include "Common/File/AndroidContentURI.h"
|
||||
|
||||
@@ -1233,6 +1235,79 @@ bool TestVolumeFunc() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestLinAlg() {
|
||||
static const float m1[16] = {
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16
|
||||
};
|
||||
static const float m2[16] = {
|
||||
56, 0, 24, 2,
|
||||
0.5f, 35, 2, 4,
|
||||
1, 6, 1, 2,
|
||||
4, 0, -1, -4
|
||||
};
|
||||
static const float correct[16] = {
|
||||
298.f, 380.f, 462.f, 544.f,
|
||||
245.5f, 287.f, 328.5f, 370.f,
|
||||
66.f, 76.f, 86.f, 96.f,
|
||||
-57.f, -58.f, -59.f, -60.f,
|
||||
};
|
||||
|
||||
float d[16]{};
|
||||
|
||||
fast_matrix_mul_4x4(d, m1, m2);
|
||||
|
||||
for (int i = 0; i < 16; i += 4) {
|
||||
// printf("%0.2f, %0.2f, %0.2f, %0.2f,\n", d[i], d[i + 1], d[i + 2], d[i + 3]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
EXPECT_EQ_FLOAT(d[i], correct[i]);
|
||||
}
|
||||
|
||||
|
||||
// OK, now test 4x3 multiplication.
|
||||
float a4x4[16];
|
||||
float b4x4[16];
|
||||
|
||||
ConvertMatrix4x3To4x4(a4x4, m1);
|
||||
ConvertMatrix4x3To4x4(b4x4, m1);
|
||||
Matrix4ByMatrix4(d, a4x4, b4x4);
|
||||
|
||||
for (int i = 0; i < 16; i += 4) {
|
||||
// printf("%0.2f, %0.2f, %0.2f, %0.2f,\n", d[i], d[i + 1], d[i + 2], d[i + 3]);
|
||||
}
|
||||
|
||||
static const float correct4x4[16] = {
|
||||
30.00, 36.00, 42.00, 0.00,
|
||||
66.00, 81.00, 96.00, 0.00,
|
||||
102.00, 126.00, 150.00, 0.00,
|
||||
148.00, 182.00, 216.00, 1.00,
|
||||
};
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
EXPECT_EQ_FLOAT(d[i], correct4x4[i]);
|
||||
}
|
||||
|
||||
ConvertMatrix4x3To4x4Transposed(b4x4, m1);
|
||||
Matrix4ByMatrix4(d, a4x4, b4x4);
|
||||
|
||||
static const float correct4x4transposed[16] = {
|
||||
14.00, 32.00, 50.00, 68.00,
|
||||
32.00, 77.00, 122.00, 167.00,
|
||||
50.00, 122.00, 194.00, 266.00,
|
||||
68.00, 167.00, 266.00, 366.00,
|
||||
};
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
EXPECT_EQ_FLOAT(d[i], correct4x4transposed[i]);
|
||||
}
|
||||
// TODO: Add direct 4x3 x 4x3 multiplication
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestSplitSearch() {
|
||||
std::string part1 = "The quick brown fox jumps";
|
||||
std::string part2 = " over the lazy dog.";
|
||||
@@ -1329,6 +1404,7 @@ TestItem availableTests[] = {
|
||||
TEST_ITEM(VolumeFunc),
|
||||
TEST_ITEM(SplitSearch),
|
||||
TEST_ITEM(FriendlyPath),
|
||||
TEST_ITEM(LinAlg),
|
||||
};
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
Reference in new issue
Block a user