Skip to content

fix(VR): remove pixeloffset overload#2106

Merged
alandtse merged 5 commits into
community-shaders:devfrom
alandtse:stereopt_no_overload
Apr 14, 2026
Merged

fix(VR): remove pixeloffset overload#2106
alandtse merged 5 commits into
community-shaders:devfrom
alandtse:stereopt_no_overload

Conversation

@alandtse
Copy link
Copy Markdown
Collaborator

@alandtse alandtse commented Apr 12, 2026

Depends on #2097

Summary by CodeRabbit

  • New Features

    • VR: per-pixel POM offsets are written to a dedicated R16 texture for stereo blending, depth-aware reprojection, and debug visualization; UI shows a restart-required notice to enable reprojection.
  • Bug Fixes

    • Corrected parallax fallback/init behavior and added explicit POM presence signaling to avoid false positives.
  • Refactor

    • Removed POM encoding from reflectance output and migrated to a dedicated POM offset path.
  • Performance

    • Enabled stereo-optimized shader/runtime paths and bindings to support efficient stereo reprojection.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 12, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7fc98314-902e-4478-ae8c-51efc771fb4b

📥 Commits

Reviewing files that changed from the base of the PR and between 6327b0a and c82084c.

📒 Files selected for processing (1)
  • src/Globals.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Globals.cpp

📝 Walkthrough

Walkthrough

Adds a dedicated single-channel POM offset texture and sentinel, threads a hasPOM out-flag from parallax into Lighting, writes per-pixel offsets (or sentinel) to a UAV, ensures the UAV is created/cleared/bound, and updates StereoBlend to read the new SRV for VR reprojection.

Changes

Cohort / File(s) Summary
Parallax Function Updates
features/Extended Materials/Shaders/ExtendedMaterials/ExtendedMaterials.hlsli
Conditionally added out bool hasPOM to GetParallaxCoords overloads under VR_STEREO_OPT, initialize hasPOM = false and set hasPOM = true when POM executes; changed fallback pixelOffset init from 0.50.0.
Lighting Shader POM Output
package/Shaders/Lighting.hlsl
Added RWTexture2D<float> PomOffsetTex : register(u7) under VR_STEREO_OPT && !SNOW; threaded hasPOM through GetParallaxCoords calls; removed POM encoding in psout.Reflectance.w and write hasPOM ? pixelOffset : Stereo::POM_NO_DATA to the PomOffset UAV.
Stereo Blend Input
package/Shaders/VR/StereoBlendCS.hlsl
Replaced Texture2D<float4> ReflectanceTexture : register(t3) with Texture2D<float> PomOffsetTexture : register(t3); changed POM gating to sentinel/sign test (pomVal >= 0.0) and updated debug visualization and comments.
VRStereoOptimizations Resources/API
src/Features/VRStereoOptimizations.h, src/Features/VRStereoOptimizations.cpp
Added texPomOffset (DXGI_FORMAT_R16_FLOAT) with SRV/UAV, accessors GetPomOffsetSRV()/GetPomOffsetUAV(), ClearPomOffsetTexture() clearing to kPomOffsetNoData = -1.0f; updated debug/UI text.
Deferred Integration
src/Deferred.cpp
Call stereoOpt.ClearPomOffsetTexture() at deferred start when VR-gated; removed forced write-mask override for RT[5].
VR Feature Load & Defines
src/Features/VR.cpp, src/Features/VR.h
SetupResources() now requires Mode SRV plus PomOffset SRV and UAV for stereoOpt.loaded; HasShaderDefine() enables VR_STEREO_OPT for Utility and Lighting shader types when CanDispatchStencil().
Stereo Blend Binding
src/Features/VR/StereoBlend.cpp
Bind dedicated POM offset SRV from stereoOpt.GetPomOffsetSRV() to compute shader slot previously using reflectance SRV.
D3D Hooking
src/Globals.cpp
Added vtable detour for ID3D11DeviceContext::OMSetRenderTargets to rebind PomOffset UAV at UAV slot 7 during deferred pass when stereoOpt is loaded; install gated on isVR and stereoMode != Off.
Shader Common
package/Shaders/Common/VR.hlsli
Added static const float POM_NO_DATA = -1.0 in Stereo namespace under VR_STEREO_OPT, matching CPU sentinel.

Sequence Diagram

sequenceDiagram
    participant Deferred as Deferred
    participant Lighting as LightingPS
    participant PomUAV as PomOffsetTex_UAV
    participant D3D as D3D11_Device
    participant StereoBlend as StereoBlendCS
    participant PomSRV as PomOffsetTexture_SRV

    Deferred->>Deferred: ClearPomOffsetTexture() (write -1.0 sentinel)
    Deferred->>Lighting: Run lighting pass (per-pixel)
    Lighting->>Lighting: GetParallaxCoords(..., out hasPOM)
    alt hasPOM == true
        Lighting->>PomUAV: Write pixelOffset (>= 0.0)
    else hasPOM == false
        Lighting->>PomUAV: Write POM_NO_DATA (-1.0)
    end
    Lighting->>D3D: OMSetRenderTargets(...)
    D3D->>D3D: Hook may rebind POM UAV at UAV slot 7
    StereoBlend->>PomSRV: Sample PomOffsetTexture
    alt pomOffset >= 0.0
        StereoBlend->>StereoBlend: Apply POM reprojection correction
    else
        StereoBlend->>StereoBlend: Skip POM adjustment
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • doodlum

Poem

🐰 I hopped through shaders, soft and spry,
I moved offsets to a single-channel sky.
Sentinel says "-1" where no POM fed,
Lighting writes, Stereo reads — the stitch is spread.
The rabbit naps; VR frames leap high.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(VR): remove pixeloffset overload' directly describes a core change: removing a pixelOffset parameter overload from the GetParallaxCoords function signature across the codebase.

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

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

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

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

@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

🧹 Nitpick comments (1)
src/Features/VRStereoOptimizations.h (1)

66-67: Consider adding an auto-closing issue keyword in the PR description.

If this fully resolves the dependency bug/feature, add Closes #2097 (or `Fixes `#2097) so tracking is automatic.

As per coding guidelines: "When reviewing PRs, please provide suggestions for ... Issue References ... 'Fixes #123' or 'Closes #123' for bug fixes."

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

In `@src/Features/VRStereoOptimizations.h` around lines 66 - 67, Add an
auto-closing issue keyword to the PR description so the change that touches
StereoMode and disocclusionDepthThreshold automatically closes the tracked
issue; update the PR description to include a line like "Closes `#2097`" (or
"Fixes `#2097`") referencing the relevant issue number and ensure it appears in
the top-level PR body so merging will auto-close the issue.
🤖 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/Features/VR.cpp`:
- Around line 123-127: The readiness check currently sets stereoOpt.loaded based
only on stereoOpt.GetModeTextureSRV(), but overwrite mode also needs the POM
texture (texPomOffset); update the logic in the branch that calls
stereoOpt.SetupResources() so that stereoOpt.loaded is true only if
GetModeTextureSRV() != nullptr AND, when stereoOpt.settings.stereoMode indicates
the overwrite/PO M path, the texPomOffset resource was successfully created
(non-null). Ensure this change references stereoOpt.settings.stereoMode,
VRStereoOptimizations::StereoMode::Off, stereoOpt.SetupResources(),
stereoOpt.GetModeTextureSRV(), and texPomOffset so failure to create
texPomOffset will set stereoOpt.loaded = false and allow graceful degradation.

In `@src/Features/VRStereoOptimizations.cpp`:
- Around line 244-249: The UAV clear in
VRStereoOptimizations::ClearPomOffsetTexture uses {0,0,0,0} which conflicts with
Lighting.hlsl's no-POM sentinel (-1.0) and StereoBlendCS.hlsl's logic that
treats >=0.0 as valid; change the clear value to use the no-POM sentinel (e.g.,
-1.0f in the relevant component(s)) so untouched pixels are marked as no-POM
before calling
globals::d3d::context->ClearUnorderedAccessViewFloat(texPomOffset->uav.get(),
...); ensure the same component layout expected by
StereoBlendCS.hlsl/Lighting.hlsl is used.

In `@src/Globals.cpp`:
- Around line 388-393: The detour installation currently gates
stl::detour_vfunc<33, ID3D11DeviceContext_OMSetRenderTargets>,
stl::detour_vfunc<36, ID3D11DeviceContext_OMSetDepthStencilState>, and
stl::detour_vfunc<53, ID3D11DeviceContext_ClearDepthStencilView> behind
globals::features::vr.stereoOpt.settings.stereoMode, preventing enabling stereo
later without restart; remove the stereoMode check so the hooks are installed
regardless of the current stereoMode (e.g., keep the check only on
globals::game::isVR or install unconditionally) so the detours are registered
once and will take effect when the user changes stereoMode at runtime.

---

Nitpick comments:
In `@src/Features/VRStereoOptimizations.h`:
- Around line 66-67: Add an auto-closing issue keyword to the PR description so
the change that touches StereoMode and disocclusionDepthThreshold automatically
closes the tracked issue; update the PR description to include a line like
"Closes `#2097`" (or "Fixes `#2097`") referencing the relevant issue number and
ensure it appears in the top-level PR body so merging will auto-close the issue.
🪄 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: 681ec89a-b9f6-4011-bfc1-244a8a1f5944

📥 Commits

Reviewing files that changed from the base of the PR and between d556a95 and e2364a6.

📒 Files selected for processing (10)
  • features/Extended Materials/Shaders/ExtendedMaterials/ExtendedMaterials.hlsli
  • package/Shaders/Lighting.hlsl
  • package/Shaders/VR/StereoBlendCS.hlsl
  • src/Deferred.cpp
  • src/Features/VR.cpp
  • src/Features/VR.h
  • src/Features/VR/StereoBlend.cpp
  • src/Features/VRStereoOptimizations.cpp
  • src/Features/VRStereoOptimizations.h
  • src/Globals.cpp

Comment thread src/Features/VR.cpp
Comment thread src/Features/VRStereoOptimizations.cpp
Comment thread src/Globals.cpp Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

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

@ParticleTroned
Copy link
Copy Markdown
Contributor

ParticleTroned commented Apr 13, 2026

TB works again as it should.
remaining issues:~

  1. CS ui not stereo/per eye sync
  2. HAM issue Hostile found
  3. in this test SRP caused about 0.4ms extra costs. In my previous test this was about 0.7ms but this was PR2002 and with rain. This test was sunny, hence lighter.

@alandtse alandtse force-pushed the stereopt_no_overload branch from e2364a6 to 629a84c Compare April 13, 2026 04:07
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: 1

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

263-265: Gate this clear on the stereo path being active.

REL::Module::IsVR() is broader than the feature state here. If VRStereoOptimizations is initialized while StereoMode::Off, this still pays a full-frame UAV clear every deferred frame for a disabled path. Please key this off an active-state/helper instead of module type alone. As per coding guidelines, "Consider GPU workload and performance impact when implementing graphics features, with special attention to shader compilation and runtime performance."

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

In `@src/Deferred.cpp` around lines 263 - 265, Replace the broad module check
REL::Module::IsVR() with a stereo-path active check so the POM offset UAV clear
only runs when the VR stereo path is enabled; specifically, in the block that
calls globals::features::vr.stereoOpt.ClearPomOffsetTexture(), gate it on the
stereo feature's active state (for example use
globals::features::vr.stereoOpt.IsActive() or check
globals::features::vr.stereoOpt.GetStereoMode() != StereoMode::Off) instead of
REL::Module::IsVR() so the clear is skipped when the stereo path is initialized
but inactive.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package/Shaders/Lighting.hlsl`:
- Around line 360-365: The comment on the PomOffsetTex RWTexture2D is wrong:
change the sentinel description to indicate that -1.0 means "no POM" and values
>= 0 mean "POM ran" (this matches the clear-to -1.0f in the VRStereo
optimization code and the StereoBlendCS check for >= 0); update the comment next
to PomOffsetTex in Lighting.hlsl and fix the corresponding explanatory comments
in Deferred.cpp and VRStereoOptimizations.h so they consistently state "-1.0 =
no POM; >= 0 = POM ran" and mention that StereoBlendCS treats >= 0 as POM having
executed.

---

Nitpick comments:
In `@src/Deferred.cpp`:
- Around line 263-265: Replace the broad module check REL::Module::IsVR() with a
stereo-path active check so the POM offset UAV clear only runs when the VR
stereo path is enabled; specifically, in the block that calls
globals::features::vr.stereoOpt.ClearPomOffsetTexture(), gate it on the stereo
feature's active state (for example use
globals::features::vr.stereoOpt.IsActive() or check
globals::features::vr.stereoOpt.GetStereoMode() != StereoMode::Off) instead of
REL::Module::IsVR() so the clear is skipped when the stereo path is initialized
but inactive.
🪄 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: 4561a89c-d8e8-4426-ae64-4332fbfee19e

📥 Commits

Reviewing files that changed from the base of the PR and between e2364a6 and 629a84c.

📒 Files selected for processing (10)
  • features/Extended Materials/Shaders/ExtendedMaterials/ExtendedMaterials.hlsli
  • package/Shaders/Lighting.hlsl
  • package/Shaders/VR/StereoBlendCS.hlsl
  • src/Deferred.cpp
  • src/Features/VR.cpp
  • src/Features/VR.h
  • src/Features/VR/StereoBlend.cpp
  • src/Features/VRStereoOptimizations.cpp
  • src/Features/VRStereoOptimizations.h
  • src/Globals.cpp
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/Features/VR/StereoBlend.cpp
  • src/Features/VR.h
  • src/Features/VR.cpp
  • src/Features/VRStereoOptimizations.cpp
  • src/Globals.cpp
  • package/Shaders/VR/StereoBlendCS.hlsl
  • features/Extended Materials/Shaders/ExtendedMaterials/ExtendedMaterials.hlsli

Comment thread package/Shaders/Lighting.hlsl
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: 2

🤖 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 263-265: The POM clear is always executed on VR frames even when
stereo reprojection is inactive; update the conditional around the
ClearPomOffsetTexture() call to also check stereoOpt state (e.g.,
globals::features::vr.stereoOpt.loaded and that
globals::features::vr.stereoOpt.mode is not StereoMode::Off) so
ClearPomOffsetTexture() is only invoked when stereo reprojection is active.

In `@src/Globals.cpp`:
- Around line 294-307: The hook in thunk currently re-binds the POM offset UAV
unconditionally during globals::deferred->deferredPass which leaves the UAV
bound when the MRTs are being cleared; modify the condition to also check
NumViews != 0 before calling stereoOpt.GetPomOffsetUAV() and
This->OMSetRenderTargetsAndUnorderedAccessViews so the UAV is only rebound
during actual render passes (NumViews > 0) and will be unbound during
OMSetRenderTargets(0, nullptr, nullptr) teardown (preventing conflicts with
DrawStereoBlend's CS SRV binding).
🪄 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: 7a9a4a6e-487e-4ed9-8314-c2058730a348

📥 Commits

Reviewing files that changed from the base of the PR and between 629a84c and e170388.

📒 Files selected for processing (7)
  • package/Shaders/Common/VR.hlsli
  • package/Shaders/Lighting.hlsl
  • package/Shaders/VR/StereoBlendCS.hlsl
  • src/Deferred.cpp
  • src/Features/VRStereoOptimizations.cpp
  • src/Features/VRStereoOptimizations.h
  • src/Globals.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Features/VRStereoOptimizations.h

Comment thread src/Deferred.cpp
Comment thread src/Globals.cpp
@alandtse alandtse merged commit 469f0a7 into community-shaders:dev Apr 14, 2026
17 checks passed
YtzyFvra pushed a commit to YtzyFvra/skyrim-community-shaders that referenced this pull request Apr 19, 2026
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