xref: /aosp_15_r20/external/mesa3d/docs/isl/hiz.rst (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard WorkerHierarchical Depth (HiZ)
2*61046927SAndroid Build Coastguard Worker========================
3*61046927SAndroid Build Coastguard Worker
4*61046927SAndroid Build Coastguard WorkerTODO: Add detailed docs like we have for CCS
5*61046927SAndroid Build Coastguard Worker
6*61046927SAndroid Build Coastguard WorkerHiZ/stencil on Sandy Bridge
7*61046927SAndroid Build Coastguard Worker---------------------------
8*61046927SAndroid Build Coastguard Worker
9*61046927SAndroid Build Coastguard WorkerProperly enabling HiZ on Sandy Bridge requires certain special considerations.
10*61046927SAndroid Build Coastguard WorkerFrom the Sandy Bridge PRM Vol. 2, Pt. 1, 7.5.3 "Hierarchical Depth Buffer" (p.
11*61046927SAndroid Build Coastguard Worker312):
12*61046927SAndroid Build Coastguard Worker
13*61046927SAndroid Build Coastguard Worker   The hierarchical depth buffer does not support the LOD field, it is assumed
14*61046927SAndroid Build Coastguard Worker   by hardware to be zero. A separate hierarchical depth buffer is required
15*61046927SAndroid Build Coastguard Worker   for each LOD used, and the corresponding buffer’s state delivered to
16*61046927SAndroid Build Coastguard Worker   hardware each time a new depth buffer state with modified LOD is delivered.
17*61046927SAndroid Build Coastguard Worker
18*61046927SAndroid Build Coastguard WorkerThe ``3DSTATE_STENCIL_BUFFER`` packet for separate stencil (required for HiZ)
19*61046927SAndroid Build Coastguard Workeron sandy bridge also lacks an LOD field.  Empirically, the hardware doesn't
20*61046927SAndroid Build Coastguard Workerpull the stencil LOD from ``3DSTATE_DEPTH_BUFFER``, it's just always 0 like
21*61046927SAndroid Build Coastguard Workerwith HiZ.
22*61046927SAndroid Build Coastguard Worker
23*61046927SAndroid Build Coastguard WorkerAs stated in the PRM, this means we need a separate HiZ or stencil buffer for
24*61046927SAndroid Build Coastguard Workereach LOD.  However, it's not quite as simple as that.  If you ignore layered
25*61046927SAndroid Build Coastguard Workerrendering, things are pretty straightforward: you need one HiZ surface for each
26*61046927SAndroid Build Coastguard Workermain surface slice. With layered rendering, however, we have to be a bit more
27*61046927SAndroid Build Coastguard Workerclever because we need a "real" array surface at each LOD.  ISL solves this
28*61046927SAndroid Build Coastguard Workerwith a special miptree layout for layered rendering
29*61046927SAndroid Build Coastguard Worker:c:enumerator:`isl_dim_layout.ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ` which lays
30*61046927SAndroid Build Coastguard Workerout the surface as a miptree of layered images instead of an array of miptrees.
31*61046927SAndroid Build Coastguard WorkerSee the docs for
32*61046927SAndroid Build Coastguard Worker:c:enumerator:`isl_dim_layout.ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ` for a nice
33*61046927SAndroid Build Coastguard Workerdescription along with an ASCII art diagram of the layout.
34*61046927SAndroid Build Coastguard Worker
35*61046927SAndroid Build Coastguard WorkerAlso, neither ``3DSTATE_STENCIL_BUFFER`` nor ``3DSTATE_HIER_DEPTH_BUFFER`` have
36*61046927SAndroid Build Coastguard Workertheir own surface dimensions or layout information on Sandy Bridge.  They're
37*61046927SAndroid Build Coastguard Workerjust an address and a surface pitch.  Instead, all that other information is
38*61046927SAndroid Build Coastguard Workerpulled from ``3DSTATE_DEPTH_BUFFER``.  When you combine this with the lack of
39*61046927SAndroid Build Coastguard WorkerLOD, this means that, technically, we have a full-sized single-LOD stencil or
40*61046927SAndroid Build Coastguard WorkerHiZ surface at each miplevel of which only the upper left-hand corner of each
41*61046927SAndroid Build Coastguard Workerarray slice ever gets used.  The net effect of this is that, in
42*61046927SAndroid Build Coastguard Worker:c:enumerator:`isl_dim_layout.ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ`, all LODs
43*61046927SAndroid Build Coastguard Workershare the same QPitch even though it's horribly wasteful.  This is actually
44*61046927SAndroid Build Coastguard Workerpretty convenient for ISL because we only have the one
45*61046927SAndroid Build Coastguard Worker:c:member:`isl_surf.array_pitch_el_rows` field.
46*61046927SAndroid Build Coastguard Worker
47*61046927SAndroid Build Coastguard WorkerDue to difficulties with plumbing relocation deltas through ISL's
48*61046927SAndroid Build Coastguard Workerdepth/stencil/hiz emit interface, we can't handle this all automatically in
49*61046927SAndroid Build Coastguard WorkerISL.  Instead, it's left up to the driver to do this offsetting.  ISL does
50*61046927SAndroid Build Coastguard Workerprovide helpers for computing the offsets and they work fine with
51*61046927SAndroid Build Coastguard Worker:c:enumerator:`isl_dim_layout.ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ` so all that's
52*61046927SAndroid Build Coastguard Workerreally required is to call the ISL helper and add the computed offset to the
53*61046927SAndroid Build Coastguard WorkerHiZ or stencil buffer address.  The following is an excerpt from BLORP where we
54*61046927SAndroid Build Coastguard Workerdo this as an example:
55*61046927SAndroid Build Coastguard Worker
56*61046927SAndroid Build Coastguard Worker.. code-block:: c
57*61046927SAndroid Build Coastguard Worker
58*61046927SAndroid Build Coastguard Worker   struct blorp_address hiz_address = params->depth.aux_addr;
59*61046927SAndroid Build Coastguard Worker   #if GFX_VER == 6
60*61046927SAndroid Build Coastguard Worker   /* Sandy bridge hardware does not technically support mipmapped HiZ.
61*61046927SAndroid Build Coastguard Worker    * However, we have a special layout that allows us to make it work
62*61046927SAndroid Build Coastguard Worker    * anyway by manually offsetting to the specified miplevel.
63*61046927SAndroid Build Coastguard Worker    */
64*61046927SAndroid Build Coastguard Worker   assert(info.hiz_surf->dim_layout == ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ);
65*61046927SAndroid Build Coastguard Worker   uint32_t offset_B;
66*61046927SAndroid Build Coastguard Worker   isl_surf_get_image_offset_B_tile_sa(info.hiz_surf,
67*61046927SAndroid Build Coastguard Worker                                       info.view->base_level, 0, 0,
68*61046927SAndroid Build Coastguard Worker                                       &offset_B, NULL, NULL);
69*61046927SAndroid Build Coastguard Worker   hiz_address.offset += offset_B;
70*61046927SAndroid Build Coastguard Worker   #endif
71*61046927SAndroid Build Coastguard Worker
72*61046927SAndroid Build Coastguard Worker   info.hiz_address =
73*61046927SAndroid Build Coastguard Worker      blorp_emit_reloc(batch, dw + isl_dev->ds.hiz_offset / 4,
74*61046927SAndroid Build Coastguard Worker                       hiz_address, 0);
75