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