Skip to content

perf(ISL): shift size bias calc to CPU#1343

Merged
alandtse merged 1 commit into
community-shaders:devfrom
sicsix:isl-lightsize-opt
Jul 31, 2025
Merged

perf(ISL): shift size bias calc to CPU#1343
alandtse merged 1 commit into
community-shaders:devfrom
sicsix:isl-lightsize-opt

Conversation

@sicsix
Copy link
Copy Markdown
Collaborator

@sicsix sicsix commented Jul 31, 2025

Summary by CodeRabbit

  • Refactor
    • Renamed light size-related properties to improve consistency across lighting features. This change does not affect user-facing functionality.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 31, 2025

Walkthrough

This change refactors the way light attenuation is calculated by renaming the size variable to sizeBias across relevant structures and shaders. The computation of the attenuation bias is updated to use a precomputed sizeBias value instead of recalculating it in the shader, streamlining the data flow from C++ to shader code.

Changes

Cohort / File(s) Change Summary
Shader Attenuation Calculation Update
features/Inverse Square Lighting/Shaders/InverseSquareLighting/InverseSquareLighting.hlsli
Modified the attenuation calculation to use light.sizeBias instead of computing from light.size.
Light Structure Member Rename
features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli,
src/Features/LightLimitFix.h
Renamed struct member size to sizeBias in both HLSL and C++ Light/LightData structures.
C++ Light Processing Update
src/Features/InverseSquareLighting.cpp
Updated assignment to use and compute sizeBias for lights, matching the new shader expectations.

Sequence Diagram(s)

sequenceDiagram
    participant Cpp as C++ Light Processing
    participant Shader as Shader

    Cpp->>Cpp: Compute sizeBias = ScaledUnitsSq * size^2 * 0.5
    Cpp->>Shader: Pass Light struct with sizeBias
    Shader->>Shader: Use light.sizeBias in attenuation calculation
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • alandtse

Poem

A tweak to how our lights now gleam,
With sizeBias in the shader stream.
No more confusion, no more strife,
Just cleaner code and brighter life.
The rabbits cheer, the code’s precise—
Illuminating change is nice!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93c4fef and c3039c7.

📒 Files selected for processing (4)
  • features/Inverse Square Lighting/Shaders/InverseSquareLighting/InverseSquareLighting.hlsli (1 hunks)
  • features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli (1 hunks)
  • src/Features/InverseSquareLighting.cpp (1 hunks)
  • src/Features/LightLimitFix.h (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent 4-byte size, proper 16-byte alignment in constant buffers, and cross-platform compatibility when passing data between C++ and HLSL shaders.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent size, alignment, and cross-platform compatibility when passing data to shader constant buffers.
Learnt from: davo0411
PR: doodlum/skyrim-community-shaders#1070
File: src/State.cpp:79-83
Timestamp: 2025-05-30T11:44:15.542Z
Learning: In the Skyrim Community Shaders project, the `smoothDrawCalls` array in the `State` class is declared as type `double` in `src/State.h`, which is the correct floating-point type for performing exponential moving average smoothing calculations.
features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli (4)

Learnt from: alandtse
PR: #577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use uint type instead of bool for compatibility reasons. This ensures consistent 4-byte size, proper 16-byte alignment in constant buffers, and cross-platform compatibility when passing data between C++ and HLSL shaders.

Learnt from: alandtse
PR: #577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use uint type instead of bool for compatibility reasons. This ensures consistent size, alignment, and cross-platform compatibility when passing data to shader constant buffers.

Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-01T18:01:07.079Z
Learning: In the skyrim-community-shaders project, simple scalar constants in HLSL shaders use #define (e.g., #define NTHREADS 128), while more complex constants use static const within namespaces (e.g., Math namespace in Math.hlsli). For epsilon standardization, #define is the appropriate choice since epsilon values are simple scalar constants.

Learnt from: alandtse
PR: #577
File: features/Wetness Effects/Shaders/WetnessEffects/WetnessEffects.hlsli:57-61
Timestamp: 2025-06-17T05:40:22.785Z
Learning: Default parameter values are supported in the HLSL compiler used by the skyrim-community-shaders project, contrary to standard HLSL (FXC/DXC) limitations.

src/Features/LightLimitFix.h (1)

Learnt from: alandtse
PR: #577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use uint type instead of bool for compatibility reasons. This ensures consistent 4-byte size, proper 16-byte alignment in constant buffers, and cross-platform compatibility when passing data between C++ and HLSL shaders.

features/Inverse Square Lighting/Shaders/InverseSquareLighting/InverseSquareLighting.hlsli (1)

Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-01T18:01:07.079Z
Learning: In the skyrim-community-shaders project, simple scalar constants in HLSL shaders use #define (e.g., #define NTHREADS 128), while more complex constants use static const within namespaces (e.g., Math namespace in Math.hlsli). For epsilon standardization, #define is the appropriate choice since epsilon values are simple scalar constants.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Validate shader compilation (Flatrim, .github/configs/shader-validation.yaml)
  • GitHub Check: Validate shader compilation (VR, .github/configs/shader-validation-vr.yaml)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (4)
features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli (1)

41-41: LGTM: Consistent renaming for performance optimization.

The renaming of size to sizeBias aligns with the PR objective to move size bias calculation to CPU. The struct layout remains unchanged, maintaining compatibility with C++ counterparts.

src/Features/LightLimitFix.h (1)

56-56: LGTM: Maintains shader interface compatibility.

The renaming to sizeBias is consistent with the corresponding shader structure and supports the performance optimization by enabling pre-computed bias values.

src/Features/InverseSquareLighting.cpp (1)

66-66: Excellent performance optimization—please verify the constant definitions

The move to precompute sizeBias on the CPU is mathematically correct and will reduce per-pixel work in the shader. However, searches didn’t locate definitions for ScaledUnitsSq or SCALED_UNITS_SQ in the codebase.

• Confirm that the C++ ScaledUnitsSq value exactly matches the HLSL SCALED_UNITS_SQ constant
• Ensure both are kept in sync (e.g., defined in a shared header or copied correctly)

features/Inverse Square Lighting/Shaders/InverseSquareLighting/InverseSquareLighting.hlsli (1)

15-15: Excellent shader optimization: Eliminates per-pixel calculations.

The change replaces SCALED_UNITS_SQ * light.size * light.size / 2.0f with the pre-computed light.sizeBias, eliminating 3 arithmetic operations per pixel. This directly addresses the PR objective of moving size bias calculation to CPU for better performance.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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.

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.

@github-actions
Copy link
Copy Markdown

Using provided base ref: 93c4fef
Using base ref: 93c4fef
Base commit date: 2025-07-30T22:18:47-07:00 (Wednesday, July 30, 2025 10:18 PM)
No actionable suggestions for changed features.

@github-actions
Copy link
Copy Markdown

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

@alandtse alandtse merged commit 3c80909 into community-shaders:dev Jul 31, 2025
15 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Sep 4, 2025
@coderabbitai coderabbitai Bot mentioned this pull request May 8, 2026
4 tasks
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