Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/intel/isl/isl_surface_state.c
4547 views
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 uint64_t
30
__gen_combine_address(__attribute__((unused)) void *data,
31
__attribute__((unused)) void *loc, uint64_t addr,
32
uint32_t delta)
33
{
34
return addr + delta;
35
}
36
37
#include "genxml/gen_macros.h"
38
#include "genxml/genX_pack.h"
39
40
#include "isl_priv.h"
41
42
#if GFX_VER >= 8
43
static const uint8_t isl_encode_halign[] = {
44
[4] = HALIGN4,
45
[8] = HALIGN8,
46
[16] = HALIGN16,
47
};
48
#elif GFX_VER >= 7
49
static const uint8_t isl_encode_halign[] = {
50
[4] = HALIGN_4,
51
[8] = HALIGN_8,
52
};
53
#endif
54
55
#if GFX_VER >= 8
56
static const uint8_t isl_encode_valign[] = {
57
[4] = VALIGN4,
58
[8] = VALIGN8,
59
[16] = VALIGN16,
60
};
61
#elif GFX_VER >= 6
62
static const uint8_t isl_encode_valign[] = {
63
[2] = VALIGN_2,
64
[4] = VALIGN_4,
65
};
66
#endif
67
68
#if GFX_VER >= 8
69
static const uint8_t isl_encode_tiling[] = {
70
[ISL_TILING_LINEAR] = LINEAR,
71
[ISL_TILING_X] = XMAJOR,
72
[ISL_TILING_Y0] = YMAJOR,
73
[ISL_TILING_Yf] = YMAJOR,
74
[ISL_TILING_Ys] = YMAJOR,
75
#if GFX_VER <= 11
76
[ISL_TILING_W] = WMAJOR,
77
#endif
78
};
79
#endif
80
81
#if GFX_VER >= 7
82
static const uint32_t isl_encode_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 GFX_VER >= 12
90
static const uint32_t isl_encode_aux_mode[] = {
91
[ISL_AUX_USAGE_NONE] = AUX_NONE,
92
[ISL_AUX_USAGE_MC] = AUX_NONE,
93
[ISL_AUX_USAGE_MCS] = AUX_CCS_E,
94
[ISL_AUX_USAGE_GFX12_CCS_E] = AUX_CCS_E,
95
[ISL_AUX_USAGE_CCS_E] = AUX_CCS_E,
96
[ISL_AUX_USAGE_HIZ_CCS_WT] = AUX_CCS_E,
97
[ISL_AUX_USAGE_MCS_CCS] = AUX_MCS_LCE,
98
[ISL_AUX_USAGE_STC_CCS] = AUX_CCS_E,
99
};
100
#elif GFX_VER >= 9
101
static const uint32_t isl_encode_aux_mode[] = {
102
[ISL_AUX_USAGE_NONE] = AUX_NONE,
103
[ISL_AUX_USAGE_HIZ] = AUX_HIZ,
104
[ISL_AUX_USAGE_MCS] = AUX_CCS_D,
105
[ISL_AUX_USAGE_CCS_D] = AUX_CCS_D,
106
[ISL_AUX_USAGE_CCS_E] = AUX_CCS_E,
107
};
108
#elif GFX_VER >= 8
109
static const uint32_t isl_encode_aux_mode[] = {
110
[ISL_AUX_USAGE_NONE] = AUX_NONE,
111
[ISL_AUX_USAGE_HIZ] = AUX_HIZ,
112
[ISL_AUX_USAGE_MCS] = AUX_MCS,
113
[ISL_AUX_USAGE_CCS_D] = AUX_MCS,
114
};
115
#endif
116
117
static uint8_t
118
get_surftype(enum isl_surf_dim dim, isl_surf_usage_flags_t usage)
119
{
120
switch (dim) {
121
default:
122
unreachable("bad isl_surf_dim");
123
case ISL_SURF_DIM_1D:
124
assert(!(usage & ISL_SURF_USAGE_CUBE_BIT));
125
return SURFTYPE_1D;
126
case ISL_SURF_DIM_2D:
127
if ((usage & ISL_SURF_USAGE_CUBE_BIT) &&
128
(usage & ISL_SURF_USAGE_TEXTURE_BIT)) {
129
/* We need SURFTYPE_CUBE to make cube sampling work */
130
return SURFTYPE_CUBE;
131
} else {
132
/* Everything else (render and storage) treat cubes as plain
133
* 2D array textures
134
*/
135
return SURFTYPE_2D;
136
}
137
case ISL_SURF_DIM_3D:
138
assert(!(usage & ISL_SURF_USAGE_CUBE_BIT));
139
return SURFTYPE_3D;
140
}
141
}
142
143
/**
144
* Get the horizontal and vertical alignment in the units expected by the
145
* hardware. Note that this does NOT give you the actual hardware enum values
146
* but an index into the isl_encode_[hv]align arrays above.
147
*/
148
UNUSED static struct isl_extent3d
149
get_image_alignment(const struct isl_surf *surf)
150
{
151
if (GFX_VER >= 9) {
152
if (isl_tiling_is_std_y(surf->tiling) ||
153
surf->dim_layout == ISL_DIM_LAYOUT_GFX9_1D) {
154
/* The hardware ignores the alignment values. Anyway, the surface's
155
* true alignment is likely outside the enum range of HALIGN* and
156
* VALIGN*.
157
*/
158
return isl_extent3d(4, 4, 1);
159
} else {
160
/* In Skylake, RENDER_SUFFACE_STATE.SurfaceVerticalAlignment is in units
161
* of surface elements (not pixels nor samples). For compressed formats,
162
* a "surface element" is defined as a compression block. For example,
163
* if SurfaceVerticalAlignment is VALIGN_4 and SurfaceFormat is an ETC2
164
* format (ETC2 has a block height of 4), then the vertical alignment is
165
* 4 compression blocks or, equivalently, 16 pixels.
166
*/
167
return isl_surf_get_image_alignment_el(surf);
168
}
169
} else {
170
/* Pre-Skylake, RENDER_SUFFACE_STATE.SurfaceVerticalAlignment is in
171
* units of surface samples. For example, if SurfaceVerticalAlignment
172
* is VALIGN_4 and the surface is singlesampled, then for any surface
173
* format (compressed or not) the vertical alignment is
174
* 4 pixels.
175
*/
176
return isl_surf_get_image_alignment_sa(surf);
177
}
178
}
179
180
#if GFX_VER >= 8
181
static uint32_t
182
get_qpitch(const struct isl_surf *surf)
183
{
184
switch (surf->dim_layout) {
185
default:
186
unreachable("Bad isl_surf_dim");
187
case ISL_DIM_LAYOUT_GFX4_2D:
188
if (GFX_VER >= 9) {
189
if (surf->dim == ISL_SURF_DIM_3D && surf->tiling == ISL_TILING_W) {
190
/* This is rather annoying and completely undocumented. It
191
* appears that the hardware has a bug (or undocumented feature)
192
* regarding stencil buffers most likely related to the way
193
* W-tiling is handled as modified Y-tiling. If you bind a 3-D
194
* stencil buffer normally, and use texelFetch on it, the z or
195
* array index will get implicitly multiplied by 2 for no obvious
196
* reason. The fix appears to be to divide qpitch by 2 for
197
* W-tiled surfaces.
198
*/
199
return isl_surf_get_array_pitch_el_rows(surf) / 2;
200
} else {
201
return isl_surf_get_array_pitch_el_rows(surf);
202
}
203
} else {
204
/* From the Broadwell PRM for RENDER_SURFACE_STATE.QPitch
205
*
206
* "This field must be set to an integer multiple of the Surface
207
* Vertical Alignment. For compressed textures (BC*, FXT1,
208
* ETC*, and EAC* Surface Formats), this field is in units of
209
* rows in the uncompressed surface, and must be set to an
210
* integer multiple of the vertical alignment parameter "j"
211
* defined in the Common Surface Formats section."
212
*/
213
return isl_surf_get_array_pitch_sa_rows(surf);
214
}
215
case ISL_DIM_LAYOUT_GFX9_1D:
216
/* QPitch is usually expressed as rows of surface elements (where
217
* a surface element is an compression block or a single surface
218
* sample). Skylake 1D is an outlier.
219
*
220
* From the Skylake BSpec >> Memory Views >> Common Surface
221
* Formats >> Surface Layout and Tiling >> 1D Surfaces:
222
*
223
* Surface QPitch specifies the distance in pixels between array
224
* slices.
225
*/
226
return isl_surf_get_array_pitch_el(surf);
227
case ISL_DIM_LAYOUT_GFX4_3D:
228
/* QPitch doesn't make sense for ISL_DIM_LAYOUT_GFX4_3D since it uses a
229
* different pitch at each LOD. Also, the QPitch field is ignored for
230
* these surfaces. From the Broadwell PRM documentation for QPitch:
231
*
232
* This field specifies the distance in rows between array slices. It
233
* is used only in the following cases:
234
* - Surface Array is enabled OR
235
* - Number of Mulitsamples is not NUMSAMPLES_1 and Multisampled
236
* Surface Storage Format set to MSFMT_MSS OR
237
* - Surface Type is SURFTYPE_CUBE
238
*
239
* None of the three conditions above can possibly apply to a 3D surface
240
* so it is safe to just set QPitch to 0.
241
*/
242
return 0;
243
}
244
}
245
#endif /* GFX_VER >= 8 */
246
247
void
248
isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
249
const struct isl_surf_fill_state_info *restrict info)
250
{
251
struct GENX(RENDER_SURFACE_STATE) s = { 0 };
252
253
s.SurfaceType = get_surftype(info->surf->dim, info->view->usage);
254
255
if (info->view->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT)
256
assert(isl_format_supports_rendering(dev->info, info->view->format));
257
else if (info->view->usage & ISL_SURF_USAGE_TEXTURE_BIT)
258
assert(isl_format_supports_sampling(dev->info, info->view->format));
259
260
/* From the Sky Lake PRM Vol. 2d, RENDER_SURFACE_STATE::SurfaceFormat
261
*
262
* This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*)
263
* format if the Surface Type is SURFTYPE_1D
264
*/
265
if (info->surf->dim == ISL_SURF_DIM_1D)
266
assert(!isl_format_is_compressed(info->view->format));
267
268
if (isl_format_is_compressed(info->surf->format)) {
269
/* You're not allowed to make a view of a compressed format with any
270
* format other than the surface format. None of the userspace APIs
271
* allow for this directly and doing so would mess up a number of
272
* surface parameters such as Width, Height, and alignments. Ideally,
273
* we'd like to assert that the two formats match. However, we have an
274
* S3TC workaround that requires us to do reinterpretation. So assert
275
* that they're at least the same bpb and block size.
276
*/
277
ASSERTED const struct isl_format_layout *surf_fmtl =
278
isl_format_get_layout(info->surf->format);
279
ASSERTED const struct isl_format_layout *view_fmtl =
280
isl_format_get_layout(info->surf->format);
281
assert(surf_fmtl->bpb == view_fmtl->bpb);
282
assert(surf_fmtl->bw == view_fmtl->bw);
283
assert(surf_fmtl->bh == view_fmtl->bh);
284
}
285
286
s.SurfaceFormat = info->view->format;
287
288
#if GFX_VER >= 12
289
/* The BSpec description of this field says:
290
*
291
* "This bit field, when set, indicates if the resource is created as
292
* Depth/Stencil resource."
293
*
294
* "SW must set this bit for any resource that was created with
295
* Depth/Stencil resource flag. Setting this bit allows HW to properly
296
* interpret the data-layout for various cases. For any resource that's
297
* created without Depth/Stencil resource flag, it must be reset."
298
*
299
* Even though the docs for this bit seem to imply that it's required for
300
* anything which might have been used for depth/stencil, empirical
301
* evidence suggests that it only affects CCS compression usage. There are
302
* a few things which back this up:
303
*
304
* 1. The docs are also pretty clear that this bit was added as part
305
* of enabling Gfx12 depth/stencil lossless compression.
306
*
307
* 2. The only new difference between depth/stencil and color images on
308
* Gfx12 (where the bit was added) is how they treat CCS compression.
309
* All other differences such as alignment requirements and MSAA layout
310
* are already covered by other bits.
311
*
312
* Under these assumptions, it makes sense for ISL to model this bit as
313
* being an extension of AuxiliarySurfaceMode where STC_CCS and HIZ_CCS_WT
314
* are indicated by AuxiliarySurfaceMode == CCS_E and DepthStencilResource
315
* == true.
316
*/
317
s.DepthStencilResource = info->aux_usage == ISL_AUX_USAGE_HIZ_CCS_WT ||
318
info->aux_usage == ISL_AUX_USAGE_STC_CCS;
319
#endif
320
321
#if GFX_VER <= 5
322
s.ColorBufferComponentWriteDisables = info->write_disables;
323
s.ColorBlendEnable = info->blend_enable;
324
#else
325
assert(info->write_disables == 0);
326
#endif
327
328
#if GFX_VERx10 == 75
329
s.IntegerSurfaceFormat =
330
isl_format_has_int_channel((enum isl_format) s.SurfaceFormat);
331
#endif
332
333
assert(info->surf->logical_level0_px.width > 0 &&
334
info->surf->logical_level0_px.height > 0);
335
336
s.Width = info->surf->logical_level0_px.width - 1;
337
s.Height = info->surf->logical_level0_px.height - 1;
338
339
/* In the gfx6 PRM Volume 1 Part 1: Graphics Core, Section 7.18.3.7.1
340
* (Surface Arrays For all surfaces other than separate stencil buffer):
341
*
342
* "[DevSNB] Errata: Sampler MSAA Qpitch will be 4 greater than the value
343
* calculated in the equation above , for every other odd Surface Height
344
* starting from 1 i.e. 1,5,9,13"
345
*
346
* Since this Qpitch errata only impacts the sampler, we have to adjust the
347
* input for the rendering surface to achieve the same qpitch. For the
348
* affected heights, we increment the height by 1 for the rendering
349
* surface.
350
*/
351
if (GFX_VER == 6 && (info->view->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) &&
352
info->surf->samples > 1 &&
353
(info->surf->logical_level0_px.height % 4) == 1)
354
s.Height++;
355
356
switch (s.SurfaceType) {
357
case SURFTYPE_1D:
358
case SURFTYPE_2D:
359
/* From the Ivy Bridge PRM >> RENDER_SURFACE_STATE::MinimumArrayElement:
360
*
361
* "If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
362
* must be set to zero if this surface is used with sampling engine
363
* messages."
364
*
365
* This restriction appears to exist only on Ivy Bridge.
366
*/
367
if (GFX_VERx10 == 70 && !ISL_DEV_IS_BAYTRAIL(dev) &&
368
(info->view->usage & ISL_SURF_USAGE_TEXTURE_BIT) &&
369
info->surf->samples > 1)
370
assert(info->view->base_array_layer == 0);
371
372
s.MinimumArrayElement = info->view->base_array_layer;
373
374
/* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
375
*
376
* For SURFTYPE_1D, 2D, and CUBE: The range of this field is reduced
377
* by one for each increase from zero of Minimum Array Element. For
378
* example, if Minimum Array Element is set to 1024 on a 2D surface,
379
* the range of this field is reduced to [0,1023].
380
*
381
* In other words, 'Depth' is the number of array layers.
382
*/
383
s.Depth = info->view->array_len - 1;
384
385
/* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
386
*
387
* For Render Target and Typed Dataport 1D and 2D Surfaces:
388
* This field must be set to the same value as the Depth field.
389
*/
390
if (info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
391
ISL_SURF_USAGE_STORAGE_BIT))
392
s.RenderTargetViewExtent = s.Depth;
393
break;
394
case SURFTYPE_CUBE:
395
s.MinimumArrayElement = info->view->base_array_layer;
396
/* Same as SURFTYPE_2D, but divided by 6 */
397
s.Depth = info->view->array_len / 6 - 1;
398
if (info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
399
ISL_SURF_USAGE_STORAGE_BIT))
400
s.RenderTargetViewExtent = s.Depth;
401
break;
402
case SURFTYPE_3D:
403
/* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
404
*
405
* If the volume texture is MIP-mapped, this field specifies the
406
* depth of the base MIP level.
407
*/
408
s.Depth = info->surf->logical_level0_px.depth - 1;
409
410
/* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
411
*
412
* For Render Target and Typed Dataport 3D Surfaces: This field
413
* indicates the extent of the accessible 'R' coordinates minus 1 on
414
* the LOD currently being rendered to.
415
*
416
* The docs specify that this only matters for render targets and
417
* surfaces used with typed dataport messages. Prior to Ivy Bridge, the
418
* Depth field has more bits than RenderTargetViewExtent so we can have
419
* textures with more levels than we can render to. In order to prevent
420
* assert-failures in the packing function below, we only set the field
421
* when it's actually going to be used by the hardware.
422
*
423
* Similaraly, the MinimumArrayElement field is ignored by all hardware
424
* prior to Sky Lake when texturing and we want it set to 0 anyway.
425
* Since it's already initialized to 0, we can just leave it alone for
426
* texture surfaces.
427
*/
428
if (info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
429
ISL_SURF_USAGE_STORAGE_BIT)) {
430
s.MinimumArrayElement = info->view->base_array_layer;
431
s.RenderTargetViewExtent = info->view->array_len - 1;
432
}
433
break;
434
default:
435
unreachable("bad SurfaceType");
436
}
437
438
#if GFX_VER >= 12
439
/* Wa_1806565034: Only set SurfaceArray if arrayed surface is > 1. */
440
s.SurfaceArray = info->surf->dim != ISL_SURF_DIM_3D &&
441
info->view->array_len > 1;
442
#elif GFX_VER >= 7
443
s.SurfaceArray = info->surf->dim != ISL_SURF_DIM_3D;
444
#endif
445
446
if (info->view->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
447
/* For render target surfaces, the hardware interprets field
448
* MIPCount/LOD as LOD. The Broadwell PRM says:
449
*
450
* MIPCountLOD defines the LOD that will be rendered into.
451
* SurfaceMinLOD is ignored.
452
*/
453
s.MIPCountLOD = info->view->base_level;
454
s.SurfaceMinLOD = 0;
455
} else {
456
/* For non render target surfaces, the hardware interprets field
457
* MIPCount/LOD as MIPCount. The range of levels accessible by the
458
* sampler engine is [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
459
*/
460
s.SurfaceMinLOD = info->view->base_level;
461
s.MIPCountLOD = MAX(info->view->levels, 1) - 1;
462
}
463
464
#if GFX_VER >= 9
465
/* We don't use miptails yet. The PRM recommends that you set "Mip Tail
466
* Start LOD" to 15 to prevent the hardware from trying to use them.
467
*/
468
s.TiledResourceMode = NONE;
469
s.MipTailStartLOD = 15;
470
#endif
471
472
#if GFX_VER >= 6
473
const struct isl_extent3d image_align = get_image_alignment(info->surf);
474
s.SurfaceVerticalAlignment = isl_encode_valign[image_align.height];
475
#if GFX_VER >= 7
476
s.SurfaceHorizontalAlignment = isl_encode_halign[image_align.width];
477
#endif
478
#endif
479
480
if (info->surf->dim_layout == ISL_DIM_LAYOUT_GFX9_1D) {
481
/* For gfx9 1-D textures, surface pitch is ignored */
482
s.SurfacePitch = 0;
483
} else {
484
s.SurfacePitch = info->surf->row_pitch_B - 1;
485
}
486
487
#if GFX_VER >= 8
488
s.SurfaceQPitch = get_qpitch(info->surf) >> 2;
489
#elif GFX_VER == 7
490
s.SurfaceArraySpacing = info->surf->array_pitch_span ==
491
ISL_ARRAY_PITCH_SPAN_COMPACT;
492
#endif
493
494
#if GFX_VER >= 8
495
assert(GFX_VER < 12 || info->surf->tiling != ISL_TILING_W);
496
s.TileMode = isl_encode_tiling[info->surf->tiling];
497
#else
498
s.TiledSurface = info->surf->tiling != ISL_TILING_LINEAR,
499
s.TileWalk = info->surf->tiling == ISL_TILING_Y0 ? TILEWALK_YMAJOR :
500
TILEWALK_XMAJOR,
501
#endif
502
503
#if GFX_VER >= 8
504
s.RenderCacheReadWriteMode = WriteOnlyCache;
505
#else
506
s.RenderCacheReadWriteMode = 0;
507
#endif
508
509
#if GFX_VER >= 11
510
/* We've seen dEQP failures when enabling this bit with UINT formats,
511
* which particularly affects blorp_copy() operations. It shouldn't
512
* have any effect on UINT textures anyway, so disable it for them.
513
*/
514
s.EnableUnormPathInColorPipe =
515
!isl_format_has_int_channel(info->view->format);
516
#endif
517
518
s.CubeFaceEnablePositiveZ = 1;
519
s.CubeFaceEnableNegativeZ = 1;
520
s.CubeFaceEnablePositiveY = 1;
521
s.CubeFaceEnableNegativeY = 1;
522
s.CubeFaceEnablePositiveX = 1;
523
s.CubeFaceEnableNegativeX = 1;
524
525
#if GFX_VER >= 6
526
s.NumberofMultisamples = ffs(info->surf->samples) - 1;
527
#if GFX_VER >= 7
528
s.MultisampledSurfaceStorageFormat =
529
isl_encode_multisample_layout[info->surf->msaa_layout];
530
#endif
531
#endif
532
533
#if (GFX_VERx10 >= 75)
534
if (info->view->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT)
535
assert(isl_swizzle_supports_rendering(dev->info, info->view->swizzle));
536
537
s.ShaderChannelSelectRed = (enum GENX(ShaderChannelSelect)) info->view->swizzle.r;
538
s.ShaderChannelSelectGreen = (enum GENX(ShaderChannelSelect)) info->view->swizzle.g;
539
s.ShaderChannelSelectBlue = (enum GENX(ShaderChannelSelect)) info->view->swizzle.b;
540
s.ShaderChannelSelectAlpha = (enum GENX(ShaderChannelSelect)) info->view->swizzle.a;
541
#else
542
assert(isl_swizzle_is_identity(info->view->swizzle));
543
#endif
544
545
s.SurfaceBaseAddress = info->address;
546
547
#if GFX_VER >= 6
548
s.MOCS = info->mocs;
549
#endif
550
551
#if GFX_VERx10 >= 45
552
if (info->x_offset_sa != 0 || info->y_offset_sa != 0) {
553
/* There are fairly strict rules about when the offsets can be used.
554
* These are mostly taken from the Sky Lake PRM documentation for
555
* RENDER_SURFACE_STATE.
556
*/
557
assert(info->surf->tiling != ISL_TILING_LINEAR);
558
assert(info->surf->dim == ISL_SURF_DIM_2D);
559
assert(isl_is_pow2(isl_format_get_layout(info->view->format)->bpb));
560
assert(info->surf->levels == 1);
561
assert(info->surf->logical_level0_px.array_len == 1);
562
assert(info->aux_usage == ISL_AUX_USAGE_NONE);
563
564
if (GFX_VER >= 8) {
565
/* Broadwell added more rules. */
566
assert(info->surf->samples == 1);
567
if (isl_format_get_layout(info->view->format)->bpb == 8)
568
assert(info->x_offset_sa % 16 == 0);
569
if (isl_format_get_layout(info->view->format)->bpb == 16)
570
assert(info->x_offset_sa % 8 == 0);
571
}
572
573
#if GFX_VER >= 7
574
s.SurfaceArray = false;
575
#endif
576
}
577
578
const unsigned x_div = 4;
579
const unsigned y_div = GFX_VER >= 8 ? 4 : 2;
580
assert(info->x_offset_sa % x_div == 0);
581
assert(info->y_offset_sa % y_div == 0);
582
s.XOffset = info->x_offset_sa / x_div;
583
s.YOffset = info->y_offset_sa / y_div;
584
#else
585
assert(info->x_offset_sa == 0);
586
assert(info->y_offset_sa == 0);
587
#endif
588
589
#if GFX_VER >= 7
590
if (info->aux_usage != ISL_AUX_USAGE_NONE) {
591
/* Check valid aux usages per-gen */
592
if (GFX_VER >= 12) {
593
assert(info->aux_usage == ISL_AUX_USAGE_MCS ||
594
info->aux_usage == ISL_AUX_USAGE_CCS_E ||
595
info->aux_usage == ISL_AUX_USAGE_GFX12_CCS_E ||
596
info->aux_usage == ISL_AUX_USAGE_MC ||
597
info->aux_usage == ISL_AUX_USAGE_HIZ_CCS_WT ||
598
info->aux_usage == ISL_AUX_USAGE_MCS_CCS ||
599
info->aux_usage == ISL_AUX_USAGE_STC_CCS);
600
} else if (GFX_VER >= 9) {
601
assert(info->aux_usage == ISL_AUX_USAGE_HIZ ||
602
info->aux_usage == ISL_AUX_USAGE_MCS ||
603
info->aux_usage == ISL_AUX_USAGE_CCS_D ||
604
info->aux_usage == ISL_AUX_USAGE_CCS_E);
605
} else if (GFX_VER >= 8) {
606
assert(info->aux_usage == ISL_AUX_USAGE_HIZ ||
607
info->aux_usage == ISL_AUX_USAGE_MCS ||
608
info->aux_usage == ISL_AUX_USAGE_CCS_D);
609
} else if (GFX_VER >= 7) {
610
assert(info->aux_usage == ISL_AUX_USAGE_MCS ||
611
info->aux_usage == ISL_AUX_USAGE_CCS_D);
612
}
613
614
/* The docs don't appear to say anything whatsoever about compression
615
* and the data port. Testing seems to indicate that the data port
616
* completely ignores the AuxiliarySurfaceMode field.
617
*
618
* On gfx12 HDC supports compression.
619
*/
620
if (GFX_VER < 12)
621
assert(!(info->view->usage & ISL_SURF_USAGE_STORAGE_BIT));
622
623
if (isl_surf_usage_is_depth(info->surf->usage))
624
assert(isl_aux_usage_has_hiz(info->aux_usage));
625
626
if (isl_surf_usage_is_stencil(info->surf->usage))
627
assert(info->aux_usage == ISL_AUX_USAGE_STC_CCS);
628
629
if (isl_aux_usage_has_hiz(info->aux_usage)) {
630
/* For Gfx8-10, there are some restrictions around sampling from HiZ.
631
* The Skylake PRM docs for RENDER_SURFACE_STATE::AuxiliarySurfaceMode
632
* say:
633
*
634
* "If this field is set to AUX_HIZ, Number of Multisamples must
635
* be MULTISAMPLECOUNT_1, and Surface Type cannot be SURFTYPE_3D."
636
*
637
* On Gfx12, the docs are a bit less obvious but the restriction is
638
* the same. The limitation isn't called out explicitly but the docs
639
* for the CCS_E value of RENDER_SURFACE_STATE::AuxiliarySurfaceMode
640
* say:
641
*
642
* "If Number of multisamples > 1, programming this value means
643
* MSAA compression is enabled for that surface. Auxillary surface
644
* is MSC with tile y."
645
*
646
* Since this interpretation ignores whether the surface is
647
* depth/stencil or not and since multisampled depth buffers use
648
* ISL_MSAA_LAYOUT_INTERLEAVED which is incompatible with MCS
649
* compression, this means that we can't even specify MSAA depth CCS
650
* in RENDER_SURFACE_STATE::AuxiliarySurfaceMode.
651
*/
652
assert(info->surf->samples == 1);
653
654
/* The dimension must not be 3D */
655
assert(info->surf->dim != ISL_SURF_DIM_3D);
656
657
/* The format must be one of the following: */
658
switch (info->view->format) {
659
case ISL_FORMAT_R32_FLOAT:
660
case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
661
case ISL_FORMAT_R16_UNORM:
662
break;
663
default:
664
assert(!"Incompatible HiZ Sampling format");
665
break;
666
}
667
}
668
669
#if GFX_VER >= 12
670
s.MemoryCompressionEnable = info->aux_usage == ISL_AUX_USAGE_MC;
671
#endif
672
#if GFX_VER >= 8
673
s.AuxiliarySurfaceMode = isl_encode_aux_mode[info->aux_usage];
674
#else
675
s.MCSEnable = true;
676
#endif
677
}
678
679
/* The auxiliary buffer info is filled when it's useable by the HW.
680
*
681
* Starting with Gfx12, the only form of compression that can be used
682
* with RENDER_SURFACE_STATE which requires an aux surface is MCS.
683
* HiZ still requires a surface but the HiZ surface can only be
684
* accessed through 3DSTATE_HIER_DEPTH_BUFFER.
685
*
686
* On all earlier hardware, an aux surface is required for all forms
687
* of compression.
688
*/
689
if ((GFX_VER < 12 && info->aux_usage != ISL_AUX_USAGE_NONE) ||
690
(GFX_VER >= 12 && isl_aux_usage_has_mcs(info->aux_usage))) {
691
692
assert(info->aux_surf != NULL);
693
694
struct isl_tile_info tile_info;
695
isl_surf_get_tile_info(info->aux_surf, &tile_info);
696
uint32_t pitch_in_tiles =
697
info->aux_surf->row_pitch_B / tile_info.phys_extent_B.width;
698
699
s.AuxiliarySurfaceBaseAddress = info->aux_address;
700
s.AuxiliarySurfacePitch = pitch_in_tiles - 1;
701
702
#if GFX_VER >= 8
703
/* Auxiliary surfaces in ISL have compressed formats but the hardware
704
* doesn't expect our definition of the compression, it expects qpitch
705
* in units of samples on the main surface.
706
*/
707
s.AuxiliarySurfaceQPitch =
708
isl_surf_get_array_pitch_sa_rows(info->aux_surf) >> 2;
709
#endif
710
}
711
#endif
712
713
#if GFX_VER >= 8 && GFX_VER < 11
714
/* From the CHV PRM, Volume 2d, page 321 (RENDER_SURFACE_STATE dword 0
715
* bit 9 "Sampler L2 Bypass Mode Disable" Programming Notes):
716
*
717
* This bit must be set for the following surface types: BC2_UNORM
718
* BC3_UNORM BC5_UNORM BC5_SNORM BC7_UNORM
719
*/
720
if (GFX_VER >= 9 || dev->info->is_cherryview) {
721
switch (info->view->format) {
722
case ISL_FORMAT_BC2_UNORM:
723
case ISL_FORMAT_BC3_UNORM:
724
case ISL_FORMAT_BC5_UNORM:
725
case ISL_FORMAT_BC5_SNORM:
726
case ISL_FORMAT_BC7_UNORM:
727
s.SamplerL2BypassModeDisable = true;
728
break;
729
default:
730
/* From the SKL PRM, Programming Note under Sampler Output Channel
731
* Mapping:
732
*
733
* If a surface has an associated HiZ Auxilliary surface, the
734
* Sampler L2 Bypass Mode Disable field in the RENDER_SURFACE_STATE
735
* must be set.
736
*/
737
if (GFX_VER >= 9 && info->aux_usage == ISL_AUX_USAGE_HIZ)
738
s.SamplerL2BypassModeDisable = true;
739
break;
740
}
741
}
742
#endif
743
744
if (isl_aux_usage_has_fast_clears(info->aux_usage)) {
745
if (info->use_clear_address) {
746
#if GFX_VER >= 10
747
s.ClearValueAddressEnable = true;
748
s.ClearValueAddress = info->clear_address;
749
#else
750
unreachable("Gfx9 and earlier do not support indirect clear colors");
751
#endif
752
}
753
754
#if GFX_VER == 11
755
/*
756
* From BXML > GT > Shared Functions > vol5c Shared Functions >
757
* [Structure] RENDER_SURFACE_STATE [BDW+] > ClearColorConversionEnable:
758
*
759
* Project: Gfx11
760
*
761
* "Enables Pixel backend hw to convert clear values into native format
762
* and write back to clear address, so that display and sampler can use
763
* the converted value for resolving fast cleared RTs."
764
*
765
* Summary:
766
* Clear color conversion must be enabled if the clear color is stored
767
* indirectly and fast color clears are enabled.
768
*/
769
if (info->use_clear_address) {
770
s.ClearColorConversionEnable = true;
771
}
772
#endif
773
774
#if GFX_VER >= 12
775
assert(info->use_clear_address);
776
#elif GFX_VER >= 9
777
if (!info->use_clear_address) {
778
s.RedClearColor = info->clear_color.u32[0];
779
s.GreenClearColor = info->clear_color.u32[1];
780
s.BlueClearColor = info->clear_color.u32[2];
781
s.AlphaClearColor = info->clear_color.u32[3];
782
}
783
#elif GFX_VER >= 7
784
/* Prior to Sky Lake, we only have one bit for the clear color which
785
* gives us 0 or 1 in whatever the surface's format happens to be.
786
*/
787
if (isl_format_has_int_channel(info->view->format)) {
788
for (unsigned i = 0; i < 4; i++) {
789
assert(info->clear_color.u32[i] == 0 ||
790
info->clear_color.u32[i] == 1);
791
}
792
s.RedClearColor = info->clear_color.u32[0] != 0;
793
s.GreenClearColor = info->clear_color.u32[1] != 0;
794
s.BlueClearColor = info->clear_color.u32[2] != 0;
795
s.AlphaClearColor = info->clear_color.u32[3] != 0;
796
} else {
797
for (unsigned i = 0; i < 4; i++) {
798
assert(info->clear_color.f32[i] == 0.0f ||
799
info->clear_color.f32[i] == 1.0f);
800
}
801
s.RedClearColor = info->clear_color.f32[0] != 0.0f;
802
s.GreenClearColor = info->clear_color.f32[1] != 0.0f;
803
s.BlueClearColor = info->clear_color.f32[2] != 0.0f;
804
s.AlphaClearColor = info->clear_color.f32[3] != 0.0f;
805
}
806
#endif
807
}
808
809
GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &s);
810
}
811
812
void
813
isl_genX(buffer_fill_state_s)(const struct isl_device *dev, void *state,
814
const struct isl_buffer_fill_state_info *restrict info)
815
{
816
uint64_t buffer_size = info->size_B;
817
818
/* Uniform and Storage buffers need to have surface size not less that the
819
* aligned 32-bit size of the buffer. To calculate the array lenght on
820
* unsized arrays in StorageBuffer the last 2 bits store the padding size
821
* added to the surface, so we can calculate latter the original buffer
822
* size to know the number of elements.
823
*
824
* surface_size = isl_align(buffer_size, 4) +
825
* (isl_align(buffer_size) - buffer_size)
826
*
827
* buffer_size = (surface_size & ~3) - (surface_size & 3)
828
*/
829
if ((info->format == ISL_FORMAT_RAW ||
830
info->stride_B < isl_format_get_layout(info->format)->bpb / 8) &&
831
!info->is_scratch) {
832
assert(info->stride_B == 1);
833
uint64_t aligned_size = isl_align(buffer_size, 4);
834
buffer_size = aligned_size + (aligned_size - buffer_size);
835
}
836
837
uint32_t num_elements = buffer_size / info->stride_B;
838
839
if (GFX_VER >= 7) {
840
/* From the IVB PRM, SURFACE_STATE::Height,
841
*
842
* For typed buffer and structured buffer surfaces, the number
843
* of entries in the buffer ranges from 1 to 2^27. For raw buffer
844
* surfaces, the number of entries in the buffer is the number of bytes
845
* which can range from 1 to 2^30.
846
*/
847
if (info->format == ISL_FORMAT_RAW) {
848
assert(num_elements <= (1ull << 30));
849
assert(num_elements > 0);
850
} else {
851
assert(num_elements <= (1ull << 27));
852
}
853
} else {
854
assert(num_elements <= (1ull << 27));
855
}
856
857
struct GENX(RENDER_SURFACE_STATE) s = { 0, };
858
859
s.SurfaceFormat = info->format;
860
861
s.SurfaceType = SURFTYPE_BUFFER;
862
#if GFX_VERx10 >= 125
863
if (info->is_scratch) {
864
/* From the BSpec:
865
*
866
* "For surfaces of type SURFTYPE_SCRATCH, valid range of pitch is:
867
* [63,262143] -> [64B, 256KB]. Also, for SURFTYPE_SCRATCH, the
868
* pitch must be a multiple of 64bytes."
869
*/
870
assert(info->format == ISL_FORMAT_RAW);
871
assert(info->stride_B % 64 == 0);
872
assert(info->stride_B <= 256 * 1024);
873
s.SurfaceType = SURFTYPE_SCRATCH;
874
}
875
#else
876
assert(!info->is_scratch);
877
#endif
878
879
s.SurfacePitch = info->stride_B - 1;
880
881
#if GFX_VER >= 6
882
s.SurfaceVerticalAlignment = isl_encode_valign[4];
883
#if GFX_VER >= 7
884
s.SurfaceHorizontalAlignment = isl_encode_halign[4];
885
s.SurfaceArray = false;
886
#endif
887
#endif
888
889
#if GFX_VER >= 7
890
s.Height = ((num_elements - 1) >> 7) & 0x3fff;
891
s.Width = (num_elements - 1) & 0x7f;
892
s.Depth = ((num_elements - 1) >> 21) & 0x3ff;
893
#else
894
s.Height = ((num_elements - 1) >> 7) & 0x1fff;
895
s.Width = (num_elements - 1) & 0x7f;
896
s.Depth = ((num_elements - 1) >> 20) & 0x7f;
897
#endif
898
899
if (GFX_VER == 12 && dev->info->revision == 0) {
900
/* TGL-LP A0 has a HW bug (fixed in later HW) which causes buffer
901
* textures with very close base addresses (delta < 64B) to corrupt each
902
* other. We can sort-of work around this by making small buffer
903
* textures 1D textures instead. This doesn't fix the problem for large
904
* buffer textures but the liklihood of large, overlapping, and very
905
* close buffer textures is fairly low and the point is to hack around
906
* the bug so we can run apps and tests.
907
*/
908
if (info->format != ISL_FORMAT_RAW &&
909
info->stride_B == isl_format_get_layout(info->format)->bpb / 8 &&
910
num_elements <= (1 << 14)) {
911
s.SurfaceType = SURFTYPE_1D;
912
s.Width = num_elements - 1;
913
s.Height = 0;
914
s.Depth = 0;
915
}
916
}
917
918
#if GFX_VER >= 6
919
s.NumberofMultisamples = MULTISAMPLECOUNT_1;
920
#endif
921
922
#if (GFX_VER >= 8)
923
s.TileMode = LINEAR;
924
#else
925
s.TiledSurface = false;
926
#endif
927
928
#if (GFX_VER >= 8)
929
s.RenderCacheReadWriteMode = WriteOnlyCache;
930
#else
931
s.RenderCacheReadWriteMode = 0;
932
#endif
933
934
s.SurfaceBaseAddress = info->address;
935
#if GFX_VER >= 6
936
s.MOCS = info->mocs;
937
#endif
938
939
#if (GFX_VERx10 >= 75)
940
s.ShaderChannelSelectRed = (enum GENX(ShaderChannelSelect)) info->swizzle.r;
941
s.ShaderChannelSelectGreen = (enum GENX(ShaderChannelSelect)) info->swizzle.g;
942
s.ShaderChannelSelectBlue = (enum GENX(ShaderChannelSelect)) info->swizzle.b;
943
s.ShaderChannelSelectAlpha = (enum GENX(ShaderChannelSelect)) info->swizzle.a;
944
#endif
945
946
GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &s);
947
}
948
949
void
950
isl_genX(null_fill_state)(void *state,
951
const struct isl_null_fill_state_info *restrict info)
952
{
953
struct GENX(RENDER_SURFACE_STATE) s = {
954
.SurfaceType = SURFTYPE_NULL,
955
/* We previously had this format set to B8G8R8A8_UNORM but ran into
956
* hangs on IVB. R32_UINT seems to work for everybody.
957
*
958
* https://gitlab.freedesktop.org/mesa/mesa/-/issues/1872
959
*/
960
.SurfaceFormat = ISL_FORMAT_R32_UINT,
961
#if GFX_VER >= 7
962
.SurfaceArray = info->size.depth > 1,
963
#endif
964
#if GFX_VER >= 8
965
.TileMode = YMAJOR,
966
#else
967
.TiledSurface = true,
968
.TileWalk = TILEWALK_YMAJOR,
969
#endif
970
#if GFX_VER == 7
971
/* According to PRMs: "Volume 4 Part 1: Subsystem and Cores – Shared
972
* Functions"
973
*
974
* RENDER_SURFACE_STATE::Surface Vertical Alignment
975
*
976
* "This field must be set to VALIGN_4 for all tiled Y Render Target
977
* surfaces."
978
*
979
* Affect IVB, HSW.
980
*/
981
.SurfaceVerticalAlignment = VALIGN_4,
982
#endif
983
.MIPCountLOD = info->levels,
984
.Width = info->size.width - 1,
985
.Height = info->size.height - 1,
986
.Depth = info->size.depth - 1,
987
.RenderTargetViewExtent = info->size.depth - 1,
988
#if GFX_VER <= 5
989
.MinimumArrayElement = info->minimum_array_element,
990
.ColorBufferComponentWriteDisables = 0xf,
991
#endif
992
};
993
GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &s);
994
}
995
996