Skip to content

Runtime: MSVC fallback for always_inline and flatten - #446

Open
Fructose0517 wants to merge 1 commit into
ran-j:mainfrom
Fructose0517:fix-msvc-gcc-attributes
Open

Fructose0517 wants to merge 1 commit into
ran-j:mainfrom
Fructose0517:fix-msvc-gcc-attributes

Conversation

@Fructose0517

Copy link
Copy Markdown

What

Since #359, gs_cpu_backend.cpp and ps2_gs_memory.cpp use __attribute__((always_inline)) (8 functions) and __attribute__((flatten)) (2 functions) directly. MSVC has no __attribute__, so ps2_runtime no longer compiles with it: the windows-msvc-x86_64 job fails at Build on main (ccc1655) with C4430/C2065 'always_inline': undeclared identifier in gs_cpu_backend.cpp and C2988 unrecognizable template declaration in ps2_gs_memory.cpp.

This change adds two macros to ps2xRuntime/include/types.h, which both files already include (through ps2_gs_memory.h), in the same style as PS2_FLOAT_NOINLINE in ps2_runtime_macros.h:

#if defined(_MSC_VER) && !defined(__clang__)
#define PS2_FORCE_INLINE __forceinline
#define PS2_FLATTEN
#else
#define PS2_FORCE_INLINE inline __attribute__((always_inline))
#define PS2_FLATTEN __attribute__((flatten))
#endif

and uses them in place of the attributes. GCC and Clang (clang-cl included) get exactly the attributes they had; MSVC gets __forceinline, and nothing for flatten, which is only a hint and has no MSVC equivalent.

Tests

No new test: the build is the test.

  • Windows, MSVC 19.51 (14.51 toolset), configured and built the way the CI job does (cmake -B build, cmake --build build --config Release, no extra flags): ps2_runtime, ps2EntryRunner, ps2_recomp, ps2_analyzer, ps2x_tests and the gs_cache test programs build, and ps2x_tests passes 523 of 523. Without the change ps2_runtime stops at the errors above (the CI run on ccc1655).
  • One target still fails, for an unrelated reason: ps2xStudio (GUI.cpp: 'Display', 'IsOk', 'GetFilePathName', 'Close' are not members of IGFD::FileDialog). ps2xStudio/CMakeLists.txt fetches ImGuiFileDialog at master, whose API no longer has these (fetched today at badc2be). So the CI job will still report a failed Build until that dependency is pinned, which has its own small PR; with both, the whole CI-style build succeeds and ps2x_tests passes 523 of 523.
  • Linux, GCC 13.3: both changed files compile at -O2 -msse4.1 (I could not build the whole runtime on this machine: no FFmpeg development packages).

The Linux CI jobs fail on main for a separate reason (a missing <cstring> in ps2xTest/src/code_generator_tests.cpp); that has its own small PR.

Checked on a game

Found while porting a game, which builds the runtime with MSVC and has so far force-included a header that defines __attribute__(x) away. This change makes that header unnecessary for upstream's sources.

🤖 Generated with Claude Code

gs_cpu_backend.cpp and ps2_gs_memory.cpp used __attribute__((always_inline))
and __attribute__((flatten)) directly, which MSVC does not know, so the
runtime no longer compiled with MSVC (the windows-msvc CI job fails at
Build). Two macros in types.h, PS2_FORCE_INLINE and PS2_FLATTEN, keep the
attributes on GCC and Clang and use __forceinline (and nothing for flatten,
a hint) on MSVC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant