VSE: speedup timeline drawing, and improve waveform display #115311

Merged
Aras Pranckevicius merged 17 commits from aras_p/blender:vse-draw-opt into main 2023-11-29 20:25:30 +01:00

17 Commits

Author SHA1 Message Date
Aras Pranckevicius be09dfdc29 VSE: retiming draw code: code style, simplify
buildbot/vexp-code-patch-coordinator Build done. Details
2023-11-28 18:27:25 +02:00
Aras Pranckevicius 27817960d2 VSE: simplify code from PR review 2023-11-28 10:27:22 +02:00
Aras Pranckevicius d9c163c8b8 VSE: cleanup VBO usage code in SeqQuadsBatch 2023-11-28 10:21:00 +02:00
Aras Pranckevicius 2202c6f6f4 VSE: bring back "line" waveform drawing parts
Their use case was explained in the code review here
#115311 (comment)
2023-11-27 19:32:04 +02:00
Aras Pranckevicius 79bb07df3b VSE: fix visual ordering issues between unselected and selected strips
Also fixes already existing problem where strip text overlay would
appear "behind" other text overlays, while dragging selected
strip over others.
2023-11-27 19:15:04 +02:00
Aras Pranckevicius 7e72cda82a Merge branch 'main' into vse-draw-opt 2023-11-27 18:26:41 +02:00
Aras Pranckevicius 5f4c5c7369 VSE: code comments 2023-11-25 11:31:08 +02:00
Aras Pranckevicius 93217906f2 VSE: cleanup 2023-11-24 15:40:19 +02:00
Aras Pranckevicius 62115186a4 Merge branch 'main' into vse-draw-opt 2023-11-24 15:21:59 +02:00
Aras Pranckevicius b6f54f5b4a VSE: change most of remaining code to batch quads, cleanup
Where possible, change most of remaining strip drawing parts to use
batched drawing. And now that's done, there's much less need
to separate all of it by "layers", and most of it can go back to the
style of "for all strips: draw these parts" since that all goes
through the same batcher. However thumbnails and the locked
state are still treated as "separate layers" since they use different
shader.
2023-11-24 15:20:44 +02:00
Aras Pranckevicius ed057916a8 VSE: optimize fcurve overlay drawing
Similar to waveform overlay: draw it via batched quads.
On Sprite Fright Edit, fcurve overlay drawing goes
from 11.1ms down to 5.8ms, with most of the remaining cost inside
id_data_find_fcurve.
2023-11-24 11:36:26 +02:00
Aras Pranckevicius cfcd46d855 VSE: optimize draw_channels by speeding up rna_SeqTimelineChannel_owner_get
Drawing the channels list was taking about 3ms on my machine, almost all
of that time querying *all* the VSE strips for each channel mute/lock
button. That is done due to some complexicated code from, where deep
from inside button it calls ui_but_get_fcurve which eventually calls
rna_SeqTimelineChannel_path, which calls rna_SeqTimelineChannel_owner_get,
which was proceeding to construct a set of all the strips.

It's a good question whether this "all the strips" set could be cached
somewhere.

But for now, just change the code to not query all the strips, but
instead query a set of all meta strips, since that's what the code is
only interested in anyway. This makes draw_channels go from 3.0ms
down to 1.3ms.
2023-11-24 10:42:53 +02:00
Aras Pranckevicius 84fd6a17eb VSE: batch draw optimization for draw_strip_offsets
Same story as in previous commits; something like 12ms -> 1ms
with whole sprite fright edit timeline visible.
2023-11-23 20:54:01 +02:00
Aras Pranckevicius b485388b57 VSE: speedup / improve waveform overlay drawing
Drawing strip waveform overlays is both expensive, and has issues due
to how it is being rendered. A design proposal to draw them as
square samples: #115274
and this follows that. While at it:
- The complicated logic to switch between single line and triangle strip
  was removed. Instead the squares are drawn using the same batching
  mechanism added in previous commits.
- Fixes the issue of waveform overshooting the actual data, due to
  sample interpolation wrongly using -0.5..+0.5 range instead of 0..1
  range. This was sometimes causing parts of waveform to be displayed
  as "clipped" too, when in fact actual audio is not.
- Fixes the issue of waveform sample accumulation when pixel covers
  multiple samples, to not properly include all the samples. Was caused
  by start of range using rounded sample number, while end of frame
  using truncated frame number.

In Sprite Fright Edit data set, with whole timeline visible (2702
strips), repainting the timeline UI with audio waveforms takes
(Windows, Ryzen 5950X, RTX 3080Ti): 19.5ms -> 15.1ms
(draw_seq_waveform_overlay 13.5ms -> 8.7ms). Large part of remaining
cost is id_data_find_fcurve lookups.
2023-11-23 20:11:35 +02:00
Aras Pranckevicius 67435f15d0 VSE: fixes for previous commits 2023-11-23 17:44:46 +02:00
Aras Pranckevicius aceff20c3b VSE: speedup timeline drawing pt 2
Drawing of retiming keys was spending almost all the time inside
SEQ_retiming_selection_contains, with essentially squared complexity
(for each retiming key, scanning all existing keys).

Instead, build selected keys into a hashmap via
SEQ_retiming_selection_get for way faster lookup.

In Sprite Fright Edit data set, with whole timeline visible (2702
strips), repainting the timeline UI with audio waveforms takes
(Windows, Ryzen 5950X, RTX 3080Ti): 23ms -> 19.5ms (retime_keys_draw
5.7ms -> 0.9ms)
2023-11-23 17:44:10 +02:00
Aras Pranckevicius b25ac443ef VSE: speedup timeline drawing
The strips and retiming items were drawn one at a time, switching
between GPU shaders, geometry topologies and using tiny immediate
mode batches (often two triangles) for everything.

Optimize that by going way larger GPU batches, like:
- Draw all strip backgrounds at once,
- Draw all strip handles at once,
- Draw all strip outlines at once,
- Draw all retiming continuity sections at once,
- Draw all retiming keyframes at once.

There's no efficient way to draw separate quads in GPU IMM API, so
instead this adds SeqQuadsBatch utility that batches up to 1024
quads for drawing, using indexed vertices.

In Sprite Fright Edit data set, with whole timeline visible (2702
strips), repainting the timeline UI with audio waveforms on takes:

Windows (Ryzen 5950X, RTX 3080Ti): 46ms -> 23ms. Of the time still
left, 14ms is drawing sound waveforms. Remaining cost is other overheads
not directly related to actual rendering (some squared complexity
selection queries, f-curve existence lookups etc.).
2023-11-23 10:56:05 +02:00