fix: typed uav loads and add logging#2235
Conversation
📝 WalkthroughWalkthroughThis PR updates GPU resource format types across screen-space shadows and terrain blending shaders to improve compatibility. Multiple textures transition from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
Automated formatting by clang-format, prettier, and other hooks. See https://pre-commit.ci for details.
|
No actionable suggestions for changed features. |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Deferred.cpp`:
- Around line 409-424: The DepthTexture binding uses
Util::GetCurrentSceneDepthSRV(false) with a predicate that differs from the
shader's terrain-blending compile-time condition; ensure the same predicate is
used by changing the conditional that decides the t3 binding to the exact
expression used inside Util::GetCurrentSceneDepthSRV(false) (i.e., check
terrainBlending.loaded && terrainBlending.settings.Enabled or the exact same
symbol sequence), so when terrainBlending is loaded but disabled we bind the
non-blended SRV and when enabled we bind the blended R32 SRV—update the
conditional around the t3 (DepthTexture) binding where
Util::GetCurrentSceneDepthSRV(false) is called (also apply the same fix at the
analogous block around lines ~704-707).
In `@src/Features/ScreenSpaceShadows.cpp`:
- Around line 116-122: The shaders are compiled with TERRAIN_BLENDING whenever
terrainBlending.loaded is true, but the runtime SRV selection in
Util::GetCurrentSceneDepthSRV(false) uses terrainBlending.loaded &&
terrainBlending.settings.Enabled, causing a type mismatch; update the compile
predicate at each compile site (e.g., where raymarchCS is created and the other
two compile calls) to use the same condition (terrainBlending.loaded &&
terrainBlending.settings.Enabled) so the defines vector only contains
{"TERRAIN_BLENDING",""} when the blended R32 depth SRV will actually be bound,
keeping shader typing aligned with Util::GetCurrentSceneDepthSRV(false).
In `@src/State.cpp`:
- Around line 211-215: CheckTypedUAVLoadSupport() currently just logs and
returns void; change it to compute and return a persistent result (e.g., a
map/bitset of format->bool) or populate a new State member like
supportsTypedUAVForFormat (or supportsTypedUAV) inside State, then call that
from State::Setup() before Feature::SetupResources so each Feature can read
State::supportsTypedUAVForFormat (or receive the support struct via argument)
and skip/disable typed-UAV initialization or choose non-typed-load shader paths
during SetupResources and at runtime; update Feature::SetupResources() and any
shader-selection/runtime paths to consult the stored support info so unsupported
GPUs gracefully degrade instead of proceeding into undefined typed-UAV loads
(also apply same change to the related logic in the other affected block).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fd10c168-4ca7-4af5-9267-056ff5676469
📒 Files selected for processing (10)
features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/RaymarchCS.hlslfeatures/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ScreenSpaceShadows.hlslifeatures/Screen-Space Shadows/Shaders/ScreenSpaceShadows/StereoSyncCS.hlslfeatures/Screen-Space Shadows/Shaders/ScreenSpaceShadows/bend_sss_gpu.hlslifeatures/Terrain Blending/Shaders/TerrainBlending/DepthBlend.hlslpackage/Shaders/DeferredCompositePS.hlslsrc/Deferred.cppsrc/Features/ScreenSpaceShadows.cppsrc/State.cppsrc/State.h
|
✅ A pre-release build is available for this PR: |
# Conflicts: # package/Shaders/DeferredCompositeCS.hlsl # src/Deferred.cpp
There was a problem hiding this comment.
♻️ Duplicate comments (2)
src/Deferred.cpp (1)
642-646:⚠️ Potential issue | 🟠 Major | ⚡ Quick winUse the same terrain-blending predicate for shader compile and depth binding
TERRAIN_BLENDINGis compiled onterrainBlending.loaded(Line 644 / Line 677), but depth binding at Line 361 usesUtil::GetCurrentSceneDepthSRV(false), which only returns blended depth whenloaded && settings.Enabled. Keep these predicates identical to avoid variant/binding mismatch.Suggested fix
- if (globals::features::terrainBlending.loaded) + if (globals::features::terrainBlending.loaded && globals::features::terrainBlending.settings.Enabled) defines.push_back({ "TERRAIN_BLENDING", nullptr }); ... - if (globals::features::terrainBlending.loaded) + if (globals::features::terrainBlending.loaded && globals::features::terrainBlending.settings.Enabled) defines.push_back({ "TERRAIN_BLENDING", nullptr });Also applies to: 675-679
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Deferred.cpp` around lines 642 - 646, The shader define TERRAIN_BLENDING is being added based only on globals::features::terrainBlending.loaded, but the depth SRV binding uses Util::GetCurrentSceneDepthSRV(false) which returns blended depth only when both loaded and settings.Enabled; make the predicates identical by changing the define sites (the defines.push_back({ "TERRAIN_BLENDING", nullptr }) occurrences) to only add TERRAIN_BLENDING when globals::features::terrainBlending.loaded && settings.Enabled (the same condition as used by Util::GetCurrentSceneDepthSRV(false)), and update the other define occurrence likewise so compile-time variant and runtime depth binding match.src/State.cpp (1)
669-725:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftPersist probe results and gate unsupported typed-UAV paths
State::CheckTypedUAVLoadSupport()(Line 669) is still diagnostics-only. Even when unsupported formats are detected,State::Setup()continues into feature setup with no fallback/gating, so unsupported GPUs can still hit undefined typed-UAV reads.Suggested direction
-void State::CheckTypedUAVLoadSupport() +TypedUAVLoadSupport State::CheckTypedUAVLoadSupport() { + TypedUAVLoadSupport result{}; ... - if (anyUnsupported) { + if (anyUnsupported) { logger::warn(...); } + return result; } void State::Setup() { + typedUAVLoadSupport = CheckTypedUAVLoadSupport(); Feature::ForEachLoadedFeature("SetupResources", [](Feature* feature) { feature->SetupResources(); }); }Then wire
typedUAVLoadSupportinto feature setup/runtime shader-path selection so unsupported formats degrade gracefully instead of running typed-load code paths.As per coding guidelines "Include proper resource management and graceful degradation for DirectX 11 resources and user input validation to prevent crashes from malformed configurations".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/State.cpp` around lines 669 - 725, State::CheckTypedUAVLoadSupport currently only logs results; persist an aggregated result (add a member like bool typedUAVLoadSupport or a bitmask per DXGI_FORMAT) and set it from CheckTypedUAVLoadSupport after probing kFormats (set false if anyUnsupported or clear specific-format bits). Then update State::Setup to consult that member before enabling features or binding shaders that perform RWTexture<T> typed reads — if typedUAVLoadSupport is false, disable or skip enabling Dynamic Cubemaps, Grass Collision, Terrain Shadows, Skylighting, HDR Display UI brightness and VR stereo optimisations (or select fallback/untyped shader paths), and emit a clear logger::warn noting which features were gated so runtime avoids undefined typed-UAV reads.
🧹 Nitpick comments (1)
src/State.cpp (1)
206-223: ⚡ Quick winPR metadata suggestion: tighten title and link issue
Current title is valid but repetitive. Consider:
fix(state): probe and gate typed uav load support(or equivalent), and addFixes #<id>/Addresses #<id>in the PR body if applicable.As per coding guidelines "
**/*: provide suggestions for conventional commit titles and issue references when relevant".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/State.cpp` around lines 206 - 223, Update the PR metadata: tighten the title to a conventional-commit style (e.g., "fix(state): probe and gate typed uav load support") and add an issue reference like "Fixes #<id>" or "Addresses #<id>" in the PR body; mention the changed behavior in State::Setup (CheckTypedUAVLoadSupport invocation) so reviewers can map the commit to the code path (State::Setup, CheckTypedUAVLoadSupport, Feature::ForEachLoadedFeature).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/Deferred.cpp`:
- Around line 642-646: The shader define TERRAIN_BLENDING is being added based
only on globals::features::terrainBlending.loaded, but the depth SRV binding
uses Util::GetCurrentSceneDepthSRV(false) which returns blended depth only when
both loaded and settings.Enabled; make the predicates identical by changing the
define sites (the defines.push_back({ "TERRAIN_BLENDING", nullptr })
occurrences) to only add TERRAIN_BLENDING when
globals::features::terrainBlending.loaded && settings.Enabled (the same
condition as used by Util::GetCurrentSceneDepthSRV(false)), and update the other
define occurrence likewise so compile-time variant and runtime depth binding
match.
In `@src/State.cpp`:
- Around line 669-725: State::CheckTypedUAVLoadSupport currently only logs
results; persist an aggregated result (add a member like bool
typedUAVLoadSupport or a bitmask per DXGI_FORMAT) and set it from
CheckTypedUAVLoadSupport after probing kFormats (set false if anyUnsupported or
clear specific-format bits). Then update State::Setup to consult that member
before enabling features or binding shaders that perform RWTexture<T> typed
reads — if typedUAVLoadSupport is false, disable or skip enabling Dynamic
Cubemaps, Grass Collision, Terrain Shadows, Skylighting, HDR Display UI
brightness and VR stereo optimisations (or select fallback/untyped shader
paths), and emit a clear logger::warn noting which features were gated so
runtime avoids undefined typed-UAV reads.
---
Nitpick comments:
In `@src/State.cpp`:
- Around line 206-223: Update the PR metadata: tighten the title to a
conventional-commit style (e.g., "fix(state): probe and gate typed uav load
support") and add an issue reference like "Fixes #<id>" or "Addresses #<id>" in
the PR body; mention the changed behavior in State::Setup
(CheckTypedUAVLoadSupport invocation) so reviewers can map the commit to the
code path (State::Setup, CheckTypedUAVLoadSupport,
Feature::ForEachLoadedFeature).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 39a6fcbe-798b-487a-b9ee-bd198daa8eaf
📒 Files selected for processing (4)
package/Shaders/DeferredCompositeCS.hlslsrc/Deferred.cppsrc/State.cppsrc/State.h
🚧 Files skipped from review as they are similar to previous changes (1)
- src/State.h
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alan Tse <alandtse@gmail.com> (cherry picked from commit 898f402)
Summary by CodeRabbit
New Features
Improvements