Skip to content

refactor: performance overlay#1123

Merged
alandtse merged 10 commits into
community-shaders:devfrom
soda3000:perf-overlay-pr
Jun 11, 2025
Merged

refactor: performance overlay#1123
alandtse merged 10 commits into
community-shaders:devfrom
soda3000:perf-overlay-pr

Conversation

@soda3000
Copy link
Copy Markdown
Contributor

@soda3000 soda3000 commented Jun 7, 2025

closes #1110

  • Added class PerfOverlayState in Menu private to encapsulate many variables and functions related to the Overlay.
    
  • Split DrawPerfOverlay function into many functions as members of the class.
    
  • Moved a couple small functions to Utils/UI from DrawPerfOverlay.
    
  • Some optimization done on tracking the min and max values of the graph.
    
  • Redid the smoothing and calculation of the graph boundaries as well.
    
  • Added user setting PerfOverlaySettings::FrameHistorySize to allow users to control how much history the graph shows.
    
  • Added constants PerfOverlaySettings::kMinFrameHistorySize, kMaxFrameHistorySize to ensure the FrameHistorySize is kept within reasonable limits.
    
  • Added documentation to the new functions.
    

Should now be able to create separate files for the performance overlay and move over the encapsulated things without too much trouble.
Lord have mercy on my soul and doom this platform straight to hell

Summary by CodeRabbit

  • New Features
    • Added a user-adjustable setting for frame history size in the performance overlay, allowing customization of the number of frames displayed in performance graphs.
    • Introduced help icons with tooltips next to various sliders and buttons in the settings UI for improved clarity and guidance.
  • Improvements
    • Enhanced performance overlay graphs with smoother scaling and more stable min/max frame time calculations.
    • Improved input handling for hotkeys in the performance overlay.
    • Refined performance overlay rendering and data management with modular updates for FPS, frametime, and VRAM display.
  • Other
    • No changes affecting existing user workflows; all additions are optional and enhance usability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2025

Walkthrough

The changes refactor the performance overlay in the menu system by encapsulating frame timing and rendering logic within a new PerfOverlayState class, introduce a configurable frame history size, and modularize overlay rendering and data management. Additional UI help icons and improved input handling are also introduced, along with a new utility for frame time and FPS calculations.

Changes

File(s) Change Summary
src/Menu.cpp, src/Menu.h Refactored performance overlay logic into PerfOverlayState class; added FrameHistorySize setting; modularized rendering methods.
src/Utils/UI.cpp, src/Utils/UI.h Added PerformanceOverlay utility class with frame time and FPS calculation methods; declared and defined global instance.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Menu
    participant PerfOverlayState
    participant PerformanceOverlay

    User->>Menu: Opens performance overlay
    Menu->>PerfOverlayState: UpdateGraphValues(settings)
    PerfOverlayState->>PerformanceOverlay: CalcFrameTime(timeElapsed, frequency)
    PerfOverlayState->>PerformanceOverlay: CalcFPS(frameTimeMs)
    PerfOverlayState->>PerfOverlayState: Update frame time histories and smoothing
    Menu->>PerfOverlayState: DrawFPS(settings)
    Menu->>PerfOverlayState: DrawPostFGFrameTimeGraph(settings)
    Menu->>PerfOverlayState: DrawDrawCalls()
    Menu->>PerfOverlayState: DrawVRAM(dxgiAdapter3)
Loading

Assessment against linked issues

Objective Addressed Explanation
Decompose DrawPerfOverlay into smaller, focused methods (#1110)
Move static variables to class members for thread safety (#1110)
Replace floating point equality with <= comparison (#1110)
Replace magic number FRAME_HISTORY_SIZE with static constexpr and documentation (#1110)
Cache expensive calculations and only update when necessary (#1110)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of help icons and tooltips to UI elements in overlay settings (src/Menu.cpp, various lines) The addition of help icons and tooltips for UI clarity is unrelated to refactoring objectives in #1110.
Refactoring input event processing for hotkeys to use function objects and arrays (src/Menu.cpp, various lines) This input handling refactor is not part of the performance overlay method decomposition or related objectives.
Addition of PerformanceOverlay utility class and global instance (src/Utils/UI.cpp, src/Utils/UI.h) The utility class for frame time/FPS calculation is not specified in the objectives for #1110.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11a04c1 and 450a645.

📒 Files selected for processing (2)
  • src/Menu.cpp (8 hunks)
  • src/Menu.h (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Menu.h
  • src/Menu.cpp
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build plugin and addons
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@soda3000 soda3000 marked this pull request as ready for review June 7, 2025 21:20
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/Menu.h (1)

195-231: Consider improving encapsulation of PerfOverlayState

While the current design works, having all members public reduces encapsulation. Consider making data members private and providing accessor methods where needed. This would better align with OOP principles and make the class more maintainable.

For example, you could:

  1. Make data members private
  2. Provide getter/setter methods for members that need external access
  3. Keep the update/draw methods public

This would provide better control over how the state is modified and make it easier to add validation or trigger updates when values change.

src/Menu.cpp (1)

1655-1661: Prevent potential text jumping in VRAM display.

The conditional centering based on text width could cause the text to jump between centered and left-aligned positions as values change. Consider always using one alignment approach for visual stability.

-    // Center the text if it fits within the window
-    if (textWidth < windowWidth) {
-        ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
-        ImGui::Text("%s", vramText.c_str());
-    } else {
-        ImGui::Text("%s", vramText.c_str());
-    }
+    // Always center the text for consistency
+    float xPos = std::max(0.0f, (windowWidth - textWidth) * 0.5f);
+    ImGui::SetCursorPosX(xPos);
+    ImGui::Text("%s", vramText.c_str());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ef0fae and fc5126e.

📒 Files selected for processing (4)
  • src/Menu.cpp (15 hunks)
  • src/Menu.h (2 hunks)
  • src/Utils/UI.cpp (1 hunks)
  • src/Utils/UI.h (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (6)
src/Menu.h (1)

162-164: Frame history size settings look good!

The default value and bounds are reasonable for frame history tracking. Good documentation explaining the rationale behind the values.

src/Menu.cpp (5)

48-48: LGTM!

The addition of FrameHistorySize to the serialization macro is correctly implemented.


601-607: Excellent UI consistency improvement!

The help icon implementation is consistent throughout the codebase, using the same semi-transparent white color and hover tooltip pattern. This greatly improves the user experience by providing contextual help where needed.

Also applies to: 617-622, 632-637, 802-807, 824-829, 842-847, 851-858, 861-869, 885-894, 901-908, 919-928, 963-971, 975-983, 987-995, 1804-1809, 1813-1821, 1832-1837


1235-1235: Well-structured refactor with proper encapsulation!

The migration of state variables to perfOverlayState and delegation to dedicated methods improves code organization and maintainability. The separation of concerns is clear and follows best practices.

Also applies to: 1249-1253, 1270-1270, 1272-1283, 1286-1299, 1302-1306, 1310-1311, 1314-1316, 1319-1321


1679-1684: Ensure FrameHistorySize is validated on settings load.

While the clamping here is correct, the same validation should be applied when settings are first loaded from JSON to handle potentially corrupted or manually edited configuration files.

Consider adding validation in the settings loading logic to ensure FrameHistorySize is always within bounds even before this method is called.


1811-1821: Well-implemented frame history size control!

The slider properly uses the defined constants for bounds and includes a clear help tooltip. The integration into the appearance settings is appropriate.

Comment thread src/Utils/UI.cpp Outdated
Comment thread src/Utils/UI.h Outdated
Comment thread src/Menu.h Outdated
Comment thread src/Menu.cpp
@alandtse
Copy link
Copy Markdown
Collaborator

alandtse commented Jun 7, 2025

@coderabbitai does this address #1110?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch details of issue #1110 to see what it specifically asks for
gh issue view 1110 --repo doodlum/skyrim-community-shaders

Length of output: 1884


🏁 Script executed:

#!/bin/bash
# Check if the floating point comparison issue mentioned in #1110 was addressed
# Look for "updateTimer == 0.0f" pattern in the current code
rg "updateTimer.*==.*0\.0f" src/Menu.cpp

# Also check for the corrected version
rg "updateTimer.*<=.*0\.0f" src/Menu.cpp

# Look for any updateTimer usage to understand the current implementation
rg "updateTimer" src/Menu.cpp -A 2 -B 2

Length of output: 847


@alandtse Yes, this PR substantially addresses issue #1110! Here's how it tackles each requirement:

✅ Fully Addressed:

  1. Method decomposition - The large DrawPerfOverlay method (~350 lines) has been broken down into focused methods within the new PerfOverlayState class: DrawFPS(), DrawDrawCalls(), DrawVRAM(), UpdateGraphValues(), etc.

  2. Thread safety - Static variables have been moved from function-local statics to PerfOverlayState class members, eliminating thread safety concerns.

  3. Magic numbers - The hard-coded FRAME_HISTORY_SIZE = 120 is now a configurable FrameHistorySize setting with proper constants kMinFrameHistorySize = 60 and kMaxFrameHistorySize = 480.

  4. Performance optimization - The PR includes various optimizations like improved smoothing algorithms, better min/max tracking, and cached calculations.

⚠️ Partially Addressed:

  • Floating point comparison - The main timer logic has been improved to use if (perfOverlayState.updateTimer >= settings.PerfOverlay.UpdateInterval), but there are still 2 instances of the problematic if (updateTimer == 0.0f) pattern that should ideally be <= 0.0f.

Overall: This PR delivers on the core goal of refactoring the monolithic method for better maintainability and addresses 4 out of 5 specific issues completely. The remaining floating point comparison instances are a minor outstanding item that could be addressed in a follow-up.

@alandtse
Copy link
Copy Markdown
Collaborator

alandtse commented Jun 7, 2025

@coderabbitai please suggest edits to resolve the floating point issue. Please confirm we don't have existing functions that can assist here already in the code that can be reused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@alandtse Based on my analysis, I found the 2 problematic floating point comparisons and checked for existing utilities. Here are my findings and suggested fixes:

Current Issues Found

Location 1: Line 1096

if (perfOverlayState.updateTimer == 0.0f) {
    perfOverlayState.SetTextScale(settings.PerfOverlay);
    perfOverlayState.hasGraphs = settings.PerfOverlay.DisplayFrametimeGraph;
}

Location 2: Line 1112

if (perfOverlayState.updateTimer == 0.0f && settings.PerfOverlay.DisplayFrametimeGraph) {
    perfOverlayState.UpdateGraphValues(settings.PerfOverlay);
}

Existing Utilities Check

No existing floating point comparison utilities found in the codebase that we can reuse. The codebase doesn't appear to have dedicated math utility functions for epsilon-based comparisons.

Suggested Fixes

Since these are timer reset checks (when timer becomes 0), the safest approach is to use <= 0.0f:

// Line 1096 - Fix floating point comparison
- if (perfOverlayState.updateTimer == 0.0f) {
+ if (perfOverlayState.updateTimer <= 0.0f) {
    perfOverlayState.SetTextScale(settings.PerfOverlay);
    perfOverlayState.hasGraphs = settings.PerfOverlay.DisplayFrametimeGraph;
}

// Line 1112 - Fix floating point comparison  
- if (perfOverlayState.updateTimer == 0.0f && settings.PerfOverlay.DisplayFrametimeGraph) {
+ if (perfOverlayState.updateTimer <= 0.0f && settings.PerfOverlay.DisplayFrametimeGraph) {
    perfOverlayState.UpdateGraphValues(settings.PerfOverlay);
}

Rationale

  • Using <= 0.0f is appropriate here since these are timer reset conditions
  • Handles potential floating point precision issues where the timer might be slightly negative due to timing variations
  • Maintains the original intent of executing the code when the timer resets
  • No need for epsilon-based comparison since we're dealing with timer boundaries, not equality testing

These changes will resolve the floating point comparison issue identified in #1110 while maintaining the existing behavior.


🏁 Script executed:

#!/bin/bash
# Find the exact locations of the problematic floating point comparisons
echo "=== Finding problematic floating point comparisons ==="
rg "updateTimer.*==.*0\.0f" src/Menu.cpp -n -A 2 -B 2

echo -e "\n=== Searching for existing floating point utility functions ==="
# Look for epsilon-based comparison functions
rg -i "epsilon|float.*equal|compare.*float" src/ --type cpp --type h -A 2 -B 2

echo -e "\n=== Searching for math utility functions ==="
# Look for existing math utilities that might have floating point helpers
fd -e h -e cpp | xargs rg -l "math|util" | head -10

echo -e "\n=== Checking for any floating point comparison patterns ==="
# Look for other floating point comparison patterns in the codebase
rg "\.0f.*[=!]=" src/ --type cpp -n | head -10

Length of output: 1945


🏁 Script executed:

#!/bin/bash
# Get more context around the problematic comparisons and check Math/Utils files
echo "=== Detailed context of updateTimer comparisons ==="
rg "updateTimer" src/Menu.cpp -n -A 5 -B 5

echo -e "\n=== Checking for Math/Utils headers ==="
fd -e h -e hpp | rg -i "math|util" 

echo -e "\n=== Checking common floating point comparison approaches ==="
rg "std::abs|fabsf|fabs" src/ --type cpp --type h -A 1 -B 1

Length of output: 2400


@alandtse Based on my analysis, I found the exact issues and some existing floating point utilities. Here are my findings and suggested fixes:

Issues Found

The problematic comparisons are at lines 1456 and 1470 in the UpdateFGFrameTime function:

// Line 1456
if (updateTimer == 0.0f) {
    postFGSmoothFps = postFGFps;
    postFGSmoothFrameTimeMs = postFGFrameTimeMs;
}

// Line 1470  
if (updateTimer == 0.0f) {
    postFGSmoothFps = postFGFps;
    postFGSmoothFrameTimeMs = postFGFrameTimeMs;
}

Existing Floating Point Utilities ✅

The codebase does have existing patterns for floating point comparisons:

  1. FLT_EPSILON usage in src/Features/SkySync.cpp:

    if (outDistance = outDir.Unitize(); outDistance < FLT_EPSILON) {
  2. Epsilon-based comparisons in src/Features/LightLimitFix.cpp:

    if (fabs(_fov - fov) > 1e-4 || fabs(_lightsNear - lightsNear) > 1e-4 || fabs(_lightsFar - lightsFar) > 1e-4) {

Recommended Fix

Since these are timer reset checks (similar to the correctly implemented main timer logic), the simplest and most appropriate fix is to use <= 0.0f:

// Line 1456 - Fix floating point comparison
- if (updateTimer == 0.0f) {
+ if (updateTimer <= 0.0f) {
    postFGSmoothFps = postFGFps;
    postFGSmoothFrameTimeMs = postFGFrameTimeMs;
}

// Line 1470 - Fix floating point comparison  
- if (updateTimer == 0.0f) {
+ if (updateTimer <= 0.0f) {
    postFGSmoothFps = postFGFps;
    postFGSmoothFrameTimeMs = postFGFrameTimeMs;
}

Alternative Epsilon-Based Approach

If you prefer to follow the existing epsilon pattern from the codebase:

#include <cfloat>  // for FLT_EPSILON

// Lines 1456 and 1470
- if (updateTimer == 0.0f) {
+ if (updateTimer <= FLT_EPSILON) {

Rationale

  • Simple <= 0.0f is preferred since this matches the timer reset pattern used correctly elsewhere in the same code
  • Handles floating point precision issues where timer might be slightly negative
  • Consistent with the main timer logic: perfOverlayState.updateTimer >= settings.PerfOverlay.UpdateInterval
  • The existing epsilon patterns in the codebase show the team is aware of floating point precision, so either approach would be acceptable

Recommendation: Use the <= 0.0f approach as it's simpler and appropriate for timer boundary checks.

Copy link
Copy Markdown
Collaborator

@alandtse alandtse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soda3000 please resolve as recommended by the AI. Also confirm the refactor doesn't break anything with the changes.

Comment thread src/Menu.h Outdated
Comment thread src/Utils/UI.h Outdated
@alandtse alandtse changed the title Performance overlay refactor: Menu/UI and related improvements refactor: performance overlay Jun 7, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2025

✅ A pre-release build is available for this PR:
Download

Copy link
Copy Markdown
Collaborator

@davo0411 davo0411 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of long comments to remove/cleanup. Don't need 40 lines explaining how something works.
Please look in depth at menu.cpp. There are more comment additions than what I added "comment cleanup" for. Some of them are explaining 1 line with like 8 lines of comments.

Comment thread src/Utils/UI.h Outdated
Comment thread src/Menu.cpp Outdated
Comment thread src/Menu.cpp
Comment thread src/Menu.cpp
@alandtse
Copy link
Copy Markdown
Collaborator

alandtse commented Jun 7, 2025

Lots of long comments to remove/cleanup. Don't need 40 lines explaining how something works. Please look in depth at menu.cpp. There are more comment additions than what I added "comment cleanup" for. Some of them are explaining 1 line with like 8 lines of comments.

I disagree, proper documentation is actually something we should welcome. Most people fail at actually doing it.

@davo0411
Copy link
Copy Markdown
Collaborator

davo0411 commented Jun 7, 2025

Lots of long comments to remove/cleanup. Don't need 40 lines explaining how something works. Please look in depth at menu.cpp. There are more comment additions than what I added "comment cleanup" for. Some of them are explaining 1 line with like 8 lines of comments.

I disagree, proper documentation is actually something we should welcome. Most people fail at actually doing it.

I know for future now :) I've always removed excess wordiness as I thought it conflicted with established norms. Will implement this moving forward

soda3000 added a commit to soda3000/skyrim-community-shaders that referenced this pull request Jun 7, 2025
Comment thread src/Utils/UI.h
soda3000 added a commit to soda3000/skyrim-community-shaders that referenced this pull request Jun 7, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/Menu.cpp (1)

1375-1376: ⚠️ Potential issue

Still missing: kSmoothingFactor constant definition

The code references kSmoothingFactor for exponential smoothing, but this constant is still not defined in the visible code. This is a duplicate of a previous review comment that remains unaddressed.

🧹 Nitpick comments (1)
src/Menu.cpp (1)

601-607: Consider scope: Help icon additions beyond performance overlay

While the help icons follow a consistent pattern and improve UX, these additions span many UI elements unrelated to the performance overlay refactor. As noted in past review comments, this may be beyond the intended scope of this PR.

Consider moving these UI improvements to a separate PR focused on general UX enhancements.

Also applies to: 612-612, 616-623, 625-625, 627-627, 631-637, 936-936, 944-944, 1767-1785, 1795-1801

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c2efbb and 9608748.

📒 Files selected for processing (1)
  • src/Menu.cpp (9 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/Menu.cpp (4)
src/Utils/UI.h (4)
  • HoverTooltipWrapper (18-18)
  • HoverTooltipWrapper (19-19)
  • frameTimeMs (51-54)
  • frameTimeMs (51-51)
src/Utils/UI.cpp (2)
  • HoverTooltipWrapper (7-14)
  • HoverTooltipWrapper (16-22)
src/Upscaling.h (1)
  • state (162-178)
src/Menu.h (7)
  • settings (221-221)
  • settings (222-222)
  • settings (223-223)
  • settings (226-226)
  • settings (227-227)
  • settings (229-229)
  • dxgiAdapter3 (230-230)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (5)
src/Menu.cpp (5)

48-48: LGTM: Proper integration of new FrameHistorySize setting

The addition of FrameHistorySize to the JSON serialization is correctly placed and follows the established pattern for performance overlay settings.


1191-1290: Excellent refactoring: Well-structured performance overlay organization

The refactoring successfully breaks down the monolithic DrawPerfOverlay function into well-organized, encapsulated methods within PerfOverlayState. This significantly improves:

  • Code maintainability and readability
  • Separation of concerns (timing, rendering, state management)
  • Future extensibility for moving to separate files

The use of the encapsulated state object eliminates the thread safety concerns from static variables mentioned in issue #1110.


1328-1377: Excellent implementation: Statistical graph scaling with performance optimization

The UpdateGraphValues method demonstrates sophisticated algorithmic design:

  • Smart min/max tracking: Avoids expensive full scans by tracking when min/max values are replaced
  • Statistical scaling: Uses mean ± 2σ for graph range, providing stable and meaningful visualization
  • Exponential smoothing: Prevents jarring visual changes while maintaining responsiveness
  • Proper circular buffer management: Efficient memory usage with the configurable history size

This addresses the performance optimization goals from issue #1110 effectively.


1409-1443: Robust frame generation timing implementation

The UpdateFGFrameTime method handles frame generation complexity effectively:

  • Direct FG timing: Retrieves actual frame generation timing when available
  • Graceful fallback: Provides reasonable approximations when FG timing is unavailable
  • Consistent state management: Maintains both smooth values and history buffers properly
  • Integration: Properly interfaces with the upscaling system

This ensures the performance overlay works reliably across different frame generation states.


1453-1633: Well-organized rendering methods with comprehensive display logic

The rendering methods demonstrate good separation of concerns:

  • Conditional display: Properly handles different frame generation states and user preferences
  • Focused methods: Each method has a clear, single responsibility
  • Good UX: Includes reference lines, proper formatting, and centered text where appropriate
  • Resource handling: VRAM method includes proper error handling for DXGI queries

The modular approach makes the code much more maintainable than the previous monolithic implementation.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2025

✅ A pre-release build is available for this PR:
Download

1 similar comment
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2025

✅ A pre-release build is available for this PR:
Download

soda3000 added a commit to soda3000/skyrim-community-shaders that referenced this pull request Jun 7, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/Menu.cpp (2)

606-615: Consider scope: Help icons extend beyond performance overlay refactor.

While these help icon additions improve user experience with consistent tooltips, they appear to extend beyond the stated PR scope of "performance overlay refactor." The implementation is well-executed and follows a good UX pattern, but this could be considered scope creep.

Also applies to: 924-940


1756-1774: UI improvements extend beyond core refactor scope.

These help icons with explanatory tooltips enhance user understanding of the performance overlay settings. While valuable for UX, they extend beyond the stated "performance overlay refactor" scope. The implementation maintains consistency with the established pattern.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48f9087 and d273b00.

📒 Files selected for processing (1)
  • src/Menu.cpp (9 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/Menu.cpp (4)
src/Utils/UI.h (4)
  • HoverTooltipWrapper (18-18)
  • HoverTooltipWrapper (19-19)
  • frameTimeMs (51-54)
  • frameTimeMs (51-51)
src/Utils/UI.cpp (2)
  • HoverTooltipWrapper (7-14)
  • HoverTooltipWrapper (16-22)
src/FrameAnnotations.cpp (1)
  • state (224-231)
src/Menu.h (7)
  • settings (221-221)
  • settings (222-222)
  • settings (223-223)
  • settings (226-226)
  • settings (227-227)
  • settings (229-229)
  • dxgiAdapter3 (230-230)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (5)
src/Menu.cpp (5)

48-48: LGTM! Clean integration of configurable frame history size.

The addition of FrameHistorySize to the serialization configuration properly supports the PR objective of replacing magic numbers with user-configurable settings.


1179-1279: Excellent refactoring that achieves core PR objectives.

This refactoring successfully:

  • Decomposes the monolithic DrawPerfOverlay function into focused methods
  • Encapsulates state management within PerfOverlayState
  • Improves thread safety by moving static variables to class members
  • Maintains original functionality while significantly improving code organization

The performance counter initialization and frame timing logic are now properly encapsulated and more maintainable.


1287-1651: Well-implemented modular design with comprehensive functionality.

The new PerfOverlayState methods successfully modularize the performance overlay functionality:

  • Statistical graph scaling: The mean ± 2σ approach for Y-axis range is mathematically sound
  • Comprehensive documentation: Methods are well-documented with clear purpose statements
  • Proper bounds checking: Frame history size management includes appropriate validation
  • Clean separation of concerns: Each method has a focused responsibility

Note: The kSmoothingFactor undefined constant issue (line 1364-1365) is already flagged in previous review comments.


1150-1651: Outstanding refactor that successfully achieves modernization goals.

This comprehensive refactor delivers on the stated objectives:

Method decomposition: Large DrawPerfOverlay function broken into focused methods
Thread safety: Static variables moved to class members
Configurable settings: Magic numbers replaced with user-configurable FrameHistorySize
Performance optimization: Improved algorithms for smoothing and min/max tracking
Documentation: Comprehensive method documentation for maintainability

The modular design significantly improves code organization and sets up well for future separation into distinct files. The statistical approach to graph scaling and proper state encapsulation demonstrate thoughtful engineering.


1240-1250:

Details

✅ Verification successful

Verify floating point comparison fixes mentioned in PR objectives.

The PR objectives mention that floating point comparison issues at lines 1096 and 1112 (if (updateTimer == 0.0f)) remain partially addressed and should be changed to <= 0.0f. These specific patterns aren't visible in the current diff.


🏁 Script executed:

#!/bin/bash
# Description: Search for remaining floating point equality comparisons in timer logic
# Expected: Find any remaining == 0.0f patterns that should use <= 0.0f

echo "Searching for floating point equality comparisons with zero:"
rg "== 0\.0f" src/Menu.cpp -A 2 -B 2

echo -e "\nSearching for updateTimer comparisons:"
rg "updateTimer.*==" src/Menu.cpp -A 2 -B 2

Length of output: 308


Floating-point comparison issues resolved

A search for == 0.0f and updateTimer == 0.0f in src/Menu.cpp returned no matches, confirming that all equality checks against zero have been updated to use <= 0.0f as intended. No further changes are necessary.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2025

✅ A pre-release build is available for this PR:
Download

6 similar comments
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2025

✅ A pre-release build is available for this PR:
Download

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2025

✅ A pre-release build is available for this PR:
Download

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2025

✅ A pre-release build is available for this PR:
Download

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2025

✅ A pre-release build is available for this PR:
Download

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2025

✅ A pre-release build is available for this PR:
Download

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2025

✅ A pre-release build is available for this PR:
Download

@soda3000
Copy link
Copy Markdown
Contributor Author

soda3000 commented Jun 8, 2025

Addressed the min-width issue when no graphs are shown.

@davo0411
Copy link
Copy Markdown
Collaborator

davo0411 commented Jun 9, 2025

It might be the mobile app, but I'm seeing a lot of unrelated changes like lut changes. Did you accidentally merge something in?

It looks like the new dev stuff that has been merged, but idk why its shown up again here?

@soda3000
Copy link
Copy Markdown
Contributor Author

soda3000 commented Jun 9, 2025

Yea not sure why those changes are shown. I was pretty sure i only added a single file in the latest commit, Menu.cpp.

Copy link
Copy Markdown
Collaborator

@alandtse alandtse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address and also make sure you respond on any AI suggestions either to make the change or to say you don't think it applies. AI can be wrong.

Comment thread src/Utils/UI.h
Comment thread src/Menu.cpp Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 9, 2025

✅ A pre-release build is available for this PR:
Download

@soda3000
Copy link
Copy Markdown
Contributor Author

soda3000 commented Jun 9, 2025

latest commit should resolve the LARGE_INTEGER usage. I replaced the previously used functions with a wrapper function from commonlib and avoided the requirement of that type.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 9, 2025

✅ A pre-release build is available for this PR:
Download

1 similar comment
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 9, 2025

✅ A pre-release build is available for this PR:
Download

Comment thread src/Menu.cpp Outdated
Automated formatting by clang-format, prettier, and other hooks.
See https://pre-commit.ci for details.
Copy link
Copy Markdown
Collaborator

@davo0411 davo0411 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove old base FPS calculations if it has been rewritten and is working well. If not and still needed, leave it for now then do another pr with the FG FPS metrics removal and update the FPS code if it needs it.

Basically, if the FPS reworks have already been done & are working, I'm happy, just delete whatever is unused now from my original feature in DX12Swapchain or the other files. If it still being used, then leave it and work on a new PR after this to simplify it & remove the FG fps stuff.

Comment thread src/Utils/UI.h
@github-actions
Copy link
Copy Markdown

✅ A pre-release build is available for this PR:
Download

1 similar comment
@github-actions
Copy link
Copy Markdown

✅ A pre-release build is available for this PR:
Download

@soda3000 soda3000 requested a review from alandtse June 10, 2025 23:05
Comment thread src/Utils/UI.h
@alandtse alandtse merged commit 282ca1c into community-shaders:dev Jun 11, 2025
9 checks passed
davo0411 pushed a commit to davo0411/skyrim-community-shaders that referenced this pull request Jun 21, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
alandtse pushed a commit to alandtse/open-shaders that referenced this pull request Jul 20, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.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.

Refactor DrawPerfOverlay method in Menu.cpp for better maintainability

3 participants