rslc is the slang compiler everywhere. ./configure --enable-glslang
--enable-spirv_cross links the system's glslang and SPIRV-Cross next to
it when both are found, and only then does Settings > Drivers offer a
Shader Compiler choice between the two: one setting read per stage
picks the path, with nothing copied.
The MSVC 2010 project builds Vulkan and rslc. Samples that used the
vendored copies run on rslc or the system's SPIRV-Cross.
HAVE_HLSL is the Direct3D 9 HLSL driver. The unity build carries
SPIRV-Cross's HLSL emitter for it and for the Direct3D 10, 11 and 12
drivers, whose slang passes are translated to HLSL, and slang_process()
asks SPIRV-Cross for HLSL whenever a driver wants it; a build without
the emitter is refused there, with the backend named in the error.
samples/gfx/slang_hlsl_backend runs the real slang_process() on a
stock pass against SPIRV-Cross built for a Direct3D 11 build without
HAVE_HLSL and for a build with no Direct3D, and checks the unity
build's switch for each Direct3D configuration.
The vendored loader moves to deps/openxr without the hex and handle
helpers (handles cast through XR_HANDLE_TO_U64/XR_U64_TO_HANDLE and print
with snprintf and PRIx64 from retro_common_api.h), platform_exports.h,
the CMake common_config and GLAD branches, and the CMake header list.
Its runtime, active instance, recorder table, messenger table and
property set are published by pointer and replaced by compare-exchange.
Creating, destroying and reinitializing take a one-word instance claim
and are refused, never made to wait, while another call holds it; that
also keeps xrInitializeLoaderKHR from unloading the runtime under a
create. An unloaded runtime is retired and freed once no enumeration can
still hold it. samples/openxr/loader_threads drives all of it from
several threads against a stand-in runtime, under TSan and ASan.
* deps: add openxr-sdk
* openxr: initial implementation
* openxr: build the vendored loader from the tree, drop the CMake step
The OpenXR loader is compiled like every other vendored dependency
instead of through a cmake invocation run from a $(shell) at Android.mk
parse time against one hardcoded NDK path: griffin_cpp pulls in the
loader, jsoncpp and (on Android) the jnipp/android-jni-wrappers broker
sources, griffin.c picks up the generated C dispatch table, and the
loader links statically into retroarch-activity, so the prebuilt
libopenxr_loader.so module and its packaging disappear. The loader is
C++17, so the quest build appends -std=gnu++17 after the global gnu++11.
Makefile.common gains an equivalent HAVE_OPENXR block (platform-neutral
sources only) and qb grows a disabled-by-default HAVE_OPENXR switch, so
a future desktop OpenXR backend builds the same loader through configure
rather than growing a second build path.
* openxr: move the vendored loader onto libretro-common threading
The loader's C++11 threading (std::mutex, std::shared_timed_mutex, and
jnipp's std::atomic_bool) is replaced with rthreads slocks and
retro_atomic. Cold paths - the global loader lock, the property
overrides, the debug-messenger map - keep plain mutual exclusion as
lazily-created slocks published with a CAS. The two read-mostly
structures become lock-free: the runtime dispatch table is a single
acquire/release-published slot, since the loader only ever has one live
runtime instance, and the logger's recorder list is an immutable
snapshot that the LogMessage paths walk wait-free while writers rebuild
and republish it under a cold slock, retiring superseded snapshots and
removed recorders until teardown so a reader never touches freed
memory. One behavioural delta, noted in loader_logger.hpp: a removal no
longer waits for in-flight readers, so a log call racing it can reach
the removed recorder once more before it drops out of view.
The per-frame xr* dispatch (the generated trampolines through the
cached dispatch table) was already lock-free and is unchanged; this
puts the whole tree on one threading layer and drops the libstdc++
thread machinery from the loader. Verified with per-TU and
griffin-shape amalgamated C++17 builds of every touched TU, plus a
TSan and ASan/UBSan/LeakSan harness driving concurrent LogMessage
readers against recorder add/remove churn and concurrent first-use
slock creation.
* openxr: route Vulkan instance/device creation by context, not build
On a HAVE_OPENXR build every VkInstance and VkDevice went through
xrCreateVulkanInstanceKHR/xrCreateVulkanDeviceKHR unconditionally, so
the flat vk_android fallback the driver takes when a session is
unavailable could never create a working context, and the queue-family
probe still queried surface support with a null surface after computing
the headless answer. Creation now routes through OpenXR only when the
live context is android_vk_openxr - everything else keeps
vkCreateInstance/vkCreateDevice - and vulkan_common reaches the XR
instance and system id through accessors on the context driver instead
of another TU's static, which only linked because of griffin include
order. The headless surface check is a single call that never passes
VK_NULL_HANDLE.
In vulkan.c the swap-interval emulation and BFI frame-duping recursion
are skipped under an XR session: the compositor owns pacing, and
re-entering vulkan_frame would issue a second xrBeginFrame before
xrEndFrame (the context's begin_frame also guards against re-entry
now). The HW fence wait keeps one shared condition with XR added inside
a single #ifdef so the non-XR build preprocesses exactly as before, the
dangling HAVE_OPENXR_2D probe is gone, and the eye loop and
vulkan_frame_eye declarations are C89.
* openxr: fix quest input regressions, make shared state cross-thread safe
android_joypad_state's axis-to-button path required port 0 under
HAVE_OPENXR, so physical pads on ports 1+ lost all analog input on the
quest build; it now goes through android_joypad_axis, which merges the
XR sticks for port 0 and falls through to the plain Android state for
every other port. Window motion events are only suppressed while an
OpenXR session is actually live instead of being compiled out (the
unreachable duplicate source check is gone), the never-defined HAVE_XR
gates are removed so the file matches the behaviour the quest build has
actually been tested with, and the INIT_WINDOW reinit check is braced
with its declaration at block top for the C89 lanes.
The shared OpenXR input state (buttons, axes, attach flag, menu long
press) is written by openxr_input_sync on the frame loop's thread -
the video thread under threaded video - and read by the input drivers
on the main thread, so it moves onto retro_atomic with a swap-consumed
long-press flag. The shared readers also lose their android_vk_ prefix
(they serve the GL path too) and live in openxr_input.h; the long-press
hotkey check in input_driver.c gains the ANDROID guard its definition
has always had.
* openxr: report VR availability honestly, decouple GL path from Vulkan
gl2's set_vr_content_info returned true unconditionally, so a core
asking for VR on the flat fallback context was told a session existed
and got a 0x0 recommended eye size; it now reports unavailable unless
the OpenXR context owns a live session, video_driver refuses and
unwinds a request when no eye target size is available, and the Vulkan
driver treats a NULL info as the documented disable instead of a probe,
clearing its stereo state. The unused RUNLOOP_FLAG_CORE_VR_CONTENT is
dropped: it sat on the deliberately retired bit 31 (1 << 31 in a signed
enum besides), and the bool the code actually uses stays, with its
comment naming the real environment calls.
griffin no longer nests the GL OpenXR context, the shared OpenXR input
TU and the loader dispatch table under HAVE_VULKAN, so a GLES-only
HAVE_OPENXR build links instead of failing on prototypes. The GL
context's end_frame declarations move to block top for the C89 lanes,
the stray C++ comment is gone, and the magenta debug clear on the eye
buffer is black.
* android: keep quest manifest entries out of the shared manifest
The Oculus app id meta-data and the installLocation flip to auto landed
in the manifest every Android build ships. The app id moves to the
quest flavor's overlay manifest where it belongs, and installLocation
returns to internalOnly, which is set deliberately: external-storage
installs have broken content paths and services before. If the quest
build needs auto, it can set it in its own overlay.
* deps/openxr: trim the vendored SDK to what the tree builds
The full SDK checkout came with its own CI configs, CMake build system,
gradle/prefab/vcxproj packaging, jsoncpp's test suites, examples,
docs and devtools, jnipp's project files, and the unused non-core
dispatch table. All of it goes: what stays is the OpenXR headers, the
loader and common sources the tree compiles, the lib_json sources and
headers, jnipp and the android-jni-wrappers, the generated core
dispatch table, and every license file (LICENSE, COPYING.adoc, the
LICENSES directory and REUSE sidecars of kept files, jsoncpp's and
jnipp's licenses). README.md stays as provenance for the vendored
version.
* ci/android: carry the quest flavor's debug apk as an artifact
assembleDebug already builds every flavor, so the quest build compiles
on each CI run now that the loader builds through ndk-build with no
host cmake step; uploading its apk makes a quest regression visible in
the artifact list and gives testers a build to sideload. openxr_input
also includes verbosity.h itself instead of leaning on griffin include
order for RARCH_ERR.
* openxr: parse manifests with libretro-common rjson, drop jsoncpp
The loader's JSON use is three manifest/broker walks over a small value
tree, so a ~250-line Json::Value subset backed by rjson (loader_json)
replaces the vendored jsoncpp - a megabyte of C++ the binary already
duplicated, since rjson is compiled into every RetroArch build. The
shim keeps jsoncpp's names and the exact semantics the loader relies
on: missing members read as a shared null, mutable indexing creates
members, extension_version accepts both its string and integer
spellings, and the parser takes comments, trailing data and a UTF-8
BOM like the CharReaderBuilder defaults did, so nothing previously
loadable becomes unloadable.
Verified against the old implementation as an oracle: a harness driving
RuntimeManifestFile and ApiLayerManifestFile over valid, relative-path,
malformed, wrong-version, field-missing, trailing-data and commented
manifests produces byte-identical results on both, runs clean under
ASan/UBSan/LeakSan, and the quest, GLES-only and OpenXR-off NDK builds
all still link.
* android: declare the OpenXR runtime brokers and their permissions
The vendored loader discovers the active runtime by querying the
ContentProviders at org.khronos.openxr.runtime_broker and
org.khronos.openxr.system_runtime_broker (android_utilities.cpp). The
quest flavor targets API 34, where package-visibility filtering hides
any provider authority the app does not declare, and the manifest
carried no queries element at all, so broker resolution was working
only at the OS vendor's grace. Declare the two authorities the loader
actually queries, together with the Khronos broker permissions - both
normal protection level, granted silently at install with no user
prompt - so the generic installable broker also serves the app, not
just Meta's unenforcing one.
Everything lives in the quest overlay, where the loader ships: the
headtracking uses-feature in particular must never migrate to the
shared manifest, since required=true there would delist the app for
every non-VR device on the Play store; a comment now says so.
* jni: cleanroom rjni layer in libretro-common, used tree-wide
All JNI plumbing moves behind one cleanroom libretro-common layer:
rjni registers the process JavaVM once (CAS, first wins), caches each
thread's JNIEnv in destructor-capable TLS - GetEnv tells threads the
VM already owns, which are left alone, from threads rjni attaches,
which are detached again when they exit - and provides lock-free
once-caches for class global references, method IDs and field IDs,
the VM crossings that make JNI call sites expensive. The exception
guard switches to ExceptionCheck, which creates no local reference.
The call wrapper macros move here verbatim from platform_unix.h, so
every JNI user in the tree shares one header.
platform_unix keeps jni_thread_getenv as the entry-point name but it
is rjni_env now, with the local key machinery deleted, and the
KeyCharacterMap path resolves through process-lifetime rjni caches,
so a driver restart re-resolves nothing. Verified with a fake-VM
harness under TSan and ASan/UBSan/LeakSan (8 threads, attach/detach
balance asserted), a real OpenJDK 21 VM exercising the caches from
four native threads, the C89 lane, NDK arm64 at -Werror, and MinGW.
* openxr: drop jnipp and android-jni-wrappers, query the broker through rjni
The loader's two remaining vendored C++ dependencies existed only to
make JNI calls, which the tree now does through libretro-common's
rjni, so android_utilities is rewritten on raw JNI with an rjni
once-cache for every broker class, method and field - same URIs, same
log lines, same installable-then-system fallback - and
loader_init_data reads the asset manager and nativeLibraryDir the same
way (a dead getApplicationContext call did not survive the rewrite).
With jnipp gone this also deletes the only exception-throwing code in
the loader, so the Android path is safe under -fno-exceptions
unconditionally, and the last C++11 threading construct, jnipp's
thread_local, leaves the tree with it.
jnipp and android-jni-wrappers are removed from deps, griffin and the
Android include paths. Both rewritten files pass standalone NDK arm64
syntax checks, the quest ndk-build links, the GLES-only and plain
shapes still build, and the Windows-shape loader amalgam still
compiles under MinGW.
* openxr: filesystem code on libretro-common file_path/retro_dirent
filesystem_utils keeps its interface but its three implementation
branches - C++17 <filesystem>, experimental, and the per-platform
fallbacks - are replaced by one body over libretro-common's
file_path, path_stat and retro_dirent, matching the std::filesystem
semantics this build shipped (parent/trailing-slash decomposition,
absolute-child replacement in CombinePaths, the Windows canonical
no-op). stdfs_conditions.h goes with the branches. Three behavioural
deltas, each for the better: FindFilesInPath and GetCanonicalPath
return false on a missing path where directory_iterator and
std::filesystem::canonical threw (the loader builds -fno-exceptions
elsewhere), and ParsePathList no longer corrupts the middle entries
of XR_API_LAYER_PATH lists with three or more paths, an upstream
substr count bug present in every branch.
Verified by a function-level oracle, old implementation against new
over a fixture tree (files, subdirs, symlinks, dangling links, path
lists): byte-identical except the two corrupted-list lines, now
correct; ASan/UBSan/LeakSan clean; and the manifest-file oracle from
the rjson conversion rerun on the new filesystem, byte-identical
including relative library_path resolution. Quest ndk-build links
and the Windows-shape loader amalgam compiles under MinGW.
* openxr: remove the loader's exception handling
Nothing in the loader throws any more - jsoncpp, jnipp and the
std::filesystem calls went in earlier changes - so the exception
machinery guarding the C ABI goes too: exception_handling.hpp and the
71 XRLOADER_ABI_TRY/CATCH wrappers around the entry points in
loader_core and xr_generated_loader, the empty catch blocks in the
ApiLayerInterface and RuntimeInterface destructors, and the dead
jsoncpp exception-mode guard in manifest_file. The whole loader now
compiles under -fno-exceptions, which the compiler itself enforces as
proof that no try, catch or throw remains; griffin keeps building it
with exceptions enabled only because glslang shares the TU. The one
reachable delta is allocation failure inside an entry point, which
terminates instead of unwinding to XR_ERROR_OUT_OF_MEMORY - the
loader is statically linked into the frontend, where that is already
the outcome everywhere else in the process.
Verified with -fno-exceptions compiles of the full loader in Linux,
MinGW and NDK arm64 shapes, the manifest-file oracle byte-identical
under ASan/UBSan/LeakSan, and quest plus plain ndk-builds linking on
the PR's rebased head.
* openxr: filesystem_utils on direct libretro-common calls where one fits
Every function here is now a direct libretro-common call where one
with std::filesystem's semantics exists: PathExists is
path_is_valid, CombinePaths joins through
fill_pathname_join_special, and the hand-rolled separator macros
give way to PATH_CHAR_IS_SLASH and PATH_DEFAULT_SLASH_C; only the
env path-list separator keeps a local define, since libretro-common
has no such constant. What stays hand-written is documented in
place as a deliberate semantic difference from libretro-common's
contracts: GetParentPath (fill_pathname_basedir fabricates "./"
for a bare filename and keeps trailing slashes), GetAbsolutePath
(path_resolve_realpath without symlink resolution would normalise
dots, which std::filesystem::absolute does not), ParsePathList
(string_split's strtok collapses empty entries), and
FindFilesInPath wants bare names where dir_list_new returns full
paths, so the retro_dirent primitives are the fit.
FileSysUtilsGetCurrentPath had no caller anywhere in the loader and
leaves the interface, surviving only as the static getcwd helper
behind GetAbsolutePath. The last two <stdexcept> references go too:
manifest_file's include was dead since the exception removal, and
vulkan_debug_object_namer.hpp was referenced by nothing in the
tree. Both oracles rerun byte-identical - the function-level one
over the fixture tree and the manifest-file one under
ASan/UBSan/LeakSan - and the loader still compiles -fno-exceptions
in Linux, MinGW and NDK shapes, with quest and plain ndk-builds
linking.
* openxr: guard the context drivers' XR platform defines
The Android build also passes XR_USE_PLATFORM_ANDROID on the command
line, so the bare defines the two OpenXR context drivers carry for
standalone compilation redefine it - and the graphics-API macros
alongside it are one -D away from the same collision. Wrap all of
them in #ifndef so either source of the define wins quietly,
whichever compiles the file first in the griffin TU.
---------
Co-authored-by: libretroadmin <[email protected]>
Sixteen #if/#endif pairs across twelve files enclose nothing, so they
select no code in any configuration. Removing them leaves preprocessor
output identical.
Final slice of the arc. gfx/drivers_shader/shader_gl3.cpp becomes
shader_gl3.c: the gl3_shader namespace and all 56 qualifications go away,
C++ headers are dropped, casts and nullptr become C, the header's struct
tags get file-local typedefs, the nested Parameter type moves to file
scope, and the reference parameters become pointers or by-value PODs. The
RAII glslang_include_cache_guard -- the struct slang_process.h keeps under
__cplusplus for this file alone -- becomes an explicit handle freed on
every exit.
Three defects the gates caught, none of them visible on review:
C++ resolved gl3_pass_reflect_parameter by overload. C cannot, so the
texture variant was renamed, and three call sites that had been taking it
silently bound to the semantic-meta function instead. -Wunused-function on
the now-uncalled variant is what exposed that.
The include cache carried a comment claiming its scope close freed it.
Nothing did, and LSan measured 120 bytes leaked per preset. That is the
third variant in this arc of a C++ lifetime whose replacement was
incomplete.
The C89 gate found 14 mixed declarations; the two for-init declarations
needed a separate sweep, since -Wdeclaration-after-statement does not
flag them and only MSVC's C lane would have.
The include moves from griffin_cpp.cpp to griffin.c beside spirv_opengl.c,
which already carries the identical guard, copied verbatim rather than
re-derived. Preprocessing griffin.c resolves it zero times under the ARM64
profile and 873 under the x64 one. Removing it from griffin_cpp.cpp leaves
only optional Qt sources ahead of the vendored SPIRV-Cross block, which is
safe because NOMINMAX is defined at the top of that file rather than
supplied by whichever source happens to come first.
Codegen: the C build is 108 instructions heavier (+1.5%). Pointerizing the
per-frame semantic-texture layer removed the per-frame part of that, and
the demangled per-function diff puts the remainder in create_from_preset,
compile_pass and create_deferred -- the hoisted declarations and the
explicit frees C requires, all of it one-time setup. The per-frame path is
at parity or better: build_offscreen_passes is 17 instructions lighter.
Across the arc the translation unit went from 17407 instructions to 7097.
Verified: nine chain lifecycles clean under ASan, UBSan and LSan with leak
detection on, 543 rendered-output hashes plus 12 chain-creation failures
identical across the 555-preset corpus, both the production build and the
C89 gate at zero, griffin_cpp.cpp compiles as one amalgamated unit, and
slang_process.c, spirv_opengl.c and shader_gl3.c cohabit a single C
translation unit without collisions.
The vendored SPIRV-Cross sources in this amalgamation were protected from
the windows.h min()/max() macros only by accident: shader_vulkan.cpp was
the first RetroArch source in the TU and its first header,
gfx/include/vulkan/vk_sdk_platform.h, defines NOMINMAX. Moving that file to
griffin.c for the C89 conversion removed the definition, so shader_gl3.cpp
now reaches windows.h through retro_miscellaneous.h with the macros live
and spirv_common.hpp fails on std::numeric_limits<int32_t>::min(), which is
not parenthesized the way spirv_cross_containers.hpp is. That is the
C2589/C2059 cascade on the MSVC x64 lanes; the ARM64 lane escaped it only
because it sets neither HAVE_VULKAN nor HAVE_OPENGL_CORE and so had no
RetroArch source ahead of the vendored ones at all.
NOMINMAX is now defined beside WIN32_LEAN_AND_MEAN at the top of the file,
where it does not depend on which sources happen to be enabled, with the
history recorded in a comment. A tripwire before the vendored SPIRV-Cross
includes fails the build with a direct message if the macros are ever
defined at that point again, rather than letting the diagnostics land
inside SPIRV-Cross.
The C89 rename moved the shader_vulkan include from griffin_cpp.cpp to
griffin.c but placed it inside the existing HAVE_SLANG block, dropping the
HAVE_VULKAN half of the guard it had carried. HAVE_SLANG without
HAVE_VULKAN is a real configuration -- the MSVC lanes ship D3D plus slang
and no Vulkan -- so griffin.c compiled shader_vulkan.c into a build where
neither gfx/common/vulkan_common.c nor the Vulkan symbol wrapper is
present, producing 60 unresolved externals at link on ARM64 Release and
every other non-Vulkan MSVC lane. The file compiles fine there, so nothing
short of a link catches it.
The include moves to its own '#if defined(HAVE_VULKAN) && defined(HAVE_SLANG)'
block, matching the guard verbatim from griffin_cpp.cpp, with the reason
recorded in a comment. The now-empty guard left behind in griffin_cpp.cpp
is removed.
Verified by preprocessing griffin.c under the MSVC define set: the include
resolves zero times without HAVE_VULKAN and still resolves with it, against
a negative control on the broken commit that pulls it in either way.
Rename gfx/drivers_shader/shader_vulkan.cpp to shader_vulkan.c and convert
the remaining C++ syntax: 14 autos become indexed loops and typed pointers,
casts become C casts, the extern "C" wrapper goes away, file-local typedefs
cover the header struct tags, and 35 reference parameters become pointers
or by-value PODs. All mixed declarations are hoisted for C89 and the three
for-init declarations are gone, so the file now clears
-Werror=declaration-after-statement clean for the MSVC lanes.
The incompatible-pointer-types gate caught two real conversion bugs before
they could ship: both set_semantic_texture wrappers compared the write_count
POINTER against VULKAN_MAX_DESCRIPTOR_WRITES and forwarded unsigned** into
the flush, and seven build_semantics call sites passed the batch counter by
value. Both would have corrupted descriptor batching at runtime.
Texture, VkViewport and the semantic-texture layer stay pointer-passed on
the per-frame path: by-value conversion initially cost +124 instructions
(+1.6%) in build_semantics/build_commands from struct copies at every call;
with the layer pointerized the final delta versus the C++ object is +4
instructions (0.1%), i.e. codegen parity.
The griffin include moves from griffin_cpp.cpp to griffin.c beside
slang_process.c (single-TU cohabitation of both files compiles clean), and
the Xcode project entry switches to sourcecode.c.c. griffin.c itself does
not compile at origin/master in this environment (pre-existing rc_export.h
include gap and test_input.c collisions), so the cohabitation TU stands in
for that lane.
Verified: 7/7 harness lifecycles under ASan+UBSan+LSan (leaks enabled),
byte-exact parameter/pass dumps across 1643 presets, production build with
zero warnings.
The C API integration defined SPIRV_CROSS_C_API_HLSL=1
unconditionally in griffin_cpp.cpp, but the amalgamation includes
spirv_hlsl.cpp only under HAVE_HLSL. On every griffin lane without
that flag - Android NDK and the Apple Metal project - the wrapper's
HLSL sections referenced CompilerHLSL methods and its vtable with the
backend never compiled: undefined-symbol link failures. Windows
lanes define HAVE_HLSL, which is why Windows-shaped verification
missed it.
Make the macro mirror the include guard, and document the invariant:
each SPIRV_CROSS_C_API_* macro must be truthy exactly when the
matching backend source is amalgamated (glsl and msl are
unconditional here, so their macros stay 1; the Makefile.common
object list is unconditional for all backends, so its =1 defines are
consistent).
Verified with a symbol-closure check over the amalgamated object
under both feature profiles: compiled without HAVE_HLSL (the
Android/Metal shape) and with it (the Windows shape),
nm reports zero undefined spirv_cross:: symbols in either object -
and the same check on the pre-fix object shows the six undefined
CompilerHLSL symbols, so the closure check now runs on every
drivers_shader delivery as a standing gate.
After the SPIRV-Cross C API port nothing C++ remained but syntax:
reference locals in the offset setters and reflection paths become
pointers, bare enum type names gain the enum keyword, declarations
move ahead of statements for C89 (in the offset setters the pointer
targets are still resolved only after the resize_min call, which may
reallocate the array they point into), and the two bare video_shader
uses gain the struct keyword. The file moves from the griffin_cpp
amalgamation into griffin.c; Makefile object lists are name-based and
need no change, the GL-only Apple project does not build the slang
stack, and the Metal project reaches the file through griffin.c with
SPIRV-Cross already on its header search paths.
The translation unit now compiles as C (and still as C++ for
CXX_BUILD, verified both ways with -Werror=declaration-after-statement
on the C side). Static-name audit over all 752 files amalgamated by
griffin.c found no collisions. Byte-exact against the C++ build over
all 1643 libretro/slang-shaders files; ASan+UBSan+LSan and TSan clean
over the corpus and byte-exact under instrumentation; the
uninitialized-reflection lifecycle repro still faults on the buggy
pattern and passes on the shipped one; the C-struct-member initializer
audit over both chain files is clean. Codegen vs the C++ compile of
the same code: -1.1% instructions (4538 -> 4490), .text 24699 ->
24443 bytes, end-to-end compile+reflect over 400 presets 11.41s vs
11.50s.
Rewrite the SPIRV-Cross usage in slang_process.cpp - cross
compilation, reflection, buffer-range walking and type validation -
from the C++ API onto the vendored spirv_cross_c wrapper. One
spvc_context per slang_process()/slang_reflect_spirv() call owns
every IR, compiler, options object, resource list and compiled
source string, so teardown is a single spvc_context_destroy() on
every path and the try/catch + new/delete + std::string usage is
gone: SPIRV-Cross exceptions are absorbed into error codes inside
the wrapper. The MSL binding remaps keep the same explicit 1:1
mapping the CompilerMSL lambdas set up. Requesting the HLSL
backend without HAVE_HLSL now fails cleanly instead of running the
rest of the function against NULL compilers.
slang_process.h no longer includes spirv_cross.hpp or declares
slang_reflect (now static); shader_vulkan.cpp and shader_gl3.cpp
gain the <string> include they had been getting transitively.
deps/SPIRV-Cross/spirv_cross_c.cpp joins the build with the
GLSL/HLSL/MSL backend sections enabled, in Makefile.common for the
standalone build and beside the other vendored SPIRV-Cross sources
in griffin_cpp.cpp for the griffin lanes.
Verified byte-exact against both the pre-conversion implementation
and the current C++-API implementation over all 1643 .slang files in
libretro/slang-shaders, including full reflection with populated
semantic maps. ASan+UBSan+LSan clean over the corpus and byte-exact
under instrumentation (the vptr checker is disabled for the vendored
spirv_cross_c.cpp only: its opaque handles are 'struct spvc_type_s :
SPIRType' downcasts by upstream design); TSan clean with 4 threads.
griffin_cpp.cpp and griffin_glslang.cpp each compile as one
amalgamated TU, and the glslang bridge closure still reaches none of
the windows.h-bearing headers.
Codegen (x86-64 gcc 13 -O3): the slang_process TU drops 55.3% of
its instructions (10159 -> 4538; .text 53.3KB -> 24.7KB) as the
SPIRV-Cross template instantiations disappear; the program gains the
shared spirv_cross_c wrapper TU (89KB .text) which the planned
d3d/gl3/metal conversions will reuse. End-to-end compile+reflect
over 400 presets measures faster than the original implementation
(11.50s vs 12.10s), parse path unchanged (~3.6s vs baseline ~3.9s).
The previous commit left slang_cache.cpp written in plain C (fixed
buffers, malloc, C89 declaration placement, guarded extern "C"), so
the rename is mechanical. griffin moves the include from
griffin_cpp.cpp to griffin.c, which is what makes the MSVC lanes
compile it in C mode; Makefile.common's OBJ entry is name-based and
unchanged. Compiles both as C (-Werror=declaration-after-statement)
and as C++ for CXX_BUILD.
* add aggressive caching to slang shader backend
* fix griffin builds
* switch to libretro-common hash method to avoid mbedtls dep for MSVC/UWP buildfix
* switch to libretro-common functions when possible
---------
Co-authored-by: hunterk <[email protected]>
Rewrite the upstream C++14 Discord-RPC library (deps/discord-rpc, ~2000
lines across 14 files) as plain C89 and merge it into network/discord.c
following retroarch and libretro-common conventions. The result is a
single self-contained translation unit.
What changed in the implementation
----------------------------------
* No background IO thread. The runloop already calls Discord_RunCallbacks
and Discord_UpdateConnection every frame, so the upstream IoThreadHolder
(with its std::thread, std::condition_variable, and std::mutex) was
doing nothing useful in single-threaded mode and causing wakeup overhead
in multi-threaded mode. Removing it eliminates all five mutex locks and
five atomic_bool exchanges per RunCallbacks invocation.
* No auto-register. Discord_Register/Discord_RegisterSteamGame are kept
as exported no-op stubs for ABI compatibility, but the per-OS desktop
file / registry / Info.plist logic is dropped along with its psapi /
advapi32 / xdg-mime dependencies. RetroArch never used the discord://
URL handler functionality these provided.
* C++ -> C89 translations:
- std::atomic_bool / std::atomic_uint -> plain bool / unsigned (single
threaded model)
- std::mutex / std::lock_guard -> removed entirely
- std::thread / std::condition_variable -> removed entirely
- std::chrono -> cpu_features_get_time_usec()
- std::mt19937_64 + uniform_real_dist -> rand() with bounded jitter
- MsgQueue<T,N> template -> typed ring-buffer arrays
- JsonWriter / JsonDocument / JsonReader RAII classes -> functions over
rjsonwriter_t* / rjson_t*
- BaseConnection inheritance (Unix/Win) -> #ifdef-gated discord_pipe_*
functions
- C++ lambdas for onConnect/onDisconnect -> static functions
* The wire protocol is preserved byte-for-byte. Frame header layout
(8 bytes, two little-endian uint32), opcode values, JSON field ordering
(presence flushed before send-queue, nonce-as-string, party.size as
array, instance as bool), and the upstream behavior of clearing handlers
on disconnect (so the disconnected callback only fires on subsequent
disconnects, not the first - this matches upstream and is invisible
because RetroArch's handler is a no-op stub) are all preserved.
What changed elsewhere
----------------------
* runloop.c, retroarch.c: drop the #ifdef DISCORD_DISABLE_IO_THREAD
guards around Discord_UpdateConnection. With no IO thread to disable,
the call is unconditional.
* griffin/griffin.c, griffin_cpp.cpp, griffin_objc.m: drop the seven
deps/discord-rpc/src/* unity-build #include directives. griffin.c
keeps the network/discord.c include unchanged.
* Makefile.common: collapse the 30-line discord block to four lines.
Drops NEED_CXX_LINKER, INCLUDE_DIRS += -Ideps/discord-rpc/include,
DISCORD_DISABLE_IO_THREAD toggle, all seven deps OBJ entries, and
the Win32-only -lpsapi -ladvapi32 link libraries (only needed by
the discarded discord_register_win.c).
* deps/discord-rpc/: removed entirely (15 files).
Verification
------------
The rewrite was exercised against a regression suite (188 assertions
across three test programs) that covers: every JSON serializer with
parsed-back equivalence checks against the upstream wire format, INT64
edge cases, frame header layout, ring-buffer fill/overflow/wraparound,
backoff bounds, and a full end-to-end Unix-socket dialogue against a
mock Discord server through handshake -> READY -> SET_ACTIVITY ->
SUBSCRIBE x3 -> PING -> PONG -> CLOSE. All 188 assertions pass.
Performance (gcc 13, -O2, x86_64; median of 5 runs)
---------------------------------------------------
Per-frame steady-state cost (RunCallbacks + UpdateConnection together):
upstream (IO thread) 52 ns/frame
upstream (no IO thread) 79 ns/frame
rewrite 47 ns/frame (-40% vs no-thread upstream)
Per-call costs:
Discord_UpdatePresence: ~unchanged (831 ns vs 806 ns; both bound by
JSON serialization which uses the same
rjsonwriter_* underneath)
Discord_RunCallbacks: 5 ns vs 37 ns (-86%; mutex+atomic removal)
Discord_UpdateConnection: 43 ns vs 41 ns (within noise)
Build metrics:
.text size: 16.3 KB vs 21.4 KB (-24%)
.data size: 12 B vs 52 B (-77%)
Compile time: 0.63 s vs 2.85 s (-78%; one .c file vs five .cpp)
Files changed
-------------
modified: Makefile.common (-24 lines)
modified: network/discord.h (+87, -2 lines; absorbs the
public Discord-RPC types and
function declarations that
formerly came from
deps/discord-rpc/include/discord_rpc.h)
modified: network/discord.c (+1604 lines net; folds in
the entire RPC layer)
modified: runloop.c (-2 lines)
modified: retroarch.c (-2 lines)
modified: griffin/griffin.c (-6 lines)
modified: griffin/griffin_cpp.cpp (-17 lines)
modified: griffin/griffin_objc.m (-4 lines)
removed: deps/discord-rpc/ (15 files, ~2000 lines)
Summary of what this delivers
Before After
Files 17 (14 C++/C/m + headers) 1 (network/discord.c)
Languages C++14, C, Objective-C C89
Lines ~2,000 in deps + 454 in network 2,042 in network
Compile time 2.85s 0.63 s (−78%)
Code size (.text) 21.4 KB 16.3 KB (−24%)
Per-frame overhead 79ns 47ns (−40%)
Build deps psapi, advapi32, xdg-mime, NEED_CXX_LINKER none
Test coverage none 188 assertions, all pass
* Add dummy game ai subsystem
* First working prototype of a machine learning model that can override player input
* Update README.md
* Update README.md
* Fix loading path on Windows
* Change ai override to player 2
* Added quick menu show game ai option
* Implemented Quick Menu entry for Game AI options
* Redirect debug logs to retroarch log system + properly support player override
* Added support to use framebuffer as input to the AI
* Added pixel format parameter to API
* Fix game name
* code clean-up of game_ai.cpp
* Update README.md - Windows Build
* Update README.md
* Update README.md
* Update README.md
* Update config.params.sh
turn off GAME_AI feature by default
* Fix compile error in menu_displaylist.c
* Add missing #define in menu_cbs_title.c
* Added new game_ai entry in griffin_cpp
* Remove GAME_AI entry in msg_hash_us.c
* Fix compile error in menu_displaylist.h
* Removed GAME AI references from README.md
* Fixes coding style + add GameAI lib API header
* Convert comment to legacy + remove unused code
* Additional coding style fixes to game_ai.cpp
* Fix identation issues in game_ai.cpp
* Removed some debug code in game_ai.cpp
* Add game_ai_lib in deps
* Replace assert with retro_assert
* Update Makefile.common
* Converting game_ai from cpp to c. First step.
* Convert game_ai from CPP to C. STEP 2: add C function calls
* Convert game_ai from CPP to C. Final Step
* Added shutdown function for game ai lib
* Update game_ai_lib README
* Fix crash when loading/unloading multiple games
* Convert some glslang files to C (OSIndependent files)
* Fix some strings that were preventing Unix from being compilable
* Remove leftover for Apple in griffin_glslang.cpp - fixes compilation