-
-
Notifications
You must be signed in to change notification settings - Fork 33
Internals
VKVG has a triple buffering system. First, points and paths are emitted with path commands (MoveTo
, LineTo
, CurveTo
, etc..). Draw commands (Fill
, Stroke
) construct vertices with indices and output result in buffers on the cpu side. Depending on the Preserve suffix presence for the draw command, point and path arrays are preserve or not.
Two command buffers are used, one for execution and one for recording. On Stroke or fill, draw commands are recorded into the recording buffer. On flushing, the two buffers are swapped and the recording one pass in the executing state, the swapping is guarded with the flush fence of the context that is raised on execution completion.
Solid color is part of the vertices, so that for solid fill or stroke, drawing commands may be combined in a single draw call. (optimizing the draw batch size). This imply that while emitting vertices in the cache, draw commands recording for solid fill (in ear clipping only) or stroke are delayed until a pipeline change, a push constant update, a buffer resize, ... is required. So you may draw multiple solid colored shapes and finally have only one draw command emitted.
On flushing, cpu caches with vertices and indices are also copied into vulkan buffers while the command buffers are swapped.
This architecture allows drawing while the gpu is working.
The path array holds the subpath topology to pass to the draw commands (fill, stroke). While the point array is a list of 2d coordinates, the path array hold the points count of each subpath. The array is composed of 32 bit integers with only 30 coding bits, the remaining 2 bits are use for additional information's on the path topology.
The most significant bit of the subpath lenth is the Close/open state. If the subpath contains at least one curve, the second most significant bit is set to one (PATH_HAS_CURVES bit), and the whole subpath is segmented. Each segment length follows the subpath total count with the most significant bit set for curved segment, and unset for straight ones. This differentiation is requested for line joins which may occur only between straight segments. Inside curves, no line joins may be emitted.