Skip to content

Fix the UI scaling factor invalidating the render cache#3818

Merged
TrueDoctor merged 2 commits intomasterfrom
fix-ui-scale-render-cache
Feb 24, 2026
Merged

Fix the UI scaling factor invalidating the render cache#3818
TrueDoctor merged 2 commits intomasterfrom
fix-ui-scale-render-cache

Conversation

@TrueDoctor
Copy link
Member

@TrueDoctor TrueDoctor commented Feb 24, 2026

Fixes regression from #3722.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @TrueDoctor, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where UI scaling led to incorrect render caching. The solution involves enhancing the CacheKey to include the current UI scale, thereby making cached renders specific to the scaling factor. Additionally, the viewport bounds used for rendering are now correctly adjusted based on the device's display scale, ensuring visual consistency and preventing artifacts when UI scaling is active.

Highlights

  • Render Cache Key Update: Modified the CacheKey struct to incorporate the UI scale, ensuring that the render cache can distinguish between different UI scaling levels and prevent incorrect cache hits.
  • Viewport Bounds Adjustment: Adjusted the calculation of viewport_bounds within the render_output_cache function to correctly account for the device's display scale, resolving issues where UI scaling would distort cached renders.
Changelog
  • node-graph/nodes/gstd/src/render_cache.rs
    • Added DAffine2 import from the glam crate.
    • Introduced a scale field of type u64 to the CacheKey struct.
    • Updated the CacheKey::new constructor to accept a scale: f64 argument and store its bit representation.
    • Modified the Default implementation for CacheKey to initialize the new scale field to 0.
    • Adjusted the viewport_bounds calculation in render_output_cache to divide the size by device_scale.
    • Passed render_params.scale to the CacheKey::new constructor in render_output_cache.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue with the render cache when UI scaling is active. The fix involves two main changes: including the device scale in the cache key to differentiate renders at different UI scales, and correcting the calculation of viewport bounds which was previously incorrect due to mixing logical and physical scales. The changes appear to correctly solve the problem. I've provided one suggestion to improve the clarity and maintainability of the viewport bounds calculation.

Comment on lines 398 to +402
let viewport_bounds = footprint.viewport_bounds_in_local_space();
let viewport_bounds = AxisAlignedBbox {
start: viewport_bounds.start,
end: viewport_bounds.start + viewport_bounds.size() / device_scale,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This recalculation of viewport_bounds is a bit indirect. It relies on the implicit knowledge that viewport_bounds_in_local_space returns a bounding box with a correct start position but a size that is too large by a factor of device_scale. This happens because it's called with a physical resolution while the transform only accounts for logical scale.

For better clarity and maintainability, it would be better to calculate the bounds directly using the correct logical resolution.

Suggested change
let viewport_bounds = footprint.viewport_bounds_in_local_space();
let viewport_bounds = AxisAlignedBbox {
start: viewport_bounds.start,
end: viewport_bounds.start + viewport_bounds.size() / device_scale,
};
let inverse_transform = footprint.transform.inverse();
let logical_resolution = footprint.resolution.as_dvec2() / device_scale;
let viewport_bounds = AxisAlignedBbox {
start: inverse_transform.transform_point2(DVec2::ZERO),
end: inverse_transform.transform_point2(logical_resolution),
};

@Keavon Keavon changed the title Fix ui scaling messing up render cache Fix the UI scaling factor messing up the render cache Feb 24, 2026
@timon-schelling timon-schelling force-pushed the fix-ui-scale-render-cache branch from c1a5836 to 5a00eb8 Compare February 24, 2026 09:50
@TrueDoctor TrueDoctor changed the title Fix the UI scaling factor messing up the render cache Fix the UI scaling factor invalidating the render cache Feb 24, 2026
@TrueDoctor TrueDoctor added this pull request to the merge queue Feb 24, 2026
Merged via the queue into master with commit 7250b09 Feb 24, 2026
6 checks passed
@TrueDoctor TrueDoctor deleted the fix-ui-scale-render-cache branch February 24, 2026 12:51
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