Skip to content

fix: compiler remaining tasks#2276

Merged
alandtse merged 2 commits into
community-shaders:devfrom
davo0411:fix/compiler-remaining-tasks
May 5, 2026
Merged

fix: compiler remaining tasks#2276
alandtse merged 2 commits into
community-shaders:devfrom
davo0411:fix/compiler-remaining-tasks

Conversation

@davo0411
Copy link
Copy Markdown
Collaborator

@davo0411 davo0411 commented May 4, 2026

[15:54:03.843] [28964] [I] [ShaderTiming] Very slow 12317ms | queue_wait=0ms | remaining=18446744073709551615 | defines=5 | src=111008B | prio=3350 | Lighting:Pixel:GLINT TRUE_PBR DEFERRED WETNESS_EFFECTS WATER_EFFECTS VOLUMETRIC_SHADOWS UNIFIED_WATER TERRAIN_VARIATION TERRAIN_SHADOWS SSS SCREEN_SPACE_SHADOWS LOD_BLENDING ISL LIGHT_LIMIT_FIX CS_HAIR EXTENDED_TRANSLUCENCY EXTENDED_MATERIALS EXP_HEIGHT_FOG CLOUD_SHADOWS TERRAIN_BLENDING SKYLIGHTING IBL DYNAMIC_CUBEMAPS LANDSCAPE MULTI_TEXTURE ANISO_LIGHTING VC

Previously it shows something like that ^ with nonsense for "remaining"
Now correctly shows the below, accurately counting down the remaining shaders to compile:
[16:52:52.354] [28832] [I] [ShaderTiming] Very slow 11714ms | queue_wait=115ms | remaining=5 | defines=4 | src=109690B | prio=2320 | Lighting:Pixel:GLINT TRUE_PBR DEFERRED WETNESS_EFFECTS WATER_EFFECTS VOLUMETRIC_SHADOWS UNIFIED_WATER TERRAIN_SHADOWS SSS SCREEN_SPACE_SHADOWS LOD_BLENDING ISL LIGHT_LIMIT_FIX CS_HAIR EXTENDED_TRANSLUCENCY EXTENDED_MATERIALS EXP_HEIGHT_FOG CLOUD_SHADOWS TERRAIN_BLENDING SKYLIGHTING IBL DYNAMIC_CUBEMAPS ANISO_LIGHTING VC
[16:52:52.638] [8144 ] [I] [ShaderTiming] Very slow 12022ms | queue_wait=52ms | remaining=4 | defines=5 | src=109690B | prio=2350 | Lighting:Pixel:GLINT TRUE_PBR DEFERRED WETNESS_EFFECTS WATER_EFFECTS VOLUMETRIC_SHADOWS UNIFIED_WATER TERRAIN_SHADOWS SSS SCREEN_SPACE_SHADOWS LOD_BLENDING ISL LIGHT_LIMIT_FIX CS_HAIR EXTENDED_TRANSLUCENCY EXTENDED_MATERIALS EXP_HEIGHT_FOG CLOUD_SHADOWS TERRAIN_BLENDING SKYLIGHTING IBL DYNAMIC_CUBEMAPS ANISO_LIGHTING DO_ALPHA_TEST VC
[16:53:07.486] [24744] [I] [ShaderTiming] Very slow 26880ms | queue_wait=49ms | remaining=3 | defines=6 | src=109690B | prio=3080 | Lighting:Pixel:TRUE_PBR DEFERRED WETNESS_EFFECTS WATER_EFFECTS VOLUMETRIC_SHADOWS UNIFIED_WATER TERRAIN_VARIATION TERRAIN_SHADOWS SSS SCREEN_SPACE_SHADOWS LOD_BLENDING ISL LIGHT_LIMIT_FIX CS_HAIR EXTENDED_TRANSLUCENCY EXTENDED_MATERIALS EXP_HEIGHT_FOG CLOUD_SHADOWS TERRAIN_BLENDING SKYLIGHTING IBL DYNAMIC_CUBEMAPS LOD_LAND_BLEND LANDSCAPE MULTI_TEXTURE VC
[16:53:13.901] [10880] [I] [ShaderTiming] Very slow 33314ms | queue_wait=30ms | remaining=2 | defines=5 | src=109690B | prio=3350 | Lighting:Pixel:GLINT TRUE_PBR DEFERRED WETNESS_EFFECTS WATER_EFFECTS VOLUMETRIC_SHADOWS UNIFIED_WATER TERRAIN_VARIATION TERRAIN_SHADOWS SSS SCREEN_SPACE_SHADOWS LOD_BLENDING ISL LIGHT_LIMIT_FIX CS_HAIR EXTENDED_TRANSLUCENCY EXTENDED_MATERIALS EXP_HEIGHT_FOG CLOUD_SHADOWS TERRAIN_BLENDING SKYLIGHTING IBL DYNAMIC_CUBEMAPS LANDSCAPE MULTI_TEXTURE ANISO_LIGHTING VC
[16:53:14.455] [8924 ] [I] [ShaderTiming] Very slow 33895ms | queue_wait=2ms | remaining=1 | defines=7 | src=109690B | prio=3410 | Lighting:Pixel:GLINT TRUE_PBR DEFERRED WETNESS_EFFECTS WATER_EFFECTS VOLUMETRIC_SHADOWS UNIFIED_WATER TERRAIN_VARIATION TERRAIN_SHADOWS SSS SCREEN_SPACE_SHADOWS LOD_BLENDING ISL LIGHT_LIMIT_FIX CS_HAIR EXTENDED_TRANSLUCENCY EXTENDED_MATERIALS EXP_HEIGHT_FOG CLOUD_SHADOWS TERRAIN_BLENDING SKYLIGHTING IBL DYNAMIC_CUBEMAPS LOD_LAND_BLEND LANDSCAPE MULTI_TEXTURE ANISO_LIGHTING VC

Summary by CodeRabbit

  • Bug Fixes
    • Improved shader compilation timing logs so concurrent updates no longer produce invalid or negative "remaining" values, yielding consistent and reliable debug output during parallel shader builds.

Copilot AI review requested due to automatic review settings May 4, 2026 07:16
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

📝 Walkthrough

Walkthrough

ProcessCompilationSet's remaining-task logging now snapshots atomic counters and uses saturating arithmetic to compute remaining tasks, avoiding unsigned underflow when counters race (e.g., totalTasks can transiently be zero).

Changes

Shader Timing Underflow Prevention

Layer / File(s) Summary
Atomic Snapshot
src/ShaderCache.cpp
Atomically load totalTasks, completedTasks, and failedTasks to capture a consistent snapshot for logging.
Saturating Computation
src/ShaderCache.cpp
Compute done = completed + failed; set doneIncludingCurrent = (done < total) ? done + 1 : done; compute remaining = (total > doneIncludingCurrent) ? (total - doneIncludingCurrent) : 0 to avoid unsigned underflow.
Logging Site
src/ShaderCache.cpp
Use the computed remaining value in [ShaderTiming] logging output instead of previous direct unsigned subtraction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • alandtse
  • doodlum

Poem

🐰
I peeked at counters, soft and small,
I added checks to guard their fall.
No more wrap-around in the night,
Remaining tasks are now polite.
A tiny hop, a careful fix — delight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title 'fix: compiler remaining tasks' directly relates to the main change: fixing incorrect remaining task calculations in shader compiler logging by replacing unsafe subtraction with saturating arithmetic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

No actionable suggestions for changed features.

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 updates shader-compilation telemetry in ShaderCache so the developer-facing timing logs no longer underflow the remaining count when async compilation state is reset during a build.

Changes:

  • Replaced the direct total - completed - failed subtraction with a saturating calculation.
  • Reads totalTasks, completedTasks, and failedTasks explicitly from atomics for the log-only remaining value.
  • Documents the race with Clear() that previously produced uint64_t underflow in shader timing logs.

Comment thread src/ShaderCache.cpp Outdated
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.

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

2969-2974: ⚡ Quick win

Factor out the saturated remaining-count calculation.

This fixes the timing log, but StopCompilation() still uses raw subtraction for the same counters, so the same race can still leak into logs there. A shared helper would keep both call sites consistent.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ShaderCache.cpp` around lines 2969 - 2974, Create a shared helper that
computes the saturated remaining task count from a compilation set instead of
duplicating the subtraction logic: implement a function (e.g.,
computeSaturatedRemaining or saturatedRemainingFor) that reads
compilationSet.totalTasks, compilationSet.completedTasks, and
compilationSet.failedTasks with the same memory_order_relaxed loads and returns
(total > done ? total - done : 0); replace the inline calculation in
ShaderCache.cpp (the current remaining computation using total/completed/failed)
and update StopCompilation() to call this helper so both call sites use the same
race-safe saturated subtraction logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/ShaderCache.cpp`:
- Around line 2969-2974: Create a shared helper that computes the saturated
remaining task count from a compilation set instead of duplicating the
subtraction logic: implement a function (e.g., computeSaturatedRemaining or
saturatedRemainingFor) that reads compilationSet.totalTasks,
compilationSet.completedTasks, and compilationSet.failedTasks with the same
memory_order_relaxed loads and returns (total > done ? total - done : 0);
replace the inline calculation in ShaderCache.cpp (the current remaining
computation using total/completed/failed) and update StopCompilation() to call
this helper so both call sites use the same race-safe saturated subtraction
logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 027f85b3-ef03-4943-950a-3b7b63866a57

📥 Commits

Reviewing files that changed from the base of the PR and between d919016 and fed05b3.

📒 Files selected for processing (1)
  • src/ShaderCache.cpp

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

github-actions Bot commented May 4, 2026

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

@alandtse alandtse changed the title fix: compiler remaining tasks having wrong duration fix: compiler remaining tasks May 5, 2026
@alandtse alandtse merged commit 159367b into community-shaders:dev May 5, 2026
14 checks passed
@davo0411 davo0411 deleted the fix/compiler-remaining-tasks branch May 5, 2026 02:43
SkrubbySkrubInAShrub pushed a commit that referenced this pull request May 14, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 15, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 16, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@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.

3 participants