From c4d26dcb103a38602fc6d3732213b1efeea88e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 4 Jun 2019 22:24:19 +0200 Subject: [PATCH 01/21] ARM64 vmmul experiment: Disable if S and T matrices overlap. If this fixes anything in #12082, we have a regalloc bug I guess... --- Core/MIPS/ARM64/Arm64CompVFPU.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Core/MIPS/ARM64/Arm64CompVFPU.cpp b/Core/MIPS/ARM64/Arm64CompVFPU.cpp index 19ad4ed8d5..d89bfd36a4 100644 --- a/Core/MIPS/ARM64/Arm64CompVFPU.cpp +++ b/Core/MIPS/ARM64/Arm64CompVFPU.cpp @@ -1227,10 +1227,11 @@ namespace MIPSComp { GetMatrixRegs(tregs, sz, _VT); GetMatrixRegs(dregs, sz, _VD); - MatrixOverlapType soverlap = GetMatrixOverlap(_VS, _VD, sz); - MatrixOverlapType toverlap = GetMatrixOverlap(_VT, _VD, sz); + MatrixOverlapType sdoverlap = GetMatrixOverlap(_VS, _VD, sz); + MatrixOverlapType tdoverlap = GetMatrixOverlap(_VT, _VD, sz); + MatrixOverlapType stoverlap = GetMatrixOverlap(_VS, _VT, sz); - if (soverlap || toverlap) { + if (sdoverlap != OVERLAP_NONE || tdoverlap != OVERLAP_NONE || stoverlap != OVERLAP_NONE) { DISABLE; } else { for (int a = 0; a < n; a++) { From 649b7a5671479b3c1a3ff8a7199dbc76ad9efa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 5 Jun 2019 00:02:32 +0200 Subject: [PATCH 02/21] ARM64 vmmov experiment: Reduce precision by using FMUL+FADD instead of FMADD. May help #12082 and thus also #11179 and #9843. --- Core/MIPS/ARM64/Arm64CompVFPU.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/MIPS/ARM64/Arm64CompVFPU.cpp b/Core/MIPS/ARM64/Arm64CompVFPU.cpp index d89bfd36a4..c0264bae6c 100644 --- a/Core/MIPS/ARM64/Arm64CompVFPU.cpp +++ b/Core/MIPS/ARM64/Arm64CompVFPU.cpp @@ -1240,7 +1240,8 @@ namespace MIPSComp { fp.FMUL(fpr.V(dregs[a * 4 + b]), fpr.V(sregs[b * 4]), fpr.V(tregs[a * 4])); for (int c = 1; c < n; c++) { fpr.MapDirtyInInV(dregs[a * 4 + b], sregs[b * 4 + c], tregs[a * 4 + c], false); - fp.FMADD(fpr.V(dregs[a * 4 + b]), fpr.V(sregs[b * 4 + c]), fpr.V(tregs[a * 4 + c]), fpr.V(dregs[a * 4 + b])); + fp.FMUL(S0, fpr.V(sregs[b * 4 + c]), fpr.V(tregs[a * 4 + c])); + fp.FADD(fpr.V(dregs[a * 4 + b]), fpr.V(dregs[a * 4 + b]), S0); } } } From c80961e41ccf20c439c63d21c6ff8e32d31ff155 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Thu, 6 Jun 2019 15:17:08 +0800 Subject: [PATCH 03/21] UWP: fix prebuild commands --- UWP/UWP.vcxproj | 200 +++++++++++++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 80 deletions(-) diff --git a/UWP/UWP.vcxproj b/UWP/UWP.vcxproj index 53d38241e1..293a138c6c 100644 --- a/UWP/UWP.vcxproj +++ b/UWP/UWP.vcxproj @@ -204,12 +204,16 @@ _DEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -225,12 +229,16 @@ copy AssetsNormal\*.* Assets /Y _DEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -246,12 +254,16 @@ copy AssetsNormal\*.* Assets /Y NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -267,12 +279,16 @@ copy AssetsNormal\*.* Assets /Y NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -288,12 +304,16 @@ copy AssetsNormal\*.* Assets /Y GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageGold.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsGold\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageGold.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsGold\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -309,12 +329,16 @@ copy AssetsGold\*.* Assets /Y GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageGold.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsGold\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageGold.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsGold\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -330,12 +354,16 @@ copy AssetsGold\*.* Assets /Y _DEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -351,12 +379,16 @@ copy AssetsNormal\*.* Assets /Y NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -372,12 +404,16 @@ copy AssetsNormal\*.* Assets /Y GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageGold.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsGold\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageGold.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsGold\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -393,12 +429,16 @@ copy AssetsGold\*.* Assets /Y _DEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -414,12 +454,16 @@ copy AssetsNormal\*.* Assets /Y NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageNormal.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsNormal\*.* Assets /Y -../Windows/git-version-gen.cmd - + + + copy PackageNormal.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsNormal\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + @@ -435,20 +479,16 @@ copy AssetsNormal\*.* Assets /Y GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - copy PackageGold.appxmanifest Package.appxmanifest /Y -mkdir Assets -copy AssetsGold\*.* Assets /Y -../Windows/git-version-gen.cmd - - - - - - robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 - EXIT 0 - - + + + copy PackageGold.appxmanifest Package.appxmanifest /Y + mkdir Assets + copy AssetsGold\*.* Assets /Y + ../Windows/git-version-gen.cmd + robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + EXIT 0 + + From f49999efcab873883627e82fd7580762cdb031c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 6 Jun 2019 09:34:23 +0200 Subject: [PATCH 04/21] Revert "ARM64 vmmul experiment: Disable if S and T matrices overlap." This reverts commit c4d26dcb103a38602fc6d3732213b1efeea88e5b. --- Core/MIPS/ARM64/Arm64CompVFPU.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Core/MIPS/ARM64/Arm64CompVFPU.cpp b/Core/MIPS/ARM64/Arm64CompVFPU.cpp index c0264bae6c..243890f1ea 100644 --- a/Core/MIPS/ARM64/Arm64CompVFPU.cpp +++ b/Core/MIPS/ARM64/Arm64CompVFPU.cpp @@ -1227,11 +1227,10 @@ namespace MIPSComp { GetMatrixRegs(tregs, sz, _VT); GetMatrixRegs(dregs, sz, _VD); - MatrixOverlapType sdoverlap = GetMatrixOverlap(_VS, _VD, sz); - MatrixOverlapType tdoverlap = GetMatrixOverlap(_VT, _VD, sz); - MatrixOverlapType stoverlap = GetMatrixOverlap(_VS, _VT, sz); + MatrixOverlapType soverlap = GetMatrixOverlap(_VS, _VD, sz); + MatrixOverlapType toverlap = GetMatrixOverlap(_VT, _VD, sz); - if (sdoverlap != OVERLAP_NONE || tdoverlap != OVERLAP_NONE || stoverlap != OVERLAP_NONE) { + if (soverlap || toverlap) { DISABLE; } else { for (int a = 0; a < n; a++) { From 420156d9b331d79c9687742b3f6dccda17f59e66 Mon Sep 17 00:00:00 2001 From: Aaron Kling Date: Thu, 6 Jun 2019 11:42:32 -0500 Subject: [PATCH 05/21] libretro: Add SpvPostProcess.cpp to the static makefiles A glslang submodule update added this file --- libretro/Makefile.common | 1 + 1 file changed, 1 insertion(+) diff --git a/libretro/Makefile.common b/libretro/Makefile.common index d310bc0b81..0fa0187167 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -243,6 +243,7 @@ SOURCES_CXX += \ $(EXTDIR)/glslang/SPIRV/GlslangToSpv.cpp \ $(EXTDIR)/glslang/SPIRV/Logger.cpp \ $(EXTDIR)/glslang/SPIRV/SpvBuilder.cpp \ + $(EXTDIR)/glslang/SPIRV/SpvPostProcess.cpp \ $(EXTDIR)/SPIRV-Cross/spirv_cfg.cpp \ $(EXTDIR)/SPIRV-Cross/spirv_cross.cpp \ $(EXTDIR)/SPIRV-Cross/spirv_cross_util.cpp \ From 5d0f2caf3405d1f7b6d9ed5e3abf30a328567504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 6 Jun 2019 20:53:31 +0200 Subject: [PATCH 06/21] Update submodules lang, pspautotests --- assets/lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/lang b/assets/lang index a1993a6dd7..9d93983574 160000 --- a/assets/lang +++ b/assets/lang @@ -1 +1 @@ -Subproject commit a1993a6dd7e963c9bba0d8b81d826169b2627c6c +Subproject commit 9d93983574606d2af15be8cc0b49604bb4cafad6 From 7252999921e2a869d2a083b0353fc43883f06393 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Fri, 7 Jun 2019 05:13:47 +0800 Subject: [PATCH 07/21] UWP: project filiter update, add assets to other architectures --- UWP/UWP.vcxproj | 779 ++++++++++++++++++++++++++++++++++++++-- UWP/UWP.vcxproj.filters | 330 +++++++++++++---- 2 files changed, 993 insertions(+), 116 deletions(-) diff --git a/UWP/UWP.vcxproj b/UWP/UWP.vcxproj index 293a138c6c..cb0c31dded 100644 --- a/UWP/UWP.vcxproj +++ b/UWP/UWP.vcxproj @@ -189,6 +189,9 @@ False Never B57919568D3F60B8D25EC6856DE94173682C548C + False + 1 + OnApplicationRun @@ -204,8 +207,8 @@ _DEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -213,7 +216,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -229,8 +232,8 @@ _DEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -238,7 +241,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -254,8 +257,8 @@ NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -263,7 +266,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -279,8 +282,8 @@ NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -288,7 +291,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -304,8 +307,8 @@ GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y @@ -313,7 +316,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -329,8 +332,8 @@ GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y @@ -338,7 +341,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -354,8 +357,8 @@ _DEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -363,7 +366,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -379,8 +382,8 @@ NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -388,7 +391,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -404,8 +407,8 @@ GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y @@ -413,7 +416,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -429,8 +432,8 @@ _DEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -438,7 +441,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -454,8 +457,8 @@ NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y @@ -463,7 +466,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -479,8 +482,8 @@ GOLD;NDEBUG;%(PreprocessorDefinitions) pch.h - - + + copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y @@ -488,7 +491,7 @@ robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 EXIT 0 - + @@ -600,91 +603,253 @@ true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true @@ -696,206 +861,575 @@ true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true @@ -904,96 +1438,267 @@ true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true true true + true + true + true + true + true + true + true + true + true true @@ -1050,4 +1755,4 @@ - + \ No newline at end of file diff --git a/UWP/UWP.vcxproj.filters b/UWP/UWP.vcxproj.filters index 944fd711c8..1d02ecab32 100644 --- a/UWP/UWP.vcxproj.filters +++ b/UWP/UWP.vcxproj.filters @@ -38,6 +38,18 @@ {ef87b390-608f-4c6d-a0ad-88963875ed11} + + {0c1cdb21-de65-4a10-962e-46b9bb0ff717} + + + {a861f712-3285-448d-b7a0-f6d39ac4c4b9} + + + {d51ae335-1279-4484-bfbf-2caa2efba6d9} + + + {d2294c79-82bd-470f-b984-f838f0fbcd25} + @@ -110,89 +122,249 @@ Content - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\lang + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\flash0\font + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + + + Content\shaders + Content + + + Content + + \ No newline at end of file From 792d9e30bad0d9e00daa24c12e4e8e58d87b2ba8 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Fri, 7 Jun 2019 05:15:24 +0800 Subject: [PATCH 08/21] UWP: enable SYSPROP_LANGREGION --- UWP/PPSSPP_UWPMain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 2ff75df9e1..97a96da69a 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -42,6 +42,7 @@ using namespace Concurrency; // UGLY! PPSSPP_UWPMain *g_main; extern WindowsAudioBackend *winAudioBackend; +std::string langRegion; // TODO: Use Microsoft::WRL::ComPtr<> for D3D11 objects? // TODO: See https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/WindowsAudioSession for WASAPI with UWP // TODO: Low latency input: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/LowLatencyInput/cpp @@ -76,7 +77,6 @@ PPSSPP_UWPMain::PPSSPP_UWPMain(App ^app, const std::shared_ptr Date: Fri, 7 Jun 2019 05:16:27 +0800 Subject: [PATCH 09/21] TextDrawerUWP based on DirectWrite --- Core/Config.h | 3 +- UI/NativeApp.cpp | 10 +- UWP/NativeUWP/NativeUWP.vcxproj | 4 +- UWP/NativeUWP/NativeUWP.vcxproj.filters | 6 + ext/native/gfx_es2/draw_text.cpp | 3 + ext/native/gfx_es2/draw_text_uwp.cpp | 528 ++++++++++++++++++++++++ ext/native/gfx_es2/draw_text_uwp.h | 59 +++ 7 files changed, 609 insertions(+), 4 deletions(-) create mode 100644 ext/native/gfx_es2/draw_text_uwp.cpp create mode 100644 ext/native/gfx_es2/draw_text_uwp.h diff --git a/Core/Config.h b/Core/Config.h index 8f580fe89b..1c1f4c4bc9 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -21,6 +21,7 @@ #include #include +#include "ppsspp_config.h" #include "Common/CommonTypes.h" extern const char *PPSSPP_GIT_VERSION; @@ -72,7 +73,7 @@ public: bool bIgnoreWindowsKey; bool bRestartRequired; #endif -#if defined(USING_WIN_UI) || defined(USING_QT_UI) +#if defined(USING_WIN_UI) || defined(USING_QT_UI) || PPSSPP_PLATFORM(UWP) std::string sFont; #endif diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index ffce33b799..d12e1f2b9e 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -108,6 +108,9 @@ #if defined(USING_QT_UI) #include #endif +#if PPSSPP_PLATFORM(UWP) +#include +#endif // The new UI framework, for initialization @@ -646,7 +649,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch // Note to translators: do not translate this/add this to PPSSPP-lang's files. // It's intended to be custom for every user. // Only add it to your own personal copies of PPSSPP. -#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP) +#if PPSSPP_PLATFORM(UWP) + // Roboto font is loaded in TextDrawerUWP. + g_Config.sFont = des->T("Font", "Roboto"); +#elif defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP) // TODO: Could allow a setting to specify a font file to load? // TODO: Make this a constant if we can sanely load the font on other systems? AddFontResourceEx(L"assets/Roboto-Condensed.ttf", FR_PRIVATE, NULL); @@ -729,7 +735,7 @@ static UI::Style MakeStyle(uint32_t fg, uint32_t bg) { } static void UIThemeInit() { -#if (defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)) || defined(USING_QT_UI) +#if defined(USING_WIN_UI) || PPSSPP_PLATFORM(UWP) || defined(USING_QT_UI) ui_theme.uiFont = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 22); ui_theme.uiFontSmall = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 15); ui_theme.uiFontSmaller = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 12); diff --git a/UWP/NativeUWP/NativeUWP.vcxproj b/UWP/NativeUWP/NativeUWP.vcxproj index 0d09121db9..5e629dc1dc 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj +++ b/UWP/NativeUWP/NativeUWP.vcxproj @@ -419,6 +419,7 @@ + @@ -1462,6 +1463,7 @@ + @@ -1642,4 +1644,4 @@ - + \ No newline at end of file diff --git a/UWP/NativeUWP/NativeUWP.vcxproj.filters b/UWP/NativeUWP/NativeUWP.vcxproj.filters index f7c7dddd41..2bda07e6a3 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj.filters +++ b/UWP/NativeUWP/NativeUWP.vcxproj.filters @@ -474,6 +474,9 @@ data + + gfx + @@ -747,5 +750,8 @@ data + + gfx + \ No newline at end of file diff --git a/ext/native/gfx_es2/draw_text.cpp b/ext/native/gfx_es2/draw_text.cpp index b71c1ddc4c..168f84f151 100644 --- a/ext/native/gfx_es2/draw_text.cpp +++ b/ext/native/gfx_es2/draw_text.cpp @@ -7,6 +7,7 @@ #include "util/text/utf8.h" #include "gfx_es2/draw_text.h" #include "gfx_es2/draw_text_win.h" +#include "gfx_es2/draw_text_uwp.h" #include "gfx_es2/draw_text_qt.h" #include "gfx_es2/draw_text_android.h" @@ -45,6 +46,8 @@ TextDrawer *TextDrawer::Create(Draw::DrawContext *draw) { TextDrawer *drawer = nullptr; #if defined(_WIN32) && !PPSSPP_PLATFORM(UWP) drawer = new TextDrawerWin32(draw); +#elif PPSSPP_PLATFORM(UWP) + drawer = new TextDrawerUWP(draw); #elif defined(USING_QT_UI) drawer = new TextDrawerQt(draw); #elif PPSSPP_PLATFORM(ANDROID) diff --git a/ext/native/gfx_es2/draw_text_uwp.cpp b/ext/native/gfx_es2/draw_text_uwp.cpp new file mode 100644 index 0000000000..7b0d989ba7 --- /dev/null +++ b/ext/native/gfx_es2/draw_text_uwp.cpp @@ -0,0 +1,528 @@ +#include "base/display.h" +#include "base/logging.h" +#include "base/stringutil.h" +#include "thin3d/thin3d.h" +#include "util/hash/hash.h" +#include "util/text/wrap_text.h" +#include "util/text/utf8.h" +#include "gfx_es2/draw_text.h" +#include "gfx_es2/draw_text_uwp.h" + + +#if PPSSPP_PLATFORM(UWP) + +#include +#include +#include +#include + +enum { + MAX_TEXT_WIDTH = 4096, + MAX_TEXT_HEIGHT = 512 +}; + +class TextDrawerFontContext { +public: + ~TextDrawerFontContext() { + Destroy(); + } + + void Create() { + if (textFmt) { + Destroy(); + } + + if (factory == nullptr) return; + + HRESULT hr = factory->CreateTextFormat( + fname.c_str(), + fontCollection, + weight, + DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, + MulDiv(height, (int)(96.0f * (1.0f / dpiScale)), 72), + L"", + &textFmt + ); + } + void Destroy() { + textFmt->Release(); + textFmt = nullptr; + } + + IDWriteFactory4* factory = nullptr; + IDWriteFontCollection1* fontCollection = nullptr; + IDWriteTextFormat* textFmt = nullptr; + std::wstring fname; + int height; + DWRITE_FONT_WEIGHT weight; + float dpiScale; +}; + +struct TextDrawerContext { + ID2D1Bitmap1* bitmap; + ID2D1Bitmap1* mirror_bmp; +}; + +TextDrawerUWP::TextDrawerUWP(Draw::DrawContext *draw) : TextDrawer(draw), ctx_(nullptr) { + HRESULT hr; + // It's fine to assume we are using D3D11 in UWP + ID3D11Device* d3ddevice = (ID3D11Device *)draw->GetNativeObject(Draw::NativeObject::DEVICE); + + IDXGIDevice* dxgiDevice; + hr = d3ddevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); + if (FAILED(hr)) FLOG("ID3DDevice QueryInterface IDXGIDevice failed"); + + // Initialize the Direct2D Factory. + D2D1_FACTORY_OPTIONS options = {}; + D2D1CreateFactory( + D2D1_FACTORY_TYPE_SINGLE_THREADED, + __uuidof(ID2D1Factory5), + &options, + (void**)&m_d2dFactory + ); + + // Initialize the DirectWrite Factory. + DWriteCreateFactory( + DWRITE_FACTORY_TYPE_SHARED, + __uuidof(IDWriteFactory5), + (IUnknown**)&m_dwriteFactory + ); + + // Create D2D Device and DeviceContext. + // TODO: We have one sitting right in DX::DeviceResource, there might be a way to use that instead. + hr = m_d2dFactory->CreateDevice(dxgiDevice, &m_d2dDevice); + if (FAILED(hr)) FLOG("D2D CreateDevice failed"); + hr = m_d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &m_d2dContext); + if (FAILED(hr)) FLOG("D2D CreateDeviceContext failed"); + + // Load the Roboto font + hr = m_dwriteFactory->CreateFontFileReference(L"Content/Roboto-Condensed.ttf", nullptr, &m_fontFile); + if (FAILED(hr)) ELOG("CreateFontFileReference failed"); + hr = m_dwriteFactory->CreateFontSetBuilder(&m_fontSetBuilder); + if (FAILED(hr)) ELOG("CreateFontSetBuilder failed"); + hr = m_fontSetBuilder->AddFontFile(m_fontFile); + hr = m_fontSetBuilder->CreateFontSet(&m_fontSet); + hr = m_dwriteFactory->CreateFontCollectionFromFontSet(m_fontSet, &m_fontCollection); + + ctx_ = new TextDrawerContext(); + + D2D1_BITMAP_PROPERTIES1 properties; + properties.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + properties.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED; + properties.dpiX = 96.0f; + properties.dpiY = 96.0f; + properties.bitmapOptions = D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_TARGET; + properties.colorContext = nullptr; + + // Create main drawing bitmap + m_d2dContext->CreateBitmap( + D2D1::SizeU(MAX_TEXT_WIDTH, MAX_TEXT_HEIGHT), + nullptr, + 0, + &properties, + &ctx_->bitmap + ); + m_d2dContext->SetTarget(ctx_->bitmap); + + // Create mirror bitmap for mapping + properties.bitmapOptions = D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ; + m_d2dContext->CreateBitmap( + D2D1::SizeU(MAX_TEXT_WIDTH, MAX_TEXT_HEIGHT), + nullptr, + 0, + &properties, + &ctx_->mirror_bmp + ); + + m_d2dContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White, 1.0f), &m_d2dWhiteBrush); + +} + +TextDrawerUWP::~TextDrawerUWP() { + ClearCache(); + + fontMap_.clear(); + + ctx_->bitmap->Release(); + ctx_->mirror_bmp->Release(); + + m_d2dWhiteBrush->Release(); + m_d2dContext->Release(); + m_d2dDevice->Release(); + m_d2dFactory->Release(); + m_dwriteFactory->Release(); + delete ctx_; +} + +uint32_t TextDrawerUWP::SetFont(const char *fontName, int size, int flags) { + uint32_t fontHash = fontName ? hash::Adler32((const uint8_t *)fontName, strlen(fontName)) : 0; + fontHash ^= size; + fontHash ^= flags << 10; + + auto iter = fontMap_.find(fontHash); + if (iter != fontMap_.end()) { + fontHash_ = fontHash; + return fontHash; + } + + std::wstring fname; + if (fontName) + fname = ConvertUTF8ToWString(fontName); + else + fname = L"Tahoma"; + + TextDrawerFontContext *font = new TextDrawerFontContext(); + font->weight = DWRITE_FONT_WEIGHT_LIGHT; + font->height = size; + font->fname = fname; + font->dpiScale = dpiScale_; + font->factory = m_dwriteFactory; + font->fontCollection = m_fontCollection; + font->Create(); + + fontMap_[fontHash] = std::unique_ptr(font); + fontHash_ = fontHash; + return fontHash; +} + +void TextDrawerUWP::SetFont(uint32_t fontHandle) { + auto iter = fontMap_.find(fontHandle); + if (iter != fontMap_.end()) { + fontHash_ = fontHandle; + } +} + +void TextDrawerUWP::MeasureString(const char *str, size_t len, float *w, float *h) { + CacheKey key{ std::string(str, len), fontHash_ }; + + TextMeasureEntry *entry; + auto iter = sizeCache_.find(key); + if (iter != sizeCache_.end()) { + entry = iter->second.get(); + } else { + IDWriteTextFormat* format = nullptr; + auto iter = fontMap_.find(fontHash_); + if (iter != fontMap_.end()) { + format = iter->second->textFmt; + } + + std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(std::string(str, len), "\n", "\r\n"), "&&", "&")); + + format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING); + + IDWriteTextLayout* layout; + m_dwriteFactory->CreateTextLayout( + (LPWSTR)wstr.c_str(), + (int)wstr.size(), + format, + MAX_TEXT_WIDTH, + MAX_TEXT_HEIGHT, + &layout + ); + + DWRITE_TEXT_METRICS metrics; + layout->GetMetrics(&metrics); + + entry = new TextMeasureEntry(); + entry->width = metrics.width + 1; + entry->height = metrics.height + 1; + sizeCache_[key] = std::unique_ptr(entry); + } + + entry->lastUsedFrame = frameCount_; + *w = entry->width * fontScaleX_ * dpiScale_; + *h = entry->height * fontScaleY_ * dpiScale_; +} + +void TextDrawerUWP::MeasureStringRect(const char *str, size_t len, const Bounds &bounds, float *w, float *h, int align) { + + IDWriteTextFormat* format = nullptr; + auto iter = fontMap_.find(fontHash_); + if (iter != fontMap_.end()) { + format = iter->second->textFmt; + } + + std::string toMeasure = std::string(str, len); + if (align & FLAG_WRAP_TEXT) { + bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0; + WrapString(toMeasure, toMeasure.c_str(), rotated ? bounds.h : bounds.w); + } + + std::vector lines; + SplitString(toMeasure, '\n', lines); + float total_w = 0.0f; + float total_h = 0.0f; + for (size_t i = 0; i < lines.size(); i++) { + CacheKey key{ lines[i], fontHash_ }; + + TextMeasureEntry *entry; + auto iter = sizeCache_.find(key); + if (iter != sizeCache_.end()) { + entry = iter->second.get(); + } else { + std::wstring wstr = ConvertUTF8ToWString(lines[i].length() == 0 ? " " : ReplaceAll(lines[i], "&&", "&")); + + if (align & ALIGN_HCENTER) + format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); + else if (align & ALIGN_LEFT) + format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING); + else if (align & ALIGN_RIGHT) + format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING); + + IDWriteTextLayout* layout; + m_dwriteFactory->CreateTextLayout( + (LPWSTR)wstr.c_str(), + (int)wstr.size(), + format, + MAX_TEXT_WIDTH, + MAX_TEXT_HEIGHT, + &layout + ); + + DWRITE_TEXT_METRICS metrics; + layout->GetMetrics(&metrics); + + entry = new TextMeasureEntry(); + entry->width = metrics.width + 1; + entry->height = metrics.height + 1; + sizeCache_[key] = std::unique_ptr(entry); + } + entry->lastUsedFrame = frameCount_; + + if (total_w < entry->width * fontScaleX_) { + total_w = entry->width * fontScaleX_; + } + total_h += entry->height * fontScaleY_; + } + *w = total_w * dpiScale_; + *h = total_h * dpiScale_; +} + +void TextDrawerUWP::DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align) { + using namespace Draw; + if (!strlen(str)) + return; + + CacheKey key{ std::string(str), fontHash_ }; + + target.Flush(true); + + TextStringEntry *entry; + + auto iter = cache_.find(key); + if (iter != cache_.end()) { + entry = iter->second.get(); + entry->lastUsedFrame = frameCount_; + } + else { + // Render the string to our bitmap and save to a GL texture. + std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(str, "\n", "\r\n")); + SIZE size; + + IDWriteTextFormat* format = nullptr; + auto iter = fontMap_.find(fontHash_); + if (iter != fontMap_.end()) { + format = iter->second->textFmt; + } + + if (align & ALIGN_HCENTER) + format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); + else if (align & ALIGN_LEFT) + format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING); + else if (align & ALIGN_RIGHT) + format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING); + + IDWriteTextLayout* layout; + m_dwriteFactory->CreateTextLayout( + (LPWSTR)wstr.c_str(), + (int)wstr.size(), + format, + MAX_TEXT_WIDTH, + MAX_TEXT_HEIGHT, + &layout + ); + + DWRITE_TEXT_METRICS metrics; + layout->GetMetrics(&metrics); + + // Set the max size the same as current size, avoiding alignment issues + layout->SetMaxHeight(metrics.height); + layout->SetMaxWidth(metrics.width); + + size.cx = metrics.width + 1; + size.cy = metrics.height + 1; + + // Prevent zero-sized textures, which can occur. Not worth to avoid + // creating the texture altogether in this case. One example is a string + // containing only '\r\n', see issue #10764. + if (size.cx == 0) + size.cx = 1; + if (size.cy == 0) + size.cy = 1; + + entry = new TextStringEntry(); + entry->width = size.cx; + entry->height = size.cy; + entry->bmWidth = (size.cx + 3) & ~3; + entry->bmHeight = (size.cy + 3) & ~3; + entry->lastUsedFrame = frameCount_; + + m_d2dContext->BeginDraw(); + m_d2dContext->Clear(); + m_d2dContext->DrawTextLayout(D2D1::Point2F(0.0f, 0.0f), layout, m_d2dWhiteBrush); + m_d2dContext->EndDraw(); + + layout->Release(); + + D2D1_POINT_2U dstP = D2D1::Point2U(0, 0); + D2D1_RECT_U srcR = D2D1::RectU(0, 0, entry->bmWidth, entry->bmHeight); + D2D1_MAPPED_RECT map; + ctx_->mirror_bmp->CopyFromBitmap(&dstP, ctx_->bitmap, &srcR); + ctx_->mirror_bmp->Map(D2D1_MAP_OPTIONS_READ, &map); + + DataFormat texFormat; + // For our purposes these are equivalent, so just choose the supported one. D3D can emulate them. + if (draw_->GetDataFormatSupport(Draw::DataFormat::A4R4G4B4_UNORM_PACK16) & FMT_TEXTURE) + texFormat = Draw::DataFormat::A4R4G4B4_UNORM_PACK16; + else if (draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16) & FMT_TEXTURE) + texFormat = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + else + texFormat = Draw::DataFormat::R8G8B8A8_UNORM; + + // Convert the bitmap to a Thin3D compatible array of 16-bit pixels. Can't use a single channel format + // because we need white. Well, we could using swizzle, but not all our backends support that. + TextureDesc desc{}; + uint32_t *bitmapData32 = nullptr; + uint16_t *bitmapData16 = nullptr; + if (texFormat == Draw::DataFormat::R8G8B8A8_UNORM || texFormat == Draw::DataFormat::B8G8R8A8_UNORM) { + bitmapData32 = new uint32_t[entry->bmWidth * entry->bmHeight]; + for (int y = 0; y < entry->bmHeight; y++) { + for (int x = 0; x < entry->bmWidth; x++) { + uint8_t bAlpha = (uint8_t)(map.bits[map.pitch * y + x * 4] & 0xff); + bitmapData32[entry->bmWidth * y + x] = (bAlpha << 24) | 0x00ffffff; + } + } + desc.initData.push_back((uint8_t *)bitmapData32); + } else if (texFormat == Draw::DataFormat::B4G4R4A4_UNORM_PACK16) { + bitmapData16 = new uint16_t[entry->bmWidth * entry->bmHeight]; + for (int y = 0; y < entry->bmHeight; y++) { + for (int x = 0; x < entry->bmWidth; x++) { + uint8_t bAlpha = (uint8_t)((map.bits[map.pitch * y + x * 4] & 0xff) >> 4); + bitmapData16[entry->bmWidth * y + x] = (bAlpha) | 0xfff0; + } + } + desc.initData.push_back((uint8_t *)bitmapData16); + } else if (texFormat == Draw::DataFormat::A4R4G4B4_UNORM_PACK16) { + bitmapData16 = new uint16_t[entry->bmWidth * entry->bmHeight]; + for (int y = 0; y < entry->bmHeight; y++) { + for (int x = 0; x < entry->bmWidth; x++) { + uint8_t bAlpha = (uint8_t)((map.bits[map.pitch * y + x * 4] & 0xff) >> 4); + bitmapData16[entry->bmWidth * y + x] = (bAlpha << 12) | 0x0fff; + } + } + desc.initData.push_back((uint8_t *)bitmapData16); + } + + ctx_->mirror_bmp->Unmap(); + + desc.type = TextureType::LINEAR2D; + desc.format = texFormat; + desc.width = entry->bmWidth; + desc.height = entry->bmHeight; + desc.depth = 1; + desc.mipLevels = 1; + desc.tag = "TextDrawer"; + entry->texture = draw_->CreateTexture(desc); + if (bitmapData16) + delete[] bitmapData16; + if (bitmapData32) + delete[] bitmapData32; + cache_[key] = std::unique_ptr(entry); + } + + draw_->BindTexture(0, entry->texture); + + // Okay, the texture is bound, let's draw. + float w = entry->width * fontScaleX_ * dpiScale_; + float h = entry->height * fontScaleY_ * dpiScale_; + float u = entry->width / (float)entry->bmWidth; + float v = entry->height / (float)entry->bmHeight; + DrawBuffer::DoAlign(align, &x, &y, &w, &h); + target.DrawTexRect(x, y, x + w, y + h, 0.0f, 0.0f, u, v, color); + target.Flush(true); + +} + +void TextDrawerUWP::RecreateFonts() { + for (auto& iter : fontMap_) { + iter.second->dpiScale = dpiScale_; + iter.second->Create(); + } +} + +void TextDrawerUWP::ClearCache() { + for (auto &iter : cache_) { + if (iter.second->texture) + iter.second->texture->Release(); + } + cache_.clear(); + sizeCache_.clear(); +} + +void TextDrawerUWP::DrawStringRect(DrawBuffer &target, const char *str, const Bounds &bounds, uint32_t color, int align) { + float x = bounds.x; + float y = bounds.y; + if (align & ALIGN_HCENTER) { + x = bounds.centerX(); + } else if (align & ALIGN_RIGHT) { + x = bounds.x2(); + } + if (align & ALIGN_VCENTER) { + y = bounds.centerY(); + } else if (align & ALIGN_BOTTOM) { + y = bounds.y2(); + } + + std::string toDraw = str; + if (align & FLAG_WRAP_TEXT) { + bool rotated = (align & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) != 0; + WrapString(toDraw, str, rotated ? bounds.h : bounds.w); + } + + DrawString(target, toDraw.c_str(), x, y, color, align); +} + +void TextDrawerUWP::OncePerFrame() { + frameCount_++; + // If DPI changed (small-mode, future proper monitor DPI support), drop everything. + float newDpiScale = CalculateDPIScale(); + if (newDpiScale != dpiScale_) { + dpiScale_ = newDpiScale; + ClearCache(); + RecreateFonts(); + } + + // Drop old strings. Use a prime number to reduce clashing with other rhythms + if (frameCount_ % 23 == 0) { + for (auto iter = cache_.begin(); iter != cache_.end();) { + if (frameCount_ - iter->second->lastUsedFrame > 100) { + if (iter->second->texture) + iter->second->texture->Release(); + cache_.erase(iter++); + } else { + iter++; + } + } + + for (auto iter = sizeCache_.begin(); iter != sizeCache_.end(); ) { + if (frameCount_ - iter->second->lastUsedFrame > 100) { + sizeCache_.erase(iter++); + } else { + iter++; + } + } + } +} + +#endif diff --git a/ext/native/gfx_es2/draw_text_uwp.h b/ext/native/gfx_es2/draw_text_uwp.h new file mode 100644 index 0000000000..995a62c6ee --- /dev/null +++ b/ext/native/gfx_es2/draw_text_uwp.h @@ -0,0 +1,59 @@ +#pragma once + +#include "ppsspp_config.h" + +#include +#include "gfx_es2/draw_text.h" + +#if PPSSPP_PLATFORM(UWP) + +#include +#include + +struct TextDrawerContext; +// Internal struct but all details in .cpp file (pimpl to avoid pulling in excessive headers here) +class TextDrawerFontContext; + +class TextDrawerUWP : public TextDrawer { +public: + TextDrawerUWP(Draw::DrawContext *draw); + ~TextDrawerUWP(); + + uint32_t SetFont(const char *fontName, int size, int flags) override; + void SetFont(uint32_t fontHandle) override; // Shortcut once you've set the font once. + void MeasureString(const char *str, size_t len, float *w, float *h) override; + void MeasureStringRect(const char *str, size_t len, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) override; + void DrawString(DrawBuffer &target, const char *str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) override; + void DrawStringRect(DrawBuffer &target, const char *str, const Bounds &bounds, uint32_t color, int align) override; + // Use for housekeeping like throwing out old strings. + void OncePerFrame() override; + +protected: + void ClearCache() override; + void RecreateFonts(); // On DPI change + + TextDrawerContext *ctx_; + std::map> fontMap_; + + uint32_t fontHash_; + std::map> cache_; + std::map> sizeCache_; + + + // Direct2D drawing components. + ID2D1Factory5* m_d2dFactory; + ID2D1Device4* m_d2dDevice; + ID2D1DeviceContext4* m_d2dContext; + ID2D1Bitmap1* m_d2dTargetBitmap; + ID2D1SolidColorBrush* m_d2dWhiteBrush; + + // DirectWrite drawing components. + IDWriteFactory5* m_dwriteFactory; + IDWriteFontFile* m_fontFile; + IDWriteFontSet* m_fontSet; + IDWriteFontSetBuilder1* m_fontSetBuilder; + IDWriteFontCollection1* m_fontCollection; + +}; + +#endif From eb9581b43e16be22a30ca5383549f7f093ca0fd4 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Fri, 7 Jun 2019 05:40:06 +0800 Subject: [PATCH 10/21] UWP: fix && in English UI labels --- ext/native/gfx_es2/draw_text_uwp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/native/gfx_es2/draw_text_uwp.cpp b/ext/native/gfx_es2/draw_text_uwp.cpp index 7b0d989ba7..424a8d6358 100644 --- a/ext/native/gfx_es2/draw_text_uwp.cpp +++ b/ext/native/gfx_es2/draw_text_uwp.cpp @@ -317,7 +317,7 @@ void TextDrawerUWP::DrawString(DrawBuffer &target, const char *str, float x, flo } else { // Render the string to our bitmap and save to a GL texture. - std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(str, "\n", "\r\n")); + std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(str, "\n", "\r\n"), "&&", "&")); SIZE size; IDWriteTextFormat* format = nullptr; From 56a87932bfd12d1f317220aff21deb8a92da5c87 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Fri, 7 Jun 2019 06:07:21 +0800 Subject: [PATCH 11/21] UWP: fix prebuild commands --- UWP/UWP.vcxproj | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/UWP/UWP.vcxproj b/UWP/UWP.vcxproj index cb0c31dded..35cb743325 100644 --- a/UWP/UWP.vcxproj +++ b/UWP/UWP.vcxproj @@ -212,8 +212,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -237,8 +237,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -262,8 +262,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -287,8 +287,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -312,8 +312,8 @@ copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -337,8 +337,8 @@ copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -362,8 +362,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -387,8 +387,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -412,8 +412,8 @@ copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -437,8 +437,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -462,8 +462,8 @@ copy PackageNormal.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsNormal\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -487,8 +487,8 @@ copy PackageGold.appxmanifest Package.appxmanifest /Y mkdir Assets copy AssetsGold\*.* Assets /Y - ../Windows/git-version-gen.cmd robocopy "..\Assets\." "Content\." /xf *.vsh /E /R:0 /W:0 + ../Windows/git-version-gen.cmd EXIT 0 @@ -1755,4 +1755,4 @@ - \ No newline at end of file + From 98c75085a79391978270c9bc21e1d2d1cfd3aca9 Mon Sep 17 00:00:00 2001 From: plaidman Date: Fri, 7 Jun 2019 09:21:46 -0400 Subject: [PATCH 12/21] adding arm64 platform to libretro makefile --- libretro/Makefile | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libretro/Makefile b/libretro/Makefile index 8970ddc036..d146db3d93 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -83,8 +83,30 @@ else ifneq (,$(findstring rpi,$(platform))) INCFLAGS += -I/opt/vc/include CPUFLAGS += -DARMv5_ONLY PLATFORM_EXT := unix - TARGET_ARCH = arm LDFLAGS += -lrt -ldl + +# ARM64 +else ifneq (,$(findstring arm64,$(platform))) + TARGET := $(TARGET_NAME)_libretro.so + TARGET_ARCH = arm64 + fpic := -fPIC + LDFLAGS += -shared -Wl,--version-script=link.T -Wl,--no-undefined + FFMPEGINCFLAGS += -I$(FFMPEGDIR)/linux/aarch64/include + FFMPEGLIBDIR := $(FFMPEGDIR)/linux/aarch64/lib + FFMPEGLDFLAGS += -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale + INCFLAGS += -I. + HAVE_NEON=1 + ifneq (,$(findstring gles,$(platform))) + GLES := 1 + GL_LIB := -lGLESv2 -lEGL + LDFLAGS += -lGLESv2 -lEGL + else + GL_LIB := -lGL + endif + CPUFLAGS += -D__arm64__ -DARM64_ASM -D__NEON_OPT + PLATCFLAGS += -DARM64 + LDFLAGS += -lrt -ldl + PLATFORM_EXT := unix # i.MX6 else ifneq (,$(findstring imx6,$(platform))) From 2db67e17059980651feace13f927cd299b455bbf Mon Sep 17 00:00:00 2001 From: driver1998 Date: Fri, 7 Jun 2019 21:50:00 +0800 Subject: [PATCH 13/21] TextDrawerUWP: oops, forgot to release the objects used. --- ext/native/gfx_es2/draw_text_uwp.cpp | 10 ++++++++++ ext/native/gfx_es2/draw_text_uwp.h | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/native/gfx_es2/draw_text_uwp.cpp b/ext/native/gfx_es2/draw_text_uwp.cpp index 424a8d6358..52183a5c40 100644 --- a/ext/native/gfx_es2/draw_text_uwp.cpp +++ b/ext/native/gfx_es2/draw_text_uwp.cpp @@ -151,6 +151,11 @@ TextDrawerUWP::~TextDrawerUWP() { m_d2dContext->Release(); m_d2dDevice->Release(); m_d2dFactory->Release(); + + m_fontCollection->Release(); + m_fontSet->Release(); + m_fontFile->Release(); + m_fontSetBuilder->Release(); m_dwriteFactory->Release(); delete ctx_; } @@ -206,6 +211,7 @@ void TextDrawerUWP::MeasureString(const char *str, size_t len, float *w, float * if (iter != fontMap_.end()) { format = iter->second->textFmt; } + if (!format) return; std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(std::string(str, len), "\n", "\r\n"), "&&", "&")); @@ -223,6 +229,7 @@ void TextDrawerUWP::MeasureString(const char *str, size_t len, float *w, float * DWRITE_TEXT_METRICS metrics; layout->GetMetrics(&metrics); + layout->Release(); entry = new TextMeasureEntry(); entry->width = metrics.width + 1; @@ -242,6 +249,7 @@ void TextDrawerUWP::MeasureStringRect(const char *str, size_t len, const Bounds if (iter != fontMap_.end()) { format = iter->second->textFmt; } + if (!format) return; std::string toMeasure = std::string(str, len); if (align & FLAG_WRAP_TEXT) { @@ -282,6 +290,7 @@ void TextDrawerUWP::MeasureStringRect(const char *str, size_t len, const Bounds DWRITE_TEXT_METRICS metrics; layout->GetMetrics(&metrics); + layout->Release(); entry = new TextMeasureEntry(); entry->width = metrics.width + 1; @@ -325,6 +334,7 @@ void TextDrawerUWP::DrawString(DrawBuffer &target, const char *str, float x, flo if (iter != fontMap_.end()) { format = iter->second->textFmt; } + if (!format) return; if (align & ALIGN_HCENTER) format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); diff --git a/ext/native/gfx_es2/draw_text_uwp.h b/ext/native/gfx_es2/draw_text_uwp.h index 995a62c6ee..0697ea62d6 100644 --- a/ext/native/gfx_es2/draw_text_uwp.h +++ b/ext/native/gfx_es2/draw_text_uwp.h @@ -44,7 +44,6 @@ protected: ID2D1Factory5* m_d2dFactory; ID2D1Device4* m_d2dDevice; ID2D1DeviceContext4* m_d2dContext; - ID2D1Bitmap1* m_d2dTargetBitmap; ID2D1SolidColorBrush* m_d2dWhiteBrush; // DirectWrite drawing components. From 6cd12678d383993e711dc81429f4ec5b5073adb1 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Fri, 7 Jun 2019 21:52:05 +0800 Subject: [PATCH 14/21] UWP: Full screen support, config save fix --- UWP/App.cpp | 22 +++++++++++++++++----- UWP/PPSSPP_UWPMain.cpp | 8 ++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/UWP/App.cpp b/UWP/App.cpp index c190c308dd..677ac5b259 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -217,9 +217,10 @@ void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ // Run() won't start until the CoreWindow is activated. CoreWindow::GetForCurrentThread()->Activate(); // On mobile, we force-enter fullscreen mode. - if (m_isPhone) { + if (m_isPhone) g_Config.bFullScreen = true; + + if (g_Config.bFullScreen) Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->TryEnterFullScreenMode(); - } } void App::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { @@ -228,9 +229,10 @@ void App::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { // aware that a deferral may not be held indefinitely. After about five seconds, // the app will be forced to exit. SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral(); + auto app = this; - create_task([this, deferral]() { - m_deviceResources->Trim(); + create_task([app, deferral]() { + app->m_deviceResources->Trim(); deferral->Complete(); }); } @@ -246,6 +248,9 @@ void App::OnResuming(Platform::Object^ sender, Platform::Object^ args) { // Window event handlers. void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) { + auto view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView(); + g_Config.bFullScreen = view->IsFullScreenMode; + int width = sender->Bounds.Width; int height = sender->Bounds.Height; float scale = m_deviceResources->GetDpi() / 96.0f; @@ -263,10 +268,17 @@ void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ ar } void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) { + + if (args->Visible == false) { + // MainScreen::OnExit and even App::OnWindowClosed + // doesn't seem to be called when closing the window + // Try to save the config here + g_Config.Save("App::OnVisibilityChanged"); + } m_windowVisible = args->Visible; } -void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) { +void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) { m_windowClosed = true; } diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 97a96da69a..b7187575f4 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -429,6 +429,14 @@ void System_SendMessage(const char *command, const char *parameter) { g_main->LoadStorageFile(file); } }); + } else if (!strcmp(command, "toggle_fullscreen")) { + auto view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView(); + if (strcmp(parameter, "0") == 0) { + view->ExitFullScreenMode(); + } + else if (strcmp(parameter, "1") == 0){ + view->TryEnterFullScreenMode(); + } } } From 8b2fcc5fe6a57123b9900e31ba808297dc5a1d39 Mon Sep 17 00:00:00 2001 From: plaidman Date: Fri, 7 Jun 2019 10:25:33 -0400 Subject: [PATCH 15/21] fix unintended line removal from rpi platform --- libretro/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/libretro/Makefile b/libretro/Makefile index d146db3d93..28d145afed 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -83,6 +83,7 @@ else ifneq (,$(findstring rpi,$(platform))) INCFLAGS += -I/opt/vc/include CPUFLAGS += -DARMv5_ONLY PLATFORM_EXT := unix + TARGET_ARCH = arm LDFLAGS += -lrt -ldl # ARM64 From 3cd037f570b2791237af2b7ad09cf7174aac1f63 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Sun, 9 Jun 2019 18:54:15 +0800 Subject: [PATCH 16/21] UWP: white space fix --- UWP/App.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UWP/App.cpp b/UWP/App.cpp index 677ac5b259..586d679581 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -278,7 +278,7 @@ void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ ar m_windowVisible = args->Visible; } -void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) { +void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) { m_windowClosed = true; } From edbefa8ee290b6bfcaa7bd06db8def4ac29f2623 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 10 Jun 2019 17:43:16 -0700 Subject: [PATCH 17/21] SDL: Adjust EGL config choice heuristics. See #12049: * Require EGL_WINDOW_BIT more strongly. * Allow EGL_NON_CONFORMANT_CONFIG (but still not EGL_SLOW_CONFIG.) --- SDL/SDLGLGraphicsContext.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SDL/SDLGLGraphicsContext.cpp b/SDL/SDLGLGraphicsContext.cpp index 12d43f790b..631c15a93d 100644 --- a/SDL/SDLGLGraphicsContext.cpp +++ b/SDL/SDLGLGraphicsContext.cpp @@ -108,10 +108,12 @@ EGLConfig EGL_FindConfig(int *contextVersion) { }; // We don't want HDR modes with more than 8 bits per component. - auto readConfigMax = [&](EGLint attr, EGLint m) -> EGLint { + // But let's assume some color is better than no color at all. + auto readConfigMax = [&](EGLint attr, EGLint m, EGLInt def = 1) -> EGLint { EGLint val = readConfig(attr); - return val > m ? 1 : val; // why not 0? + return val > m ? def : val; }; + int colorScore = readConfigMax(EGL_RED_SIZE, 8) + readConfigMax(EGL_BLUE_SIZE, 8) + readConfigMax(EGL_GREEN_SIZE, 8); int alphaScore = readConfigMax(EGL_ALPHA_SIZE, 8); int depthScore = readConfig(EGL_DEPTH_SIZE); @@ -122,11 +124,13 @@ EGLConfig EGL_FindConfig(int *contextVersion) { int transparentScore = readConfig(EGL_TRANSPARENT_TYPE) == EGL_NONE ? 50 : 0; EGLint caveat = readConfig(EGL_CONFIG_CAVEAT); - int caveatScore = caveat == EGL_NONE ? 100 : (caveat == EGL_NON_CONFORMANT_CONFIG ? 50 : 0); + // Let's assume that non-conformant configs aren't so awful. + int caveatScore = caveat == EGL_NONE ? 100 : (caveat == EGL_NON_CONFORMANT_CONFIG ? 95 : 0); #ifndef USING_FBDEV EGLint surfaceType = readConfig(EGL_SURFACE_TYPE); - int surfaceScore = (surfaceType & EGL_WINDOW_BIT) ? 100 : 0; + // Only try a non-Window config in the worst case when there are only non-Window configs. + int surfaceScore = (surfaceType & EGL_WINDOW_BIT) ? 1000 : 0; #endif EGLint renderable = readConfig(EGL_RENDERABLE_TYPE); From 58b473a64c72fdeaff4600cf046a3f7fc8bf38dd Mon Sep 17 00:00:00 2001 From: hissingshark Date: Tue, 11 Jun 2019 12:52:05 +0100 Subject: [PATCH 18/21] Fix build error --- SDL/SDLGLGraphicsContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDL/SDLGLGraphicsContext.cpp b/SDL/SDLGLGraphicsContext.cpp index 631c15a93d..1717f61c63 100644 --- a/SDL/SDLGLGraphicsContext.cpp +++ b/SDL/SDLGLGraphicsContext.cpp @@ -109,7 +109,7 @@ EGLConfig EGL_FindConfig(int *contextVersion) { // We don't want HDR modes with more than 8 bits per component. // But let's assume some color is better than no color at all. - auto readConfigMax = [&](EGLint attr, EGLint m, EGLInt def = 1) -> EGLint { + auto readConfigMax = [&](EGLint attr, EGLint m, EGLint def = 1) -> EGLint { EGLint val = readConfig(attr); return val > m ? def : val; }; From b8e3a3070a59d90feb0d2d84fe59747591d32d01 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 11 Jun 2019 15:45:20 -0700 Subject: [PATCH 19/21] interp: Use software dot for better accuracy. This gets some vdot/similar tests to give more accurate results compared to hardware. Also added flushing of zero and NaNs. --- Core/MIPS/MIPSIntVFPU.cpp | 99 +++++++++++++++++++++++-------------- Core/MIPS/MIPSVFPUUtils.cpp | 84 +++++++++++++++++++++++++++++++ Core/MIPS/MIPSVFPUUtils.h | 2 + 3 files changed, 149 insertions(+), 36 deletions(-) diff --git a/Core/MIPS/MIPSIntVFPU.cpp b/Core/MIPS/MIPSIntVFPU.cpp index 1314b1239e..72e4e0b839 100644 --- a/Core/MIPS/MIPSIntVFPU.cpp +++ b/Core/MIPS/MIPSIntVFPU.cpp @@ -463,20 +463,21 @@ namespace MIPSInt for (int a = 0; a < n; a++) { for (int b = 0; b < n; b++) { - float sum = 0.0f; + union { float f; uint32_t u; } sum = { 0.0f }; if (a == n - 1 && b == n - 1) { // S and T prefixes work on the final (or maybe first, in reverse?) dot. ApplySwizzleS(&s[b * 4], V_Quad); ApplySwizzleT(&t[a * 4], V_Quad); - for (int c = 0; c < 4; c++) { - sum += s[b * 4 + c] * t[a * 4 + c]; - } - } else { - for (int c = 0; c < n; c++) { - sum += s[b * 4 + c] * t[a * 4 + c]; - } } - d[a * 4 + b] = sum; + + sum.f = vfpu_dot(&s[b * 4], &t[a * 4]); + if (my_isnan(sum.f)) { + sum.u = 0x7f800001; + } else if ((sum.u & 0x7F800000) == 0) { + sum.u &= 0xFF800000; + } + + d[a * 4 + b] = sum.f; } } @@ -1116,7 +1117,7 @@ namespace MIPSInt void Int_VDot(MIPSOpcode op) { float s[4]{}, t[4]{}; - float d; + union { float f; uint32_t u; } d; int vd = _VD; int vs = _VS; int vt = _VT; @@ -1125,12 +1126,16 @@ namespace MIPSInt ApplySwizzleS(s, V_Quad); ReadVector(t, sz, vt); ApplySwizzleT(t, V_Quad); - d = 0.0f; - for (int i = 0; i < 4; i++) { - d += s[i] * t[i]; + + d.f = vfpu_dot(s, t); + if (my_isnan(d.f)) { + d.u = 0x7f800001; + } else if ((d.u & 0x7F800000) == 0) { + d.u &= 0xFF800000; } - ApplyPrefixD(&d, V_Single); - WriteVector(&d, V_Single, vd); + + ApplyPrefixD(&d.f, V_Single); + WriteVector(&d.f, V_Single, vd); PC += 4; EatPrefixes(); } @@ -1558,7 +1563,8 @@ namespace MIPSInt } void Int_Vtfm(MIPSOpcode op) { - float s[16]{}, t[4]{}, d[4]; + float s[16]{}, t[4]{}; + FloatBits d; int vd = _VD; int vs = _VS; int vt = _VT; @@ -1572,13 +1578,24 @@ namespace MIPSInt ReadMatrix(s, msz, vs); ReadVector(t, sz, vt); - for (int i = 0; i < ins; i++) { - d[i] = s[i * 4] * t[0]; - for (int k = 1; k < tn; k++) { - d[i] += s[i * 4 + k] * t[k]; + float t2[4]; + for (int i = 0; i < 4; i++) { + if (i < tn) { + t2[i] = t[i]; + } else if (i == ins) { + t2[i] = 1.0f; + } else { + t2[i] = 0.0f; } - if (ins >= n) { - d[i] += s[i * 4 + ins]; + } + + for (int i = 0; i < ins; i++) { + d.f[i] = vfpu_dot(&s[i * 4], t2); + + if (my_isnan(d.f[i])) { + d.u[i] = 0x7f800001; + } else if ((d.u[i] & 0x7F800000) == 0) { + d.u[i] &= 0xFF800000; } } @@ -1599,17 +1616,20 @@ namespace MIPSInt ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); // Really this is the operation all rows probably use (with constant wiring.) - d[ins] = s[ins * 4] * t[0]; - for (int k = 1; k < 4; k++) { - d[ins] += s[ins * 4 + k] * t[k]; + d.f[ins] = vfpu_dot(&s[ins * 4], t); + + if (my_isnan(d.f[ins])) { + d.u[ins] = 0x7f800001; + } else if ((d.u[ins] & 0x7F800000) == 0) { + d.u[ins] &= 0xFF800000; } // D prefix applies to the last element only. u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << ins; u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (ins + ins); currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(d, sz); - WriteVector(d, sz, vd); + ApplyPrefixD(d.f, sz); + WriteVector(d.f, sz, vd); PC += 4; EatPrefixes(); } @@ -1956,7 +1976,8 @@ namespace MIPSInt } void Int_VecDo3(MIPSOpcode op) { - float s[4], t[4], d[4]; + float s[4], t[4]; + FloatBits d; int vd = _VD; int vs = _VS; int vt = _VT; @@ -2000,10 +2021,16 @@ namespace MIPSInt for (int i = 0; i < n; i++) { switch (optype) { - case 0: d[i] = s[i] + t[i]; break; //vadd - case 1: d[i] = s[i] - t[i]; break; //vsub - case 7: d[i] = s[i] / t[i]; break; //vdiv - case 8: d[i] = s[i] * t[i]; break; //vmul + case 0: d.f[i] = s[i] + t[i]; break; //vadd + case 1: d.f[i] = s[i] - t[i]; break; //vsub + case 7: d.f[i] = s[i] / t[i]; break; //vdiv + case 8: d.f[i] = s[i] * t[i]; break; //vmul + } + + if (my_isnan(d.f[i])) { + d.u[i] = 0x7f800001; + } else if ((d.u[i] & 0x7F800000) == 0) { + d.u[i] &= 0xFF800000; } } @@ -2012,12 +2039,12 @@ namespace MIPSInt u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(d, sz); + ApplyPrefixD(d.f, sz); } else { - RetainInvalidSwizzleST(d, sz); - ApplyPrefixD(d, sz); + RetainInvalidSwizzleST(d.f, sz); + ApplyPrefixD(d.f, sz); } - WriteVector(d, sz, vd); + WriteVector(d.f, sz, vd); PC += 4; EatPrefixes(); } diff --git a/Core/MIPS/MIPSVFPUUtils.cpp b/Core/MIPS/MIPSVFPUUtils.cpp index 6c07bfef5a..1ad629d7c2 100644 --- a/Core/MIPS/MIPSVFPUUtils.cpp +++ b/Core/MIPS/MIPSVFPUUtils.cpp @@ -607,3 +607,87 @@ float Float16ToFloat32(unsigned short l) } return f; } + +static uint32_t get_uexp(uint32_t x) { + return (x >> 23) & 0xFF; +} + +static int32_t get_mant(uint32_t x) { + // Note: this returns the hidden 1. + return (x & 0x007FFFFF) | 0x00800000; +} + +static int32_t get_sign(uint32_t x) { + return x & 0x80000000; +} + +float vfpu_dot(float a[4], float b[4]) { + static const int EXTRA_BITS = 2; + union float2int { + uint32_t i; + float f; + } intermed[4]; + + for (int i = 0; i < 4; i++) { + intermed[i].f = a[i] * b[i]; + } + + uint32_t exps[4]; + int32_t mants[4]; + uint32_t max_exp = 0; + + for (int i = 0; i < 4; i++) { + exps[i] = get_uexp(intermed[i].i); + // Preserve extra bits of precision in the mantissa during the add. + mants[i] = get_mant(intermed[i].i) << EXTRA_BITS; + if (exps[i] > max_exp) { + max_exp = exps[i]; + } + } + + int32_t mant_sum = 0; + for (int i = 0; i < 4; i++) { + int exp = max_exp - exps[i]; + if (exp >= 32) { + mants[i] = 0; + } else { + mants[i] >>= max_exp - exps[i]; + } + if (get_sign(intermed[i].i)) { + mants[i] = -mants[i]; + } + mant_sum += mants[i]; + } + + uint32_t sign_sum = 0; + if (mant_sum < 0) { + sign_sum = 0x80000000; + mant_sum = -mant_sum; + } + // Chop off the extra bits. + mant_sum >>= EXTRA_BITS; + + if (mant_sum == 0 || max_exp == 0) { + return 0.0f; + } + + while (mant_sum < 0x00800000) { + mant_sum <<= 1; + max_exp -= 1; + } + while (mant_sum >= 0x01000000) { + mant_sum >>= 1; + max_exp += 1; + } + _dbg_assert_(JIT, (mant_sum & 0x00800000) != 0); + + if (max_exp >= 255) { + max_exp = 255; + mant_sum = 0; + } else if (max_exp == 0) { + return 0.0f; + } + + intermed[0].i = sign_sum | (max_exp << 23) | (mant_sum & 0x007FFFFF); + return intermed[0].f; +} diff --git a/Core/MIPS/MIPSVFPUUtils.h b/Core/MIPS/MIPSVFPUUtils.h index 5a9c59ae70..cb0ef9fa4c 100644 --- a/Core/MIPS/MIPSVFPUUtils.h +++ b/Core/MIPS/MIPSVFPUUtils.h @@ -97,6 +97,8 @@ inline float vfpu_clamp(float v, float min, float max) { return v >= max ? max : (v <= min ? min : v); } +float vfpu_dot(float a[4], float b[4]); + #define VFPU_FLOAT16_EXP_MAX 0x1f #define VFPU_SH_FLOAT16_SIGN 15 #define VFPU_MASK_FLOAT16_SIGN 0x1 From f21955cfec6fdadf3f5de95554f02af54b84e3cc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 12 Jun 2019 21:40:05 -0700 Subject: [PATCH 20/21] interp: Use vfpu_dot for vavg, vfad, vhdp. --- Core/MIPS/MIPSIntVFPU.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Core/MIPS/MIPSIntVFPU.cpp b/Core/MIPS/MIPSIntVFPU.cpp index 72e4e0b839..24d7210069 100644 --- a/Core/MIPS/MIPSIntVFPU.cpp +++ b/Core/MIPS/MIPSIntVFPU.cpp @@ -1170,10 +1170,7 @@ namespace MIPSInt } ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); - float sum = 0.0f; - for (int i = 0; i < 4; i++) { - sum += s[i] * t[i]; - } + float sum = vfpu_dot(s, t); d = my_isnan(sum) ? fabsf(sum) : sum; ApplyPrefixD(&d, V_Single); WriteVector(&d, V_Single, vd); @@ -1409,10 +1406,7 @@ namespace MIPSInt u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE); ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); - d = 0.0f; - for (int i = 0; i < 4; i++) { - d += s[i] * t[i]; - } + d = vfpu_dot(s, t); ApplyPrefixD(&d, V_Single); WriteVector(&d, V_Single, vd); PC += 4; @@ -1443,10 +1437,7 @@ namespace MIPSInt tprefixAdd = 0; ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); - d = 0.0f; - for (int i = 0; i < 4; i++) { - d += s[i] * t[i]; - } + d = vfpu_dot(s, t); ApplyPrefixD(&d, V_Single); WriteVector(&d, V_Single, vd); PC += 4; From 4d76a9362e92cedfb1d29ee265306ba9b3708d2c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 12 Jun 2019 22:17:25 -0700 Subject: [PATCH 21/21] interp: Handle NaN better in vfpu_dot. --- Core/MIPS/MIPSVFPUUtils.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Core/MIPS/MIPSVFPUUtils.cpp b/Core/MIPS/MIPSVFPUUtils.cpp index 1ad629d7c2..8de54a7834 100644 --- a/Core/MIPS/MIPSVFPUUtils.cpp +++ b/Core/MIPS/MIPSVFPUUtils.cpp @@ -635,6 +635,7 @@ float vfpu_dot(float a[4], float b[4]) { uint32_t exps[4]; int32_t mants[4]; uint32_t max_exp = 0; + uint32_t last_inf = 0; for (int i = 0; i < 4; i++) { exps[i] = get_uexp(intermed[i].i); @@ -643,6 +644,15 @@ float vfpu_dot(float a[4], float b[4]) { if (exps[i] > max_exp) { max_exp = exps[i]; } + if (exps[i] == 255) { + bool diff_sign = last_inf && get_sign(last_inf) != get_sign(intermed[i].i); + bool mant_nan = mants[i] != (0x00800000 << EXTRA_BITS); + if (diff_sign || mant_nan) { + intermed[0].i = 0x7F800001; + return intermed[0].f; + } + last_inf = intermed[i].i; + } } int32_t mant_sum = 0;