1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2016 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci *  Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci *  copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci *  to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci *  and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci *  Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci *  The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci *  paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci *  Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci *  IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include <stdint.h>
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#define __gen_address_type uint64_t
27bf215546Sopenharmony_ci#define __gen_user_data void
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_cistatic uint64_t
30bf215546Sopenharmony_ci__gen_combine_address(__attribute__((unused)) void *data,
31bf215546Sopenharmony_ci                      __attribute__((unused)) void *loc, uint64_t addr,
32bf215546Sopenharmony_ci                      uint32_t delta)
33bf215546Sopenharmony_ci{
34bf215546Sopenharmony_ci   return addr + delta;
35bf215546Sopenharmony_ci}
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "genxml/gen_macros.h"
38bf215546Sopenharmony_ci#include "genxml/genX_pack.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci#include "isl_priv.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistatic const uint32_t isl_encode_ds_surftype[] = {
43bf215546Sopenharmony_ci#if GFX_VER >= 9
44bf215546Sopenharmony_ci   /* From the SKL PRM, "3DSTATE_DEPTH_STENCIL::SurfaceType":
45bf215546Sopenharmony_ci    *
46bf215546Sopenharmony_ci    *    "If depth/stencil is enabled with 1D render target, depth/stencil
47bf215546Sopenharmony_ci    *    surface type needs to be set to 2D surface type and height set to 1.
48bf215546Sopenharmony_ci    *    Depth will use (legacy) TileY and stencil will use TileW. For this
49bf215546Sopenharmony_ci    *    case only, the Surface Type of the depth buffer can be 2D while the
50bf215546Sopenharmony_ci    *    Surface Type of the render target(s) are 1D, representing an
51bf215546Sopenharmony_ci    *    exception to a programming note above.
52bf215546Sopenharmony_ci    */
53bf215546Sopenharmony_ci   [ISL_SURF_DIM_1D] = SURFTYPE_2D,
54bf215546Sopenharmony_ci#else
55bf215546Sopenharmony_ci   [ISL_SURF_DIM_1D] = SURFTYPE_1D,
56bf215546Sopenharmony_ci#endif
57bf215546Sopenharmony_ci   [ISL_SURF_DIM_2D] = SURFTYPE_2D,
58bf215546Sopenharmony_ci   [ISL_SURF_DIM_3D] = SURFTYPE_3D,
59bf215546Sopenharmony_ci};
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci#if GFX_VERx10 >= 125
62bf215546Sopenharmony_cistatic const uint8_t isl_encode_tiling[] = {
63bf215546Sopenharmony_ci   [ISL_TILING_4]  = TILE4,
64bf215546Sopenharmony_ci   [ISL_TILING_64] = TILE64,
65bf215546Sopenharmony_ci};
66bf215546Sopenharmony_ci#endif
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_civoid
69bf215546Sopenharmony_ciisl_genX(emit_depth_stencil_hiz_s)(const struct isl_device *dev, void *batch,
70bf215546Sopenharmony_ci                                   const struct isl_depth_stencil_hiz_emit_info *restrict info)
71bf215546Sopenharmony_ci{
72bf215546Sopenharmony_ci   struct GENX(3DSTATE_DEPTH_BUFFER) db = {
73bf215546Sopenharmony_ci      GENX(3DSTATE_DEPTH_BUFFER_header),
74bf215546Sopenharmony_ci#if GFX_VER >= 6
75bf215546Sopenharmony_ci      .MOCS = info->mocs,
76bf215546Sopenharmony_ci#endif
77bf215546Sopenharmony_ci   };
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   if (info->depth_surf) {
80bf215546Sopenharmony_ci      db.SurfaceType = isl_encode_ds_surftype[info->depth_surf->dim];
81bf215546Sopenharmony_ci      db.SurfaceFormat = isl_surf_get_depth_format(dev, info->depth_surf);
82bf215546Sopenharmony_ci      db.Width = info->depth_surf->logical_level0_px.width - 1;
83bf215546Sopenharmony_ci      db.Height = info->depth_surf->logical_level0_px.height - 1;
84bf215546Sopenharmony_ci      if (db.SurfaceType == SURFTYPE_3D)
85bf215546Sopenharmony_ci         db.Depth = info->depth_surf->logical_level0_px.depth - 1;
86bf215546Sopenharmony_ci   } else if (info->stencil_surf) {
87bf215546Sopenharmony_ci      db.SurfaceType = isl_encode_ds_surftype[info->stencil_surf->dim];
88bf215546Sopenharmony_ci      db.SurfaceFormat = D32_FLOAT;
89bf215546Sopenharmony_ci      db.Width = info->stencil_surf->logical_level0_px.width - 1;
90bf215546Sopenharmony_ci      db.Height = info->stencil_surf->logical_level0_px.height - 1;
91bf215546Sopenharmony_ci      if (db.SurfaceType == SURFTYPE_3D)
92bf215546Sopenharmony_ci         db.Depth = info->stencil_surf->logical_level0_px.depth - 1;
93bf215546Sopenharmony_ci   } else {
94bf215546Sopenharmony_ci      db.SurfaceType = SURFTYPE_NULL;
95bf215546Sopenharmony_ci      db.SurfaceFormat = D32_FLOAT;
96bf215546Sopenharmony_ci   }
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci   if (info->depth_surf || info->stencil_surf) {
99bf215546Sopenharmony_ci      /* These are based entirely on the view */
100bf215546Sopenharmony_ci      db.RenderTargetViewExtent = info->view->array_len - 1;
101bf215546Sopenharmony_ci      db.LOD                  = info->view->base_level;
102bf215546Sopenharmony_ci      db.MinimumArrayElement  = info->view->base_array_layer;
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci      /* From the Haswell PRM docs for 3DSTATE_DEPTH_BUFFER::Depth
105bf215546Sopenharmony_ci       *
106bf215546Sopenharmony_ci       *    "This field specifies the total number of levels for a volume
107bf215546Sopenharmony_ci       *    texture or the number of array elements allowed to be accessed
108bf215546Sopenharmony_ci       *    starting at the Minimum Array Element for arrayed surfaces. If the
109bf215546Sopenharmony_ci       *    volume texture is MIP-mapped, this field specifies the depth of
110bf215546Sopenharmony_ci       *    the base MIP level."
111bf215546Sopenharmony_ci       *
112bf215546Sopenharmony_ci       * For 3D surfaces, we set it to the correct depth above.  For non-3D
113bf215546Sopenharmony_ci       * surfaces, this is the same as RenderTargetViewExtent.
114bf215546Sopenharmony_ci       */
115bf215546Sopenharmony_ci      if (db.SurfaceType != SURFTYPE_3D)
116bf215546Sopenharmony_ci         db.Depth = db.RenderTargetViewExtent;
117bf215546Sopenharmony_ci   }
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   if (info->depth_surf) {
120bf215546Sopenharmony_ci#if GFX_VER >= 7
121bf215546Sopenharmony_ci      db.DepthWriteEnable = true;
122bf215546Sopenharmony_ci#endif
123bf215546Sopenharmony_ci      db.SurfaceBaseAddress = info->depth_address;
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci#if GFX_VERx10 >= 125
126bf215546Sopenharmony_ci      db.TiledMode = isl_encode_tiling[info->depth_surf->tiling];
127bf215546Sopenharmony_ci      db.MipTailStartLOD = 15;
128bf215546Sopenharmony_ci      db.CompressionMode = isl_aux_usage_has_ccs(info->hiz_usage);
129bf215546Sopenharmony_ci      db.RenderCompressionFormat =
130bf215546Sopenharmony_ci         isl_get_render_compression_format(info->depth_surf->format);
131bf215546Sopenharmony_ci#elif GFX_VER <= 6
132bf215546Sopenharmony_ci      assert(info->depth_surf->tiling == ISL_TILING_Y0);
133bf215546Sopenharmony_ci      db.TiledSurface = true;
134bf215546Sopenharmony_ci      db.TileWalk = TILEWALK_YMAJOR;
135bf215546Sopenharmony_ci      db.MIPMapLayoutMode = MIPLAYOUT_BELOW;
136bf215546Sopenharmony_ci#endif
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci      db.SurfacePitch = info->depth_surf->row_pitch_B - 1;
139bf215546Sopenharmony_ci#if GFX_VER >= 8
140bf215546Sopenharmony_ci      db.SurfaceQPitch =
141bf215546Sopenharmony_ci         isl_surf_get_array_pitch_el_rows(info->depth_surf) >> 2;
142bf215546Sopenharmony_ci#endif
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_ci#if GFX_VER >= 12
145bf215546Sopenharmony_ci      db.ControlSurfaceEnable = db.DepthBufferCompressionEnable =
146bf215546Sopenharmony_ci         isl_aux_usage_has_ccs(info->hiz_usage);
147bf215546Sopenharmony_ci#endif
148bf215546Sopenharmony_ci   }
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci#if GFX_VER == 5 || GFX_VER == 6
151bf215546Sopenharmony_ci   const bool separate_stencil =
152bf215546Sopenharmony_ci      info->stencil_surf && info->stencil_surf->format == ISL_FORMAT_R8_UINT;
153bf215546Sopenharmony_ci   if (separate_stencil || info->hiz_usage == ISL_AUX_USAGE_HIZ) {
154bf215546Sopenharmony_ci      assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
155bf215546Sopenharmony_ci      /* From the IronLake PRM, Vol 2 Part 1:
156bf215546Sopenharmony_ci       *
157bf215546Sopenharmony_ci       *    3DSTATE_DEPTH_BUFFER::Separate Stencil Buffer Enable
158bf215546Sopenharmony_ci       *    If this field is enabled, Hierarchical Depth Buffer Enable must
159bf215546Sopenharmony_ci       *    also be enabled.
160bf215546Sopenharmony_ci       *
161bf215546Sopenharmony_ci       *    3DSTATE_DEPTH_BUFFER::Tiled Surface
162bf215546Sopenharmony_ci       *    When Hierarchical Depth Buffer is enabled, this bit must be set.
163bf215546Sopenharmony_ci       */
164bf215546Sopenharmony_ci      db.SeparateStencilBufferEnable = true;
165bf215546Sopenharmony_ci      db.HierarchicalDepthBufferEnable = true;
166bf215546Sopenharmony_ci      db.TiledSurface = true;
167bf215546Sopenharmony_ci   }
168bf215546Sopenharmony_ci#endif
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci#if GFX_VER >= 6
171bf215546Sopenharmony_ci   struct GENX(3DSTATE_STENCIL_BUFFER) sb = {
172bf215546Sopenharmony_ci      GENX(3DSTATE_STENCIL_BUFFER_header),
173bf215546Sopenharmony_ci      .MOCS = info->mocs,
174bf215546Sopenharmony_ci   };
175bf215546Sopenharmony_ci#else
176bf215546Sopenharmony_ci#  define sb db
177bf215546Sopenharmony_ci#endif
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   if (info->stencil_surf) {
180bf215546Sopenharmony_ci#if GFX_VER >= 7 && GFX_VER < 12
181bf215546Sopenharmony_ci      db.StencilWriteEnable = true;
182bf215546Sopenharmony_ci#endif
183bf215546Sopenharmony_ci#if GFX_VERx10 >= 125
184bf215546Sopenharmony_ci      sb.TiledMode = isl_encode_tiling[info->stencil_surf->tiling];
185bf215546Sopenharmony_ci      sb.MipTailStartLOD = 15;
186bf215546Sopenharmony_ci      sb.CompressionMode = isl_aux_usage_has_ccs(info->stencil_aux_usage);
187bf215546Sopenharmony_ci      sb.RenderCompressionFormat =
188bf215546Sopenharmony_ci         isl_get_render_compression_format(info->stencil_surf->format);
189bf215546Sopenharmony_ci#endif
190bf215546Sopenharmony_ci#if GFX_VER >= 12
191bf215546Sopenharmony_ci      sb.StencilWriteEnable = true;
192bf215546Sopenharmony_ci      sb.SurfaceType = SURFTYPE_2D;
193bf215546Sopenharmony_ci      sb.Width = info->stencil_surf->logical_level0_px.width - 1;
194bf215546Sopenharmony_ci      sb.Height = info->stencil_surf->logical_level0_px.height - 1;
195bf215546Sopenharmony_ci      sb.Depth = sb.RenderTargetViewExtent = info->view->array_len - 1;
196bf215546Sopenharmony_ci      sb.SurfLOD = info->view->base_level;
197bf215546Sopenharmony_ci      sb.MinimumArrayElement = info->view->base_array_layer;
198bf215546Sopenharmony_ci      assert(info->stencil_aux_usage == ISL_AUX_USAGE_NONE ||
199bf215546Sopenharmony_ci             info->stencil_aux_usage == ISL_AUX_USAGE_STC_CCS);
200bf215546Sopenharmony_ci      sb.StencilCompressionEnable =
201bf215546Sopenharmony_ci         info->stencil_aux_usage == ISL_AUX_USAGE_STC_CCS;
202bf215546Sopenharmony_ci      sb.ControlSurfaceEnable = sb.StencilCompressionEnable;
203bf215546Sopenharmony_ci#elif GFX_VERx10 >= 75
204bf215546Sopenharmony_ci      sb.StencilBufferEnable = true;
205bf215546Sopenharmony_ci#endif
206bf215546Sopenharmony_ci      sb.SurfaceBaseAddress = info->stencil_address;
207bf215546Sopenharmony_ci      sb.SurfacePitch = info->stencil_surf->row_pitch_B - 1;
208bf215546Sopenharmony_ci#if GFX_VER >= 8
209bf215546Sopenharmony_ci      sb.SurfaceQPitch =
210bf215546Sopenharmony_ci         isl_surf_get_array_pitch_el_rows(info->stencil_surf) >> 2;
211bf215546Sopenharmony_ci#endif
212bf215546Sopenharmony_ci   } else {
213bf215546Sopenharmony_ci#if GFX_VER >= 12
214bf215546Sopenharmony_ci      sb.SurfaceType = SURFTYPE_NULL;
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_ci      /* The docs seem to indicate that if surf-type is null, then we may need
217bf215546Sopenharmony_ci       * to match the depth-buffer value for `Depth`. It may be a
218bf215546Sopenharmony_ci       * documentation bug, since the other fields don't require this.
219bf215546Sopenharmony_ci       *
220bf215546Sopenharmony_ci       * TODO: Confirm documentation and remove setting of `Depth` if not
221bf215546Sopenharmony_ci       * required.
222bf215546Sopenharmony_ci       */
223bf215546Sopenharmony_ci      sb.Depth = db.Depth;
224bf215546Sopenharmony_ci#endif
225bf215546Sopenharmony_ci   }
226bf215546Sopenharmony_ci
227bf215546Sopenharmony_ci#if GFX_VER >= 6
228bf215546Sopenharmony_ci   struct GENX(3DSTATE_HIER_DEPTH_BUFFER) hiz = {
229bf215546Sopenharmony_ci      GENX(3DSTATE_HIER_DEPTH_BUFFER_header),
230bf215546Sopenharmony_ci      .MOCS = info->mocs,
231bf215546Sopenharmony_ci   };
232bf215546Sopenharmony_ci   struct GENX(3DSTATE_CLEAR_PARAMS) clear = {
233bf215546Sopenharmony_ci      GENX(3DSTATE_CLEAR_PARAMS_header),
234bf215546Sopenharmony_ci   };
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci   assert(info->hiz_usage == ISL_AUX_USAGE_NONE ||
237bf215546Sopenharmony_ci          isl_aux_usage_has_hiz(info->hiz_usage));
238bf215546Sopenharmony_ci   if (isl_aux_usage_has_hiz(info->hiz_usage)) {
239bf215546Sopenharmony_ci      assert(GFX_VER >= 12 || info->hiz_usage == ISL_AUX_USAGE_HIZ);
240bf215546Sopenharmony_ci      db.HierarchicalDepthBufferEnable = true;
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ci      hiz.SurfaceBaseAddress = info->hiz_address;
243bf215546Sopenharmony_ci      hiz.SurfacePitch = info->hiz_surf->row_pitch_B - 1;
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci#if GFX_VERx10 >= 125
246bf215546Sopenharmony_ci      /* From 3DSTATE_HIER_DEPTH_BUFFER_BODY::TiledMode,
247bf215546Sopenharmony_ci       *
248bf215546Sopenharmony_ci       *    HZ buffer only supports Tile4 mode
249bf215546Sopenharmony_ci       *
250bf215546Sopenharmony_ci       * and from Bspec 47009, "Hierarchical Depth Buffer",
251bf215546Sopenharmony_ci       *
252bf215546Sopenharmony_ci       *    The format of the data in the hierarchical depth buffer is not
253bf215546Sopenharmony_ci       *    documented here, as this surface needs only to be allocated by
254bf215546Sopenharmony_ci       *    software.
255bf215546Sopenharmony_ci       *
256bf215546Sopenharmony_ci       * We choose to apply the second quote to the first. ISL describes HiZ
257bf215546Sopenharmony_ci       * with a tiling that has the same extent as Tile4 (128Bx32), but a
258bf215546Sopenharmony_ci       * different internal layout. This has two benefits: 1) it allows us to
259bf215546Sopenharmony_ci       * have the correct allocation size and 2) we can continue to use a
260bf215546Sopenharmony_ci       * tiling that was determined to exist on some prior platforms.
261bf215546Sopenharmony_ci       */
262bf215546Sopenharmony_ci      assert(info->hiz_surf->tiling == ISL_TILING_HIZ);
263bf215546Sopenharmony_ci      hiz.TiledMode = TILE4;
264bf215546Sopenharmony_ci#endif
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci#if GFX_VER >= 12
267bf215546Sopenharmony_ci      hiz.HierarchicalDepthBufferWriteThruEnable =
268bf215546Sopenharmony_ci         info->hiz_usage == ISL_AUX_USAGE_HIZ_CCS_WT;
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ci      /* The bspec docs for this bit are fairly unclear about exactly what is
271bf215546Sopenharmony_ci       * and isn't supported with HiZ write-through.  It's fairly clear that
272bf215546Sopenharmony_ci       * you can't sample from a multisampled depth buffer with CCS.  This
273bf215546Sopenharmony_ci       * limitation isn't called out explicitly but the docs for the CCS_E
274bf215546Sopenharmony_ci       * value of RENDER_SURFACE_STATE::AuxiliarySurfaceMode say:
275bf215546Sopenharmony_ci       *
276bf215546Sopenharmony_ci       *    "If Number of multisamples > 1, programming this value means MSAA
277bf215546Sopenharmony_ci       *    compression is enabled for that surface. Auxiliary surface is MSC
278bf215546Sopenharmony_ci       *    with tile y."
279bf215546Sopenharmony_ci       *
280bf215546Sopenharmony_ci       * Since this interpretation ignores whether the surface is
281bf215546Sopenharmony_ci       * depth/stencil or not and since multisampled depth buffers use
282bf215546Sopenharmony_ci       * ISL_MSAA_LAYOUT_INTERLEAVED which is incompatible with MCS
283bf215546Sopenharmony_ci       * compression, this means that we can't even specify MSAA depth CCS in
284bf215546Sopenharmony_ci       * RENDER_SURFACE_STATE::AuxiliarySurfaceMode.  The BSpec also says, for
285bf215546Sopenharmony_ci       * 3DSTATE_HIER_DEPTH_BUFFER::HierarchicalDepthBufferWriteThruEnable,
286bf215546Sopenharmony_ci       *
287bf215546Sopenharmony_ci       *    "This bit must NOT be set for >1x MSAA modes, since sampler
288bf215546Sopenharmony_ci       *    doesn't support sampling from >1x MSAA depth buffer."
289bf215546Sopenharmony_ci       *
290bf215546Sopenharmony_ci       * Again, this is all focused around what the sampler can do and not
291bf215546Sopenharmony_ci       * what the depth hardware can do.
292bf215546Sopenharmony_ci       *
293bf215546Sopenharmony_ci       * Reading even more internal docs which can't be quoted here makes it
294bf215546Sopenharmony_ci       * pretty clear that, even if it's not currently called out in the
295bf215546Sopenharmony_ci       * BSpec, HiZ+CCS write-through isn't intended to work with MSAA and we
296bf215546Sopenharmony_ci       * shouldn't try to use it.  Treat it as if it's disallowed even if the
297bf215546Sopenharmony_ci       * BSpec doesn't explicitly document that.
298bf215546Sopenharmony_ci       */
299bf215546Sopenharmony_ci      if (hiz.HierarchicalDepthBufferWriteThruEnable)
300bf215546Sopenharmony_ci         assert(info->depth_surf->samples == 1);
301bf215546Sopenharmony_ci#endif
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci#if GFX_VER >= 8
304bf215546Sopenharmony_ci      /* From the SKL PRM Vol2a:
305bf215546Sopenharmony_ci       *
306bf215546Sopenharmony_ci       *    The interpretation of this field is dependent on Surface Type
307bf215546Sopenharmony_ci       *    as follows:
308bf215546Sopenharmony_ci       *    - SURFTYPE_1D: distance in pixels between array slices
309bf215546Sopenharmony_ci       *    - SURFTYPE_2D/CUBE: distance in rows between array slices
310bf215546Sopenharmony_ci       *    - SURFTYPE_3D: distance in rows between R - slices
311bf215546Sopenharmony_ci       *
312bf215546Sopenharmony_ci       * Unfortunately, the docs aren't 100% accurate here.  They fail to
313bf215546Sopenharmony_ci       * mention that the 1-D rule only applies to linear 1-D images.
314bf215546Sopenharmony_ci       * Since depth and HiZ buffers are always tiled, they are treated as
315bf215546Sopenharmony_ci       * 2-D images.  Prior to Sky Lake, this field is always in rows.
316bf215546Sopenharmony_ci       */
317bf215546Sopenharmony_ci      hiz.SurfaceQPitch =
318bf215546Sopenharmony_ci         isl_surf_get_array_pitch_sa_rows(info->hiz_surf) >> 2;
319bf215546Sopenharmony_ci#endif
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci      clear.DepthClearValueValid = true;
322bf215546Sopenharmony_ci#if GFX_VER >= 8
323bf215546Sopenharmony_ci      clear.DepthClearValue = info->depth_clear_value;
324bf215546Sopenharmony_ci#else
325bf215546Sopenharmony_ci      switch (info->depth_surf->format) {
326bf215546Sopenharmony_ci      case ISL_FORMAT_R32_FLOAT: {
327bf215546Sopenharmony_ci         union { float f; uint32_t u; } fu;
328bf215546Sopenharmony_ci         fu.f = info->depth_clear_value;
329bf215546Sopenharmony_ci         clear.DepthClearValue = fu.u;
330bf215546Sopenharmony_ci         break;
331bf215546Sopenharmony_ci      }
332bf215546Sopenharmony_ci      case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
333bf215546Sopenharmony_ci         clear.DepthClearValue = info->depth_clear_value * ((1u << 24) - 1);
334bf215546Sopenharmony_ci         break;
335bf215546Sopenharmony_ci      case ISL_FORMAT_R16_UNORM:
336bf215546Sopenharmony_ci         clear.DepthClearValue = info->depth_clear_value * ((1u << 16) - 1);
337bf215546Sopenharmony_ci         break;
338bf215546Sopenharmony_ci      default:
339bf215546Sopenharmony_ci         unreachable("Invalid depth type");
340bf215546Sopenharmony_ci      }
341bf215546Sopenharmony_ci#endif
342bf215546Sopenharmony_ci   }
343bf215546Sopenharmony_ci#endif /* GFX_VER >= 6 */
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci   /* Pack everything into the batch */
346bf215546Sopenharmony_ci   uint32_t *dw = batch;
347bf215546Sopenharmony_ci   GENX(3DSTATE_DEPTH_BUFFER_pack)(NULL, dw, &db);
348bf215546Sopenharmony_ci   dw += GENX(3DSTATE_DEPTH_BUFFER_length);
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci#if GFX_VER >= 6
351bf215546Sopenharmony_ci   GENX(3DSTATE_STENCIL_BUFFER_pack)(NULL, dw, &sb);
352bf215546Sopenharmony_ci   dw += GENX(3DSTATE_STENCIL_BUFFER_length);
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci   GENX(3DSTATE_HIER_DEPTH_BUFFER_pack)(NULL, dw, &hiz);
355bf215546Sopenharmony_ci   dw += GENX(3DSTATE_HIER_DEPTH_BUFFER_length);
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci   GENX(3DSTATE_CLEAR_PARAMS_pack)(NULL, dw, &clear);
358bf215546Sopenharmony_ci   dw += GENX(3DSTATE_CLEAR_PARAMS_length);
359bf215546Sopenharmony_ci#endif
360bf215546Sopenharmony_ci}
361