101e04c3fSmrgIntel Surface Layout 201e04c3fSmrg 301e04c3fSmrgIntroduction 401e04c3fSmrg============ 501e04c3fSmrgisl is a small library that calculates the layout of Intel GPU surfaces, queries 601e04c3fSmrgthose layouts, and queries the properties of surface formats. 701e04c3fSmrg 801e04c3fSmrg 901e04c3fSmrgIndependence from User APIs 1001e04c3fSmrg=========================== 1101e04c3fSmrgisl's API is independent of any user-facing graphics API, such as OpenGL and 1201e04c3fSmrgVulkan. This independence allows isl to be used a shared component by multiple 1301e04c3fSmrgIntel drivers. 1401e04c3fSmrg 1501e04c3fSmrgRather than mimic the user-facing APIs, the isl API attempts to reflect Intel 1601e04c3fSmrghardware: the actual memory layout of Intel GPU surfaces and how one programs 1701e04c3fSmrgthe GPU to use those surfaces. For example: 1801e04c3fSmrg 1901e04c3fSmrg - The tokens of `enum isl_format` (such as `ISL_FORMAT_R8G8B8A8_UNORM`) 2001e04c3fSmrg match those of the hardware enum `SURFACE_FORMAT` rather than the OpenGL 2101e04c3fSmrg or Vulkan format tokens. And the values of `isl_format` and 2201e04c3fSmrg `SURFACE_FORMAT` are identical. 2301e04c3fSmrg 2401e04c3fSmrg - The OpenGL and Vulkan APIs contain depth and stencil formats. However the 2501e04c3fSmrg hardware enum `SURFACE_FORMAT` does not, and therefore neither does `enum 2601e04c3fSmrg isl_format`. Rather than define new pixel formats that have no hardware 2701e04c3fSmrg counterpart, isl records the intent to use a surface as a depth or stencil 2801e04c3fSmrg buffer with the usage flags `ISL_SURF_USAGE_DEPTH_BIT` and 2901e04c3fSmrg `ISL_SURF_USAGE_STENCIL_BIT`. 3001e04c3fSmrg 3101e04c3fSmrg - `struct isl_surf` distinguishes between the surface's logical dimension 3201e04c3fSmrg from the user API's perspective (`enum isl_surf_dim`, which may be 1D, 2D, 3301e04c3fSmrg or 3D) and the layout of those dimensions in memory (`enum isl_dim_layout`). 3401e04c3fSmrg 3501e04c3fSmrg 3601e04c3fSmrgSurface Units 3701e04c3fSmrg============= 3801e04c3fSmrg 3901e04c3fSmrgIntro 4001e04c3fSmrg----- 4101e04c3fSmrgISL takes care in its equations to correctly handle conversion among surface 4201e04c3fSmrgunits (such as pixels and compression blocks) and to carefully distinguish 4301e04c3fSmrgbetween a surface's logical layout in the client API and its physical layout 4401e04c3fSmrgin memory. 4501e04c3fSmrg 4601e04c3fSmrgSymbol names often explicitly declare their unit with a suffix: 4701e04c3fSmrg 4801e04c3fSmrg - px: logical pixels 4901e04c3fSmrg - sa: physical surface samples 5001e04c3fSmrg - el: physical surface elements 5101e04c3fSmrg - sa_rows: rows of physical surface samples 5201e04c3fSmrg - el_rows: rows of physical surface elements 5301e04c3fSmrg 5401e04c3fSmrgLogical units are independent of hardware generation and are closely related 5501e04c3fSmrgto the user-facing API (OpenGL and Vulkan). Physical units are dependent on 5601e04c3fSmrghardware generation and reflect the surface's layout in memory. 5701e04c3fSmrg 5801e04c3fSmrgDefinitions 5901e04c3fSmrg----------- 6001e04c3fSmrg- Logical Pixels (px): 6101e04c3fSmrg 6201e04c3fSmrg The surface's layout from the perspective of the client API (OpenGL and 6301e04c3fSmrg Vulkan) is in units of logical pixels. Logical pixels are independent of the 6401e04c3fSmrg surface's layout in memory. 6501e04c3fSmrg 6601e04c3fSmrg A surface's width and height, in units of logical pixels, is not affected by 6701e04c3fSmrg the surface's sample count. For example, consider a VkImage created with 6801e04c3fSmrg VkImageCreateInfo{width=w0, height=h0, samples=s0}. The surface's width and 6901e04c3fSmrg height at level 0 is, in units of logical pixels, w0 and h0 regardless of 7001e04c3fSmrg the value of s0. 7101e04c3fSmrg 7201e04c3fSmrg For example, the logical array length of a 3D surface is always 1, even on 737ec681f3Smrg Gfx9 where the surface's memory layout is that of an array surface 747ec681f3Smrg (ISL_DIM_LAYOUT_GFX4_2D). 7501e04c3fSmrg 7601e04c3fSmrg- Physical Surface Samples (sa): 7701e04c3fSmrg 7801e04c3fSmrg For a multisampled surface, this unit has the obvious meaning. 7901e04c3fSmrg A singlesampled surface, from ISL's perspective, is simply a multisampled 8001e04c3fSmrg surface whose sample count is 1. 8101e04c3fSmrg 8201e04c3fSmrg For example, consider a 2D single-level non-array surface with samples=4, 8301e04c3fSmrg width_px=64, and height_px=64 (note that the suffix 'px' indicates logical 8401e04c3fSmrg pixels). If the surface's multisample layout is ISL_MSAA_LAYOUT_INTERLEAVED, 8501e04c3fSmrg then the extent of level 0 is, in units of physical surface samples, 8601e04c3fSmrg width_sa=128, height_sa=128, depth_sa=1, array_length_sa=1. If 8701e04c3fSmrg ISL_MSAA_LAYOUT_ARRAY, then width_sa=64, height_sa=64, depth_sa=1, 8801e04c3fSmrg array_length_sa=4. 8901e04c3fSmrg 9001e04c3fSmrg- Physical Surface Elements (el): 9101e04c3fSmrg 9201e04c3fSmrg This unit allows ISL to treat compressed and uncompressed formats 9301e04c3fSmrg identically in many calculations. 9401e04c3fSmrg 9501e04c3fSmrg If the surface's pixel format is compressed, such as ETC2, then a surface 9601e04c3fSmrg element is equivalent to a compression block. If uncompressed, then 9701e04c3fSmrg a surface element is equivalent to a surface sample. As a corollary, for 9801e04c3fSmrg a given surface a surface element is at least as large as a surface sample. 9901e04c3fSmrg 10001e04c3fSmrgErrata 10101e04c3fSmrg------ 10201e04c3fSmrgISL acquired the term 'surface element' from the Broadwell PRM [1], which 10301e04c3fSmrgdefines it as follows: 10401e04c3fSmrg 10501e04c3fSmrg An element is defined as a pixel in uncompresed surface formats, and as 10601e04c3fSmrg a compression block in compressed surface formats. For MSFMT_DEPTH_STENCIL 10701e04c3fSmrg type multisampled surfaces, an element is a sample. 10801e04c3fSmrg 10901e04c3fSmrg 11001e04c3fSmrgReferences 11101e04c3fSmrg========== 11201e04c3fSmrg[1]: Broadwell PRM >> Volume 2d: Command Reference: Structures >> 11301e04c3fSmrg RENDER_SURFACE_STATE Surface Vertical Alignment (p325) 114