From fd88f79d075619c59ebf0480d551b101afde9c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 10 Feb 2025 11:51:22 -0600 Subject: [PATCH] CrossSIMD: Fix more no-simd fallbacks. The depth rasterizer now works in TEST_FALLBACK mode. --- Common/Math/CrossSIMD.h | 54 ++++++++++++++++----------------- Common/UI/Root.cpp | 3 -- Core/Config.cpp | 6 ++++ GPU/Common/DepthRaster.cpp | 1 + GPU/Common/DrawEngineCommon.cpp | 10 +++--- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Common/Math/CrossSIMD.h b/Common/Math/CrossSIMD.h index c530a27780..b5050d75d6 100644 --- a/Common/Math/CrossSIMD.h +++ b/Common/Math/CrossSIMD.h @@ -765,18 +765,18 @@ struct Mat4F32 { mat.m[1] = src[1]; mat.m[2] = src[2]; mat.m[3] = 0.0f; - mat.m[0] = src[3]; - mat.m[1] = src[4]; - mat.m[2] = src[5]; - mat.m[3] = 0.0f; - mat.m[0] = src[6]; - mat.m[1] = src[7]; - mat.m[2] = src[8]; - mat.m[3] = 0.0f; - mat.m[0] = src[9]; - mat.m[1] = src[10]; - mat.m[2] = src[11]; - mat.m[3] = 1.0f; + mat.m[4] = src[3]; + mat.m[5] = src[4]; + mat.m[6] = src[5]; + mat.m[7] = 0.0f; + mat.m[8] = src[6]; + mat.m[9] = src[7]; + mat.m[10] = src[8]; + mat.m[11] = 0.0f; + mat.m[12] = src[9]; + mat.m[13] = src[10]; + mat.m[14] = src[11]; + mat.m[15] = 1.0f; return mat; } @@ -1083,23 +1083,21 @@ struct Vec4F32 { return temp; } - // In-place transpose. Fast on SIMD, not ideal on not. + // In-place transpose. static void Transpose(Vec4F32 &col0, Vec4F32 &col1, Vec4F32 &col2, Vec4F32 &col3) { - std::swap(col0.v[1], col1.v[0]); - std::swap(col0.v[2], col2.v[0]); - std::swap(col0.v[3], col3.v[0]); - - std::swap(col1.v[0], col0.v[1]); - std::swap(col1.v[2], col2.v[1]); - std::swap(col1.v[3], col3.v[1]); - - std::swap(col2.v[0], col0.v[2]); - std::swap(col2.v[1], col1.v[2]); - std::swap(col2.v[3], col3.v[2]); - - std::swap(col3.v[0], col0.v[3]); - std::swap(col3.v[1], col1.v[3]); - std::swap(col3.v[2], col2.v[3]); + float m[16]; + for (int i = 0; i < 4; i++) { + m[0 + i] = col0.v[i]; + m[4 + i] = col1.v[i]; + m[8 + i] = col2.v[i]; + m[12 + i] = col3.v[i]; + } + for (int i = 0; i < 4; i++) { + col0.v[i] = m[i * 4 + 0]; + col1.v[i] = m[i * 4 + 1]; + col2.v[i] = m[i * 4 + 2]; + col3.v[i] = m[i * 4 + 3]; + } } inline Vec4F32 AsVec3ByMatrix44(const Mat4F32 &m) { diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index 20eb0b4807..25cb5a7e0a 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -97,9 +97,6 @@ bool IsFocusMovementEnabled() { } void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets) { - _assert_(root); - _assert_(&dc); - Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds(); MeasureSpec horiz(EXACTLY, rootBounds.w); diff --git a/Core/Config.cpp b/Core/Config.cpp index d95bfac817..b0d8579ea3 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -40,6 +40,7 @@ #include "Common/File/FileUtil.h" #include "Common/File/VFS/VFS.h" #include "Common/Log/LogManager.h" +#include "Common/Math/CrossSIMD.h" #include "Common/OSVersion.h" #include "Common/System/Display.h" #include "Common/System/System.h" @@ -140,6 +141,11 @@ std::string DefaultLangRegion() { } static int DefaultDepthRaster() { +#ifdef CROSSSIMD_SLOW + // No SIMD acceleration for the depth rasterizer. + // Default to off. + return (int)DepthRasterMode::OFF; +#endif // For 64-bit ARM and x86 with SIMD, enable depth raster. #if PPSSPP_ARCH(ARM64_NEON) || PPSSPP_ARCH(SSE2) diff --git a/GPU/Common/DepthRaster.cpp b/GPU/Common/DepthRaster.cpp index a6c43d017a..c46278f36b 100644 --- a/GPU/Common/DepthRaster.cpp +++ b/GPU/Common/DepthRaster.cpp @@ -348,6 +348,7 @@ int DepthRasterClipIndexedRectangles(int *tx, int *ty, float *tz, const float *t } // These names are wrong .. until we transpose. + // TODO: Maybe combine two rects here at a time. But hardly relevant for performance. Vec4F32 x = Vec4F32::Load(verts[0]); Vec4F32 y = Vec4F32::Load(verts[1]); Vec4F32 z = Vec4F32::Zero(); diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index c27c79e528..9d77882c9c 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -56,9 +56,6 @@ DrawEngineCommon::DrawEngineCommon() : decoderMap_(32) { decIndex_ = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE); indexGen.Setup(decIndex_); -#ifdef CROSSSIMD_SLOW - useDepthRaster_ = false; -#else switch ((DepthRasterMode)g_Config.iDepthRasterMode) { case DepthRasterMode::DEFAULT: case DepthRasterMode::LOW_QUALITY: @@ -70,7 +67,7 @@ DrawEngineCommon::DrawEngineCommon() : decoderMap_(32) { case DepthRasterMode::OFF: useDepthRaster_ = false; } -#endif + if (useDepthRaster_) { depthDraws_.reserve(256); } @@ -933,12 +930,15 @@ Mat4F32 ComputeFinalProjMatrix() { gstate.getViewportXCenter() - gstate.getOffsetX(), gstate.getViewportYCenter() - gstate.getOffsetY(), gstate.getViewportZCenter(), + 0.0f, }; Mat4F32 wv = Mul4x3By4x4(Mat4x3F32(gstate.worldMatrix), Mat4F32::Load4x3(gstate.viewMatrix)); Mat4F32 m = Mul4x4By4x4(wv, Mat4F32(gstate.projMatrix)); // NOTE: Applying the translation actually works pre-divide, since W is also affected. - TranslateAndScaleInplace(m, Vec4F32::LoadF24x3_One(&gstate.viewportxscale), Vec4F32::Load(viewportTranslate)); + Vec4F32 scale = Vec4F32::LoadF24x3_One(&gstate.viewportxscale); + Vec4F32 translate = Vec4F32::Load(viewportTranslate); + TranslateAndScaleInplace(m, scale, translate); return m; }