Candera Graphics Programming - Best Practices for Traveo II

Graphics driver and Hardware related Best-Practices

Images and Color formats

Best practice for image drawing:

Bitmaps that contain transparent areas

<Origin>

drawing-7-1743143867.png

<Improved version>

drawing-7-1743143901.png

Bitmap size difference: 102312 ⇔ 49728!

Modify bitmaps with large transparent areas ("U" shape)

drawing-7-1743401243.png

<Origin>

drawing-7-1743144245.png

<Improved version>

drawing-7-1743144200.png

Bitmap size difference: 701568 ⇔ 188904 (55296 + 87528 + 46080)!

Modify bitmaps with large transparent areas (Gauge)

<Origin>

drawing-7-1743144331.png


<Improved version>

drawing-7-1743144366.png

Size difference: 925848 ⇔ 438588 (180940 + 61376 + 196272)!

Single-colored bitmaps

For single-colored bitmaps use BitmapBrushColorBlend and use an alpha only color format e.g. A8 or A4. If further size reduction is required there are also compressed formats but those prohibit scaling and rotation on all types of LBO render targets.

<Origin>

drawing-7-1743144462.png

<Improved version>

drawing-7-1743144481.png

Visual result:

drawing-7-1743401263.png

size reduction: RGBA: 222028 ⇔ 74092!


Combine Bitmaps

Bitmaps can be combined to one bitmap at design time. E.g., tube, scale, and numbers should already be combined if possible.

drawing-7-1743401290.png


Reduce number of objects from 5 to 2. Avoid rendering of non-translatable static text. Only one moving object left and maybe the gauge itself can be put into a background image.

<Origin>

drawing-7-1743144715.png

<Improved version>

drawing-7-1743144740.png

Bitmap size reduction: 1383508 (1000000 + 347508 + 36000) ⇔ 1154000 (1118000 + 36000)!


Compressed image formats

Best practice:


Usage of Bitmap profiles

There are many different bitmap formats available for Traveo2. The goal is always to use a format which uses least memory as possible. The drawback is that some formats have restrictions regarding transformation (rotation, scaling, …).
Best practice is to use RLE formats to reduce memory size. AX (A1, A2, …) formats are used to reduce memory further if just recoloring is needed (white or grayish bitmaps can be recolored in CGI Studio).
If a channel (RGBA) has less than 8 bits you will have a lossy compression.
For special use cases there are formats which can dither bitmaps (Nq, Mc, Nq_FsDithered, Mc_FsDithered. Based on the look and feel on the target, usually different formats of such type must be tested to decide what to use.

drawing-7-1742365920.png

Transformations

Best practice Scaling and Rotation:

drawing-7-1742366036.png

The red gauge should be the required size. The green scale is too big and must be scaled down by to 80%.

drawing-7-1742366072.png

Needed size of gauge will be 925848

<Origin>

drawing-7-1742366119.png

<Improved version>

drawing-7-1742366164.png

Bitmap size comparison: 1449642 ⇔ 925848!

Using Layers

In general, there is always a tradeoff between performance (incl. memory band-with) and memory consumption (e.g., VRAM). Traveo II allows, with the new introduced “Layer-modes” IBO, LBO and OTF, to steer in one of these directions.
Traveo II supports (like Cypress Amber) a huge amount of “separated” Layers, up to 5 “Main-Windows”, 3 of the windows can be split up to 8 sub-windows.
Large area screens shall always be split up to several sub screens to save VRAM consumption.

drawing-7-1742368976.png
Layer types

SurfaceFormat optimization

Before starting the project, it must be decided which format could match the expectations of a customer. If less bits per pixel are sufficient for the look and feel it should be chosen to save VRAM. Keep in mind that for overlapping Layers/RenderTargets an Alpha-value is necessary, otherwise no blending of layers is possible.

drawing-7-1742369423.png

Text

Best practice for drawing text related content:

CGI Studio related Best-Practices

General recommendation

Enable snap to device pixel. This makes sure no filters must be applied that slow down the BLIT operation.

drawing-7-1745412210.png

Only use bilinear filter if an image is rotated, scaled, or positioned between two pixels.
If none of the above happens then stick with the “nearest” filter. Be aware that bilinear is the default filter.

drawing-7-1745412244.png

Memory pools

Always use CGI Studio MemoryPool feature to be able to get some freedom to shift the Text-memory area (used for Text rendering with e.g., Freetype) and default memory area (for CGI Studio) to the right memory location (internal RAM, VRAM, HyperRAM)

Memory pool mechanism:

Memory Pools, Bins, and Backing Heap:
A memory pool represented by class MemoryPool consists of a configurable number of Bins (MemoryPoolBin). Each Bin has a defined buffer size, maintains its own free list (in debug mode also a list of allocated blocks), and thread synchronization. A Bin manages so called blocks. Each block consists of a header (BlockHeader) and the user buffer (the actual buffer returned to the application).
There are two different types of Bins – small and large block Bins. A small block Bin maintains blocks which user buffer matches exactly the size of the defined Bin buffer size. A large buffer Bin maintains blocks that have at least a user buffer size of the Bin buffer size. Small block Bins are used – as the name already indicates – for small memory allocations. A small buffer Bin has less runtime and memory overhead per allocation than a large block Bin.
Whenever the application requests an allocation of a certain number of bytes, MemoryPool will look up the Bin which buffer size matches best the requested number of bytes. If the selected Bin has entries in its free list, the Bin will best fit select one of the free list nodes.

drawing-7-1745412264.png

If a Bin free list is empty, the Bin will try to allocate a new block from the backing heap.
Thus, Bins maintain lists of blocks allocated from the backing heap. If an allocation request cannot be fulfilled by the already allocated blocks, the Bin tries to allocate the block in the backing heap.

drawing-7-1745412287.png

The above figure shows the layered architecture of FeatStd MemoryPool.

The whole memory pool configuration is done at compile time. Thus, no runtime overhead is generated.

Sticky vs Dynamic allocation:
A sticky allocation is an allocation that will never return the allocated block to the backing heap. The block will be managed by the associated Bin (Bin free list).
A block allocated dynamically (not sticky) will be immediately returned to the backing heap when the application frees the block.
With the knowledge whether an allocation is sticky or not, the backing heap can execute the allocation from two distinct memory areas – the sticky area which will never fragment and the dynamic area which can fragment.

Backing Heap:
FeatStd MemoryPool implementation does not depend on a specific backing heap. E.g., standard library malloc and free can be used to implement the backing heap. Such a backing heap is not intended for production environment but might be more convenient than a fixed size heap for development.
FeatStd MemoryPool provides an implementation of a backing heap that can be used out of the box.

drawing-7-1745411983.png

The above figure shows the memory layout of the backing heap. The sticky heap area grows top down, while the dynamic area grows bottom up.
A memory allocation in the sticky area bears no additional overhead. An allocation in the dynamic area has an overhead of 4 bytes required to coalesce consecutive free areas efficiently. Free blocks in the dynamic area are maintained in a free list. On allocation a free list entry will be selected with best fit strategy.

Memory pool Bin-size optimization

Best practice: Do the MemoryPoolBin-optimization to optimize the consumed memory and to achieve a better memory fragmentation while runtime.
To defragment the memory as much as possible and to avoid upcoming “out-of-memory” scenarios you should always do the memory pool optimization on the final application/solution.
Therefor you should perform following steps:

  1. Create your default memory pool configuration
  2. Let the application run for a while with the config, preferably run through all use cases.
  3. Shut down the application and display the statistics on the memory blocks used (e.g., display to console or create a specific text file).
  4. Create an optimized memory config based on the output statistics and start from the beginning (-> 2).

Layer usage

drawing-7-1745412031.png
drawing-7-1745412099.png

Effects

Best practice: