Realtime Compositor: Add static cached images #115511

Merged
Omar Emara merged 15 commits from OmarEmaraDev/blender:compositor-cached-images into main 2023-12-13 09:50:52 +01:00
Member

The Realtime compositor currently relies on the GPU cache in image IDs.
That cache only supports single layer images, so multi-layer images will
be acquired without a cache, introducing significant IO bottlenecks for
the GPU compositor.

This patch ignores the image GPU cache and stores the images in the
static cache manager of the compositor. Draw data was introduced to the
image ID for proper cache invalidation, like other IDs such as masks.

The downside is that the cache will no longer be shared between EEVEE
and the compositor. But realistically, images are not typically shared
between materials and compositors.

This is just a temporary solution until we have proper GPU storage
support for image buffers.

The Realtime compositor currently relies on the GPU cache in image IDs. That cache only supports single layer images, so multi-layer images will be acquired without a cache, introducing significant IO bottlenecks for the GPU compositor. This patch ignores the image GPU cache and stores the images in the static cache manager of the compositor. Draw data was introduced to the image ID for proper cache invalidation, like other IDs such as masks. The downside is that the cache will no longer be shared between EEVEE and the compositor. But realistically, images are not typically shared between materials and compositors. This is just a temporary solution until we have proper GPU storage support for image buffers.
Omar Emara added the
Interest
Compositing
Module
VFX & Video
labels 2023-11-28 10:22:41 +01:00
Omar Emara added 1 commit 2023-11-28 10:22:52 +01:00
e2082ba634 Realtime Compositor: Add static cached images
The realtime compositor currently relies on the GPU cache in image IDs.
That cache only supports single layer images, so multi-layer images will
be acquired without a cache, introducing significant IO bottlenecks for
the GPU compositor. Furthermore, the image ID GPU cache stores images in
formats that are not compatible with the realtime compositor, producing
erroneous alpha handling and data loss.

This patch ignores the image GPU cache and stores the images in the
static cache manager of the compositor. Draw data was introduced to the
image ID for proper cache invalidation, like other IDs such as masks.
The cached images are ensured to be premultiplied without data loss by
acquiring image buffers with packed alpha, then handling alpha manually.
Omar Emara added 2 commits 2023-11-29 12:22:23 +01:00
Omar Emara added 3 commits 2023-12-01 11:47:12 +01:00
Omar Emara added 1 commit 2023-12-01 15:03:53 +01:00
Omar Emara changed title from WIP: Realtime Compositor: Add static cached images to Realtime Compositor: Add static cached images 2023-12-01 15:04:10 +01:00
Omar Emara requested review from Sergey Sharybin 2023-12-01 15:09:30 +01:00

Do you have some test file you used to test this?

I was testing with the boat_wheel-lookdev file and didn't seem to experience a speedup, even by leaving a single multi-layer image and some math nodes. Not sure if that is already supposed to work, or it has different bottlenecks even in much simplified configuration.

Do you have some test file you used to test this? I was testing with the `boat_wheel-lookdev` file and didn't seem to experience a speedup, even by leaving a single multi-layer image and some math nodes. Not sure if that is already supposed to work, or it has different bottlenecks even in much simplified configuration.
Sergey Sharybin requested review from Brecht Van Lommel 2023-12-01 17:26:03 +01:00
Author
Member

@Sergey It is expected that this doesn't work yet, because of the depsgraph issue we discussed before.

@Sergey It is expected that this doesn't work yet, because of the depsgraph issue we discussed before.

@OmarEmaraDev Ah, right!

@brecht To me the change seems to be fine for until we have a deeper re-design in-place. I tested it on the user side and with some extra changes (see later) it works pretty nice. Would you be able to check it from the code side?

For that extra thing case. Currently depsgraph does special tag when ID is "pulled" into the depsgraph .This happens in the graph_tag_ids_for_visible_update. Now, the Image datablock is tagged for the flag 0, which kind of mis-communicates the fact that image is changed and cache is no longer to be trusted.

I think we can modify the code there in the following way:

    if (ID_TYPE_IS_COW(id_type) || flags != 0) {
      graph_id_tag_update(bmain, graph, id_node->id_orig, flags, DEG_UPDATE_SOURCE_VISIBILITY);
    }

I think it is fine, since if the ID is not covered by the "DEG COW" it doesn't have real evlauation, and tagging is not needed. But would be nice to have this idea verified by someone else :)
If this proposal is correct, then this PR and the proposed extra change leads to quite nice performance imrovement.

@OmarEmaraDev Ah, right! @brecht To me the change seems to be fine for until we have a deeper re-design in-place. I tested it on the user side and with some extra changes (see later) it works pretty nice. Would you be able to check it from the code side? For that extra thing case. Currently depsgraph does special tag when ID is "pulled" into the depsgraph .This happens in the `graph_tag_ids_for_visible_update`. Now, the Image datablock is tagged for the flag 0, which kind of mis-communicates the fact that image is changed and cache is no longer to be trusted. I think we can modify the code there in the following way: ``` if (ID_TYPE_IS_COW(id_type) || flags != 0) { graph_id_tag_update(bmain, graph, id_node->id_orig, flags, DEG_UPDATE_SOURCE_VISIBILITY); } ``` I think it is fine, since if the ID is not covered by the "DEG COW" it doesn't have real evlauation, and tagging is not needed. But would be nice to have this idea verified by someone else :) If this proposal is correct, then this PR and the proposed extra change leads to quite nice performance imrovement.
Omar Emara added 1 commit 2023-12-01 18:26:42 +01:00
Omar Emara added 2 commits 2023-12-05 09:55:04 +01:00
Omar Emara added 1 commit 2023-12-06 17:30:08 +01:00
Brecht Van Lommel requested changes 2023-12-12 16:19:20 +01:00
Brecht Van Lommel left a comment
Owner

This looks fine overall, just one thing I noticed.

This looks fine overall, just one thing I noticed.
@ -339,2 +342,2 @@
/* TODO: implement? */
return IDRecalcFlag(0);
DrawEngineType *owner = (DrawEngineType *)this;
DrawData *draw_data = DRW_drawdata_ensure(id, owner, sizeof(DrawData), nullptr, nullptr);

query_id_recalc_flag is used for movieclips, masks and textures. I don't think those should get drawdata?

No code was added to free such draw data, as was done for images.

`query_id_recalc_flag ` is used for movieclips, masks and textures. I don't think those should get drawdata? No code was added to free such draw data, as was done for images.
Author
Member

@brecht MovieClips, Masks, and Textures got the same code in previous commits. Their BKE free data function have the appropriate DRW_drawdata_free, and draw data exist as part of the ID structure.

Or do you mean something else?

@brecht MovieClips, Masks, and Textures got the same code in previous commits. Their BKE free data function have the appropriate `DRW_drawdata_free`, and draw data exist as part of the ID structure. Or do you mean something else?

Ah, I missed that it was already there.

No problem then.

Ah, I missed that it was already there. No problem then.
brecht marked this conversation as resolved
Brecht Van Lommel approved these changes 2023-12-12 16:26:26 +01:00
Omar Emara added 2 commits 2023-12-12 16:49:08 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
cc97cdb02e
Merge branch 'main' into compositor-cached-images
Author
Member

@blender-bot build

@blender-bot build
Omar Emara added 2 commits 2023-12-13 09:50:03 +01:00
Omar Emara merged commit 356480fabb into main 2023-12-13 09:50:52 +01:00
Omar Emara deleted branch compositor-cached-images 2023-12-13 09:50:59 +01: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 project
No Assignees
3 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#115511
No description provided.