mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-11-30 11:06:42 -08:00
Compare commits
3
Commits
e2fd48953e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e0de890bc | ||
|
|
ae433ccb1d | ||
|
|
57c083e7ad |
No files matched your search
@@ -141,6 +141,12 @@ else()
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs") # for our logging system
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs") # for our logging system
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") # fmtlib workaround
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") # fmtlib workaround
|
||||||
|
|
||||||
|
# static linking
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -static-libgcc")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc -static-libstdc++")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
# release flags
|
# release flags
|
||||||
if(CMAKE_BUILD_TYPE MATCHES "Release")
|
if(CMAKE_BUILD_TYPE MATCHES "Release")
|
||||||
|
|
||||||
@@ -160,8 +166,8 @@ else()
|
|||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility=hidden -fvisibility-inlines-hidden")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility=hidden -fvisibility-inlines-hidden")
|
||||||
|
|
||||||
# remove symbol table and relocation information
|
# remove symbol table and relocation information
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
|
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -s")
|
||||||
|
|
||||||
# performance
|
# performance
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -pipe")
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -pipe")
|
||||||
@@ -223,10 +229,6 @@ else()
|
|||||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og -pipe")
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og -pipe")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -pipe")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -pipe")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# static linking
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -static-libgcc")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc -static-libstdc++")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# default defines
|
# default defines
|
||||||
@@ -453,6 +455,7 @@ set(SOURCE_FILES ${SOURCE_FILES}
|
|||||||
games/hpm/hpm.cpp
|
games/hpm/hpm.cpp
|
||||||
games/hpm/io.cpp
|
games/hpm/io.cpp
|
||||||
games/iidx/iidx.cpp
|
games/iidx/iidx.cpp
|
||||||
|
games/iidx/dxva2.cpp
|
||||||
games/iidx/io.cpp
|
games/iidx/io.cpp
|
||||||
games/iidx/poke.cpp
|
games/iidx/poke.cpp
|
||||||
games/iidx/bi2a.cpp
|
games/iidx/bi2a.cpp
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
#include "dxva2.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <d3d9.h>
|
||||||
|
#include <dxva2api.h>
|
||||||
|
|
||||||
|
#include "avs/game.h"
|
||||||
|
#include "hooks/graphics/backends/d3d9/d3d9_backend.h"
|
||||||
|
#include "util/detour.h"
|
||||||
|
#include "util/logging.h"
|
||||||
|
|
||||||
|
namespace games::iidx {
|
||||||
|
static decltype(DXVA2CreateDirect3DDeviceManager9) *create_dxva2_manager_orig = nullptr;
|
||||||
|
static bool force_dxva2_workaround = false;
|
||||||
|
|
||||||
|
static bool has_video_player_with_dxva2_fallback(HMODULE module) {
|
||||||
|
// iidx34+ tries AVMfVideoPlayerWithDxva and falls back to MF-based software decoder
|
||||||
|
// (can install dxva2 hooks to trigger the fallback)
|
||||||
|
//
|
||||||
|
// older iidx (003 variants of iidx29-30?) uses MfVideo::DxvaDeviceImpl and does not automatically fallback
|
||||||
|
// (requires a DLL patch to trigger the fallback)
|
||||||
|
//
|
||||||
|
// this function detects the AVMfVideoPlayerWithDxva case and returns true
|
||||||
|
|
||||||
|
constexpr char player_type[] = ".?AVMfVideoPlayerWithDxva@Video@Graphics@@";
|
||||||
|
const auto *image = reinterpret_cast<const char *>(module);
|
||||||
|
const auto *dos_header = reinterpret_cast<const IMAGE_DOS_HEADER *>(image);
|
||||||
|
const auto *nt_headers =
|
||||||
|
reinterpret_cast<const IMAGE_NT_HEADERS *>(image + dos_header->e_lfanew);
|
||||||
|
|
||||||
|
const auto *section = IMAGE_FIRST_SECTION(nt_headers);
|
||||||
|
for (WORD i = 0; i < nt_headers->FileHeader.NumberOfSections; i++, section++) {
|
||||||
|
if (std::memcmp(section->Name, ".data", sizeof(".data")) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto size = std::min(section->Misc.VirtualSize, section->SizeOfRawData);
|
||||||
|
const std::string_view data(image + section->VirtualAddress, size);
|
||||||
|
const std::string_view marker(player_type, sizeof(player_type));
|
||||||
|
return data.find(marker) != std::string_view::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HRESULT WINAPI create_dxva2_manager_hook(UINT *reset_token, IDirect3DDeviceManager9 **manager) {
|
||||||
|
if (!force_dxva2_workaround && !graphics_d3d9_is_dxvk()) {
|
||||||
|
return create_dxva2_manager_orig(reset_token, manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
// dxvk can create the manager without providing a usable decoder; failing creation
|
||||||
|
// lets iidx fall back to software decoding on builds that support it.
|
||||||
|
static std::atomic_bool logged = false;
|
||||||
|
if (!logged.exchange(true, std::memory_order_relaxed)) {
|
||||||
|
log_info(
|
||||||
|
"iidx",
|
||||||
|
"DXVA2 workaround active ({}): returning E_FAIL from DXVA2CreateDirect3DDeviceManager9",
|
||||||
|
force_dxva2_workaround ? "forced on by user" : "automatically for DXVK");
|
||||||
|
}
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_dxva2_workaround(std::string_view mode) {
|
||||||
|
// default (no selection) is auto
|
||||||
|
if (mode.empty()) {
|
||||||
|
mode = "auto";
|
||||||
|
}
|
||||||
|
|
||||||
|
// forced off by user
|
||||||
|
if (mode == "off") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool forced_on_by_user = (mode == "on");
|
||||||
|
|
||||||
|
// invalid option value
|
||||||
|
if (!forced_on_by_user && mode != "auto") {
|
||||||
|
log_warning("iidx", "invalid DXVA2 workaround mode '{}'; expected auto, on, or off", mode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto module = avs::game::DLL_INSTANCE;
|
||||||
|
if (!module) {
|
||||||
|
if (forced_on_by_user) {
|
||||||
|
log_warning("iidx", "DXVA2 workaround requested, but the game DLL is not loaded");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!forced_on_by_user && !has_video_player_with_dxva2_fallback(module)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
force_dxva2_workaround = forced_on_by_user;
|
||||||
|
|
||||||
|
// install hook
|
||||||
|
create_dxva2_manager_orig = detour::iat_try(
|
||||||
|
"DXVA2CreateDirect3DDeviceManager9", create_dxva2_manager_hook, module, "dxva2.dll");
|
||||||
|
|
||||||
|
if (!create_dxva2_manager_orig) {
|
||||||
|
if (forced_on_by_user) {
|
||||||
|
log_warning("iidx", "DXVA2 workaround requested, but the DXVA2 import was not found");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forced_on_by_user) {
|
||||||
|
log_info("iidx", "DXVA2 disabled by user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace games::iidx {
|
||||||
|
void init_dxva2_workaround(std::string_view mode);
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include "bi2a.h"
|
#include "bi2a.h"
|
||||||
#include "bi2x_hook.h"
|
#include "bi2x_hook.h"
|
||||||
|
#include "dxva2.h"
|
||||||
#include "ezusb.h"
|
#include "ezusb.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "poke.h"
|
#include "poke.h"
|
||||||
@@ -311,8 +312,9 @@ namespace games::iidx {
|
|||||||
|
|
||||||
void IIDXGame::attach() {
|
void IIDXGame::attach() {
|
||||||
Game::attach();
|
Game::attach();
|
||||||
// IO boards
|
|
||||||
auto options = games::get_options(eamuse_get_game());
|
auto options = games::get_options(eamuse_get_game());
|
||||||
|
|
||||||
|
// IO boards
|
||||||
if (!options->at(launcher::Options::IIDXBIO2FW).value_bool()) {
|
if (!options->at(launcher::Options::IIDXBIO2FW).value_bool()) {
|
||||||
|
|
||||||
// reduce boot wait time
|
// reduce boot wait time
|
||||||
@@ -452,6 +454,10 @@ namespace games::iidx {
|
|||||||
|
|
||||||
#if SPICE64
|
#if SPICE64
|
||||||
|
|
||||||
|
// dxvk workaround for movie decoder
|
||||||
|
init_dxva2_workaround(
|
||||||
|
options->at(launcher::Options::IIDXNoDxva2).value_text());
|
||||||
|
|
||||||
if (TDJ_MODE) {
|
if (TDJ_MODE) {
|
||||||
sysutils::hook_EnumDisplayDevicesA();
|
sysutils::hook_EnumDisplayDevicesA();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,30 @@ HRESULT STDMETHODCALLTYPE WrappedIAudioClient::Initialize(
|
|||||||
WAVEFORMATEXTENSIBLE resample_storage = {};
|
WAVEFORMATEXTENSIBLE resample_storage = {};
|
||||||
const WAVEFORMATEX *device_format = pFormat;
|
const WAVEFORMATEX *device_format = pFormat;
|
||||||
|
|
||||||
|
#if SPICE_LINUX
|
||||||
|
WAVEFORMATEXTENSIBLE full_width_storage = {};
|
||||||
|
if (this->shared.redirected_from_exclusive &&
|
||||||
|
pFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
||||||
|
pFormat->cbSize == sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) &&
|
||||||
|
pFormat->wBitsPerSample == 32) {
|
||||||
|
const auto *ext = reinterpret_cast<const WAVEFORMATEXTENSIBLE *>(pFormat);
|
||||||
|
if (ext->SubFormat == GUID_KSDATAFORMAT_SUBTYPE_PCM &&
|
||||||
|
ext->Samples.wValidBitsPerSample == 24) {
|
||||||
|
|
||||||
|
// workaround for bug in wine
|
||||||
|
//
|
||||||
|
// Windows reads audio data in the **top** 24 bits, but Wine's PulseAudio mapping
|
||||||
|
// for this format reads the **bottom** 24 bits, causing static.
|
||||||
|
// report 32 valid bits so Wine selects s32le and reads the whole sample.
|
||||||
|
// the bottom 8 bits are zero padding, so the audio data and volume stay the same.
|
||||||
|
full_width_storage = *ext;
|
||||||
|
full_width_storage.Samples.wValidBitsPerSample = 32;
|
||||||
|
device_format = &full_width_storage.Format;
|
||||||
|
log_info("audio::wasapi", "using 32-bit PCM for Linux shared-mode 24-in-32 audio");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!this->shared.redirected_from_exclusive) {
|
if (!this->shared.redirected_from_exclusive) {
|
||||||
|
|
||||||
// when downmixing, open the real device as stereo while the game keeps writing its native
|
// when downmixing, open the real device as stereo while the game keeps writing its native
|
||||||
|
|||||||
@@ -286,8 +286,37 @@ static bool is_dx9_on_12_enabled() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool detect_dxvk(HMODULE d3d9) {
|
||||||
|
// **mostly** reliable detection for dxvk; these are used internally for debugging
|
||||||
|
constexpr WORD register_annotation = 28257;
|
||||||
|
constexpr WORD unregister_annotation = 28258;
|
||||||
|
if (!d3d9 ||
|
||||||
|
!GetProcAddress(d3d9, MAKEINTRESOURCEA(register_annotation)) ||
|
||||||
|
!GetProcAddress(d3d9, MAKEINTRESOURCEA(unregister_annotation))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// log once
|
||||||
|
static std::atomic_bool logged = false;
|
||||||
|
if (!logged.exchange(true, std::memory_order_relaxed)) {
|
||||||
|
log_info("graphics::d3d9", "DXVK detected");
|
||||||
|
deferredlogs::defer_error_messages({
|
||||||
|
"dxvk detected",
|
||||||
|
" Vulkan-based renderer may cause graphical issues or crashes",
|
||||||
|
" it should only be used if necessary on your PC",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool graphics_d3d9_is_dxvk() {
|
||||||
|
return detect_dxvk(libutils::try_module("d3d9.dll"));
|
||||||
|
}
|
||||||
|
|
||||||
static IDirect3D9 *WINAPI Direct3DCreate9_hook(UINT SDKVersion) {
|
static IDirect3D9 *WINAPI Direct3DCreate9_hook(UINT SDKVersion) {
|
||||||
log_misc("graphics::d3d9", "Direct3DCreate9 hook hit");
|
log_misc("graphics::d3d9", "Direct3DCreate9 hook hit");
|
||||||
|
graphics_d3d9_is_dxvk();
|
||||||
|
|
||||||
// remove hook
|
// remove hook
|
||||||
if (D3D9_DIRECT3D_CREATE9_ADR) {
|
if (D3D9_DIRECT3D_CREATE9_ADR) {
|
||||||
@@ -330,6 +359,7 @@ static IDirect3D9 *WINAPI Direct3DCreate9_hook(UINT SDKVersion) {
|
|||||||
|
|
||||||
static HRESULT WINAPI Direct3DCreate9Ex_hook(UINT SDKVersion, IDirect3D9Ex **d3d9ex) {
|
static HRESULT WINAPI Direct3DCreate9Ex_hook(UINT SDKVersion, IDirect3D9Ex **d3d9ex) {
|
||||||
log_misc("graphics::d3d9", "Direct3DCreate9Ex hook hit");
|
log_misc("graphics::d3d9", "Direct3DCreate9Ex hook hit");
|
||||||
|
graphics_d3d9_is_dxvk();
|
||||||
|
|
||||||
// call original
|
// call original
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
@@ -366,6 +396,7 @@ void graphics_d3d9_init() {
|
|||||||
if (!d3d9) {
|
if (!d3d9) {
|
||||||
log_info("graphics::d3d9", "skipping inline hooks");
|
log_info("graphics::d3d9", "skipping inline hooks");
|
||||||
} else {
|
} else {
|
||||||
|
detect_dxvk(d3d9);
|
||||||
|
|
||||||
// 9 on 12
|
// 9 on 12
|
||||||
Direct3DCreate9On12_orig = (Direct3DCreate9On12_t) libutils::try_proc(d3d9, "Direct3DCreate9On12");
|
Direct3DCreate9On12_orig = (Direct3DCreate9On12_t) libutils::try_proc(d3d9, "Direct3DCreate9On12");
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ static const GUID IID_WrappedIDirect3D9 = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void graphics_d3d9_init();
|
void graphics_d3d9_init();
|
||||||
|
bool graphics_d3d9_is_dxvk();
|
||||||
void graphics_d3d9_on_present(
|
void graphics_d3d9_on_present(
|
||||||
HWND hFocusWindow,
|
HWND hFocusWindow,
|
||||||
IDirect3DDevice9 *device,
|
IDirect3DDevice9 *device,
|
||||||
|
|||||||
@@ -846,6 +846,21 @@ static const std::vector<OptionDefinition> OPTION_DEFINITIONS = std::invoke([]()
|
|||||||
.game_name = "Beatmania IIDX",
|
.game_name = "Beatmania IIDX",
|
||||||
.category = "Game Overlay",
|
.category = "Game Overlay",
|
||||||
};
|
};
|
||||||
|
c[launcher::Options::IIDXNoDxva2] = {
|
||||||
|
.title = "IIDX Disable DXVA2 Decoder",
|
||||||
|
.name = "iidxnodxva2",
|
||||||
|
.desc =
|
||||||
|
"Forcibly disables the DXVA2 decoder, causing the game to use the software decoder instead "
|
||||||
|
"on some versions of IIDX",
|
||||||
|
.type = OptionType::Enum,
|
||||||
|
.game_name = "Beatmania IIDX",
|
||||||
|
.category = "Advanced Game Options",
|
||||||
|
.elements = {
|
||||||
|
{"auto", ""},
|
||||||
|
{"on", ""},
|
||||||
|
{"off", ""},
|
||||||
|
},
|
||||||
|
};
|
||||||
c[launcher::Options::LoadSoundVoltexModule] = {
|
c[launcher::Options::LoadSoundVoltexModule] = {
|
||||||
.title = "Force Load Sound Voltex Module",
|
.title = "Force Load Sound Voltex Module",
|
||||||
.name = "sdvx",
|
.name = "sdvx",
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ namespace launcher {
|
|||||||
spice2x_IIDXLEDColor,
|
spice2x_IIDXLEDColor,
|
||||||
spice2x_IIDXLEDPos,
|
spice2x_IIDXLEDPos,
|
||||||
IIDXLEDBorderless,
|
IIDXLEDBorderless,
|
||||||
|
IIDXNoDxva2,
|
||||||
LoadSoundVoltexModule,
|
LoadSoundVoltexModule,
|
||||||
SDVXForce720p,
|
SDVXForce720p,
|
||||||
SDVXPrinterEmulation,
|
SDVXPrinterEmulation,
|
||||||
|
|||||||
Reference in new issue
Block a user