1b8e80941SmrgIntel Surface Layout
2b8e80941Smrg
3b8e80941SmrgIntroduction
4b8e80941Smrg============
5b8e80941Smrgisl is a small library that calculates the layout of Intel GPU surfaces, queries
6b8e80941Smrgthose layouts, and queries the properties of surface formats.
7b8e80941Smrg
8b8e80941Smrg
9b8e80941SmrgIndependence from User APIs
10b8e80941Smrg===========================
11b8e80941Smrgisl's API is independent of any user-facing graphics API, such as OpenGL and
12b8e80941SmrgVulkan. This independence allows isl to be used a shared component by multiple
13b8e80941SmrgIntel drivers.
14b8e80941Smrg
15b8e80941SmrgRather than mimic the user-facing APIs, the isl API attempts to reflect Intel
16b8e80941Smrghardware: the actual memory layout of Intel GPU surfaces and how one programs
17b8e80941Smrgthe GPU to use those surfaces. For example:
18b8e80941Smrg
19b8e80941Smrg  - The tokens of `enum isl_format` (such as `ISL_FORMAT_R8G8B8A8_UNORM`)
20b8e80941Smrg    match those of the hardware enum `SURFACE_FORMAT` rather than the OpenGL
21b8e80941Smrg    or Vulkan format tokens.  And the values of `isl_format` and
22b8e80941Smrg    `SURFACE_FORMAT` are identical.
23b8e80941Smrg
24b8e80941Smrg  - The OpenGL and Vulkan APIs contain depth and stencil formats. However the
25b8e80941Smrg    hardware enum `SURFACE_FORMAT` does not, and therefore neither does `enum
26b8e80941Smrg    isl_format`. Rather than define new pixel formats that have no hardware
27b8e80941Smrg    counterpart, isl records the intent to use a surface as a depth or stencil
28b8e80941Smrg    buffer with the usage flags `ISL_SURF_USAGE_DEPTH_BIT` and
29b8e80941Smrg    `ISL_SURF_USAGE_STENCIL_BIT`.
30b8e80941Smrg
31b8e80941Smrg  - `struct isl_surf` distinguishes between the surface's logical dimension
32b8e80941Smrg    from the user API's perspective (`enum isl_surf_dim`, which may be 1D, 2D,
33b8e80941Smrg    or 3D) and the layout of those dimensions in memory (`enum isl_dim_layout`).
34b8e80941Smrg
35b8e80941Smrg
36b8e80941SmrgSurface Units
37b8e80941Smrg=============
38b8e80941Smrg
39b8e80941SmrgIntro
40b8e80941Smrg-----
41b8e80941SmrgISL takes care in its equations to correctly handle conversion among surface
42b8e80941Smrgunits (such as pixels and compression blocks) and to carefully distinguish
43b8e80941Smrgbetween a surface's logical layout in the client API and its physical layout
44b8e80941Smrgin memory.
45b8e80941Smrg
46b8e80941SmrgSymbol names often explicitly declare their unit with a suffix:
47b8e80941Smrg
48b8e80941Smrg   - px: logical pixels
49b8e80941Smrg   - sa: physical surface samples
50b8e80941Smrg   - el: physical surface elements
51b8e80941Smrg   - sa_rows: rows of physical surface samples
52b8e80941Smrg   - el_rows: rows of physical surface elements
53b8e80941Smrg
54b8e80941SmrgLogical units are independent of hardware generation and are closely related
55b8e80941Smrgto the user-facing API (OpenGL and Vulkan). Physical units are dependent on
56b8e80941Smrghardware generation and reflect the surface's layout in memory.
57b8e80941Smrg
58b8e80941SmrgDefinitions
59b8e80941Smrg-----------
60b8e80941Smrg- Logical Pixels (px):
61b8e80941Smrg
62b8e80941Smrg  The surface's layout from the perspective of the client API (OpenGL and
63b8e80941Smrg  Vulkan) is in units of logical pixels. Logical pixels are independent of the
64b8e80941Smrg  surface's layout in memory.
65b8e80941Smrg
66b8e80941Smrg  A surface's width and height, in units of logical pixels, is not affected by
67b8e80941Smrg  the surface's sample count. For example, consider a VkImage created with
68b8e80941Smrg  VkImageCreateInfo{width=w0, height=h0, samples=s0}. The surface's width and
69b8e80941Smrg  height at level 0 is, in units of logical pixels, w0 and h0 regardless of
70b8e80941Smrg  the value of s0.
71b8e80941Smrg
72b8e80941Smrg  For example, the logical array length of a 3D surface is always 1, even on
73b8e80941Smrg  Gen9 where the surface's memory layout is that of an array surface
74b8e80941Smrg  (ISL_DIM_LAYOUT_GEN4_2D).
75b8e80941Smrg
76b8e80941Smrg- Physical Surface Samples (sa):
77b8e80941Smrg
78b8e80941Smrg  For a multisampled surface, this unit has the obvious meaning.
79b8e80941Smrg  A singlesampled surface, from ISL's perspective, is simply a multisampled
80b8e80941Smrg  surface whose sample count is 1.
81b8e80941Smrg
82b8e80941Smrg  For example, consider a 2D single-level non-array surface with samples=4,
83b8e80941Smrg  width_px=64, and height_px=64 (note that the suffix 'px' indicates logical
84b8e80941Smrg  pixels). If the surface's multisample layout is ISL_MSAA_LAYOUT_INTERLEAVED,
85b8e80941Smrg  then the extent of level 0 is, in units of physical surface samples,
86b8e80941Smrg  width_sa=128, height_sa=128, depth_sa=1, array_length_sa=1. If
87b8e80941Smrg  ISL_MSAA_LAYOUT_ARRAY, then width_sa=64, height_sa=64, depth_sa=1,
88b8e80941Smrg  array_length_sa=4.
89b8e80941Smrg
90b8e80941Smrg- Physical Surface Elements (el):
91b8e80941Smrg
92b8e80941Smrg  This unit allows ISL to treat compressed and uncompressed formats
93b8e80941Smrg  identically in many calculations.
94b8e80941Smrg
95b8e80941Smrg  If the surface's pixel format is compressed, such as ETC2, then a surface
96b8e80941Smrg  element is equivalent to a compression block. If uncompressed, then
97b8e80941Smrg  a surface element is equivalent to a surface sample. As a corollary, for
98b8e80941Smrg  a given surface a surface element is at least as large as a surface sample.
99b8e80941Smrg
100b8e80941SmrgErrata
101b8e80941Smrg------
102b8e80941SmrgISL acquired the term 'surface element' from the Broadwell PRM [1], which
103b8e80941Smrgdefines it as follows:
104b8e80941Smrg
105b8e80941Smrg   An element is defined as a pixel in uncompresed surface formats, and as
106b8e80941Smrg   a compression block in compressed surface formats. For MSFMT_DEPTH_STENCIL
107b8e80941Smrg   type multisampled surfaces, an element is a sample.
108b8e80941Smrg
109b8e80941Smrg
110b8e80941SmrgReferences
111b8e80941Smrg==========
112b8e80941Smrg[1]: Broadwell PRM >> Volume 2d: Command Reference: Structures >>
113b8e80941Smrg     RENDER_SURFACE_STATE Surface Vertical Alignment (p325)
114