Skip to content

build(hlsl): fix warnings#1370

Merged
alandtse merged 2 commits into
community-shaders:devfrom
alandtse:hlsl_warnings_new
Aug 7, 2025
Merged

build(hlsl): fix warnings#1370
alandtse merged 2 commits into
community-shaders:devfrom
alandtse:hlsl_warnings_new

Conversation

@alandtse
Copy link
Copy Markdown
Collaborator

@alandtse alandtse commented Aug 6, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved stability of color and lighting calculations by ensuring negative values are handled safely in various shaders.
    • Fixed initialization of local variables in multiple shaders to prevent undefined behavior.
    • Corrected vector operations and type consistency in water and lighting shaders.
    • Enhanced reliability of terrain, hair, and skylighting computations with clearer and safer mathematical operations.

Copilot AI review requested due to automatic review settings August 6, 2025 08:22
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 6, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This change set applies explicit absolute value operations to inputs of power functions across multiple HLSL shader files. It ensures that negative values are converted to non-negative before exponentiation, addressing potential issues with invalid or undefined results. Additionally, several shader variables are now explicitly zero-initialized, and a minor vector calculation bug is fixed.

Changes

Cohort / File(s) Change Summary
Terrain Height Weight Abs Handling
features/Extended Materials/Shaders/ExtendedMaterials/ExtendedMaterials.hlsli
Applies abs() to terrain height weights before exponentiation in ProcessTerrainHeightWeights, ensuring non-negative bases for the power function.
Hair Shading Abs Handling
features/Hair Specular/Shaders/Hair/Hair.hlsli,
package/Shaders/Common/PBR.hlsli
Applies abs() before exponentiation in hair shading calculations, affecting the computation of scatterFresnel2 and hair transmission terms.
IBL and Color Channel Extraction
features/IBL/Shaders/IBL/DiffuseIBLCS.hlsl
Explicitly extracts .xyz (RGB) from sampled float4 color, ensuring only RGB channels are used in spherical harmonics coefficient accumulation.
Cluster Building Abs Handling
features/Light Limit Fix/Shaders/LightLimitFix/ClusterBuildingCS.hlsl
Applies abs() to the light range ratio before exponentiation in cluster near/far calculations.
Cluster Culling Loop Variable Rename
features/Light Limit Fix/Shaders/LightLimitFix/ClusterCullingCS.hlsl
Renames a loop variable from i to j in the copy loop for visible light indices; logic remains unchanged.
Skylighting Probe Validity Refactor
features/Skylighting/Shaders/Skylighting/UpdateProbesCS.hlsl
Refactors probe validity check with intermediate variables and explicit type casts for clarity and correctness.
Terrain Shadow Height Initialization
features/Terrain Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlsl
Changes pastHeights initialization to explicit zero, ensuring defined value before conditional assignment.
Color Space Conversion Abs Handling
package/Shaders/Common/Color.hlsli,
package/Shaders/Common/DisplayMapping.hlsli,
package/Shaders/Common/FrameBuffer.hlsli
Applies abs() to color values before exponentiation in gamma/linear conversions and PQ mapping, ensuring non-negative power function inputs.
Shader Output Zero Initialization
package/Shaders/DistantTree.hlsl,
package/Shaders/Effect.hlsl,
package/Shaders/RunGrass.hlsl
Initializes shader output structs to zero at declaration using casts, ensuring all fields are set to zero initially.
Water Shader Initialization and Vector Fix
package/Shaders/Water.hlsl
Changes initialization of float variables to 0.0, and corrects a vector subtraction bug in the pixel shader main function.

Sequence Diagram(s)

sequenceDiagram
    participant ShaderFunction
    participant InputValue
    participant AbsFunction
    participant PowFunction
    participant Output

    ShaderFunction->>InputValue: Receives input (may be negative)
    ShaderFunction->>AbsFunction: Applies abs(input)
    AbsFunction->>PowFunction: Passes non-negative value
    PowFunction->>Output: Raises to power and returns result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A whisker twitch, a shader fix,
Abs before pow—no negative tricks!
Colors and heights, all safe and bright,
Zeroed-out structs, outputs just right.
With every hop, the code grows clear,
This bunny reviews with a gleeful cheer! 🐇✨

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 d14a976 and c5b568e.

📒 Files selected for processing (1)
  • features/Skylighting/Shaders/Skylighting/UpdateProbesCS.hlsl (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • features/Skylighting/Shaders/Skylighting/UpdateProbesCS.hlsl
✨ Finishing Touches
🧪 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.
  • 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.

Support

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

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes various HLSL compiler warnings by addressing initialization issues and negative base value warnings in power functions across multiple shader files.

  • Proper initialization of output structures and variables to prevent uninitialized variable warnings
  • Wrapping power function bases with abs() to avoid warnings about negative values raised to fractional powers
  • Fixing syntax errors in function calls and variable declarations

Reviewed Changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
package/Shaders/Water.hlsl Standardizes float initialization format and fixes function call syntax
package/Shaders/RunGrass.hlsl Initializes PS_OUTPUT structure to zero
package/Shaders/Effect.hlsl Initializes PS_OUTPUT structure to zero
package/Shaders/DistantTree.hlsl Initializes VS_OUTPUT structure to zero
package/Shaders/Common/PBR.hlsli Wraps BaseColor with abs() in pow() calls
package/Shaders/Common/FrameBuffer.hlsli Wraps linearColor with abs() in pow() call
package/Shaders/Common/DisplayMapping.hlsli Wraps pow() function bases with abs()
package/Shaders/Common/Color.hlsli Wraps color values with abs() in pow() calls
features/Terrain Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlsl Initializes float2 variable to zero
features/Skylighting/Shaders/Skylighting/UpdateProbesCS.hlsl Fixes type conversion issues with signed/unsigned comparisons
features/Light Limit Fix/Shaders/LightLimitFix/ClusterCullingCS.hlsl Renames loop variable to avoid conflicts
features/Light Limit Fix/Shaders/LightLimitFix/ClusterBuildingCS.hlsl Wraps division result with abs() in pow() calls
features/IBL/Shaders/IBL/DiffuseIBLCS.hlsl Adds explicit .xyz swizzle to texture sample
features/Hair Specular/Shaders/Hair/Hair.hlsli Wraps subtraction result with abs() in pow() call
features/Extended Materials/Shaders/ExtendedMaterials/ExtendedMaterials.hlsli Wraps weights with abs() in pow() call

Comment thread package/Shaders/Water.hlsl
Comment thread features/Skylighting/Shaders/Skylighting/UpdateProbesCS.hlsl Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 6, 2025

Using provided base ref: 24f8d4f
Using base ref: 24f8d4f
Base commit date: 2025-08-04T21:50:56-07:00 (Monday, August 04, 2025 09:50 PM)
No actionable suggestions for changed features.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 6, 2025

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

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