perf(terrain shadows): half res and 4x faster updates#2163
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughDecouples heightmap and shadow texture coordinate spaces: heightmap is resized to half resolution at load, and shader/CPU now use separate pixel dimensions and coordinates for height sampling versus shadow read/write. Changes
Sequence Diagram(s)sequenceDiagram
participant CPU as CPU (TerrainShadows.cpp)
participant GPU as GPU Shader (ShadowUpdate.cs.hlsl)
participant HeightTex as Height Texture (TexHeight)
participant ShadowTex as RW Shadow Texture (RWTexShadowHeights)
CPU->>HeightTex: Load DDS -> ScratchImage -> Resize (half-res)
CPU->>HeightTex: CreateTexture with resized data
CPU->>GPU: UpdateShadow CB (shadowDims, PxSize from ShadowTex)
CPU->>GPU: Dispatch compute
GPU->>HeightTex: Sample height using heightPxCoord (GetInterpolatedHeight)
GPU->>ShadowTex: Read/Write using shadowPxCoord (initial fetch, ray-step, final write)
GPU-->>CPU: Dispatch completes (shadow texture updated)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
No actionable suggestions for changed features. |
There was a problem hiding this comment.
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 `@features/Terrain` Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlsl:
- Around line 66-68: Update the comment block in ShadowUpdate.cs.hlsl to be
implementation-neutral: replace "Heightmap is sampled at full resolution; shadow
is written at half resolution per axis" with wording that describes two
independent coordinate spaces (heightmap sampling space vs shadow-pixel space)
and note that the CPU path may resize the height texture independently of shadow
resolution; keep the note that LightPxDir and PxSize are expressed in
shadow-pixel units and ensure the comment clarifies that sampling/resizing can
be done separately for each space.
In `@src/Features/TerrainShadows.cpp`:
- Around line 230-237: The downsampling uses linear filtering
(DirectX::TEX_FILTER_LINEAR) which can blur peak heights and cause shadow light
leaks for narrow ridges; in the block that reads rawImage / rawMeta and calls
DirectX::Resize, change the filter to TEX_FILTER_POINT (or make the filter
selectable/configurable) to preserve exact height samples, then run visual tests
on varied terrain and document the chosen filter and tradeoffs so we can revert
to linear only if performance/VRAM needs outweigh the visual cost.
🪄 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: bf6f3469-1ce3-4a71-885c-2095ec8fc80e
📒 Files selected for processing (2)
features/Terrain Shadows/Shaders/TerrainShadows/ShadowUpdate.cs.hlslsrc/Features/TerrainShadows.cpp
|
✅ A pre-release build is available for this PR: |
davo0411
left a comment
There was a problem hiding this comment.
does this also effectively separate shadow updates from overwriting the height texture itself?
the textures were always separate. note that the height texture is downscaled too. |
|
@coderabbitai why did this have an extreme negative performance impact |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainLet me look at the actual code changes to diagnose the performance regression. 🏁 Script executed: Length of output: 4529 The CPP output was cut off. Let me get the full file content. 🏁 Script executed: Length of output: 12 Let me search for the files differently. 🏁 Script executed: Length of output: 377 🏁 Script executed: Length of output: 4856
Root Cause: Dispatch Count Not Scaled DownThe AI-generated summary explicitly notes: "The dispatch dimensions were not changed." In In the shader, the wraparound logic in main handles threads that go out of UV range: float2 threadUV = rawThreadUV - floor(rawThreadUV); // wraparoundThis means the excess thread groups (groups Secondary Issue: Redundant
|
Summary by CodeRabbit