Skip to content

fix: typed uav loads and add logging#2235

Merged
alandtse merged 3 commits into
devfrom
typed-uavs
Apr 30, 2026
Merged

fix: typed uav loads and add logging#2235
alandtse merged 3 commits into
devfrom
typed-uavs

Conversation

@doodlum
Copy link
Copy Markdown
Collaborator

@doodlum doodlum commented Apr 29, 2026

Summary by CodeRabbit

  • New Features

    • Added GPU capability detection to identify hardware support for advanced texture operations, with diagnostic warnings for unsupported configurations.
  • Improvements

    • Enhanced precision for screen-space shadows and depth textures.
    • Improved terrain blending shader support with automatic format detection.
    • Updated texture format alignment between shaders and graphics resources for better stability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

This PR updates GPU resource format types across screen-space shadows and terrain blending shaders to improve compatibility. Multiple textures transition from unorm half to unorm float precision, and depth textures now conditionally declare types based on TERRAIN_BLENDING configuration. C++ code adds conditional shader compilation support and a new GPU capability probe for typed UAV load compatibility.

Changes

Cohort / File(s) Summary
Screen-Space Shadows Shader Resources
features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/RaymarchCS.hlsl, features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ScreenSpaceShadows.hlsli, features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/StereoSyncCS.hlsl, features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/bend_sss_gpu.hlsli
Updated depth and shadow texture types: DepthTexture now conditionally typed based on TERRAIN_BLENDING (float vs. unorm-float); OutputTexture, SrcShadowTexture, and OutShadowTexture changed from unorm half to unorm float.
Terrain Blending Shader
features/Terrain Blending/Shaders/TerrainBlending/DepthBlend.hlsl
Changed BlendedDepthTexture16 UAV type from unorm half to unorm float.
Deferred Rendering
src/Deferred.cpp
Added TERRAIN_BLENDING conditional define during shader compilation in composite paths; updated depth SRV binding to use GetCurrentSceneDepthSRV(false); annotated SRV slot bindings with comments.
Screen-Space Shadows Implementation
src/Features/ScreenSpaceShadows.cpp
Injected TERRAIN_BLENDING define into RaymarchCS and StereoSyncCS shader compilation when terrain blending is loaded; updated depth SRV sourcing via GetCurrentSceneDepthSRV(false).
GPU Capability Detection
src/State.cpp, src/State.h
Added new CheckTypedUAVLoadSupport() method to probe D3D11 GPU support for typed UAV loads across relevant DXGI formats at startup, logging per-format results.
Deferred Composite Shader
package/Shaders/DeferredCompositeCS.hlsl
Added conditional TERRAIN_BLENDING directive to switch depth texture declaration between Texture2D<float> (terrain blending enabled) and Texture2D<unorm float> (disabled).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • alandtse
  • jiayev

Poem

🐰 Half-precision textures hop away,
Float formats bloom in vibrant ray,
Terrain blending picks its type with care,
UAV loads now check the air!
GPU dreams align, so bright and true,

🚥 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.
Title check ✅ Passed The title accurately describes the main objectives of the changeset: fixing typed UAV load support across multiple shader files and adding logging for format support detection.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch typed-uavs

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

Automated formatting by clang-format, prettier, and other hooks.
See https://pre-commit.ci for details.
@github-actions
Copy link
Copy Markdown

No actionable suggestions for changed features.

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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 651426e and 0d518b1.

📒 Files selected for processing (10)
  • features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/RaymarchCS.hlsl
  • features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ScreenSpaceShadows.hlsli
  • features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/StereoSyncCS.hlsl
  • features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/bend_sss_gpu.hlsli
  • features/Terrain Blending/Shaders/TerrainBlending/DepthBlend.hlsl
  • package/Shaders/DeferredCompositePS.hlsl
  • src/Deferred.cpp
  • src/Features/ScreenSpaceShadows.cpp
  • src/State.cpp
  • src/State.h

Comment thread src/Deferred.cpp Outdated
Comment thread src/Features/ScreenSpaceShadows.cpp
Comment thread src/State.cpp
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

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

# Conflicts:
#	package/Shaders/DeferredCompositeCS.hlsl
#	src/Deferred.cpp
@alandtse alandtse changed the title fix: fix and log typed uav loads fix: typed uav loads and add logging Apr 30, 2026
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.

♻️ Duplicate comments (2)
src/Deferred.cpp (1)

642-646: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the same terrain-blending predicate for shader compile and depth binding

TERRAIN_BLENDING is compiled on terrainBlending.loaded (Line 644 / Line 677), but depth binding at Line 361 uses Util::GetCurrentSceneDepthSRV(false), which only returns blended depth when loaded && 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 lift

Persist 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 typedUAVLoadSupport into 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 win

PR 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 add Fixes #<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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d518b1 and 4159e70.

📒 Files selected for processing (4)
  • package/Shaders/DeferredCompositeCS.hlsl
  • src/Deferred.cpp
  • src/State.cpp
  • src/State.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/State.h

@alandtse alandtse merged commit 898f402 into dev Apr 30, 2026
18 checks passed
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 2, 2026
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)
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