Skip to content
This repository was archived by the owner on Nov 16, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
>
> **Building:** use the presets. `cmake --preset win-amd64` then
> `cmake --build out/build/win-amd64 --config Release --target install`.
> After initializing submodules, run `python3 scripts/prepare_simde.py` and
> `python3 scripts/prepare_simde.py --check` before configuring this fork.
> See [compatibility patch instructions](patches/README.md) for preparation and
> offline validation of the pinned SIMDe source.
> The x86 baseline is `REXGLUE_X86_BASELINE` (default `x86-64-v2`); the SDK's
> byte-swap helpers need SSSE3, so plain `x86-64` will not compile. For a CPU
> without AVX2, pass the same baseline to the game as well - see
Expand Down
2 changes: 1 addition & 1 deletion include/rex/ui/d3d12/d3d12_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define NOMINMAX
#endif
#include <windows.h>
#include <ObjBase.h>
#include <objbase.h>

#include <DXProgrammableCapture.h>
#include <d3d12.h>
Expand Down
29 changes: 29 additions & 0 deletions patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
SIMDe remains pinned to `71fd833d9666141edcd1d3c109a80e228303d8d7`.
The native `__m64` streaming-store compatibility fix is recorded in
`simde-native-m64-stream.patch`; no private vendor commit is required.

After initializing the SDK submodules, run from the SDK root:

```sh
python3 scripts/prepare_simde.py
python3 scripts/prepare_simde.py --check
```

The preparer accepts the exact repository root and revision, preserves unrelated
local edits, and verifies the actual patched source independently of Git's exit
status. A partial/conflicting patch fails rather than overwriting local edits.
This step is required before building with Windows Clang toolchains that
represent native `__m64` as a union rejected by `__builtin_nontemporal_store`.
The public SIMD type and its eight stored bytes remain unchanged.

Offline preparation regression, using disposable clones of locally available
Git objects (no network or original-checkout writes):

```sh
python3 tests/regression/test_prepare_simde.py /tmp/rex-simde-preparation
```

The separate `test_simde_stream_pi.py` fixture compiles the actual header and
checks bit patterns and adjacent canaries. Its optional `--windows-sysroot`
mode also checks the real Windows Clang non-temporal `i64` store. Preparation
checks do not substitute for compiler or runtime validation.
21 changes: 21 additions & 0 deletions patches/simde-native-m64-stream.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/simde/x86/sse.h b/simde/x86/sse.h
index a8855f5..fac2f98 100644
--- a/simde/x86/sse.h
+++ b/simde/x86/sse.h
@@ -4757,7 +4757,15 @@ simde_mm_stream_pi (simde__m64* mem_addr, simde__m64 a) {
#elif HEDLEY_HAS_BUILTIN(__builtin_nontemporal_store) && ( \
defined(SIMDE_ARM_NEON_A32V7_NATIVE) || defined(SIMDE_MIPS_LOONGSON_MMI_NATIVE) || \
defined(SIMDE_VECTOR_SUBSCRIPT))
- __builtin_nontemporal_store(a, mem_addr);
+ #if defined(SIMDE_X86_MMX_USE_NATIVE_TYPE)
+ /* Windows Clang represents the native __m64 type as a union, which
+ * __builtin_nontemporal_store cannot accept. Preserve its eight bytes
+ * through the private integer lane without changing the public type. */
+ simde__m64_private a_ = simde__m64_to_private(a);
+ __builtin_nontemporal_store(a_.i64[0], HEDLEY_REINTERPRET_CAST(int64_t*, mem_addr));
+ #else
+ __builtin_nontemporal_store(a, mem_addr);
+ #endif
#elif defined(SIMDE_ARM_NEON_A32V7_NATIVE)
simde__m64_private a_ = simde__m64_to_private(a);
vst1_s64(HEDLEY_REINTERPRET_CAST(int64_t *, mem_addr), a_.neon_i64);
17 changes: 16 additions & 1 deletion resources/templates/init/rexglue_cmake.inja
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ macro(rexglue_setup_target target_name)
rexglue_configure_target({{ cmake_var("target_name") }} {{ cmake_var("ARGN") }})
endmacro()

# A cross-build can reuse a host-native CLI, keeping host paths in the manifest
# usable and avoiding a target-platform codegen executable build.
set(REXGLUE_HOST_CODEGEN_EXECUTABLE "" CACHE FILEPATH
"Host-native rexglue CLI used for code generation")
if(REXGLUE_HOST_CODEGEN_EXECUTABLE)
if(NOT EXISTS "{{ cmake_var("REXGLUE_HOST_CODEGEN_EXECUTABLE") }}")
message(FATAL_ERROR "Host rexglue CLI not found: {{ cmake_var("REXGLUE_HOST_CODEGEN_EXECUTABLE") }}")
endif()
set(REXGLUE_CODEGEN_COMMAND "{{ cmake_var("REXGLUE_HOST_CODEGEN_EXECUTABLE") }}")
else()
# A target name lets CMake honor CROSSCOMPILING_EMULATOR when necessary.
set(REXGLUE_CODEGEN_COMMAND rex::rexglue)
endif()

# Codegen runs as part of the build, re-running only when an input in codegen.d
# changes. Build it alone with 'cmake --build . --target {{ names.snake_case }}_codegen'.
# Listing the sources as outputs orders any target that compiles them after
Expand All @@ -126,7 +140,8 @@ add_custom_command(
# declares some of them inside existing functions, and emit_conditional_branch
# cannot yet resolve a branch across such a split without emitting a goto to
# an unlabelled address (see the comment there).
COMMAND $<TARGET_FILE:rex::rexglue> codegen --pointer_table_scan {{ cmake_var("CMAKE_CURRENT_SOURCE_DIR") }}/{{ names.snake_case }}_manifest.toml
COMMAND "{{ cmake_var("REXGLUE_CODEGEN_COMMAND") }}" codegen --pointer_table_scan "{{ cmake_var("CMAKE_CURRENT_SOURCE_DIR") }}/{{ names.snake_case }}_manifest.toml"
DEPENDS "{{ cmake_var("REXGLUE_CODEGEN_COMMAND") }}"
DEPFILE "{{ cmake_var("CMAKE_CURRENT_SOURCE_DIR") }}/{{ entrypoint_out_dir }}/codegen.d"
WORKING_DIRECTORY {{ cmake_var("CMAKE_CURRENT_SOURCE_DIR") }}
COMMENT "Generating recompiled code for {{ names.snake_case }}"
Expand Down
100 changes: 100 additions & 0 deletions scripts/prepare_simde.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""Apply or verify the pinned SIMDe native __m64 streaming-store fix."""

import argparse
from pathlib import Path
import re
import subprocess


PIN = "71fd833d9666141edcd1d3c109a80e228303d8d7"


def verify_patched_source(checkout, patch):
"""Require every actual new-side hunk, independently of git's exit status."""
target = None
expected = None
lines = []
hunks = 0

def finish():
nonlocal hunks
if expected is None:
return
if target is None or not lines or len(lines) != expected:
raise ValueError("Invalid SIMDe patch hunk")
path = checkout / target
if path.resolve() != path or not path.is_file():
raise ValueError(f"SIMDe source verification failed: invalid source path {target}")
if "\n".join(lines) + "\n" not in path.read_text():
raise ValueError(f"SIMDe source verification failed: missing patched hunk in {target}")
hunks += 1

for line in patch.read_text().splitlines():
if line.startswith("diff --git "):
finish()
target, expected, lines = None, None, []
elif line.startswith("+++ b/"):
target = Path(line[6:])
if target.is_absolute() or ".." in target.parts:
raise ValueError("Invalid SIMDe patch target")
elif line.startswith("@@ "):
finish()
header = re.fullmatch(r"@@ -\d+(?:,\d+)? \+\d+(?:,(\d+))? @@.*", line)
if header is None:
raise ValueError("Invalid SIMDe patch header")
expected, lines = int(header.group(1) or "1"), []
elif expected is not None:
if line.startswith((" ", "+")):
lines.append(line[1:])
elif not line.startswith(("-", "\\ No newline")):
raise ValueError("Invalid SIMDe patch content")
finish()
if not hunks:
raise ValueError("SIMDe patch has no verifiable hunks")


def main():
parser = argparse.ArgumentParser(description=__doc__)
sdk = Path(__file__).resolve().parents[1]
parser.add_argument("checkout", type=Path, nargs="?", default=sdk / "thirdparty/simde")
parser.add_argument("--check", action="store_true", help="Verify only; do not modify the checkout")
args = parser.parse_args()
checkout = args.checkout.resolve()
patch = sdk / "patches/simde-native-m64-stream.patch"

def git(*arguments, check=False):
return subprocess.run(["git", "-C", str(checkout), *arguments], check=check,
cwd=checkout, capture_output=True, text=True, timeout=30)

if not checkout.is_dir():
parser.error(f"SIMDe checkout does not exist: {checkout}")
repository = git("rev-parse", "--show-toplevel")
if repository.returncode or Path(repository.stdout.strip()).resolve() != checkout:
parser.error("SIMDe checkout must be the repository root, not a subdirectory")
revision = git("rev-parse", "HEAD", check=True).stdout.strip()
if revision != PIN:
parser.error(f"Expected SIMDe {PIN}, got {revision}; use the SDK's pinned submodule revision")
if git("apply", "--reverse", "--check", str(patch)).returncode == 0:
try:
verify_patched_source(checkout, patch)
except ValueError as error:
parser.error(str(error))
print(f"PASS: SIMDe {PIN} with native __m64 streaming-store fix")
return
if args.check:
parser.error("Native __m64 streaming-store fix is missing or incomplete; run without --check")
applicability = git("apply", "--check", str(patch))
if applicability.returncode:
parser.error("Cannot apply the SIMDe fix without conflicting with existing edits:\n" +
applicability.stderr.strip())
git("apply", str(patch), check=True)
git("apply", "--reverse", "--check", str(patch), check=True)
try:
verify_patched_source(checkout, patch)
except ValueError as error:
parser.error(str(error))
print(f"Applied native __m64 streaming-store fix to SIMDe {PIN}")


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions src/core/platform_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <windows.h>
#include <windowsx.h>

#include <ObjBase.h>
#include <SDKDDKVer.h>
#include <objbase.h>
#include <sdkddkver.h>
#include <bcrypt.h>
#include <dwmapi.h>
#include <shellapi.h>
Expand Down
7 changes: 7 additions & 0 deletions src/input/input_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <rex/input/mnk/mnk_input_driver.h>
#include <rex/input/nop/nop_input_driver.h>
#include <rex/input/portal/emulated_toypad.h>
#if REX_PLATFORM_WIN32
#include <rex/input/portal/hardware_portal.h>
#endif
#include <rex/input/sdl/sdl_input_driver.h>
#include <rex/input/state_merge.h>
#include <rex/input/xinput/xinput_input_driver.h>
Expand Down Expand Up @@ -401,8 +403,13 @@ std::unique_ptr<InputSystem> CreateDefaultInputSystem(bool tool_mode) {
REXLOG_INFO("Portal: using the emulated ToyPad.");
input->SetPortal(std::make_unique<EmulatedToypad>());
} else {
#if REX_PLATFORM_WIN32
REXLOG_INFO("Portal: using a physical portal over USB.");
input->SetPortal(std::make_unique<HardwarePortal>());
#else
REXLOG_WARN("Portal: physical USB passthrough is unavailable on this platform; "
"enable toypad_emulation to use the emulated ToyPad.");
#endif
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ rex_target_pch(rexruntime
target_include_directories(rexruntime PUBLIC
$<BUILD_INTERFACE:${REXGLUE_ROOT}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
# Public UI headers expose ImGui types. Propagate its headers while keeping
# the ImGui OBJECT library linked privately into this single runtime DLL.
$<BUILD_INTERFACE:${REXGLUE_ROOT}/thirdparty/imgui>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_include_directories(rexruntime PRIVATE
Expand Down
45 changes: 45 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,48 @@ add_subdirectory(unit)

# PPC instruction tests (requires PPC toolchain)
add_subdirectory(ppc)

# Compile small production-body fixtures with fake guest threads and graphics
# objects. These tests do not require game assets or a graphics device. The
# cache-storage fixtures use POSIX stdio/file APIs, so register them on Linux
# with GNU-style compiler drivers only.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux"
AND NOT CMAKE_CROSSCOMPILING
AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
find_package(Python3 COMPONENTS Interpreter QUIET)
if(Python3_Interpreter_FOUND)
set(REXGLUE_REGRESSION_CHECKS)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|amd64|x86_64)$")
list(APPEND REXGLUE_REGRESSION_CHECKS simde_stream_pi)
endif()
foreach(check IN LISTS REXGLUE_REGRESSION_CHECKS)
add_test(NAME regression_${check}
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/regression/test_${check}.py
${CMAKE_CURRENT_BINARY_DIR}/regression/${check}
--compiler ${CMAKE_CXX_COMPILER})
set_tests_properties(regression_${check} PROPERTIES
TIMEOUT 60 LABELS "regression;asset_free")
if(check STREQUAL "timer_wait")
set_tests_properties(regression_${check} PROPERTIES TIMEOUT 100)
endif()
endforeach()
else()
message(STATUS "Python3 unavailable: production-body regression fixtures are disabled")
endif()
endif()

# Patch preparation uses local Git objects and does not execute target binaries.
if(UNIX)
find_package(Python3 COMPONENTS Interpreter QUIET)
find_package(Git QUIET)
if(Python3_Interpreter_FOUND AND Git_FOUND
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/simde/.git")
add_test(NAME regression_prepare_simde
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/regression/test_prepare_simde.py
${CMAKE_CURRENT_BINARY_DIR}/regression/prepare_simde)
set_tests_properties(regression_prepare_simde PROPERTIES
TIMEOUT 60 LABELS "regression;asset_free")
endif()
endif()
Loading