Once again use dedicated GPU buffers for path groups


QCanvasPaths in groups != -1 will now get their dedicated vertex (and,
with fills, index) buffers. The main vertex and index buffers are no
longer used when stroking or filling such paths.

Each QCRhiCachedPathGroup holds up to three QRhiBuffers. The CPU-side
data is uploaded in endPrepare() (endPaint) when the content is dirty,
as in, either a QCanvasPath is different, or, building on previous
patches, a state that affects the geometry (stroke width, AA, etc.)
changes and the path group has no vertex data for that "version" of the
QCanvasPath yet.

When it comes to QCRHIPaths, the main mechanism is used. Drawing a
completely cached path still does allocPaths etc., defering the
offseting of the stroke and fill start values since those are only known
once the GPU buffer data is laid out (the uploads are issued). The
offseting is done only in render() when issuing the actual draw calls.
As a QCRHICall has no knowledge about the QCanvasPath and what "version"
(stroke width, line cap, etc.) of it the call is for, exposing the
relevant data is done by mapping via monotonically increasing quint64
IDs issued to each entry in a path group, and having hash tables in
each path group that effectively only serve endPrepare() - render()
communication.

When it comes to "multi-pass", i.e. when using shared painters with
multiple Canvas Painter items or widgets within the same window, that
should work safely now. The path group buffers are not stored in
PerPassData, unlike the "main" vertex/index buffers. This is important,
since with path group buffers we want persistency between frames when it
comes to the buffer contents, and when items/widgets come and go within
a window, the order of PerPassData and passId will not be stable, so a
consistent path group -> buffers mapping would not be possible. Rather,
the path group owns the buffes and that's that.

Consider the following:

  item1 beginPaint ... endPaint
  item2 beginPaint ... endPaint
  item3 beginPaint ... endPaint
  Qt Quick or the widget backingstore submits the frame

If path group 123 is used in all three items, and some perform a change
either in a QCanvasPath in that group or a state change that affects the
vertex data (e.g. changes the stroke width for a stroke), that will
trigger a rebuild of the GPU buffer(s) as normal, and there is only one
version of them, not three. The trick is to release the QRhiBuffers
lazily (using QRhiResource::deleteLater), so if item1 records some draw
calls with e.g. the stroke vertex buffer of the path group, then item2
decides that the path group needs rebuilding, the stroke buffer (the old
one) will stay valid until the frame is submitted, while the path group
will now hold the new stroke vertex buffer built by item2.

Pick-to: 6.11
Task-number: QTBUG-144831
Change-Id: I3b3bd3260f355369f2de4fb9e734847309abf3cb
Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io>
commit2359553bcdbdcd6363f9727fe8ee688079ece3d6
parentab2c24aadaeff70e3d95c68a16c730d124b89d40
authorLaszlo Agocs <laszlo.agocs@qt.io>
committerLaszlo Agocs <laszlo.agocs@qt.io>
commit timeThu, 23 Apr 2026 15:16:55 +0000