make compile with mingw-w64

This commit is contained in:
oltolm 2024-08-29 22:02:28 +02:00
parent 51b4b05f0b
commit 99991e4d48
41 changed files with 201 additions and 99 deletions

View File

@ -44,6 +44,7 @@
#else
#include <cmath>
#endif
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <list>

View File

@ -3,7 +3,7 @@
#include "AudioCommon/WASAPIStream.h"
#ifdef _WIN32
#ifdef _MSC_VER
// clang-format off
#include <Audioclient.h>
@ -349,4 +349,4 @@ void WASAPIStream::SoundLoop()
}
}
#endif // _WIN32
#endif // _MSC_VER

View File

@ -3,7 +3,7 @@
#pragma once
#ifdef _WIN32
#ifdef _MSC_VER
// clang-format off
#include <Windows.h>
@ -17,6 +17,7 @@
#include <thread>
#include <vector>
#include <wrl/client.h>
#endif
#include "AudioCommon/SoundStream.h"
@ -25,11 +26,9 @@ struct IAudioRenderClient;
struct IMMDevice;
struct IMMDeviceEnumerator;
#endif
class WASAPIStream final : public SoundStream
{
#ifdef _WIN32
#ifdef _MSC_VER
public:
explicit WASAPIStream();
~WASAPIStream();
@ -56,5 +55,5 @@ private:
Microsoft::WRL::ComPtr<IAudioRenderClient> m_audio_renderer;
wil::unique_event_nothrow m_need_data_event;
WAVEFORMATEXTENSIBLE m_format;
#endif // _WIN32
#endif // _MSC_VER
};

View File

@ -16,6 +16,7 @@
}
#else // WIN32
#define NO_OLDNAMES
// Function Cross-Compatibility
#define strcasecmp _stricmp
#define strncasecmp _strnicmp

View File

@ -19,6 +19,7 @@
typedef NTSTATUS(NTAPI* PRTL_HEAP_COMMIT_ROUTINE)(IN PVOID Base, IN OUT PVOID* CommitAddress,
IN OUT PSIZE_T CommitSize);
#ifndef __MINGW32__
typedef struct _RTL_HEAP_PARAMETERS
{
ULONG Length;
@ -33,6 +34,7 @@ typedef struct _RTL_HEAP_PARAMETERS
PRTL_HEAP_COMMIT_ROUTINE CommitRoutine;
SIZE_T Reserved[2];
} RTL_HEAP_PARAMETERS, *PRTL_HEAP_PARAMETERS;
#endif
typedef PVOID (*RtlCreateHeap_t)(_In_ ULONG Flags, _In_opt_ PVOID HeapBase,
_In_opt_ SIZE_T ReserveSize, _In_opt_ SIZE_T CommitSize,
@ -204,7 +206,7 @@ void CompatPatchesInstall(LdrWatcher* watcher)
// crash if applied before module initialization (i.e. called on the Ldr
// callout path).
auto patcher = ImportPatcher(event.base_address);
patcher.PatchIAT("kernel32.dll", "HeapCreate", HeapCreateLow4GB);
patcher.PatchIAT("kernel32.dll", "HeapCreate", (void*)HeapCreateLow4GB);
}});
watcher->Install(
{{L"ucrtbase.dll"}, [](const LdrDllLoadEvent& event) {

View File

@ -11,7 +11,7 @@
#pragma once
#ifdef _WIN32
#ifdef _MSC_VER
#include <concrt.h>
#endif

View File

@ -13,7 +13,7 @@
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#ifdef _MSC_VER
#ifdef _WIN32
#include <Windows.h>
#else
#ifdef ANDROID

View File

@ -39,6 +39,7 @@
#include <direct.h> // getcwd
#include <io.h>
#include <objbase.h> // guid stuff
#include <share.h>
#include <shellapi.h>
#else
#include <dirent.h>

View File

@ -223,7 +223,7 @@ void* GLContextWGL::GetFuncAddress(const std::string& name)
func = GetProcAddress(opengl_module, name.c_str());
}
return func;
return (void*)func;
}
// Create rendering window.

View File

@ -3,8 +3,14 @@
#include "HRWrap.h"
#ifndef _MSC_VER
#include <comdef.h>
#endif
#include "Common/StringUtil.h"
namespace Common
{
#ifdef _MSC_VER
std::string GetHResultMessage(HRESULT hr)
{
auto err = winrt::hresult_error(hr);
@ -14,4 +20,11 @@ std::string GetHResultMessage(const winrt::hresult& hr)
{
return GetHResultMessage(hr.value);
}
#else
std::string GetHResultMessage(HRESULT hr)
{
_com_error err(hr);
return TStrToUTF8(err.ErrorMessage());
}
#endif
} // namespace Common

View File

@ -3,10 +3,13 @@
#pragma once
#include <windows.h>
#include <fmt/format.h>
#include <string>
#include <winerror.h>
#ifdef _MSC_VER
#include <winrt/base.h>
#endif
#include "Common/CommonTypes.h"
@ -35,6 +38,7 @@ struct fmt::formatter<Common::HRWrap>
}
};
#ifdef _MSC_VER
template <>
struct fmt::formatter<winrt::hresult>
{
@ -45,3 +49,4 @@ struct fmt::formatter<winrt::hresult>
return fmt::format_to(ctx.out(), "{} ({:#010x})", Common::GetHResultMessage(hr), hr.value);
}
};
#endif

View File

@ -9,6 +9,7 @@
#ifdef _WIN32
#include <io.h>
#include <share.h>
#include "Common/CommonFuncs.h"
#include "Common/StringUtil.h"

View File

@ -59,7 +59,8 @@ static bool InitWindowsMemoryFunctions(WindowsMemoryFunctions* functions)
void* const ptr_IsApiSetImplemented = kernelBase.GetSymbolAddress("IsApiSetImplemented");
if (!ptr_IsApiSetImplemented)
return false;
if (!static_cast<PIsApiSetImplemented>(ptr_IsApiSetImplemented)("api-ms-win-core-memory-l1-1-6"))
if (!reinterpret_cast<PIsApiSetImplemented>(ptr_IsApiSetImplemented)(
"api-ms-win-core-memory-l1-1-6"))
return false;
functions->m_api_ms_win_core_memory_l1_1_6_handle.Open("api-ms-win-core-memory-l1-1-6.dll");
@ -156,9 +157,10 @@ u8* MemArena::ReserveMemoryRegion(size_t memory_size)
u8* base;
if (m_memory_functions.m_api_ms_win_core_memory_l1_1_6_handle.IsOpen())
{
base = static_cast<u8*>(static_cast<PVirtualAlloc2>(m_memory_functions.m_address_VirtualAlloc2)(
nullptr, nullptr, memory_size, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, PAGE_NOACCESS,
nullptr, 0));
base = static_cast<u8*>(reinterpret_cast<PVirtualAlloc2>(
m_memory_functions.m_address_VirtualAlloc2)(nullptr, nullptr, memory_size,
MEM_RESERVE | MEM_RESERVE_PLACEHOLDER,
PAGE_NOACCESS, nullptr, 0));
if (base)
{
m_reserved_region = base;
@ -329,7 +331,7 @@ void* MemArena::MapInMemoryRegion(s64 offset, size_t size, void* base)
return nullptr;
}
void* rv = static_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
void* rv = reinterpret_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
m_memory_handle, nullptr, base, offset, size, MEM_REPLACE_PLACEHOLDER, PAGE_READWRITE,
nullptr, 0);
if (rv)
@ -422,7 +424,7 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
{
if (m_memory_functions.m_api_ms_win_core_memory_l1_1_6_handle.IsOpen())
{
if (static_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
if (reinterpret_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
view, MEM_PRESERVE_PLACEHOLDER))
{
if (!JoinRegionsAfterUnmap(view, size))

View File

@ -607,7 +607,7 @@ std::filesystem::path StringToPath(std::string_view path)
// path::u8string returns std::u8string starting with C++20, which is annoying to convert.
std::string PathToString(const std::filesystem::path& path)
{
#ifdef _MSC_VER
#ifdef _WIN32
return WStringToUTF8(path.native());
#else
return path.native();

View File

@ -47,7 +47,7 @@ int CurrentThreadId()
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
{
SetThreadAffinityMask(thread, mask);
SetThreadAffinityMask((HANDLE)thread, mask);
}
void SetCurrentThreadAffinity(u32 mask)
@ -66,6 +66,7 @@ void SwitchCurrentThread()
SwitchToThread();
}
#ifdef _MSC_VER
// Sets the debugger-visible name of the current thread.
// Uses trick documented in:
// https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code
@ -96,6 +97,7 @@ static void SetCurrentThreadNameViaException(const char* name)
{
}
}
#endif
static void SetCurrentThreadNameViaApi(const char* name)
{
@ -112,7 +114,9 @@ static void SetCurrentThreadNameViaApi(const char* name)
void SetCurrentThreadName(const char* name)
{
#ifdef _MSC_VER
SetCurrentThreadNameViaException(name);
#endif
SetCurrentThreadNameViaApi(name);
}

View File

@ -7,6 +7,9 @@
namespace WindowsRegistry
{
template bool ReadValue(u32* value, const std::string& subkey, const std::string& name);
template bool ReadValue(u64* value, const std::string& subkey, const std::string& name);
template <typename T>
bool ReadValue(T* value, const std::string& subkey, const std::string& name)
{

View File

@ -9,8 +9,8 @@ namespace WindowsRegistry
{
template <typename T>
bool ReadValue(T* value, const std::string& subkey, const std::string& name);
template bool ReadValue(u32* value, const std::string& subkey, const std::string& name);
template bool ReadValue(u64* value, const std::string& subkey, const std::string& name);
extern template bool ReadValue(u32* value, const std::string& subkey, const std::string& name);
extern template bool ReadValue(u64* value, const std::string& subkey, const std::string& name);
template <>
bool ReadValue(std::string* value, const std::string& subkey, const std::string& name);

View File

@ -21,6 +21,10 @@
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#ifndef _XCR_XFEATURE_ENABLED_MASK
#define _XCR_XFEATURE_ENABLED_MASK 0
#endif
#ifndef _WIN32
#ifdef __FreeBSD__
@ -55,6 +59,12 @@ static u64 xgetbv(u32 index)
#else
#if defined(_MSC_VER) || defined(__clang__)
#include <intrin.h>
#else
#include <cpuid.h>
#endif
constexpr u32 XCR_XFEATURE_ENABLED_MASK = _XCR_XFEATURE_ENABLED_MASK;
static u64 xgetbv(u32 index)

View File

@ -9,7 +9,7 @@
#include "SFML/Network/Socket.hpp"
#ifdef _WIN32
#include <ws2ipdef.h>
#include <Ws2tcpip.h>
#else
#include <sys/select.h>
#include <sys/socket.h>

View File

@ -785,8 +785,8 @@ IPCReply NetIPTopDevice::HandleGetPeerNameRequest(const IOCtlRequest& request)
IPCReply NetIPTopDevice::HandleGetHostIDRequest(const IOCtlRequest& request)
{
const DefaultInterface interface = GetSystemDefaultInterfaceOrFallback();
const u32 host_ip = ntohl(interface.inet.s_addr);
const DefaultInterface iface = GetSystemDefaultInterfaceOrFallback();
const u32 host_ip = ntohl(iface.inet.s_addr);
INFO_LOG_FMT(IOS_NET, "IOCTL_SO_GETHOSTID = {}.{}.{}.{}", host_ip >> 24, (host_ip >> 16) & 0xFF,
(host_ip >> 8) & 0xFF, host_ip & 0xFF);
return IPCReply(host_ip);
@ -1158,10 +1158,10 @@ IPCReply NetIPTopDevice::HandleGetInterfaceOptRequest(const IOCtlVRequest& reque
// XXX: this isn't exactly right; the buffer can be larger than 12 bytes,
// in which case, depending on some interface settings, SO can write 12 more bytes
memory.Write_U32(0xC, request.io_vectors[1].address);
const DefaultInterface interface = GetSystemDefaultInterfaceOrFallback();
memory.Write_U32(ntohl(interface.inet.s_addr), request.io_vectors[0].address);
memory.Write_U32(ntohl(interface.netmask.s_addr), request.io_vectors[0].address + 4);
memory.Write_U32(ntohl(interface.broadcast.s_addr), request.io_vectors[0].address + 8);
const DefaultInterface iface = GetSystemDefaultInterfaceOrFallback();
memory.Write_U32(ntohl(iface.inet.s_addr), request.io_vectors[0].address);
memory.Write_U32(ntohl(iface.netmask.s_addr), request.io_vectors[0].address + 4);
memory.Write_U32(ntohl(iface.broadcast.s_addr), request.io_vectors[0].address + 8);
break;
}
@ -1173,8 +1173,8 @@ IPCReply NetIPTopDevice::HandleGetInterfaceOptRequest(const IOCtlVRequest& reque
case 0x4006: // get routing table
{
const DefaultInterface interface = GetSystemDefaultInterfaceOrFallback();
for (InterfaceRouting route : interface.routing_table)
const DefaultInterface iface = GetSystemDefaultInterfaceOrFallback();
for (InterfaceRouting route : iface.routing_table)
{
memory.Write_U32(ntohl(route.destination.s_addr), request.io_vectors[0].address + param5);
memory.Write_U32(ntohl(route.netmask.s_addr), request.io_vectors[0].address + param5 + 4);

View File

@ -753,7 +753,7 @@ WiiSocket::ConnectingState WiiSocket::GetConnectingState() const
Common::ScopeGuard guard([&state] { Common::RestoreNetworkErrorState(state); });
#ifdef _WIN32
constexpr int (*get_errno)() = &WSAGetLastError;
int (*get_errno)() = &WSAGetLastError;
#else
constexpr int (*get_errno)() = []() { return errno; };
#endif

View File

@ -12,6 +12,8 @@
#include "Common/CommonTypes.h"
#include "Core/IOS/Device.h"
#pragma push_macro("interface")
#undef interface
namespace IOS::HLE::USB
{
constexpr u8 DEFAULT_CONFIG_NUM = 0;
@ -187,3 +189,5 @@ protected:
u64 m_id = 0xFFFFFFFFFFFFFFFF;
};
} // namespace IOS::HLE::USB
#pragma pop_macro("interface")

View File

@ -1,6 +1,6 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
IDI_ICON1 ICON "..\\..\\..\\Installer\\Dolphin.ico"
"dolphin" ICON "..\\..\\..\\Installer\\Dolphin.ico"
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
IDI_ICON1 ICON "..\\..\\..\\Installer\\Dolphin.ico"
"dolphin" ICON "..\\..\\..\\Installer\\Dolphin.ico"

View File

@ -14,6 +14,7 @@
#include <climits>
#include <cstdio>
#include <dwmapi.h>
#include <thread>
#include "VideoCommon/Present.h"
#include "resource.h"

View File

@ -1,6 +1,4 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
IDI_ICON1 ICON "..\\..\\..\\Installer\\Dolphin.ico"
"dolphin" ICON "..\\..\\..\\Installer\\Dolphin.ico"
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
IDI_ICON1 ICON "..\\..\\..\\Installer\\Dolphin.ico"

View File

@ -1,10 +1,11 @@
// Copyright 2015 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/ScopeGuard.h"
#ifdef _WIN32
#include <QCoreApplication>
#include <shlobj.h>
#include <wil/com.h>
#include <wrl/client.h>
// This file uses some identifiers which are defined as macros in Windows headers.
// Include and undefine the macros first thing we do to solve build errors.
@ -800,7 +801,8 @@ bool GameList::AddShortcutToDesktop()
if (FAILED(shell_link->SetArguments(args.c_str())))
return false;
wil::unique_cotaskmem_string desktop;
PWSTR desktop;
Common::ScopeGuard desktop_guard([&] { CoTaskMemFree(desktop); });
if (FAILED(SHGetKnownFolderPath(FOLDERID_Desktop, KF_FLAG_NO_ALIAS, nullptr, &desktop)))
return false;
@ -811,8 +813,9 @@ bool GameList::AddShortcutToDesktop()
return Common::Contains(illegal_characters, ch);
});
std::wstring desktop_path = std::wstring(desktop.get()) + UTF8ToTStr("\\" + game_name + ".lnk");
auto persist_file = shell_link.try_query<IPersistFile>();
std::wstring desktop_path = std::wstring(desktop) + UTF8ToTStr("\\" + game_name + ".lnk");
Microsoft::WRL::ComPtr<IPersistFile> persist_file;
shell_link.As(&persist_file);
if (!persist_file)
return false;

View File

@ -1169,7 +1169,7 @@ void MainWindow::SetFullScreenResolution(bool fullscreen)
DEVMODE screen_settings;
memset(&screen_settings, 0, sizeof(screen_settings));
screen_settings.dmSize = sizeof(screen_settings);
sscanf(Config::Get(Config::MAIN_FULLSCREEN_DISPLAY_RES).c_str(), "%dx%d",
sscanf(Config::Get(Config::MAIN_FULLSCREEN_DISPLAY_RES).c_str(), "%lux%lu",
&screen_settings.dmPelsWidth, &screen_settings.dmPelsHeight);
screen_settings.dmBitsPerPel = 32;
screen_settings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

View File

@ -237,7 +237,7 @@ void AudioPane::OnBackendChanged()
m_latency_slider->setEnabled(AudioCommon::SupportsLatencyControl(backend));
}
#ifdef _WIN32
#ifdef _MSC_VER
bool is_wasapi = backend == BACKEND_WASAPI;
m_wasapi_device_label->setHidden(!is_wasapi);
m_wasapi_device_combo->setHidden(!is_wasapi);

View File

@ -1,6 +1,6 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
IDI_ICON1 ICON "..\\..\\..\\Installer\\Dolphin.ico"
"dolphin" ICON "..\\..\\..\\Installer\\Dolphin.ico"
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
IDI_ICON1 ICON "..\\..\\..\\Installer\\Dolphin.ico"
"dolphin" ICON "..\\..\\..\\Installer\\Dolphin.ico"

View File

@ -19,6 +19,10 @@
#include "DolphinTool/HeaderCommand.h"
#include "DolphinTool/VerifyCommand.h"
#ifdef _WIN32
#include <windows.h>
#endif
static void PrintUsage()
{
fmt::print(std::cerr, "usage: dolphin-tool COMMAND -h\n"

View File

@ -81,7 +81,9 @@ InputBackend::InputBackend(ControllerInterface* controller_interface)
: ciface::InputBackend(controller_interface)
{
XInput::Init();
#ifdef _MSC_VER
WGInput::Init();
#endif
CM_NOTIFY_FILTER notify_filter{.cbSize = sizeof(notify_filter),
.FilterType = CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE,
@ -100,7 +102,9 @@ void InputBackend::PopulateDevices()
s_first_populate_devices_asked.Set();
ciface::DInput::PopulateDevices(GetHWND());
ciface::XInput::PopulateDevices();
#ifdef _MSC_VER
ciface::WGInput::PopulateDevices();
#endif
}
void InputBackend::HandleWindowChange()
@ -125,7 +129,9 @@ InputBackend::~InputBackend()
}
XInput::DeInit();
#ifdef _MSC_VER
WGInput::DeInit();
#endif
}
} // namespace ciface::Win32

View File

@ -7,6 +7,10 @@
#define XINPUT_GAMEPAD_GUIDE 0x0400
#endif
#ifndef XINPUT_DLL
#define XINPUT_DLL L"xinput1_4.dll"
#endif
namespace ciface::XInput
{
struct ButtonDef

View File

@ -13,7 +13,7 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
#if !defined(XINPUT_DEVSUBTYPE_FLIGHT_STICK) && !defined(__MINGW32__)
#error You are building this module against the wrong version of DirectX. You probably need to remove DXSDK_DIR from your include path and/or _WIN32_WINNT is wrong.
#endif

View File

@ -3,6 +3,7 @@
#pragma once
#include <cstdint>
#include <functional>
#include <string>

View File

@ -10,10 +10,10 @@
#include <locale>
#include <memory>
#include <sstream>
#include "Common/ScopeGuard.h"
#ifdef _WIN32
#include <shlobj.h> // for SHGetFolderPath
#include <wil/resource.h>
#endif
#include <fmt/format.h>
@ -199,13 +199,15 @@ void SetLocale(std::string locale_name)
const std::string& adjusted_locale = locale;
#endif
// setlocale sets the C locale, and global sets the C and C++ locales, so the call to setlocale
// would be redundant if it wasn't for not having any other good way to check whether
// the locale name is valid. (Constructing a std::locale object for an unsupported
// locale name throws std::runtime_error, and exception handling is disabled in Dolphin.)
// setlocale sets the C locale, and global sets the C and C++ locales, so the call to
// setlocale would be redundant if it wasn't for not having any other good way to check
// whether the locale name is valid. (Constructing a std::locale object for an unsupported
// locale name throws std::runtime_error, and exception handling is disabled in Dolphin.)
#ifndef __MINGW32__
if (!std::setlocale(LC_ALL, adjusted_locale.c_str()))
return false;
std::locale::global(std::locale(adjusted_locale));
#endif
return true;
};
@ -310,29 +312,32 @@ void SetUserDirectory(std::string custom_path)
// -> Use GetExeDirectory()\User
// Get AppData path in case we need it.
wil::unique_cotaskmem_string appdata;
bool appdata_found = SUCCEEDED(
SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, appdata.put()));
PWSTR appdata;
Common::ScopeGuard appdata_guard([&] { CoTaskMemFree(appdata); });
bool appdata_found =
SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, &appdata));
// Check our registry keys
wil::unique_hkey hkey;
HKEY hkey;
Common::ScopeGuard dolphin_hkey_guard([&] { RegCloseKey(hkey); });
DWORD local = 0;
std::unique_ptr<TCHAR[]> configPath;
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE,
hkey.put()) == ERROR_SUCCESS)
if (SUCCEEDED(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0,
KEY_QUERY_VALUE, &hkey)))
{
Common::ScopeGuard local_user_config_hkey_guard([&] { RegCloseKey(hkey); });
DWORD size = sizeof(local);
if (RegQueryValueEx(hkey.get(), TEXT("LocalUserConfig"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(&local), &size) != ERROR_SUCCESS)
if (SUCCEEDED(RegQueryValueEx(hkey, TEXT("LocalUserConfig"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(&local), &size)))
{
local = 0;
}
size = 0;
RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr, nullptr, &size);
RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, nullptr, &size);
configPath = std::make_unique<TCHAR[]>(size / sizeof(TCHAR));
if (RegQueryValueEx(hkey.get(), TEXT("UserConfigPath"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(configPath.get()), &size) != ERROR_SUCCESS)
if (SUCCEEDED(RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(configPath.get()), &size)))
{
configPath.reset();
}
@ -341,14 +346,15 @@ void SetUserDirectory(std::string custom_path)
local = local != 0 || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
// Attempt to check if the old User directory exists in Documents.
wil::unique_cotaskmem_string documents;
bool documents_found = SUCCEEDED(
SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, documents.put()));
PWSTR documents;
Common::ScopeGuard documents_guard([&] { CoTaskMemFree(documents); });
bool documents_found =
SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &documents));
std::optional<std::string> old_user_folder;
if (documents_found)
{
old_user_folder = TStrToUTF8(documents.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP;
old_user_folder = TStrToUTF8(documents) + DIR_SEP NORMAL_USER_DIR DIR_SEP;
}
if (local) // Case 1-2
@ -365,7 +371,7 @@ void SetUserDirectory(std::string custom_path)
}
else if (appdata_found) // Case 5
{
user_path = TStrToUTF8(appdata.get()) + DIR_SEP NORMAL_USER_DIR DIR_SEP;
user_path = TStrToUTF8(appdata) + DIR_SEP NORMAL_USER_DIR DIR_SEP;
// Set the UserConfigPath value in the registry for backwards compatibility with older Dolphin
// builds, which will look for the default User directory in Documents. If we set this key,

View File

@ -153,7 +153,7 @@ void Destroy()
{
// print out alive objects, but only if we actually have pending references
// note this will also print out internal live objects to the debug console
s_debug->ReportLiveDeviceObjects(D3D11_RLDO_SUMMARY | D3D11_RLDO_DETAIL);
s_debug->ReportLiveDeviceObjects(D3D11_RLDO_FLAGS(D3D11_RLDO_SUMMARY | D3D11_RLDO_DETAIL));
}
s_debug.Reset();
}

View File

@ -90,7 +90,7 @@ std::vector<BBoxType> D3DBoundingBox::Read(u32 index, u32 length)
void D3DBoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
D3D11_BOX box{index * sizeof(BBoxType),
D3D11_BOX box{static_cast<u32>(index * sizeof(BBoxType)),
0,
0,
static_cast<u32>((index + values.size()) * sizeof(BBoxType)),

View File

@ -124,8 +124,11 @@ void Gfx::SetPipeline(const AbstractPipeline* pipeline)
void Gfx::SetScissorRect(const MathUtil::Rectangle<int>& rc)
{
// TODO: Move to stateman
const CD3D11_RECT rect(rc.left, rc.top, std::max(rc.right, rc.left + 1),
std::max(rc.bottom, rc.top + 1));
D3D11_RECT rect;
rect.left = rc.left;
rect.top = rc.top;
rect.left = std::max(rc.right, rc.left + 1);
rect.bottom = std::max(rc.bottom, rc.top + 1);
D3D::context->RSSetScissorRects(1, &rect);
}
@ -133,7 +136,13 @@ void Gfx::SetViewport(float x, float y, float width, float height, float near_de
float far_depth)
{
// TODO: Move to stateman
const CD3D11_VIEWPORT vp(x, y, width, height, near_depth, far_depth);
D3D11_VIEWPORT vp;
vp.TopLeftX = x;
vp.TopLeftY = y;
vp.Width = width;
vp.Height = height;
vp.MinDepth = near_depth;
vp.MaxDepth = far_depth;
D3D::context->RSSetViewports(1, &vp);
}

View File

@ -59,9 +59,14 @@ static ComPtr<ID3D11ShaderResourceView>
CreateTexelBufferView(ID3D11Buffer* buffer, TexelBufferFormat format, DXGI_FORMAT srv_format)
{
ComPtr<ID3D11ShaderResourceView> srv;
CD3D11_SHADER_RESOURCE_VIEW_DESC srv_desc(buffer, srv_format, 0,
VertexManager::TEXEL_STREAM_BUFFER_SIZE /
VertexManager::GetTexelBufferElementSize(format));
D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
srv_desc.Format = srv_format;
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
srv_desc.BufferEx.FirstElement = 0;
srv_desc.BufferEx.NumElements =
VertexManager::TEXEL_STREAM_BUFFER_SIZE / VertexManager::GetTexelBufferElementSize(format);
srv_desc.BufferEx.Flags = 0;
HRESULT hr = D3D::device->CreateShaderResourceView(buffer, &srv_desc, &srv);
ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create SRV for texel buffer: {}", DX11HRWrap(hr));
return srv;

View File

@ -116,8 +116,8 @@ bool DXTexture::CreateSRV()
return false;
}
const CD3D11_SHADER_RESOURCE_VIEW_DESC desc(
m_texture.Get(), dimension, D3DCommon::GetSRVFormatForAbstractFormat(m_config.format), 0,
m_config.levels, 0, m_config.layers);
dimension, D3DCommon::GetSRVFormatForAbstractFormat(m_config.format), 0, m_config.levels, 0,
m_config.layers);
DEBUG_ASSERT(!m_srv);
HRESULT hr = D3D::device->CreateShaderResourceView(m_texture.Get(), &desc, m_srv.GetAddressOf());
if (FAILED(hr))
@ -132,9 +132,12 @@ bool DXTexture::CreateSRV()
bool DXTexture::CreateUAV()
{
const CD3D11_UNORDERED_ACCESS_VIEW_DESC desc(
m_texture.Get(), D3D11_UAV_DIMENSION_TEXTURE2DARRAY,
D3DCommon::GetSRVFormatForAbstractFormat(m_config.format), 0, 0, m_config.layers);
D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
desc.Format = D3DCommon::GetSRVFormatForAbstractFormat(m_config.format);
desc.Texture2DArray.MipSlice = 0;
desc.Texture2DArray.FirstArraySlice = 0;
desc.Texture2DArray.ArraySize = m_config.layers;
DEBUG_ASSERT(!m_uav);
HRESULT hr = D3D::device->CreateUnorderedAccessView(m_texture.Get(), &desc, m_uav.GetAddressOf());
if (FAILED(hr))
@ -264,7 +267,13 @@ void DXStagingTexture::CopyFromTexture(const AbstractTexture* src,
}
else
{
CD3D11_BOX src_box(src_rect.left, src_rect.top, 0, src_rect.right, src_rect.bottom, 1);
D3D11_BOX src_box;
src_box.left = src_rect.left;
src_box.top = src_rect.top;
src_box.front = 0;
src_box.right = src_rect.right;
src_box.bottom = src_rect.bottom;
src_box.back = 1;
D3D::context->CopySubresourceRegion(
m_tex.Get(), 0, static_cast<u32>(dst_rect.left), static_cast<u32>(dst_rect.top), 0,
static_cast<const DXTexture*>(src)->GetD3DTexture(),
@ -299,7 +308,13 @@ void DXStagingTexture::CopyToTexture(const MathUtil::Rectangle<int>& src_rect, A
}
else
{
CD3D11_BOX src_box(src_rect.left, src_rect.top, 0, src_rect.right, src_rect.bottom, 1);
D3D11_BOX src_box;
src_box.left = src_rect.left;
src_box.top = src_rect.top;
src_box.front = 0;
src_box.right = src_rect.right;
src_box.bottom = src_rect.bottom;
src_box.back = 1;
D3D::context->CopySubresourceRegion(
static_cast<const DXTexture*>(dst)->GetD3DTexture(),
D3D11CalcSubresource(dst_level, dst_layer, dst->GetLevels()),
@ -484,11 +499,15 @@ DXFramebuffer::Create(DXTexture* color_attachment, DXTexture* depth_attachment,
ComPtr<ID3D11DepthStencilView> dsv;
if (depth_attachment)
{
const CD3D11_DEPTH_STENCIL_VIEW_DESC desc(
depth_attachment->GetConfig().IsMultisampled() ? D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY :
D3D11_DSV_DIMENSION_TEXTURE2DARRAY,
D3DCommon::GetDSVFormatForAbstractFormat(depth_attachment->GetFormat()), 0, 0,
depth_attachment->GetLayers(), 0);
D3D11_DEPTH_STENCIL_VIEW_DESC desc;
desc.ViewDimension = depth_attachment->GetConfig().IsMultisampled() ?
D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY :
D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
desc.Format = D3DCommon::GetDSVFormatForAbstractFormat(depth_attachment->GetFormat());
desc.Texture2DArray.MipSlice = 0;
desc.Texture2DMSArray.ArraySize = depth_attachment->GetLayers();
desc.Texture2DMSArray.FirstArraySlice = 0;
desc.Flags = 0;
HRESULT hr = D3D::device->CreateDepthStencilView(depth_attachment->GetD3DTexture(), &desc,
dsv.GetAddressOf());
ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create depth stencil view for framebuffer: {}",

View File

@ -88,8 +88,8 @@ std::vector<u32> DXContext::GetAAModes(u32 adapter_index)
bool DXContext::SupportsTextureFormat(DXGI_FORMAT format)
{
constexpr u32 required = D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TEXTURECUBE |
D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE;
const u32 required = D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TEXTURECUBE |
D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE;
D3D12_FEATURE_DATA_FORMAT_SUPPORT support = {format};
return SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &support,