Refactor Render Result to allow implicit buffer sharing #108045

Merged
Sergey Sharybin merged 5 commits from Sergey/blender:render_result_implicit_sharing into main 2023-05-23 09:19:44 +02:00

Allows to share buffer data between the render result and image buffers.

The storage of the passes and buffers in the render result have been
wrapped into utility structures, with functions to operate on them.

Currently only image buffers which are sharing buffers with the render
results are using the implicit sharing. This allows proper decoupling of
the image buffers from the lifetime of the underlying render result.

Fixes #107248: Compositor ACCESS VIOLATION when updating datablocks from handlers

Additionally, this lowers the memory usage of multi-layer EXR sequences
by avoiding having two copies of render passes in memory.

It is possible to use implicit sharing in more places, but needs
some API to ensure the render result is the only owner of data before
writing to its pixels.

Allows to share buffer data between the render result and image buffers. The storage of the passes and buffers in the render result have been wrapped into utility structures, with functions to operate on them. Currently only image buffers which are sharing buffers with the render results are using the implicit sharing. This allows proper decoupling of the image buffers from the lifetime of the underlying render result. Fixes #107248: Compositor ACCESS VIOLATION when updating datablocks from handlers Additionally, this lowers the memory usage of multi-layer EXR sequences by avoiding having two copies of render passes in memory. It is possible to use implicit sharing in more places, but needs some API to ensure the render result is the only owner of data before writing to its pixels.
Sergey Sharybin added the
Module
Render & Cycles
label 2023-05-18 13:40:22 +02:00
Sergey Sharybin added 1 commit 2023-05-18 13:40:28 +02:00
1520d9148f Refactor Render Result to allow implicit buffer sharing
Allows to share buffer data between the render result and image buffers.

The storage of the passes and buffers in the render result have been
wrapped into utility structures, with functions to operate on them.

Currently only image buffers which are sharing buffers with the render
results are using the implicit sharing. This allows proper decoupling of
the image buffers from the lifetime of the underlying render result.

Fixes #107248: Compositor ACCESS VIOLATION when updating datablocks from handlers

Additionally, this lowers the memory usage of multi-layer EXR sequences
by avoiding having two copies of render passes in memory.

It is possible to use implicit sharing in more places, but needs
some API to ensure the render result is the only owner of data before
writing to its pixels.
Sergey Sharybin requested review from Brecht Van Lommel 2023-05-18 13:40:34 +02:00
Hans Goudey reviewed 2023-05-18 16:10:07 +02:00
Hans Goudey left a comment
Member

It looks like some of the logic here could be replaced with the helper functions in BLI_implicit_sharing.hh:

  • copy_shared_pointer
  • free_shared_data
  • info_for_mem_free

Even if things get more specific here in the future (less reusable), for now I think it's better to share whatever part of the logic we can, since it makes the patterns much more recognizable and reduces boilerplate.

It looks like some of the logic here could be replaced with the helper functions in `BLI_implicit_sharing.hh`: - `copy_shared_pointer` - `free_shared_data` - `info_for_mem_free` Even if things get more specific here in the future (less reusable), for now I think it's better to share whatever part of the logic we can, since it makes the patterns much more recognizable and reduces boilerplate.
@ -173,0 +176,4 @@
* Note on the implicit sharing
* ----------------------------
*
* The buffer allows to implicitly share data with other users of such data. In this case the
Member

Grammar:
allows to implicitly share -> allows implicitly sharing

Grammar: `allows to implicitly share` -> `allows implicitly sharing`
Sergey Sharybin added 2 commits 2023-05-19 09:50:28 +02:00
Brecht Van Lommel approved these changes 2023-05-19 15:36:35 +02:00
Brecht Van Lommel left a comment
Owner

The implicit sharing stuff seems quite low level and error prone, I feel like this and other places could benefit from a ImplicitSharingVector type similar to ImplicitSharingPtr. But that could require all files using image buffers to be C++, so is an idea for later.

Just one minor comment on the implementation.

The implicit sharing stuff seems quite low level and error prone, I feel like this and other places could benefit from a `ImplicitSharingVector` type similar to `ImplicitSharingPtr`. But that could require all files using image buffers to be C++, so is an idea for later. Just one minor comment on the implementation.
@ -1300,3 +1300,3 @@
* Since we now include paths, I stretched it a bit. Hope this is enough :). */
char str[SDNA_MAX_FILENAME_LENGTH];
sprintf(str, "%s%s", base_directory, includefiles[i]);
snprintf(str, sizeof(str), "%s%s", base_directory, includefiles[i]);

Use BLI_snprintf, snprintf is unsafe.

Use `BLI_snprintf`, `snprintf` is unsafe.
Author
Owner

We don't link against bf_blenlib, so would need to add the string.c to the makesdna target. Doable, but this entire change is not related to the implicit sharing. Something I was looking into to fix warning and never finished, and committed to this branch by accident.

We don't link against bf_blenlib, so would need to add the string.c to the makesdna target. Doable, but this entire change is not related to the implicit sharing. Something I was looking into to fix warning and never finished, and committed to this branch by accident.
Sergey Sharybin added 1 commit 2023-05-19 16:32:46 +02:00
Sergey Sharybin added 1 commit 2023-05-23 09:14:56 +02:00
Sergey Sharybin merged commit a5677d225b into main 2023-05-23 09:19:44 +02:00
Sergey Sharybin deleted branch render_result_implicit_sharing 2023-05-23 09:19:45 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:37 +02:00
Sign in to join this conversation.
No reviewers
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#108045
No description provided.