Viewport Compositor: Render passes support #108618

Open
opened 2023-06-05 12:57:48 +02:00 by Sergey Sharybin · 2 comments

Scope

This design task describes integration of multiple render passes of the same view layer to the viewport compositor.

While ultimately multiple view layers would need to be supported as well, it will be handled separately as there more design considerations to be solved to keep performance and memory usage under control/

Overview

The overall overview of the proposal is quite simple:

  • Render engine provides GPU textures for all render passes.
  • The compositing is done by the draw manager from the Blender side.

Breakdown

GPU texture management

The render engine manages GPU textures on the engine side, and allows them to be bound for the viewport compositor shaders. This allows the engine to have full control over data management and synchronization for updates. For example, it allows engine to do proper initialization order for the graphics interoperability.

Overlays

Some of the data which a render engine wants to visualize does not fit into the compositing pipeline, and is better suitable as an overlay. On example of such visualization is the Active Pixels (available with Cycles Debug).

Such overlays will be moved from "being" baked into the combined pass and instead will become a dedicated call in the render engine draw_overlay().

On the render engine side it will behave the same way as the current draw(): "just" draw a texture(s) with overlays.

Data structures

The proposal is to base the data passed in the API on the RenderResult, and not to create a dedicated specialized data structures. This will allow maximum code re-usaiblity between the viewport, viewport compositor, final renders, and eventually GPU compositor for the final renders.

There are changes which needs to be done in the RenderResult in order to support this, with the final goal is to allow RenderResult to point to a GPU texture instead of CPU-side memory buffer. The proposal here is to:

  • Make RenderResult use ImBuf to store passes data.
  • Make ImBuf have GPU texture without CPU side buffer.

Considerations for such decision:

  • The RenderResult is heavily integrated into the image drawing (for the Render Result image data-block, multi-layer EXR images). If the RenderResult stores data as ImBuf then it will simplify drawing, which will no longer need to do shallow copies.
  • The Image data-block already uses GPU textures, which can be moved to the ImBuf.

Synchronization

Update of the GPU texture and its use by the draw manager happens from different thread, . This is already the case where DisplayDriver takes care of synchronization.

To start with the synchronization strategy will not change:

  • The render engine will lock the GPU textures at the moment when it knows its internal render buffer is in a consistent state (in case of Cycles: when the entire wavefront finished sampling), and will copy data to the GPU textures.
  • From within the same lock the render engine will copy data needed for the overlays.
  • Once the data is copied, the render engine releases the textures lock.
  • When draw manager requests RenderResult it will lock the textures, and will hold the lock until the drawing and compositing pipeline is finished.

This potentially introduces wait-on-a-lock for the render thread: if the compositing takes longer than sampling.

When CPU rendering is used it is relatively easy and beneficial to allow "interleaving": render more samples while the draw manager is still busy with compositing. In the case of Cycles it will mean that the PathTrace will need to take time spent in drawing into account and schedule more samples to fill it in.

For the GPU rendering the story is more complicated:

  • If the rendering and compositing done on the same GPU the interleaving might not be desired at all, as a lot of supported GPUs do not allow interleaving GPGPU and viewport rendering without performance impact.
  • If the rendering is happening on a different GPU than viewport rendering then interleaving is possible.

For the latter either engine could do a guess which GPU is used for viewport, or it would need to be a dedicated API call to provide this information explicitly.

Used render passes

Currently for the viewport render the used render passes are in the full control of the render engine. This needs to be changed to something:

  • Render engine provides list of supported render passes
  • The viewport compositor provides information which of them are actually needed for the viewport

The former is probably already covered with the render passes integration used to create sockets in the Render Layers nodes.

The latter one is needed to make it so unused passes do not take memory: for example if some passes are only used to write to file.

The render pass display option (currently available in Cycles, and allows to choose which render pass is displayed in the viewport) will behave more like it does in the Image Editor where it is possible to choose between Composite output and View Layer / Passes, can then can work for any render engine.

# Scope This design task describes integration of multiple render passes of the same view layer to the viewport compositor. While ultimately multiple view layers would need to be supported as well, it will be handled separately as there more design considerations to be solved to keep performance and memory usage under control/ # Overview The overall overview of the proposal is quite simple: - Render engine provides GPU textures for all render passes. - The compositing is done by the draw manager from the Blender side. # Breakdown ## GPU texture management The render engine manages GPU textures on the engine side, and allows them to be bound for the viewport compositor shaders. This allows the engine to have full control over data management and synchronization for updates. For example, it allows engine to do proper initialization order for the graphics interoperability. ## Overlays Some of the data which a render engine wants to visualize does not fit into the compositing pipeline, and is better suitable as an overlay. On example of such visualization is the `Active Pixels` (available with `Cycles Debug`). Such overlays will be moved from "being" baked into the combined pass and instead will become a dedicated call in the render engine `draw_overlay()`. On the render engine side it will behave the same way as the current `draw()`: "just" draw a texture(s) with overlays. ## Data structures The proposal is to base the data passed in the API on the `RenderResult`, and not to create a dedicated specialized data structures. This will allow maximum code re-usaiblity between the viewport, viewport compositor, final renders, and eventually GPU compositor for the final renders. There are changes which needs to be done in the `RenderResult` in order to support this, with the final goal is to allow `RenderResult` to point to a GPU texture instead of CPU-side memory buffer. The proposal here is to: * Make `RenderResult` use `ImBuf` to store passes data. * Make `ImBuf` have GPU texture without CPU side buffer. Considerations for such decision: * The `RenderResult` is heavily integrated into the image drawing (for the `Render Result` image data-block, multi-layer EXR images). If the `RenderResult` stores data as `ImBuf` then it will simplify drawing, which will no longer need to do shallow copies. * The `Image` data-block already uses GPU textures, which can be moved to the `ImBuf`. ## Synchronization Update of the GPU texture and its use by the draw manager happens from different thread, . This is already the case where `DisplayDriver` takes care of synchronization. To start with the synchronization strategy will not change: * The render engine will lock the GPU textures at the moment when it knows its internal render buffer is in a consistent state (in case of Cycles: when the entire wavefront finished sampling), and will copy data to the GPU textures. * From within the same lock the render engine will copy data needed for the overlays. * Once the data is copied, the render engine releases the textures lock. * When draw manager requests `RenderResult` it will lock the textures, and will hold the lock until the drawing and compositing pipeline is finished. This potentially introduces wait-on-a-lock for the render thread: if the compositing takes longer than sampling. When CPU rendering is used it is relatively easy and beneficial to allow "interleaving": render more samples while the draw manager is still busy with compositing. In the case of Cycles it will mean that the `PathTrace` will need to take time spent in drawing into account and schedule more samples to fill it in. For the GPU rendering the story is more complicated: * If the rendering and compositing done on the same GPU the interleaving might not be desired at all, as a lot of supported GPUs do not allow interleaving GPGPU and viewport rendering without performance impact. * If the rendering is happening on a different GPU than viewport rendering then interleaving is possible. For the latter either engine could do a guess which GPU is used for viewport, or it would need to be a dedicated API call to provide this information explicitly. ## Used render passes Currently for the viewport render the used render passes are in the full control of the render engine. This needs to be changed to something: * Render engine provides list of supported render passes * The viewport compositor provides information which of them are actually needed for the viewport The former is probably already covered with the render passes integration used to create sockets in the Render Layers nodes. The latter one is needed to make it so unused passes do not take memory: for example if some passes are only used to write to file. The render pass display option (currently available in Cycles, and allows to choose which render pass is displayed in the viewport) will behave more like it does in the Image Editor where it is possible to choose between Composite output and View Layer / Passes, can then can work for any render engine.
Sergey Sharybin added the
Type
Design
label 2023-06-05 12:57:48 +02:00
Sergey Sharybin added this to the Compositing project 2023-06-05 12:57:55 +02:00
Member

The GPU textures are currently cached on Image level for the next reason:

  • ImBuf data is not persistent and can be freed, but its GPU textures can still be cached.
  • Tiled data are packed into 2 textures (1d texture with pointers to where a tile is stored in an Image array and the image array them selves)
    So there is some flexibility in changing the caching location, but it might have some aspects to check.

Interleaving compute and graphics pipelines (and transfer operations) are known bottleneck in both Metal/Vulkan. In OpenGL this isn't clear as it is hidden by the driver. Eevee(-next) and the Viewport compositor are relying heavily on compute shaders. If cycles would use compute shaders/direct buffer access we could use synchronizations (semaphores/fences). It would not remove all issues, but put the a different weight on the issues.

In future we could also think about using Async Compute, but that isn't supported by all GPU backends (IntelArc doesn't support this to my knowledge).

The plan still is to upgrade OpenGL to 4.3 in Blender 4.0 what would make (non-async) compute shaders available on all supported platforms.

Not sure if it matters, the viewport compositor uses half float texture formats for performance reasons. If data conversion takes place we should consider doing this in the render engine that provides the render passes. Only exception would be cryptomatte that require F32.

The GPU textures are currently cached on Image level for the next reason: - ImBuf data is not persistent and can be freed, but its GPU textures can still be cached. - Tiled data are packed into 2 textures (1d texture with pointers to where a tile is stored in an Image array and the image array them selves) So there is some flexibility in changing the caching location, but it might have some aspects to check. Interleaving compute and graphics pipelines (and transfer operations) are known bottleneck in both Metal/Vulkan. In OpenGL this isn't clear as it is hidden by the driver. Eevee(-next) and the Viewport compositor are relying heavily on compute shaders. If cycles would use compute shaders/direct buffer access we could use synchronizations (semaphores/fences). It would not remove all issues, but put the a different weight on the issues. In future we could also think about using Async Compute, but that isn't supported by all GPU backends (IntelArc doesn't support this to my knowledge). The plan still is to upgrade OpenGL to 4.3 in Blender 4.0 what would make (non-async) compute shaders available on all supported platforms. Not sure if it matters, the viewport compositor uses half float texture formats for performance reasons. If data conversion takes place we should consider doing this in the render engine that provides the render passes. Only exception would be cryptomatte that require F32.
Member

Additional benefit would be that cpu imbuf data can be freed, but gpu textures could still be kept around.

Would mention that textures views should also be supported. For example EEVEE next stores render passes in small set layered textures (values, vec4 half precision, vec4 full floats). With texture views it would be possible to point to a single layer in one of those textures. Should be transparent as GPUTexture can be a texture or a texture view.

Additional benefit would be that cpu imbuf data can be freed, but gpu textures could still be kept around. Would mention that textures views should also be supported. For example EEVEE next stores render passes in small set layered textures (values, vec4 half precision, vec4 full floats). With texture views it would be possible to point to a single layer in one of those textures. Should be transparent as GPUTexture can be a texture or a texture view.
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 project
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#108618
No description provided.