Several vello stages dynamically bump allocate intermediate data
structures. Due to graphics API limitations the backing memory
for these data structures must have been allocated at the time of
command submission even though the precise memory requirements
are unknown.
Vello currently works around this issue in two ways (see #366):
1. Vello currently prescribes a mechanism in which allocation failures
get detected by fencing back to the CPU. The client responds to
this event by creating larger GPU buffers using the bump
allocator state obtained via read-back. The client has the
choice of dropping skipping a frame or submitting the fine
stage only after any allocations failures get resolved.
2. The encoding crate hard-codes the buffers to be large enough to be
able to render paris-30k, making it unlikely for simple scenes to
under-allocate. This comes at the cost of a fixed memory watermark
of >50MB.
There may be situations when neither of these solutions are desirable
while the cost of additional CPU-side pre-processing is not considered
prohibitive for performance. It may also be acceptable to pay the cost
of generally allocating more than what's required in order to make the
this problem go away entirely (except perhaps for OOM situations).
In that spirit, this change introduces the beginnings of a
heuristic-based conservative memory estimation utility. It currently
estimates only the LineSoup buffer (which contains the curve flattening
output) within a factor of 1.1x-3.3x on the Vello test scenes (paris-30k
is estimated at 1.5x the actual requirement).
- Curves are estimated using Wang's formula which is fast to evaluate
but produces a less optimal result than Vello's analytic approach.
The overestimation is more pronounced with increased curvature
variation.
- Explicit lines (such as line-tos) get estimated precisely
- Only the LineSoup buffer is supported.
- A BumpEstimator is integrated with the Scene API (gated by a feature
flag) but the results are currently unused. Glyph runs are not
supported as the estimator is not yet aware of the path data stored
in glyph cache.