Claude/refactor reloadmod fix i l1 kd#77
Merged
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.