Skip to content

feat: performance overlay#1070

Merged
alandtse merged 15 commits into
community-shaders:devfrom
davo0411:drawcalluiupdate
Jun 4, 2025
Merged

feat: performance overlay#1070
alandtse merged 15 commits into
community-shaders:devfrom
davo0411:drawcalluiupdate

Conversation

@davo0411
Copy link
Copy Markdown
Collaborator

@davo0411 davo0411 commented May 8, 2025

Adds a performance overlay to CS.
Tracks pre and post FG FPS, Frametime, with graphs.
Tracks draw calls, code from Exist.
Tracks vram usage.

Has various settings for visuals and size. All options toggleable. Can make it a small fps counter, or a full info overlay. Overlay can move around the screen.

(New pr with cleaned commits)

Summary by CodeRabbit

  • New Features

    • Introduced a configurable performance overlay displaying real-time metrics such as FPS, frame time graphs, draw calls, and VRAM usage.
    • Added customization options for the overlay, including appearance, update frequency, position, and a toggle hotkey.
    • Overlay settings are now accessible and configurable within the display settings menu.
    • Added frame time reporting for more precise FPS calculation during frame generation.
  • Enhancements

    • Improved tracking and smoothing of draw call statistics by shader type for more accurate performance metrics.
    • Added frame generation status and timing reporting for enhanced FPS measurement when frame generation is active.

@doodlum doodlum changed the title Feat: Performance Overlay feat: performance overlay May 9, 2025
Comment thread src/Menu.cpp Outdated
Comment thread src/State.cpp
@alandtse
Copy link
Copy Markdown
Collaborator

Taking to WIP until the keypress is fixed.

@alandtse alandtse marked this pull request as draft May 11, 2025 00:34
@davo0411 davo0411 marked this pull request as ready for review May 15, 2025 10:13
@davo0411
Copy link
Copy Markdown
Collaborator Author

Hotkey fixed, ready for merge.

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.

Still need to know if there was a perf impact when the overlay is hidden. But probably can consider moving this in.

Comment thread src/Menu.cpp
Comment thread src/Menu.cpp
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2025

Walkthrough

A comprehensive performance overlay system has been added, featuring real-time metrics such as FPS, draw calls, VRAM usage, and frame time graphs. Supporting infrastructure includes new methods for frame timing and draw call tracking, as well as user-configurable overlay display and hotkey toggling. No existing logic was removed.

Changes

File(s) Change Summary
src/Menu.cpp, src/Menu.h Introduced a configurable performance overlay with real-time metrics, overlay settings UI, hotkey handling, and supporting structures.
src/DX12SwapChain.cpp, src/DX12SwapChain.h Added GetFrameTime() method for accurate frame timing using high-resolution counters.
src/State.cpp, src/State.h Implemented draw call tracking and smoothing per shader type; added member arrays for statistics.
src/Upscaling.cpp, src/Upscaling.h Added methods to query frame generation activity and timing for overlay purposes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Menu
    participant State
    participant Upscaling
    participant DX12SwapChain

    User->>Menu: Presses overlay toggle hotkey
    Menu->>Menu: Toggles performance overlay visibility

    loop Every frame (if overlay enabled)
        Menu->>State: Query drawCalls and smoothDrawCalls
        Menu->>Upscaling: IsFrameGenerationActive()
        Upscaling->>DX12SwapChain: GetFrameTime()
        DX12SwapChain-->>Upscaling: Frame time (if available)
        Upscaling-->>Menu: Frame generation status and timing
        Menu->>Menu: Update overlay metrics and graphs
        Menu->>User: Display performance overlay window
    end
Loading

Poem

In the meadow of frames, a rabbit peers,
Watching draw calls and timings appear.
With overlays bright and numbers in tow,
Performance secrets now easily show.
A hop, a skip, and graphs in the light—
Metrics and magic, all in plain sight!
🐇✨


📜 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 b329729 and c7b0199.

📒 Files selected for processing (1)
  • src/Menu.cpp (12 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/Menu.cpp (5)
src/Upscaling.h (1)
  • state (162-178)
src/ShaderCache.cpp (2)
  • IsEnabled (2088-2091)
  • IsEnabled (2088-2088)
src/Utils/UI.h (2)
  • HoverTooltipWrapper (18-18)
  • HoverTooltipWrapper (19-19)
src/Utils/UI.cpp (2)
  • HoverTooltipWrapper (5-12)
  • HoverTooltipWrapper (14-20)
src/Menu.h (1)
  • key (195-195)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (4)
src/Menu.cpp (4)

35-53: LGTM: Clean JSON serialization implementation

The performance overlay settings serialization follows the established pattern and includes all necessary configuration fields.


1495-1619: Excellent UI implementation

Well-structured settings UI with proper organization, collapsible headers, appropriate indentation, and good use of tooltips. The method maintains single responsibility and reasonable size.


1117-1133: Good timing precision improvements

The update to use high_resolution_clock provides better timing accuracy for test mode functionality. The window setup and config swapping logic is well-implemented.


235-237: Clean integration of performance overlay

The minor adjustments for font configuration, footer simplification, and overlay condition updates integrate the new functionality smoothly without disrupting existing logic.

Also applies to: 276-276, 1038-1038, 1048-1048, 1113-1114

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

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: 3

🧹 Nitpick comments (4)
src/DX12SwapChain.cpp (1)

179-200: Consider thread safety and error handling improvements.

The frame time calculation logic is correct and uses appropriate high-resolution timing. However, there are some potential improvements to consider:

  1. Thread Safety: The static variables could be corrupted if this method is called from multiple threads simultaneously.
  2. Error Handling: QueryPerformanceCounter can theoretically fail, but there's no error checking.

Consider these improvements:

 float DX12SwapChain::GetFrameTime() const
 {
-	// Calculate frame time based on swap chain presentation
-	static float lastPresentTime = 0.0f;
-	static float frameTime = 1.0f / 60.0f;  // Default to 60 fps
-	static LARGE_INTEGER frequency = {};
-	static LARGE_INTEGER currentTime = {};
+	// Calculate frame time based on swap chain presentation
+	static std::mutex timingMutex;
+	static float lastPresentTime = 0.0f;
+	static float frameTime = 1.0f / 60.0f;  // Default to 60 fps
+	static LARGE_INTEGER frequency = {};
+	
+	std::lock_guard<std::mutex> lock(timingMutex);
+	LARGE_INTEGER currentTime = {};

-	if (frequency.QuadPart == 0) {
-		QueryPerformanceFrequency(&frequency);
+	if (frequency.QuadPart == 0) {
+		if (!QueryPerformanceFrequency(&frequency)) {
+			return frameTime;  // Return default on failure
+		}
 	}

-	QueryPerformanceCounter(&currentTime);
+	if (!QueryPerformanceCounter(&currentTime)) {
+		return frameTime;  // Return last known value on failure
+	}
src/State.cpp (1)

506-509: Micro-cleanup – std::fill is clearer

-for (auto& c : drawCalls)
-    c = 0;
-for (auto& c : smoothDrawCalls)
-    c = 0;
+std::fill(std::begin(drawCalls),  std::end(drawCalls),  0);
+std::fill(std::begin(smoothDrawCalls), std::end(smoothDrawCalls), 0.f);
src/Menu.cpp (2)

1225-1260: Timer logic drifts for large UpdateInterval

deltaTime is measured from the previous frame, but lastUpdateTime is
reset every frame. Consequently updateTimer accumulates frame time,
not true elapsed wall-time, and will always be ≤ UpdateInterval + dt.
If the game is paused or stalls the overlay stops updating.

Consider:

updateTimer += std::chrono::duration<float>(
                  currentTime - lastUpdateTime).count();
lastUpdateTime = currentTime;

if (updateTimer >= settings.PerfOverlay.UpdateInterval) {
    …
    updateTimer -= settings.PerfOverlay.UpdateInterval; // keep remainder
}

1431-1444: Enum-driven table – avoid hard-coding shader names

The draw-call list is manually duplicated; any new BSShader::Type
adds maintenance burden.

for (int t = 1; t < RE::BSShader::Type::Total; ++t) {
    ImGui::Text("%s: %d",
        magic_enum::enum_name(static_cast<RE::BSShader::Type>(t)).data(),
        int(globals::state->smoothDrawCalls[t]));
}
ImGui::Text("Total: %d", int(globals::state->smoothDrawCalls[
        RE::BSShader::Type::Total]));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3025e04 and dfb8c90.

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

97-98: Clean method declaration with good documentation.

The GetFrameTime() method declaration is well-structured with appropriate const correctness and a clear comment explaining its purpose for frame generation FPS measurement.

src/State.h (1)

47-48: Good addition of draw call tracking arrays.

The smoothDrawCalls and drawCalls arrays are appropriately typed for tracking and smoothing draw call statistics per shader type. The sizing with RE::BSShader::Type::Total + 1 suggests proper indexing by shader type with an additional slot.

src/Upscaling.h (1)

50-52: Well-designed frame generation query methods.

The IsFrameGenerationActive() and GetFrameGenerationFrameTime() methods have appropriate signatures with const correctness. The return types (bool and float) are suitable for their respective purposes in the performance overlay.

src/State.cpp (1)

88-91: Bounds-safety for drawCalls index

currentShader->shaderType.get() is blindly used as an array index.
Although engine enums are usually contiguous, a corrupted/unknown shader could supply a value ≥ RE::BSShader::Type::Total, causing UB. A simple guard avoids that:

if (currentShader) {
    auto idx = currentShader->shaderType.get();
    if (idx > 0 && idx < RE::BSShader::Type::Total)
        ++drawCalls[idx];
}
src/Upscaling.cpp (1)

762-781: Guard against zero refresh-rate / missing swap-chain

GetFrameGenerationFrameTime() returns 0 on failure, but callers use the value to compute
1000 / frameTime which will divide by zero.
Consider returning std::optional<float> or at least guarding downstream computations:

auto fgTime = globals::upscaling->GetFrameGenerationFrameTime();
if (fgTime > 0.f) {
    /* safe maths */
}
src/Menu.cpp (1)

1148-1180: Style-stack balance & leak prevention

Two style vars (WindowBorderSize, ItemSpacing) and one color are pushed.
PopStyleVar() is called twice at 1476 & 1480, and PopStyleColor() once at 1481 – good.

However, an early return; before the Pops (e.g. if ImGui::Begin() fails)
would leak the style stack. Wrap drawing in a RAII helper or restructure:

if (!ImGui::Begin("Performance Overlay", …)) {
    ImGui::PopStyleVar(2);
    ImGui::PopStyleColor();
    return;
}

Comment thread src/State.cpp
Comment thread src/Menu.h
Comment thread src/Menu.cpp
@github-actions
Copy link
Copy Markdown

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

@davo0411 davo0411 requested a review from alandtse May 30, 2025 12:02
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: 1

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

1490-1614: Well-structured settings UI with minor suggestion.

The performance overlay settings UI is well-organized with clear sections and helpful tooltips. One minor suggestion:

Consider adding validation for the update interval to prevent extremely small values that could cause performance issues:

if (ImGui::SliderFloat("Update Interval", &settings.PerfOverlay.UpdateInterval, 0.001f, 2.0f, "%.2f seconds")) {
    settings.PerfOverlay.UpdateInterval = std::max(0.001f, settings.PerfOverlay.UpdateInterval);
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dfb8c90 and b329729.

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

35-53: LGTM! Comprehensive settings serialization.

The JSON serialization for PerfOverlaySettings is well-structured and includes all necessary configuration options for the performance overlay feature.


235-237: Good practice: Using float literals.

Adding the 'f' suffix to floating-point literals is good practice in C++ as it avoids implicit double-to-float conversions and makes the intended type explicit.

Also applies to: 276-276, 679-679


999-1002: Clean feature integration.

The Performance Overlay is properly integrated into the display features list alongside the existing upscaling feature.


1448-1480: Good fix: Proper VRAM error handling.

The VRAM usage section now properly addresses the division-by-zero concern from previous reviews by checking both SUCCEEDED(hr) and videoMemoryInfo.Budget > 0 before performing calculations. The fallback message for unavailable VRAM info is also appropriate.


1931-1933: Consistent hotkey implementation.

The overlay toggle key handling follows the same pattern as other hotkeys in the system and is properly integrated into the input processing logic.

Also applies to: 1948-1949


1117-1133: Good consistency improvements in test mode.

The test mode timing logic maintains consistency with the float literal improvements and the logic for alternating between test and user configurations appears correct.

Comment thread src/Menu.cpp
@github-actions
Copy link
Copy Markdown

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2025

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

@alandtse
Copy link
Copy Markdown
Collaborator

alandtse commented Jun 3, 2025

I'm still waiting for an answer to my last question to approve and merge this.

@davo0411
Copy link
Copy Markdown
Collaborator Author

davo0411 commented Jun 4, 2025

I'm still waiting for an answer to my last question to approve and merge this.

I'm sorry i missed the notification, I'll set github up on my phone so i see it first before asking on discord in future.

@alandtse alandtse merged commit 831ea04 into community-shaders:dev Jun 4, 2025
8 checks passed
@davo0411 davo0411 deleted the drawcalluiupdate branch June 19, 2025 10:52
alandtse pushed a commit to alandtse/open-shaders that referenced this pull request Jul 20, 2025
Co-authored-by: Exist <Exist@Yes>
Co-authored-by: ThePagi <ThePagi@users.noreply.github.com>
Co-authored-by: davo0411 <davo0411@users.noreply.github.com>
@coderabbitai coderabbitai Bot mentioned this pull request Sep 7, 2025
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.

3 participants