• 沒有找到結果。

The Primitive-Hierarchy Fitting Algorithm

Chapter 3 Design

3.2 The Primitive-Hierarchy Fitting Algorithm

To selection of a suitable layer for primitives much faster, we will improve the algorithm proposed by ARM. The primitive-hierarchy fitting algorithm we proposed to select appropriate layer in square hierarchy is in Figure 3-5.

⎡ ⎤ ⎡ ⎤

( )

N ScreenWidth LayeredTileWidth × ScreenHeight LayeredTileHeight

1

Figure 3-5 The primitive-hierarchy fitting algorithm for square and aligned

Figure 3-6 Tile-based Bounding Box construction. Inner one is the typical bounding box, and outer one is the tile-based bounding box. The

width of tile-based bounding box is 2 and height is 3.

To understand this algorithm, we need to define layer ID first. The bottom layer is layer 0, 2x2 grouped layer is layer 1, 4x4 grouped layer is layer 2 and so on (as Figure 3-1(a) shows). The boundaries of these layered-tiles are power of 2 and groups together to form upper layers’ layered-tiles. Assume we are using 32x32 pixels as our tile size. When the primitive comes, we first construct its tile-based bounding box as in Figure 3-6. The reason to construct such tile-based bounding box is reducing the complexity of computation circuit. The advantage of such bounding box is that it can easily find out the tile-based length of this bounding box and figure out misalignment or not by searching low-order bits of its coordinate directly. To build such bounding

Step 1. Represent primitive with tile-based bounding box

Step 2.(a) Select the shorter side of the bounding box as reference side (b) Perform ceil( log2 length-of(Ref-Side) ) to get layer ID

Step 3. Check the input primitive on selected layer is misalignment or not Yes) Step down one layer and store this primitive

No) Store this primitive into selected layer

box we will round down minimum X and Y value to nearest multiple of 32, if it is on the boundary then leave it on that boundary. And round up the maximum X and Y value to nearest multiple of 32, if it is on the boundary then shift it to next multiple of 32 in order to detect the correct tile-based length of bounding box. Also, the coordinates of tile-based bounding box are all multiple of 32 which can reduce computation complexity of hardware.

After building up the tile-based bounding box, we will select an appropriate layer to store input primitive in square hierarchies. Since all length and positions of tiles and layered-tiles are power of 2. The relationships between layered-tiles in different layers are power of 2, too. To determine which layer should use to store current primitive we might have multiple choices like shorter side, longer side or average length of tile-based bounding box. Because of the power of 2 characteristic of layered-tile’s length in each side, we can use this side’s tile-based length to perform log2 operation to figure out which layer in hierarchy should we put the primitive in. If the length of the side is not multiple of two, the result of log2 operation will contain both integer and non-zero numbers after decimal place. In order to find fittest layered-tile, we will perform a ceiling operation after log2, such that we can round up to nearest layer which can use exactly one layered-tile to cover this bounding box’s width or height.

Figure 3-7 Effects of different reference side in our algorithm

1

As Figure 3-7 above, if we choose longer side of triangle No.1 as reference side and perform log2 and ceiling operations, we will get layer ID is 2 and store it with a 4x4 layered-tile. Although, we can record this primitive with only one layered-tile, most of the screen tiles covered by this 4x4 layered-tile are not covered by this primitive. And it generates 12 unnecessary accesses in rendering. If we choose shorter side as our reference side, triangle No.1 will be recorded in layer 0 with 4 tiles. And this selection would make the shape of final selection result more suitable for this primitive and reduces unnecessary accesses in rendering. If we take another triangle, said triangle No.2 as example. If we choose longer side, this primitive will be recorded in layer 2 which generates 10 useless accesses in rendering. Otherwise, if we choose shorter side as reference side, this primitive will be recorded in layer 1 with 2 layered-tiles which generates 2 useless accesses in rendering. In our algorithm, we choose shorter side as reference side to discover a balance between useless accesses in rendering and storage size requirements.

Figure 3-8 Building lookup table and circuit for Layer ID generation 100

Although the logarithm and ceiling functions will need complex circuit and longer cycle time to finish, our implementation will use a simple way to replace these calculations. Typically, implementation of hierarchical primitive list will use limited layers to ensure hardware’s simplicity. So we can build a lookup table for this logarithm and ceiling operation, and this table can be further reduced via Karnaugh Map. As Figure 3-8 shows, assume we have five layers in our implementation with Layer ID 0 to 4. If length of reference side is larger than 10002 (810) in tiles, then output the layer ID 1002 (410) directly. The others we can use LSB 4-bit from length of reference side in tiles as input to generate 3-bit layer ID. Let input bits from bit-0 to bit-4 be A, B, C, and D. The output bit-0 can be expressed by A + BD + CD’, bit-1 A + B + CD and keep bit-2 always zero. Combine the rules above; we can build the Layer Select Logic to get the Layer ID in a simple circuit.

Figure 3-9 Circuit implementation of the primitive-hierarchy fitting algorithm.

Note that this circuit is a combinational logic. The algorithm steps simply indicates flow of signals, but not states

Primitive BBox Height Primitve BBox Width

To detect the misalignment, we can use an intuitive way since the length of both sides of layered-tiles in square hierarchies are in power of 2; such that we can detect misalignment by directly detect the low-order bits of 4 coordinates (maximum and minimum X, Y) of tile-based bounding box. Put these rules and Layer Select Logic together, we can form our circuit of layer fit algorithm.

Figure 3-9 shows the circuit implementation of primitive-hierarchy fitting algorithm. The comparator takes the input primitive’s tile-based bounding box’s width and height in number of tiles. Then output shorter side as reference side to the Layer Select Logic. The output of Layer Select Logic will be the layer ID. And the four multiplexors will check the maximum and minimum X, Y positions’ values to see whether the primitive in selected layer is misalignment or not. Since typical tile size is 32x32 pixels, the coordinates including tiles and groups must be a multiple of 32. We can determine the input primitive is misalignment or not by checking the low-order bits of its tile-based bounding box’s coordinates. If it is a misalignment then outputs layer ID -1 (step down one layer). If it’s not, outputs the selected layer ID from Layer Select Logic.

As the layer design described in section 3.1, we design two new layers called unaligned grids and rectangular layers. Both these designs have a same characteristic with square hierarchies. For unaligned grids, the height and width of a layered-tile is exactly the same with corresponding layered-tile in square hierarchies. For rectangular layers, the width of vertical rectangle and the height of horizontal rectangle are exactly the same with corresponding layered-tile in square hierarchies.

Due to this characteristic, the Layer Select Logic used in Figure 3-9 can be applied in choose appropriate layer to store primitive in unaligned grids and rectangular layers.

Figure 3-10 Circuit implementation of the primitive-hierarchy fitting algorithm, with fittings to rectangle and unaligned grid variations included

Integrate unaligned grids and rectangular layers with this algorithm. We need to give priorities in order to choose which type of layer is more appropriate to use. In our implementation, the rectangular layer has highest priority and then unaligned grid in the next place, finally square hierarchy is the lowest one. Also, we need to add an output to indicate what type of layer to use alone with layer ID.

Figure 3-11 Comparator in integrated layer selection circuit, with behavior description only

Type of Sharp

Primitive BBox Height Primitve BBox Width

Table 3-1 Table for Layer Type Select High Prim. (100) Vertical

Rectangle (10)

Yes, but boundary check failed (10) Yes, but boundary check

failed (10) Yes, but boundary check

failed (10)

Figure 3-10 shows the implementation of the whole primitive-hierarchy fitting algorithm. The priorities of these different types of hierarchies are encoded in the lookup table as Table 3-1 shows. As Figure 3-11 shows, once the comparator determines this input bounding box whether it is a high or wide rectangle, this primitive will be stored in rectangular layer corresponding to selected layer ID. But if misalignment is found in Misalignment Check, then it will output this information together to Layer Type Select in order to make the correct layer decision. The unaligned grid will be used if this bounding box is misalignment and passed the Boundary Check. Finally, if this bounding box cannot be classified as either rectangular or unaligned grid, then this primitive will be stored in square hierarchies.

相關文件