0dfeeaf90441aca87c46e43df341691d8d0bdf63
[mesa.git] / src / intel / isl / isl_surface_state.c
1 /*
2 * Copyright 2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <stdint.h>
25
26 #define __gen_address_type uint64_t
27 #define __gen_user_data void
28
29 static inline uint64_t
30 __gen_combine_address(void *data, void *loc, uint64_t addr, uint32_t delta)
31 {
32 return addr + delta;
33 }
34
35 #include "genxml/gen_macros.h"
36 #include "genxml/genX_pack.h"
37
38 #include "isl_priv.h"
39
40 #define __PASTE2(x, y) x ## y
41 #define __PASTE(x, y) __PASTE2(x, y)
42 #define isl_genX(x) __PASTE(isl_, genX(x))
43
44 #if GEN_GEN >= 8
45 static const uint8_t isl_to_gen_halign[] = {
46 [4] = HALIGN4,
47 [8] = HALIGN8,
48 [16] = HALIGN16,
49 };
50 #elif GEN_GEN >= 7
51 static const uint8_t isl_to_gen_halign[] = {
52 [4] = HALIGN_4,
53 [8] = HALIGN_8,
54 };
55 #endif
56
57 #if GEN_GEN >= 8
58 static const uint8_t isl_to_gen_valign[] = {
59 [4] = VALIGN4,
60 [8] = VALIGN8,
61 [16] = VALIGN16,
62 };
63 #elif GEN_GEN >= 6
64 static const uint8_t isl_to_gen_valign[] = {
65 [2] = VALIGN_2,
66 [4] = VALIGN_4,
67 };
68 #endif
69
70 #if GEN_GEN >= 8
71 static const uint8_t isl_to_gen_tiling[] = {
72 [ISL_TILING_LINEAR] = LINEAR,
73 [ISL_TILING_X] = XMAJOR,
74 [ISL_TILING_Y0] = YMAJOR,
75 [ISL_TILING_Yf] = YMAJOR,
76 [ISL_TILING_Ys] = YMAJOR,
77 [ISL_TILING_W] = WMAJOR,
78 };
79 #endif
80
81 #if GEN_GEN >= 7
82 static const uint32_t isl_to_gen_multisample_layout[] = {
83 [ISL_MSAA_LAYOUT_NONE] = MSFMT_MSS,
84 [ISL_MSAA_LAYOUT_INTERLEAVED] = MSFMT_DEPTH_STENCIL,
85 [ISL_MSAA_LAYOUT_ARRAY] = MSFMT_MSS,
86 };
87 #endif
88
89 #if GEN_GEN >= 9
90 static const uint32_t isl_to_gen_aux_mode[] = {
91 [ISL_AUX_USAGE_NONE] = AUX_NONE,
92 [ISL_AUX_USAGE_HIZ] = AUX_HIZ,
93 [ISL_AUX_USAGE_MCS] = AUX_CCS_D,
94 [ISL_AUX_USAGE_CCS_D] = AUX_CCS_D,
95 [ISL_AUX_USAGE_CCS_E] = AUX_CCS_E,
96 };
97 #elif GEN_GEN >= 8
98 static const uint32_t isl_to_gen_aux_mode[] = {
99 [ISL_AUX_USAGE_NONE] = AUX_NONE,
100 [ISL_AUX_USAGE_HIZ] = AUX_HIZ,
101 [ISL_AUX_USAGE_MCS] = AUX_MCS,
102 [ISL_AUX_USAGE_CCS_D] = AUX_MCS,
103 };
104 #endif
105
106 static uint8_t
107 get_surftype(enum isl_surf_dim dim, isl_surf_usage_flags_t usage)
108 {
109 switch (dim) {
110 default:
111 unreachable("bad isl_surf_dim");
112 case ISL_SURF_DIM_1D:
113 assert(!(usage & ISL_SURF_USAGE_CUBE_BIT));
114 return SURFTYPE_1D;
115 case ISL_SURF_DIM_2D:
116 if (usage & ISL_SURF_USAGE_STORAGE_BIT) {
117 /* Storage images are always plain 2-D, not cube */
118 return SURFTYPE_2D;
119 } else if (usage & ISL_SURF_USAGE_CUBE_BIT) {
120 return SURFTYPE_CUBE;
121 } else {
122 return SURFTYPE_2D;
123 }
124 case ISL_SURF_DIM_3D:
125 assert(!(usage & ISL_SURF_USAGE_CUBE_BIT));
126 return SURFTYPE_3D;
127 }
128 }
129
130 /**
131 * Get the horizontal and vertical alignment in the units expected by the
132 * hardware. Note that this does NOT give you the actual hardware enum values
133 * but an index into the isl_to_gen_[hv]align arrays above.
134 */
135 static inline struct isl_extent3d
136 get_image_alignment(const struct isl_surf *surf)
137 {
138 if (GEN_GEN >= 9) {
139 if (isl_tiling_is_std_y(surf->tiling) ||
140 surf->dim_layout == ISL_DIM_LAYOUT_GEN9_1D) {
141 /* The hardware ignores the alignment values. Anyway, the surface's
142 * true alignment is likely outside the enum range of HALIGN* and
143 * VALIGN*.
144 */
145 return isl_extent3d(4, 4, 1);
146 } else {
147 /* In Skylake, RENDER_SUFFACE_STATE.SurfaceVerticalAlignment is in units
148 * of surface elements (not pixels nor samples). For compressed formats,
149 * a "surface element" is defined as a compression block. For example,
150 * if SurfaceVerticalAlignment is VALIGN_4 and SurfaceFormat is an ETC2
151 * format (ETC2 has a block height of 4), then the vertical alignment is
152 * 4 compression blocks or, equivalently, 16 pixels.
153 */
154 return isl_surf_get_image_alignment_el(surf);
155 }
156 } else {
157 /* Pre-Skylake, RENDER_SUFFACE_STATE.SurfaceVerticalAlignment is in
158 * units of surface samples. For example, if SurfaceVerticalAlignment
159 * is VALIGN_4 and the surface is singlesampled, then for any surface
160 * format (compressed or not) the vertical alignment is
161 * 4 pixels.
162 */
163 return isl_surf_get_image_alignment_sa(surf);
164 }
165 }
166
167 #if GEN_GEN >= 8
168 static uint32_t
169 get_qpitch(const struct isl_surf *surf)
170 {
171 switch (surf->dim_layout) {
172 default:
173 unreachable("Bad isl_surf_dim");
174 case ISL_DIM_LAYOUT_GEN4_2D:
175 if (GEN_GEN >= 9) {
176 if (surf->dim == ISL_SURF_DIM_3D && surf->tiling == ISL_TILING_W) {
177 /* This is rather annoying and completely undocumented. It
178 * appears that the hardware has a bug (or undocumented feature)
179 * regarding stencil buffers most likely related to the way
180 * W-tiling is handled as modified Y-tiling. If you bind a 3-D
181 * stencil buffer normally, and use texelFetch on it, the z or
182 * array index will get implicitly multiplied by 2 for no obvious
183 * reason. The fix appears to be to divide qpitch by 2 for
184 * W-tiled surfaces.
185 */
186 return isl_surf_get_array_pitch_el_rows(surf) / 2;
187 } else {
188 return isl_surf_get_array_pitch_el_rows(surf);
189 }
190 } else {
191 /* From the Broadwell PRM for RENDER_SURFACE_STATE.QPitch
192 *
193 * "This field must be set to an integer multiple of the Surface
194 * Vertical Alignment. For compressed textures (BC*, FXT1,
195 * ETC*, and EAC* Surface Formats), this field is in units of
196 * rows in the uncompressed surface, and must be set to an
197 * integer multiple of the vertical alignment parameter "j"
198 * defined in the Common Surface Formats section."
199 */
200 return isl_surf_get_array_pitch_sa_rows(surf);
201 }
202 case ISL_DIM_LAYOUT_GEN9_1D:
203 /* QPitch is usually expressed as rows of surface elements (where
204 * a surface element is an compression block or a single surface
205 * sample). Skylake 1D is an outlier.
206 *
207 * From the Skylake BSpec >> Memory Views >> Common Surface
208 * Formats >> Surface Layout and Tiling >> 1D Surfaces:
209 *
210 * Surface QPitch specifies the distance in pixels between array
211 * slices.
212 */
213 return isl_surf_get_array_pitch_el(surf);
214 case ISL_DIM_LAYOUT_GEN4_3D:
215 /* QPitch doesn't make sense for ISL_DIM_LAYOUT_GEN4_3D since it uses a
216 * different pitch at each LOD. Also, the QPitch field is ignored for
217 * these surfaces. From the Broadwell PRM documentation for QPitch:
218 *
219 * This field specifies the distance in rows between array slices. It
220 * is used only in the following cases:
221 * - Surface Array is enabled OR
222 * - Number of Mulitsamples is not NUMSAMPLES_1 and Multisampled
223 * Surface Storage Format set to MSFMT_MSS OR
224 * - Surface Type is SURFTYPE_CUBE
225 *
226 * None of the three conditions above can possibly apply to a 3D surface
227 * so it is safe to just set QPitch to 0.
228 */
229 return 0;
230 }
231 }
232 #endif /* GEN_GEN >= 8 */
233
234 void
235 isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
236 const struct isl_surf_fill_state_info *restrict info)
237 {
238 struct GENX(RENDER_SURFACE_STATE) s = { 0 };
239
240 s.SurfaceType = get_surftype(info->surf->dim, info->view->usage);
241
242 if (info->view->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT)
243 assert(isl_format_supports_rendering(dev->info, info->view->format));
244 else if (info->view->usage & ISL_SURF_USAGE_TEXTURE_BIT)
245 assert(isl_format_supports_sampling(dev->info, info->view->format));
246
247 /* From the Sky Lake PRM Vol. 2d, RENDER_SURFACE_STATE::SurfaceFormat
248 *
249 * This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*)
250 * format if the Surface Type is SURFTYPE_1D
251 */
252 if (info->surf->dim == ISL_SURF_DIM_1D)
253 assert(!isl_format_is_compressed(info->view->format));
254
255 s.SurfaceFormat = info->view->format;
256
257 #if GEN_IS_HASWELL
258 s.IntegerSurfaceFormat = isl_format_has_int_channel(s.SurfaceFormat);
259 #endif
260
261 s.Width = info->surf->logical_level0_px.width - 1;
262 s.Height = info->surf->logical_level0_px.height - 1;
263
264 /* In the gen6 PRM Volume 1 Part 1: Graphics Core, Section 7.18.3.7.1
265 * (Surface Arrays For all surfaces other than separate stencil buffer):
266 *
267 * "[DevSNB] Errata: Sampler MSAA Qpitch will be 4 greater than the value
268 * calculated in the equation above , for every other odd Surface Height
269 * starting from 1 i.e. 1,5,9,13"
270 *
271 * Since this Qpitch errata only impacts the sampler, we have to adjust the
272 * input for the rendering surface to achieve the same qpitch. For the
273 * affected heights, we increment the height by 1 for the rendering
274 * surface.
275 */
276 if (GEN_GEN == 6 && (info->view->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) &&
277 info->surf->samples > 1 &&
278 (info->surf->logical_level0_px.height % 4) == 1)
279 s.Height++;
280
281 switch (s.SurfaceType) {
282 case SURFTYPE_1D:
283 case SURFTYPE_2D:
284 /* From the Ivy Bridge PRM >> RENDER_SURFACE_STATE::MinimumArrayElement:
285 *
286 * "If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
287 * must be set to zero if this surface is used with sampling engine
288 * messages."
289 *
290 * This restriction appears to exist only on Ivy Bridge.
291 */
292 if (GEN_GEN == 7 && !GEN_IS_HASWELL && !ISL_DEV_IS_BAYTRAIL(dev) &&
293 (info->view->usage & ISL_SURF_USAGE_TEXTURE_BIT) &&
294 info->surf->samples > 1)
295 assert(info->view->base_array_layer == 0);
296
297 s.MinimumArrayElement = info->view->base_array_layer;
298
299 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
300 *
301 * For SURFTYPE_1D, 2D, and CUBE: The range of this field is reduced
302 * by one for each increase from zero of Minimum Array Element. For
303 * example, if Minimum Array Element is set to 1024 on a 2D surface,
304 * the range of this field is reduced to [0,1023].
305 *
306 * In other words, 'Depth' is the number of array layers.
307 */
308 s.Depth = info->view->array_len - 1;
309
310 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
311 *
312 * For Render Target and Typed Dataport 1D and 2D Surfaces:
313 * This field must be set to the same value as the Depth field.
314 */
315 if (info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
316 ISL_SURF_USAGE_STORAGE_BIT))
317 s.RenderTargetViewExtent = s.Depth;
318 break;
319 case SURFTYPE_CUBE:
320 s.MinimumArrayElement = info->view->base_array_layer;
321 /* Same as SURFTYPE_2D, but divided by 6 */
322 s.Depth = info->view->array_len / 6 - 1;
323 if (info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
324 ISL_SURF_USAGE_STORAGE_BIT))
325 s.RenderTargetViewExtent = s.Depth;
326 break;
327 case SURFTYPE_3D:
328 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
329 *
330 * If the volume texture is MIP-mapped, this field specifies the
331 * depth of the base MIP level.
332 */
333 s.Depth = info->surf->logical_level0_px.depth - 1;
334
335 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
336 *
337 * For Render Target and Typed Dataport 3D Surfaces: This field
338 * indicates the extent of the accessible 'R' coordinates minus 1 on
339 * the LOD currently being rendered to.
340 *
341 * The docs specify that this only matters for render targets and
342 * surfaces used with typed dataport messages. Prior to Ivy Bridge, the
343 * Depth field has more bits than RenderTargetViewExtent so we can have
344 * textures with more levels than we can render to. In order to prevent
345 * assert-failures in the packing function below, we only set the field
346 * when it's actually going to be used by the hardware.
347 *
348 * Similaraly, the MinimumArrayElement field is ignored by all hardware
349 * prior to Sky Lake when texturing and we want it set to 0 anyway.
350 * Since it's already initialized to 0, we can just leave it alone for
351 * texture surfaces.
352 */
353 if (info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
354 ISL_SURF_USAGE_STORAGE_BIT)) {
355 s.MinimumArrayElement = info->view->base_array_layer;
356 s.RenderTargetViewExtent = info->view->array_len - 1;
357 }
358 break;
359 default:
360 unreachable("bad SurfaceType");
361 }
362
363 #if GEN_GEN >= 7
364 s.SurfaceArray = info->surf->dim != ISL_SURF_DIM_3D;
365 #endif
366
367 if (info->view->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
368 /* For render target surfaces, the hardware interprets field
369 * MIPCount/LOD as LOD. The Broadwell PRM says:
370 *
371 * MIPCountLOD defines the LOD that will be rendered into.
372 * SurfaceMinLOD is ignored.
373 */
374 s.MIPCountLOD = info->view->base_level;
375 s.SurfaceMinLOD = 0;
376 } else {
377 /* For non render target surfaces, the hardware interprets field
378 * MIPCount/LOD as MIPCount. The range of levels accessible by the
379 * sampler engine is [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
380 */
381 s.SurfaceMinLOD = info->view->base_level;
382 s.MIPCountLOD = MAX(info->view->levels, 1) - 1;
383 }
384
385 #if GEN_GEN >= 9
386 /* We don't use miptails yet. The PRM recommends that you set "Mip Tail
387 * Start LOD" to 15 to prevent the hardware from trying to use them.
388 */
389 s.TiledResourceMode = NONE;
390 s.MipTailStartLOD = 15;
391 #endif
392
393 #if GEN_GEN >= 6
394 const struct isl_extent3d image_align = get_image_alignment(info->surf);
395 s.SurfaceVerticalAlignment = isl_to_gen_valign[image_align.height];
396 #if GEN_GEN >= 7
397 s.SurfaceHorizontalAlignment = isl_to_gen_halign[image_align.width];
398 #endif
399 #endif
400
401 if (info->surf->dim_layout == ISL_DIM_LAYOUT_GEN9_1D) {
402 /* For gen9 1-D textures, surface pitch is ignored */
403 s.SurfacePitch = 0;
404 } else {
405 s.SurfacePitch = info->surf->row_pitch - 1;
406 }
407
408 #if GEN_GEN >= 8
409 s.SurfaceQPitch = get_qpitch(info->surf) >> 2;
410 #elif GEN_GEN == 7
411 s.SurfaceArraySpacing = info->surf->array_pitch_span ==
412 ISL_ARRAY_PITCH_SPAN_COMPACT;
413 #endif
414
415 #if GEN_GEN >= 8
416 s.TileMode = isl_to_gen_tiling[info->surf->tiling];
417 #else
418 s.TiledSurface = info->surf->tiling != ISL_TILING_LINEAR,
419 s.TileWalk = info->surf->tiling == ISL_TILING_Y0 ? TILEWALK_YMAJOR :
420 TILEWALK_XMAJOR,
421 #endif
422
423 #if GEN_GEN >= 8
424 s.RenderCacheReadWriteMode = WriteOnlyCache;
425 #else
426 s.RenderCacheReadWriteMode = 0;
427 #endif
428
429 if (info->view->usage & ISL_SURF_USAGE_CUBE_BIT) {
430 #if GEN_GEN >= 8
431 s.CubeFaceEnablePositiveZ = 1;
432 s.CubeFaceEnableNegativeZ = 1;
433 s.CubeFaceEnablePositiveY = 1;
434 s.CubeFaceEnableNegativeY = 1;
435 s.CubeFaceEnablePositiveX = 1;
436 s.CubeFaceEnableNegativeX = 1;
437 #else
438 s.CubeFaceEnables = 0x3f;
439 #endif
440 }
441
442 #if GEN_GEN >= 6
443 s.NumberofMultisamples = ffs(info->surf->samples) - 1;
444 #if GEN_GEN >= 7
445 s.MultisampledSurfaceStorageFormat =
446 isl_to_gen_multisample_layout[info->surf->msaa_layout];
447 #endif
448 #endif
449
450 #if (GEN_GEN >= 8 || GEN_IS_HASWELL)
451 s.ShaderChannelSelectRed = info->view->swizzle.r;
452 s.ShaderChannelSelectGreen = info->view->swizzle.g;
453 s.ShaderChannelSelectBlue = info->view->swizzle.b;
454 s.ShaderChannelSelectAlpha = info->view->swizzle.a;
455 #endif
456
457 s.SurfaceBaseAddress = info->address;
458
459 #if GEN_GEN >= 6
460 s.MOCS = info->mocs;
461 #endif
462
463 #if GEN_GEN > 4 || GEN_IS_G4X
464 if (info->x_offset_sa != 0 || info->y_offset_sa != 0) {
465 /* There are fairly strict rules about when the offsets can be used.
466 * These are mostly taken from the Sky Lake PRM documentation for
467 * RENDER_SURFACE_STATE.
468 */
469 assert(info->surf->tiling != ISL_TILING_LINEAR);
470 assert(info->surf->dim == ISL_SURF_DIM_2D);
471 assert(isl_is_pow2(isl_format_get_layout(info->view->format)->bpb));
472 assert(info->surf->levels == 1);
473 assert(info->surf->logical_level0_px.array_len == 1);
474 assert(info->aux_usage == ISL_AUX_USAGE_NONE);
475
476 if (GEN_GEN >= 8) {
477 /* Broadwell added more rules. */
478 assert(info->surf->samples == 1);
479 if (isl_format_get_layout(info->view->format)->bpb == 8)
480 assert(info->x_offset_sa % 16 == 0);
481 if (isl_format_get_layout(info->view->format)->bpb == 16)
482 assert(info->x_offset_sa % 8 == 0);
483 }
484
485 #if GEN_GEN >= 7
486 s.SurfaceArray = false;
487 #endif
488 }
489
490 const unsigned x_div = 4;
491 const unsigned y_div = GEN_GEN >= 8 ? 4 : 2;
492 assert(info->x_offset_sa % x_div == 0);
493 assert(info->y_offset_sa % y_div == 0);
494 s.XOffset = info->x_offset_sa / x_div;
495 s.YOffset = info->y_offset_sa / y_div;
496 #else
497 assert(info->x_offset_sa == 0);
498 assert(info->y_offset_sa == 0);
499 #endif
500
501 #if GEN_GEN >= 7
502 if (info->aux_surf && info->aux_usage != ISL_AUX_USAGE_NONE) {
503 struct isl_tile_info tile_info;
504 isl_surf_get_tile_info(dev, info->aux_surf, &tile_info);
505 uint32_t pitch_in_tiles =
506 info->aux_surf->row_pitch / tile_info.phys_extent_B.width;
507
508 #if GEN_GEN >= 8
509 assert(GEN_GEN >= 9 || info->aux_usage != ISL_AUX_USAGE_CCS_E);
510 s.AuxiliarySurfacePitch = pitch_in_tiles - 1;
511 /* Auxiliary surfaces in ISL have compressed formats but the hardware
512 * doesn't expect our definition of the compression, it expects qpitch
513 * in units of samples on the main surface.
514 */
515 s.AuxiliarySurfaceQPitch =
516 isl_surf_get_array_pitch_sa_rows(info->aux_surf) >> 2;
517 s.AuxiliarySurfaceBaseAddress = info->aux_address;
518 s.AuxiliarySurfaceMode = isl_to_gen_aux_mode[info->aux_usage];
519 #else
520 assert(info->aux_usage == ISL_AUX_USAGE_MCS ||
521 info->aux_usage == ISL_AUX_USAGE_CCS_D);
522 s.MCSBaseAddress = info->aux_address,
523 s.MCSSurfacePitch = pitch_in_tiles - 1;
524 s.MCSEnable = true;
525 #endif
526 }
527 #endif
528
529 #if GEN_GEN >= 8
530 /* From the CHV PRM, Volume 2d, page 321 (RENDER_SURFACE_STATE dword 0
531 * bit 9 "Sampler L2 Bypass Mode Disable" Programming Notes):
532 *
533 * This bit must be set for the following surface types: BC2_UNORM
534 * BC3_UNORM BC5_UNORM BC5_SNORM BC7_UNORM
535 */
536 if (GEN_GEN >= 9 || dev->info->is_cherryview) {
537 switch (info->view->format) {
538 case ISL_FORMAT_BC2_UNORM:
539 case ISL_FORMAT_BC3_UNORM:
540 case ISL_FORMAT_BC5_UNORM:
541 case ISL_FORMAT_BC5_SNORM:
542 case ISL_FORMAT_BC7_UNORM:
543 s.SamplerL2BypassModeDisable = true;
544 break;
545 default:
546 break;
547 }
548 }
549 #endif
550
551 if (info->aux_usage != ISL_AUX_USAGE_NONE) {
552 #if GEN_GEN >= 9
553 s.RedClearColor = info->clear_color.u32[0];
554 s.GreenClearColor = info->clear_color.u32[1];
555 s.BlueClearColor = info->clear_color.u32[2];
556 s.AlphaClearColor = info->clear_color.u32[3];
557 #elif GEN_GEN >= 7
558 /* Prior to Sky Lake, we only have one bit for the clear color which
559 * gives us 0 or 1 in whatever the surface's format happens to be.
560 */
561 if (isl_format_has_int_channel(info->view->format)) {
562 for (unsigned i = 0; i < 4; i++) {
563 assert(info->clear_color.u32[i] == 0 ||
564 info->clear_color.u32[i] == 1);
565 }
566 s.RedClearColor = info->clear_color.u32[0] != 0;
567 s.GreenClearColor = info->clear_color.u32[1] != 0;
568 s.BlueClearColor = info->clear_color.u32[2] != 0;
569 s.AlphaClearColor = info->clear_color.u32[3] != 0;
570 } else {
571 for (unsigned i = 0; i < 4; i++) {
572 assert(info->clear_color.f32[i] == 0.0f ||
573 info->clear_color.f32[i] == 1.0f);
574 }
575 s.RedClearColor = info->clear_color.f32[0] != 0.0f;
576 s.GreenClearColor = info->clear_color.f32[1] != 0.0f;
577 s.BlueClearColor = info->clear_color.f32[2] != 0.0f;
578 s.AlphaClearColor = info->clear_color.f32[3] != 0.0f;
579 }
580 #endif
581 }
582
583 GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &s);
584 }
585
586 void
587 isl_genX(buffer_fill_state_s)(void *state,
588 const struct isl_buffer_fill_state_info *restrict info)
589 {
590 uint32_t num_elements = info->size / info->stride;
591
592 if (GEN_GEN >= 7) {
593 /* From the IVB PRM, SURFACE_STATE::Height,
594 *
595 * For typed buffer and structured buffer surfaces, the number
596 * of entries in the buffer ranges from 1 to 2^27. For raw buffer
597 * surfaces, the number of entries in the buffer is the number of bytes
598 * which can range from 1 to 2^30.
599 */
600 if (info->format == ISL_FORMAT_RAW) {
601 assert(num_elements <= (1ull << 30));
602 assert((num_elements & 3) == 0);
603 } else {
604 assert(num_elements <= (1ull << 27));
605 }
606 } else {
607 assert(num_elements <= (1ull << 27));
608 }
609
610 struct GENX(RENDER_SURFACE_STATE) s = { 0, };
611
612 s.SurfaceType = SURFTYPE_BUFFER;
613 s.SurfaceFormat = info->format;
614
615 #if GEN_GEN >= 6
616 s.SurfaceVerticalAlignment = isl_to_gen_valign[4];
617 #if GEN_GEN >= 7
618 s.SurfaceHorizontalAlignment = isl_to_gen_halign[4];
619 s.SurfaceArray = false;
620 #endif
621 #endif
622
623 #if GEN_GEN >= 7
624 s.Height = ((num_elements - 1) >> 7) & 0x3fff;
625 s.Width = (num_elements - 1) & 0x7f;
626 s.Depth = ((num_elements - 1) >> 21) & 0x3ff;
627 #else
628 s.Height = ((num_elements - 1) >> 7) & 0x1fff;
629 s.Width = (num_elements - 1) & 0x7f;
630 s.Depth = ((num_elements - 1) >> 20) & 0x7f;
631 #endif
632
633 s.SurfacePitch = info->stride - 1;
634
635 #if GEN_GEN >= 6
636 s.NumberofMultisamples = MULTISAMPLECOUNT_1;
637 #endif
638
639 #if (GEN_GEN >= 8)
640 s.TileMode = LINEAR;
641 #else
642 s.TiledSurface = false;
643 #endif
644
645 #if (GEN_GEN >= 8)
646 s.RenderCacheReadWriteMode = WriteOnlyCache;
647 #else
648 s.RenderCacheReadWriteMode = 0;
649 #endif
650
651 s.SurfaceBaseAddress = info->address;
652 #if GEN_GEN >= 6
653 s.MOCS = info->mocs;
654 #endif
655
656 #if (GEN_GEN >= 8 || GEN_IS_HASWELL)
657 s.ShaderChannelSelectRed = SCS_RED;
658 s.ShaderChannelSelectGreen = SCS_GREEN;
659 s.ShaderChannelSelectBlue = SCS_BLUE;
660 s.ShaderChannelSelectAlpha = SCS_ALPHA;
661 #endif
662
663 GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &s);
664 }