Files
psxrecomp/runtime/hash_codegen.cmake
T
Matthew Stanley 1f6713bfc0 overlay cache: auto codegen-hash in the cache path (cg<N>_<hash>)
The manual PSX_OVERLAY_CODEGEN_VER must be hand-bumped on every emitter change;
when it isn't (e.g. between CPS emitter iterations), a stale-but-cgN DLL is reused
-> the v0.3.0 black screen. Now hash_codegen.cmake hashes the recompiler codegen
sources into a (gitignored) overlay_codegen_hash.h at build time; overlay_api.h
exposes PSX_OVERLAY_CODEGEN_HASH and the cache path becomes gcc/<arch-abi>/cg<N>_<hash>/.
The loader and compile_overlays.py read the same value, so any emitter change
auto-invalidates the cache (old dirs coexist, no stale load). Falls back to hash 0
when the header is absent (fresh checkout) — identical to today's single-cgN path.
Verified: build emits hash 0x347751c1; autocompile + loader both use cg4_347751c1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 18:57:52 -07:00

39 lines
1.5 KiB
CMake

# hash_codegen.cmake — generate overlay_codegen_hash.h with a content hash of the
# recompiler's codegen sources, so the overlay cache path (gcc/<arch-abi>/cg<N>_<hash>/)
# changes automatically whenever the emitter changes. This closes the gap where a
# pure-emitter change within the same manual PSX_OVERLAY_CODEGEN_VER produced a
# different DLL the cache happily reused (a stale-but-cgN load — the v0.3.0 black
# screen). Both the runtime loader (via overlay_api.h) and compile_overlays.py read
# the generated PSX_OVERLAY_CODEGEN_HASH, so the two sides never drift.
#
# Invoked as: cmake -DOUT=<header> "-DSRCS=<a>;<b>;..." -P hash_codegen.cmake
# Re-runs whenever a listed source changes (it's an add_custom_command DEPENDS).
set(_cat "")
foreach(f IN LISTS SRCS)
if(EXISTS "${f}")
file(READ "${f}" _c)
string(APPEND _cat "${_c}")
endif()
endforeach()
string(SHA256 _h "${_cat}")
string(SUBSTRING "${_h}" 0 8 _h8)
set(_content "/* AUTO-GENERATED by hash_codegen.cmake — do not edit, do not commit.
* Content hash of the recompiler codegen sources; folded into the overlay cache
* path so an emitter change never reuses a stale DLL. */
#pragma once
#define PSX_OVERLAY_CODEGEN_HASH 0x${_h8}u
")
# Only rewrite when the value actually changes, so dependents don't rebuild on
# every invocation.
if(EXISTS "${OUT}")
file(READ "${OUT}" _old)
if(_old STREQUAL _content)
return()
endif()
endif()
file(WRITE "${OUT}" "${_content}")
message(STATUS "overlay codegen hash: 0x${_h8}")