| 1 |
Units |
| 2 |
===== |
| 3 |
|
| 4 |
Almost every variable, function parameter, or struct field in ISL that carries |
| 5 |
a numeric value has explicit units associated with it. The units used in ISL |
| 6 |
are as follows: |
| 7 |
|
| 8 |
* Pixels (*px*) |
| 9 |
* Samples (*sa*) |
| 10 |
* Elements (*el*) |
| 11 |
* Tiles (*tl*) |
| 12 |
* Bytes (*B*) |
| 13 |
* Rows of some other unit size (*<unit>_rows*) |
| 14 |
|
| 15 |
These units are fundamental to ISL because they allow us to specify information |
| 16 |
about a surface in a canonical way that isn't dependent on hardware generation. |
| 17 |
Each field in an ISL data structure that stores any sort of dimension has a |
| 18 |
suffix that declares the units for that particular value: ``_el`` for elements, |
| 19 |
``_sa`` for samples, etc. If the units of the particular field aren't quite |
| 20 |
what is wanted by the hardware, we do the conversion when we emit |
| 21 |
``RENDER_SURFACE_STATE``. |
| 22 |
|
| 23 |
This is one of the primary differences between ISL and the old miptree code and |
| 24 |
one of the core design principles of ISL. In the old miptree code, we tried to |
| 25 |
keep everything in the same units as the hardware expects but this lead to |
| 26 |
unnecessary complications as the hardware evolved. One example of this |
| 27 |
difference is QPitch which specifies the distance between array slices. On |
| 28 |
Broadwell and earlier, QPitch field in ``RENDER_SURFACE_STATE`` was in |
| 29 |
rows of samples. For block-compressed images, this meant it had to be |
| 30 |
a multiple of the block height. On Skylake, it changed to always being in rows |
| 31 |
of elements so you have to divide the pitch in samples by the compression |
| 32 |
block height. Since the old surface state code tries to store things in |
| 33 |
hardware units, everyone who ever reads ``brw_mipmap_tree.qpitch`` has |
| 34 |
to change their interpretation based on hardware generation and whether or not |
| 35 |
the surface was block-compressed. In ISL, we have |
| 36 |
:c:member:`isl_surf.array_pitch_el_rows` which, as the name says, is in rows |
| 37 |
of elements. On Broadwell and earlier, we have to multiply by the block size |
| 38 |
of the texture when we finally fill out the hardware packet. However, the |
| 39 |
consistency of always being in rows of elements makes any other users of the |
| 40 |
field much simpler because they never have to look at hardware generation or |
| 41 |
whether or not the image is block-compressed. |
| 42 |
|
| 43 |
**Pixels** are the most straightforward unit and are where everything starts. A |
| 44 |
pixel simply corresponds to a single pixel (or texel if you prefer) in the |
| 45 |
surface. For multisampled surfaces, a pixel may contain one or more samples. |
| 46 |
For compressed textures, a compression block may contain one or more pixels. |
| 47 |
When initially creating a surface, everything passed to isl_surf_init is |
| 48 |
implicitly in terms of pixels because this is what all of the APIs use. |
| 49 |
|
| 50 |
The next unit in ISL's repertoire is **samples**. In a multisampled surface, |
| 51 |
each pixel corresponds to some number of samples given by |
| 52 |
:c:member:`isl_surf.samples`. The exact layout of the samples depends on |
| 53 |
the value of :c:member:`isl_surf.msaa_layout`. If the layout is |
| 54 |
:c:enumerator:`isl_msaa_layout.ISL_MSAA_LAYOUT_ARRAY` then each logical array in |
| 55 |
the surface corresponds to :c:member:`isl_surf.samples` actual slices |
| 56 |
in the resulting surface, one per array slice. If the layout is |
| 57 |
:c:enumerator:`isl_msaa_layout.ISL_MSAA_LAYOUT_INTERLEAVED` then each pixel corresponds |
| 58 |
to a 2x1, 2x2, 4x2, or 4x4 grid of samples. In order to aid in calculations, one of |
| 59 |
the first things ISL does is to compute :c:member:`isl_surf.phys_level0_sa` |
| 60 |
which gives the dimensions of the base miplevel of the surface in samples. The |
| 61 |
type of :c:member:`isl_surf.phys_level0_sa` is :c:struct:`isl_extent4d` |
| 62 |
which allows us to express both the array and interleaved cases. Most of the |
| 63 |
calculations of how the different miplevels and array slices are laid out is |
| 64 |
done in terms of samples. |
| 65 |
|
| 66 |
Next, we have surface **elements**. An element is the basic unit of actual |
| 67 |
surface memory. For multisampled textures, an element is equal to a single |
| 68 |
sample. For block compressed textures, an element corresponds to an entire |
| 69 |
compression block. The conversion from samples to elements is given by dividing |
| 70 |
by the block width and block height of the surface format. This is true |
| 71 |
regardless of whether or not the surface is multisampled; for multisampled |
| 72 |
compressed textures (these exist for certain auxiliary formats), the block |
| 73 |
width and block height are expressed in samples. Pixels cannot be converted |
| 74 |
directly to elements or vice versa; any conversion between pixels and elements |
| 75 |
*must* go through samples. |
| 76 |
|
| 77 |
The final surface unit is **tiles**. A tile is a large rectangular block of |
| 78 |
surface data that all fits in a single contiguous block of memory (usually a 4K |
| 79 |
or 64K page, depending on tile format). Tiles are used to provide an |
| 80 |
arrangement of the data in memory that yields better cache performance. The |
| 81 |
size of a tile is always specified in surface elements. |