Skip to content

Claude/refactor reloadmod fix i l1 kd#77

Merged
jmquigs merged 2 commits into
masterfrom
claude/refactor-reloadmod-fix-iL1Kd
May 12, 2026
Merged

Claude/refactor reloadmod fix i l1 kd#77
jmquigs merged 2 commits into
masterfrom
claude/refactor-reloadmod-fix-iL1Kd

Conversation

@jmquigs

@jmquigs jmquigs commented May 12, 2026

Copy link
Copy Markdown
Owner

No description provided.

claude and others added 2 commits May 12, 2026 21:08
Some games (e.g. "2015g1") first draw a modded mesh with a vertex layout
that lacks NORMAL (likely a depth/shadow pass). The mod VB gets filled
from that layout, leaving zeros where the normal should be. A later draw
with a layout that does include NORMAL then reuses the bad VB and the
mod renders with garbage normals.

Detect that mismatch and refill:
- Store a u128 bitmask of (semantic, semantic_index) pairs declared by
  the fill layout on ModD3DData11, populated in load_d3d_data11.
- On each modded draw, recompute the current layout's mask and bail out
  to the reload path if it has any bits the fill mask doesn't.
- Hot-path check is two map lookups + a bitwise op; no locks, no global.

The closure passed to check_and_render_mod gets only an immutable mod
ref, so the refill request bubbles up via an override variable and the
existing NotRenderedButLoadRequested handler does the work, via a new
mod_load::reset_for_reload helper that releases the d3d data and
transitions back to Unloaded.

https://claude.ai/code/session_018KSB4LpgEY7ZyheoHr1A4Y
@jmquigs jmquigs merged commit 5d3cb2e into master May 12, 2026
1 check passed
@jmquigs jmquigs deleted the claude/refactor-reloadmod-fix-iL1Kd branch May 13, 2026 23:46
jmquigs pushed a commit that referenced this pull request May 15, 2026
JMQ Note:

This merge includes the device state RWLock.  Previously it was
just a static mut and there was the potential for undefined behavior
since multiple parts of the code were potentially creating &mut's to
it at the same time.  Inside an RWLock, this can't happen.

Performance testing was not completely definitive but I couldn't
pinpoint any real slowdown from this.  For future work,
possibly consider parking lot
RwLock as an optimization - but I did try it briefly and did not see any
real speedup.

This required a conflict resolution between the refill code which claude
describes hereafter:

The conflict was between this branch's RwLock-based dev_state access
pattern and master's new "needs refill for layout" mod reload logic
(#77). Resolution preserves the RwLock pattern (lock acquired/dropped
in narrow scopes) while integrating the refill logic: we precompute
the current input layout's semantic mask via a brief read lock before
calling check_and_render_mod, then pass scalars into the closure so it
no longer needs the dev_state lock.

needs_refill_for_layout was refactored to accept an Option<SemanticMask>
instead of taking a reference to the layouts hashmap, so callers can
look up the mask once under their read guard rather than holding the
lock across the closure.

The post_mod_check NotRenderedButLoadRequested arm now also calls
mod_load::reset_for_reload from master, while keeping the rwlock
pattern of reading current_input_layout via a brief dev_state guard
before taking the LOADED_MODS lock.
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.

2 participants