VSE: Faster timeline thumbnail drawing #126972

Merged
Aras Pranckevicius merged 12 commits from aras_p/blender:vse_thumb_draw_gpu into main 2024-09-03 08:25:38 +02:00

VSE timeline, when many (hundreds/thousands) of thumbnails were visible, was very slow to redraw. This PR makes them 3-10x faster to redraw, by stopping doing things that are slow :) Part of #126087 thumbnail improvements task.

  • No longer do mute semitransparency or corner rounding on the CPU, do it in shader instead.
  • Stop creating a separate GPU texture for each thumbnail, on every repaint, and drawing each thumbnail as a separate draw call. Instead, put thumbnails into a single texture atlas (using a simple shelf packing algorithm), and draw them in batch, passing data via UBO. The atlas is still re-created every frame, but that does not seem to be a performance issue. Thumbnails are cropped horizontally based on how much of their parts are visible (e.g. a narrow strip on screen), so realistically the atlas size is kinda proportional to screen size, and ends up being just several megabytes of data transfer between CPU -> GPU each frame.

On this Sprite Fright edit timeline view (612 visible thumbnails), time taken to repaint the timeline window:

  • Mac (M1 Max, Metal): 68.1ms -> 4.7ms
  • Windows (Ryzen 5950X, RTX 3080Ti, OpenGL): 23.7ms -> 6.8ms

This also fixes a visual issue with thumbnails, where when strips are very tall, the "rounded corners" that were poked right into the thumbnail bitmap on the CPU were showing up due to actual bitmap being scaled up a lot. See lower corners of these strips, where red and yellow strip background respectively pokes through:

That is no longer an issue on this branch:

VSE timeline, when many (hundreds/thousands) of thumbnails were visible, was very slow to redraw. This PR makes them 3-10x faster to redraw, by stopping doing things that are slow :) Part of #126087 thumbnail improvements task. - No longer do mute semitransparency or corner rounding on the CPU, do it in shader instead. - Stop creating a separate GPU texture for each thumbnail, on every repaint, and drawing each thumbnail as a separate draw call. Instead, put thumbnails into a single texture atlas (using a simple shelf packing algorithm), and draw them in batch, passing data via UBO. The atlas is still re-created every frame, but that does not seem to be a performance issue. Thumbnails are cropped horizontally based on how much of their parts are visible (e.g. a narrow strip on screen), so realistically the atlas size is kinda proportional to screen size, and ends up being just several megabytes of data transfer between CPU -> GPU each frame. On this Sprite Fright edit timeline view (612 visible thumbnails), time taken to repaint the timeline window: ![](/attachments/9232caec-42ab-44fb-bb6c-94fc0a68b8aa) - Mac (M1 Max, Metal): **68.1ms -> 4.7ms** - Windows (Ryzen 5950X, RTX 3080Ti, OpenGL): **23.7ms -> 6.8ms** This also fixes a visual issue with thumbnails, where when strips are very tall, the "rounded corners" that were poked right into the thumbnail bitmap on the CPU were showing up due to actual bitmap being scaled up a lot. See lower corners of these strips, where red and yellow strip background respectively pokes through: ![](/attachments/1a51c047-56b0-48a4-88e9-f26ce03401e5) That is no longer an issue on this branch: ![](/attachments/a6c129a0-8ebe-495f-bca5-124e1ec4ed9f)
Aras Pranckevicius added 1 commit 2024-08-30 12:31:26 +02:00
- No longer do mute semitransparency or corner rounding on the CPU,
  do it in shader instead.
- Instead of alternating between "create texture, draw thumb, delete
  texture", create all GPU textures in one go, then draw all of them,
  then delete them.

Mac M1 Max, drawing 612 thumbnails in Sprite Fright edit timeline:
68.1ms -> 31.4ms
Aras Pranckevicius added 1 commit 2024-08-30 14:13:16 +02:00
Creating and updating hundreds of GPU textures is not fast, and
also it causes each thumb to be a separate draw call.

Arrange thumbs into a texture atlas using a simple shelf packing
algorithm, and use that one texture to render all of them.

Mac M1 Max, drawing 612 thumbnails in Sprite Fright edit timeline:
31.4ms -> 8.6ms (atlas size 4096x216).
Aras Pranckevicius added 2 commits 2024-08-30 15:57:35 +02:00
Aras Pranckevicius added 1 commit 2024-08-31 08:23:54 +02:00
Draw thumbnails in batches
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
174a65296a
Instead of doing one immediate mode quad draw per thumbnail,
put data for them into an uniform buffer and draw in batches.

Mac M1 Max, drawing 612 thumbnails in Sprite Fright edit timeline:
8.6ms -> 4.7ms
Aras Pranckevicius added 1 commit 2024-08-31 09:51:54 +02:00
Merge branch 'main' into vse_thumb_draw_gpu
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
3279a60b62
Aras Pranckevicius added 1 commit 2024-08-31 10:40:30 +02:00
Fix Mac gpu tests
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
da5781e319
'color' identifier is defined to `global_uniforms->color` there
Aras Pranckevicius added 1 commit 2024-09-01 09:48:56 +02:00
Aras Pranckevicius added 2 commits 2024-09-01 11:45:15 +02:00
Fix edges of thumbnails sometimes flickering
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
36caaec21a
Array constructor for primitive types leaves them uninitialized,
so space in the atlas in between thumbnails was getting random values
Aras Pranckevicius changed title from WIP: VSE: Faster timeline thumbnail drawing to VSE: Faster timeline thumbnail drawing 2024-09-01 11:55:32 +02:00
Author
Member

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR126972) when ready.
Aras Pranckevicius requested review from Sergey Sharybin 2024-09-01 16:35:20 +02:00
Aras Pranckevicius requested review from Richard Antalik 2024-09-01 16:35:26 +02:00
Aras Pranckevicius added 1 commit 2024-09-01 17:46:28 +02:00
When zoomed in a lot, the thumbnails were slightly "swimming" to the
sides when changing the zoom level slightly, due to them displaying
integer thumbnail image pixels over the horizontal thumbnail area.
But we don't have to do that, UVs can refer to fractions of a pixel
just fine, so switch thumbnail horizontal "crop" values to be floats.
Sergey Sharybin reviewed 2024-09-02 14:34:35 +02:00
Sergey Sharybin left a comment
Owner

Overall looks fine. But there are a couple of inlined comments.

Overall looks fine. But there are a couple of inlined comments.
@ -37,0 +37,4 @@
ImBuf *ibuf;
float left_handle, right_handle, bottom, top;
float x1, x2, y1, y2;
float cropx_min, cropx_max;

Would be nice to have a brief explanation of what exactly those are. Is it handles are in frames, top/bottom in channels., and x/y are in pixel space?

And crop is along X axis for the first/last thumbnail?

Would be nice to have a brief explanation of what exactly those are. Is it handles are in frames, top/bottom in channels., and x/y are in pixel space? And crop is along X axis for the first/last thumbnail?
aras_p marked this conversation as resolved
@ -37,0 +38,4 @@
float left_handle, right_handle, bottom, top;
float x1, x2, y1, y2;
float cropx_min, cropx_max;
bool muted;

Maybe is_muted ?

Maybe `is_muted` ?
aras_p marked this conversation as resolved
Aras Pranckevicius added 1 commit 2024-09-02 17:00:01 +02:00
Sergey Sharybin approved these changes 2024-09-02 17:32:04 +02:00
Richard Antalik approved these changes 2024-09-03 08:06:28 +02:00
Richard Antalik left a comment
Member

Seems pretty straightforward, don't see any obvious issues as well. Performance improvement is definitely noticable with dense timeline!

Seems pretty straightforward, don't see any obvious issues as well. Performance improvement is definitely noticable with dense timeline!
Aras Pranckevicius merged commit 4c8f22447f into main 2024-09-03 08:25:38 +02:00
Aras Pranckevicius deleted branch vse_thumb_draw_gpu 2024-09-03 08:25:41 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 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#126972
No description provided.