EEVEE-Next: Shadow Rendering Refactor #110979

Merged
Clément Foucault merged 34 commits from fclem/blender:eevee-next-shadow-opti into main 2023-08-17 17:35:25 +02:00

Split shadow rendering per LOD per tilemap and improve
fragment shader invocation rate by using multi-viewport.

Also changes the layout of the atlas to be 4 x 4 x Layers.
This allow to grow the atlas while keeping the content
and page indirection correct, but this isn't implemented
in this patch.

First attempt

Shadow rendering using atomic proved to be less than ideal
and performance were not quite to an acceptable level.

The previous method had issue with atomic contention when
a lot of triangle would overlap and too many fragment shader
invocations with quite complex indirection rules and biases
which made the technique costly.

The new implementation leverage multi viewport and
layered rendeing to effectively replace the need for atomic
and render directly to the shadow atlas. Using the well
supported extension these are free on modern hardware and
do not need a geometry shader.

One view per tile is needed since we use the viewport index
and the layer index as a way to index a specific tile in the
array.

Geometric Complexity Problem

The counterpart of this is that we need to draw one geometry
instance per tile which is 32x32 time more instances (at most)
than with the previous method.

This means that we will have to find a way to mitigate this
geometry cost by either reducing the number of tiles per
tilemaps (in other words, making the system less memory efficient)
or splitting complex objects' geometry into smaller, more
cull friendly chunks (for example, like the sculpt PBVH nodes).
The later seems to be a longer term solution as it requires
way too much engineering time we have right now.

Update Lag Problem

This also mean we can only update up to 64 tile per redraw
which is not enough even in the most basic cases. This leads
to missing or over shadowing when a light updates until there
is no updates and the shadow rendering can catch up.

One possible solution is to update a lower LODs first waiting
until there is no update to render. This would allow no artifact
during the transforms (unless there is too many light updates
even for lowest LOD, but that was an issue also for the
previous implementation). This could also help with the
geometric complexity.

Solution

In the end, we decided to have one view per lod. This limits
the complexity of the fragment shader (improve speed),
reduces the number of views per tilemap (fix update lag),
and reduces the number of instances.
This also mean we cannot render directly to the atlas anymore
and reverted to the atomic solution. Using the smallest
possible viewport, we assure that there isn't that much fragment
shader invocations which was one of the bottleneck. And also
reduces the amount of geometry instances that pass the
clipping test.

  • Change atlas to 2D Array
  • Change atomic to also use layers
  • Add viewport array support to main
  • Change the final code to output one view per page and set render resolution to page size
  • Setup viewport array in shadow render code, set render resolution to 4*4 pages.
  • Add non atomic rendering
  • Fix Directional shadows
  • Fix Adaptive Bias
  • Fix Update Lag
  • Fix Geometric Cost
Split shadow rendering per LOD per tilemap and improve fragment shader invocation rate by using multi-viewport. Also changes the layout of the atlas to be 4 x 4 x Layers. This allow to grow the atlas while keeping the content and page indirection correct, but this isn't implemented in this patch. # First attempt Shadow rendering using atomic proved to be less than ideal and performance were not quite to an acceptable level. The previous method had issue with atomic contention when a lot of triangle would overlap and too many fragment shader invocations with quite complex indirection rules and biases which made the technique costly. The new implementation leverage multi viewport and layered rendeing to effectively replace the need for atomic and render directly to the shadow atlas. Using the well supported extension these are free on modern hardware and do not need a geometry shader. One view per tile is needed since we use the viewport index and the layer index as a way to index a specific tile in the array. # Geometric Complexity Problem The counterpart of this is that we need to draw one geometry instance per tile which is 32x32 time more instances (at most) than with the previous method. This means that we will have to find a way to mitigate this geometry cost by either reducing the number of tiles per tilemaps (in other words, making the system less memory efficient) or splitting complex objects' geometry into smaller, more cull friendly chunks (for example, like the sculpt PBVH nodes). The later seems to be a longer term solution as it requires way too much engineering time we have right now. # Update Lag Problem This also mean we can only update up to 64 tile per redraw which is not enough even in the most basic cases. This leads to missing or over shadowing when a light updates until there is no updates and the shadow rendering can catch up. One possible solution is to update a lower LODs first waiting until there is no update to render. This would allow no artifact during the transforms (unless there is too many light updates even for lowest LOD, but that was an issue also for the previous implementation). This could also help with the geometric complexity. # Solution In the end, we decided to have one view per lod. This limits the complexity of the fragment shader (improve speed), reduces the number of views per tilemap (fix update lag), and reduces the number of instances. This also mean we cannot render directly to the atlas anymore and reverted to the atomic solution. Using the smallest possible viewport, we assure that there isn't that much fragment shader invocations which was one of the bottleneck. And also reduces the amount of geometry instances that pass the clipping test. - [x] Change atlas to 2D Array - [x] Change atomic to also use layers - [x] Add viewport array support to main - [x] Change the final code to output one view per page and set render resolution to page size - [x] Setup viewport array in shadow render code, set render resolution to 4*4 pages. - [x] Add non atomic rendering - [x] Fix Directional shadows - [x] Fix Adaptive Bias - [x] Fix Update Lag - [x] Fix Geometric Cost
Clément Foucault added 16 commits 2023-08-09 20:21:27 +02:00
abba9ab2c8 GPU: Framebuffer: Add multi viewport support
This add the possibility to define different
viewports inside a single framebuffer and
let the vertex shader decide which viewport
to render to.

This only contain the GL implementation.
00e517a5bd GPU: Add support for gpu_ViewportIndex
This follows the same emulation path as gpu_Layer.
Layer and ViewportIndex now use the same extension
`ARB_shader_viewport_layer_array`
buildbot/vexp-code-patch-coordinator Build done. Details
ee3f58cdc9
GPU: Add tests for multi viewport
buildbot/vexp-code-patch-coordinator Build done. Details
58cf3ebcd7
Vulkan: Add support for multi viewports
buildbot/vexp-code-patch-coordinator Build done. Details
627ce1f8e4
Fix geometry workaround when extension is not present
0c67996a54 Fix EEVEE-Next: Shadow: Missing shadow on first frame
This was caused by the free unused data pass in the
init phase that would reset the clip data of the first
tilemap.

Uploading and checking for an invalid index fixes the
issue.
5dc8679566 Merge branch 'main' into eevee-next-shadow-opti
# Conflicts:
#	source/blender/draw/engines/eevee_next/shaders/eevee_shadow_tilemap_init_comp.glsl
Clément Foucault added this to the EEVEE & Viewport project 2023-08-09 20:24:27 +02:00
Clément Foucault requested review from Jeroen Bakker 2023-08-09 20:24:37 +02:00
Michael Parkin-White requested changes 2023-08-09 22:14:36 +02:00
@ -861,3 +873,3 @@
struct ShadowTileData {
/** Page inside the virtual shadow map atlas. */
uint2 page;
uint3 page;
First-time contributor

Possible uint3 alignment issue sneaking in. Not sure if these are also host-resident, in which case may need to use uint3_packed

Possible uint3 alignment issue sneaking in. Not sure if these are also host-resident, in which case may need to use uint3_packed
Author
Member

These are not part of a buffer, it is only decoded data that are stored as one uint in the SSBOs. So I think it is safe as is.

These are not part of a buffer, it is only decoded data that are stored as one uint in the SSBOs. So I think it is safe as is.
First-time contributor

Ah no worries then :) Thanks!

Ah no worries then :) Thanks!
First-time contributor

Ah no worries then :) Thanks!

Ah no worries then :) Thanks!
fclem marked this conversation as resolved
Clément Foucault added 1 commit 2023-08-10 15:04:36 +02:00
Clément Foucault added 1 commit 2023-08-14 16:08:59 +02:00
Clément Foucault added 5 commits 2023-08-14 21:57:12 +02:00
Clément Foucault added 4 commits 2023-08-15 17:50:45 +02:00
Clément Foucault added 5 commits 2023-08-16 15:58:10 +02:00
Clément Foucault added 1 commit 2023-08-17 16:12:16 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
aa71b2a1cd
Introduce back the fragment shader biases
Author
Member

@blender-bot build

@blender-bot build
Clément Foucault added 1 commit 2023-08-17 17:19:49 +02:00
b411452e5f Merge branch 'main' into eevee-next-shadow-opti
# Conflicts:
#	source/blender/draw/engines/eevee_next/shaders/infos/eevee_material_info.hh
Clément Foucault requested review from Michael Parkin-White 2023-08-17 17:34:43 +02:00
Clément Foucault merged commit 672d25b02d into main 2023-08-17 17:35:25 +02:00
Clément Foucault deleted branch eevee-next-shadow-opti 2023-08-17 17:35:26 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110979
No description provided.