The polygon batch submitter.
DxPolygonBatch
00 Remarks
Submitting one draw call per polygon primitive is the main bottleneck of a large polygon scene: every FillGeometry / DrawGeometry call goes through a com interop boundary and forces direct2d to build a new geometry object.
This batch submitter appends every polygon of the same brush as an independent figure of one single ID2D1PathGeometry object, and then all of the accumulated polygons are rasterized by the gpu device through just one draw call, so the per primitive overhead is reduced from O(n) to O(n / batch_size).
The vertex buffer of the figure is written into a pinned scratch buffer that is owned by this submitter, so that no managed array has to be allocated and marshalled for each polygon primitive.
The fill mode of the batch geometry is D2D1_FILL_MODE_WINDING, so that the overlapped area of two polygons is still filled, which keeps the same visual result as drawing the polygons one by one.
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| AddPolygon | 1 | append a closed polygon primitive into the current batch |
| Flush | 1 | submit all of the accumulated polygon primitives to the gpu device |
| Discard | 1 | drop the accumulated polygon primitives without submitting them |
03 Properties
| Name | Overloads | Summary |
|---|---|---|
| PendingFigures | 1 | the amount of the polygon primitives that are accumulated in the current batch |
| CurrentKey | 1 | the brush key of the current pending batch, -1 means nothing pending |
| CurrentIsStroke | 1 | is the pending batch a stroke batch? |
04 Fields
| Name | Overloads | Summary |
|---|---|---|
| MAX_FIGURES | 1 | flush the geometry after this amount of figures so that the memory cost of a single batch is bounded. |
| MAX_SCRATCH_POINTS | 1 | the vertex capacity of the pinned scratch buffer |
| scratch | 1 | a pinned managed vertex buffer, it is reused by every polygon so that no per primitive allocation is required |
05 Members
append a closed polygon primitive into the current batch
| Name | Type | Description |
|---|---|---|
points | PointF() | the vertex buffer of the polygon |
stroke | Boolean | true for a stroke (outline) drawing and false for a fill drawing |
key | Int32 | the brush cache key, a new batch is required when the key is changed |
submit all of the accumulated polygon primitives to the gpu device
drop the accumulated polygon primitives without submitting them
This is required when the render target that owns the pending geometry is not usable any more (a removed gpu device for example): the pending figures can not be rasterized any more, so they are released directly instead of being drawn.
the amount of the polygon primitives that are accumulated in the current batch
the brush key of the current pending batch, -1 means nothing pending
is the pending batch a stroke batch?
flush the geometry after this amount of figures so that the memory cost of a single batch is bounded.
the vertex capacity of the pinned scratch buffer
a pinned managed vertex buffer, it is reused by every polygon so that no per primitive allocation is required