From d58ee6670ef6e00725cb8284bc76335fb7b53c43 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 1 Mar 2017 12:51:06 +0100 Subject: [PATCH] UWP: Fix audio sample rate, savestates, memory leak. --- Core/MemMap.cpp | 17 +++++++++++------ UI/NativeApp.cpp | 2 +- UWP/CommonUWP/CommonUWP.vcxproj | 3 +++ UWP/NativeUWP/NativeUWP.vcxproj | 1 - UWP/NativeUWP/NativeUWP.vcxproj.filters | 3 --- UWP/PPSSPP_UWPMain.cpp | 4 ++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index c2f3248211..1584d2537a 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -129,6 +129,7 @@ inline static bool CanIgnoreView(const MemoryView &view) { ; #endif +#if !PPSSPP_PLATFORM(UWP) static bool Memory_TryBase(u32 flags) { // OK, we know where to find free space. Now grab it! // We just mimic the popular BAT setup. @@ -152,10 +153,7 @@ static bool Memory_TryBase(u32 flags) { if (view.flags & MV_MIRROR_PREVIOUS) { position = last_position; } -#if PPSSPP_PLATFORM(UWP) - // For both 32-bit and 64-bit, we need to use address masking. - *(view.out_ptr) = (u8*)VirtualAllocFromApp(base + (view.virtual_address & MEMVIEW32_MASK), view.size, MEM_COMMIT, PAGE_READWRITE); -#elif PPSSPP_ARCH(64BIT) +#if PPSSPP_ARCH(64BIT) *view.out_ptr = (u8*)g_arena.CreateView( position, view.size, base + view.virtual_address); if (!*view.out_ptr) { @@ -180,7 +178,6 @@ static bool Memory_TryBase(u32 flags) { } return true; -#if !PPSSPP_PLATFORM(UWP) bail: // Argh! ERROR! Free what we grabbed so far so we can try again. for (int j = 0; j <= i; j++) { @@ -195,14 +192,18 @@ bail: } } return false; -#endif } +#endif bool MemoryMap_Setup(u32 flags) { #if PPSSPP_PLATFORM(UWP) // We just grab all 256MB. // We should be able to avoid COMMIT-ing here, TODO. base = (u8*)VirtualAllocFromApp(0, 0x10000000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + for (int i = 0; i < num_views; i++) { + const MemoryView &view = views[i]; + (*view.out_ptr) = (uint8_t *)base + (views[i].virtual_address & Memory::MEMVIEW32_MASK); + } return true; #else // Figure out how much memory we need to allocate in total. @@ -265,6 +266,10 @@ void MemoryMap_Shutdown(u32 flags) { *views[i].out_ptr = nullptr; } g_arena.ReleaseSpace(); + +#if PPSSPP_PLATFORM(UWP) + VirtualFree(base, 0, MEM_RELEASE); +#endif } void Init() { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 1d205a9fdd..3f8059380a 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -636,7 +636,7 @@ void NativeInitGraphics(GraphicsContext *graphicsContext) { #ifdef _WIN32 winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend); #if PPSSPP_PLATFORM(UWP) - // TODO UWP + winAudioBackend->Init(0, &Win32Mix, 44100); #else winAudioBackend->Init(MainWindow::GetHWND(), &Win32Mix, 44100); #endif diff --git a/UWP/CommonUWP/CommonUWP.vcxproj b/UWP/CommonUWP/CommonUWP.vcxproj index 8f3f555ee0..004aad58df 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj +++ b/UWP/CommonUWP/CommonUWP.vcxproj @@ -137,6 +137,7 @@ true ../..;../../ext/native;../../ext/snappy;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) NOMINMAX;_UNICODE;UNICODE;%(PreprocessorDefinitions) + pch.h Console @@ -166,6 +167,7 @@ true ../..;../../ext/native;../../ext/snappy;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) NOMINMAX;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions) + pch.h Console @@ -195,6 +197,7 @@ true ../..;../../ext/native;../../ext/snappy;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) NOMINMAX;_UNICODE;UNICODE;%(PreprocessorDefinitions) + pch.h Console diff --git a/UWP/NativeUWP/NativeUWP.vcxproj b/UWP/NativeUWP/NativeUWP.vcxproj index a5f235d6a5..c1702dee22 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj +++ b/UWP/NativeUWP/NativeUWP.vcxproj @@ -279,7 +279,6 @@ - diff --git a/UWP/NativeUWP/NativeUWP.vcxproj.filters b/UWP/NativeUWP/NativeUWP.vcxproj.filters index 1147ba48c8..8bab84d583 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj.filters +++ b/UWP/NativeUWP/NativeUWP.vcxproj.filters @@ -515,9 +515,6 @@ thread - - thread - thread diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 79b40f5325..729762b4c4 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -35,7 +35,7 @@ using namespace Concurrency; // UGLY! PPSSPP_UWPMain *g_main; - +extern WindowsAudioBackend *winAudioBackend; // 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 @@ -284,7 +284,7 @@ std::string System_GetProperty(SystemProperty prop) { int System_GetPropertyInt(SystemProperty prop) { switch (prop) { case SYSPROP_AUDIO_SAMPLE_RATE: - return 48000; //winAudioBackend ? winAudioBackend->GetSampleRate() : -1; + return winAudioBackend ? winAudioBackend->GetSampleRate() : -1; case SYSPROP_DISPLAY_REFRESH_RATE: return 60000; case SYSPROP_DEVICE_TYPE: