Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/intel/isl/isl.c
4547 views
1
/*
2
* Copyright 2015 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 <assert.h>
25
#include <stdarg.h>
26
#include <stdio.h>
27
28
#include "genxml/genX_bits.h"
29
30
#include "isl.h"
31
#include "isl_gfx4.h"
32
#include "isl_gfx6.h"
33
#include "isl_gfx7.h"
34
#include "isl_gfx8.h"
35
#include "isl_gfx9.h"
36
#include "isl_gfx12.h"
37
#include "isl_priv.h"
38
39
void
40
isl_memcpy_linear_to_tiled(uint32_t xt1, uint32_t xt2,
41
uint32_t yt1, uint32_t yt2,
42
char *dst, const char *src,
43
uint32_t dst_pitch, int32_t src_pitch,
44
bool has_swizzling,
45
enum isl_tiling tiling,
46
isl_memcpy_type copy_type)
47
{
48
#ifdef USE_SSE41
49
if (copy_type == ISL_MEMCPY_STREAMING_LOAD) {
50
_isl_memcpy_linear_to_tiled_sse41(
51
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
52
tiling, copy_type);
53
return;
54
}
55
#endif
56
57
_isl_memcpy_linear_to_tiled(
58
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
59
tiling, copy_type);
60
}
61
62
void
63
isl_memcpy_tiled_to_linear(uint32_t xt1, uint32_t xt2,
64
uint32_t yt1, uint32_t yt2,
65
char *dst, const char *src,
66
int32_t dst_pitch, uint32_t src_pitch,
67
bool has_swizzling,
68
enum isl_tiling tiling,
69
isl_memcpy_type copy_type)
70
{
71
#ifdef USE_SSE41
72
if (copy_type == ISL_MEMCPY_STREAMING_LOAD) {
73
_isl_memcpy_tiled_to_linear_sse41(
74
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
75
tiling, copy_type);
76
return;
77
}
78
#endif
79
80
_isl_memcpy_tiled_to_linear(
81
xt1, xt2, yt1, yt2, dst, src, dst_pitch, src_pitch, has_swizzling,
82
tiling, copy_type);
83
}
84
85
void PRINTFLIKE(3, 4) UNUSED
86
__isl_finishme(const char *file, int line, const char *fmt, ...)
87
{
88
va_list ap;
89
char buf[512];
90
91
va_start(ap, fmt);
92
vsnprintf(buf, sizeof(buf), fmt, ap);
93
va_end(ap);
94
95
fprintf(stderr, "%s:%d: FINISHME: %s\n", file, line, buf);
96
}
97
98
static void
99
isl_device_setup_mocs(struct isl_device *dev)
100
{
101
if (dev->info->ver >= 12) {
102
if (dev->info->is_dg1) {
103
/* L3CC=WB */
104
dev->mocs.internal = 5 << 1;
105
/* Displayables on DG1 are free to cache in L3 since L3 is transient
106
* and flushed at bottom of each submission.
107
*/
108
dev->mocs.external = 5 << 1;
109
} else {
110
/* TODO: Set PTE to MOCS 61 when the kernel is ready */
111
/* TC=1/LLC Only, LeCC=1/Uncacheable, LRUM=0, L3CC=1/Uncacheable */
112
dev->mocs.external = 3 << 1;
113
/* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
114
dev->mocs.internal = 2 << 1;
115
116
/* L1 - HDC:L1 + L3 + LLC */
117
dev->mocs.l1_hdc_l3_llc = 48 << 1;
118
}
119
} else if (dev->info->ver >= 9) {
120
/* TC=LLC/eLLC, LeCC=PTE, LRUM=3, L3CC=WB */
121
dev->mocs.external = 1 << 1;
122
/* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
123
dev->mocs.internal = 2 << 1;
124
} else if (dev->info->ver >= 8) {
125
/* MEMORY_OBJECT_CONTROL_STATE:
126
* .MemoryTypeLLCeLLCCacheabilityControl = UCwithFenceifcoherentcycle,
127
* .TargetCache = L3DefertoPATforLLCeLLCselection,
128
* .AgeforQUADLRU = 0
129
*/
130
dev->mocs.external = 0x18;
131
/* MEMORY_OBJECT_CONTROL_STATE:
132
* .MemoryTypeLLCeLLCCacheabilityControl = WB,
133
* .TargetCache = L3DefertoPATforLLCeLLCselection,
134
* .AgeforQUADLRU = 0
135
*/
136
dev->mocs.internal = 0x78;
137
} else if (dev->info->ver >= 7) {
138
if (dev->info->is_haswell) {
139
/* MEMORY_OBJECT_CONTROL_STATE:
140
* .LLCeLLCCacheabilityControlLLCCC = 0,
141
* .L3CacheabilityControlL3CC = 1,
142
*/
143
dev->mocs.internal = 1;
144
dev->mocs.external = 1;
145
} else {
146
/* MEMORY_OBJECT_CONTROL_STATE:
147
* .GraphicsDataTypeGFDT = 0,
148
* .LLCCacheabilityControlLLCCC = 0,
149
* .L3CacheabilityControlL3CC = 1,
150
*/
151
dev->mocs.internal = 1;
152
dev->mocs.external = 1;
153
}
154
} else {
155
dev->mocs.internal = 0;
156
dev->mocs.external = 0;
157
}
158
}
159
160
/**
161
* Return an appropriate MOCS entry for the given usage flags.
162
*/
163
uint32_t
164
isl_mocs(const struct isl_device *dev, isl_surf_usage_flags_t usage,
165
bool external)
166
{
167
if (external)
168
return dev->mocs.external;
169
170
if (dev->info->ver >= 12 && !dev->info->is_dg1) {
171
if (usage & ISL_SURF_USAGE_STAGING_BIT)
172
return dev->mocs.internal;
173
174
/* Using L1:HDC for storage buffers breaks Vulkan memory model
175
* tests that use shader atomics. This isn't likely to work out,
176
* and we can't know a priori whether they'll be used. So just
177
* continue with ordinary internal MOCS for now.
178
*/
179
if (usage & ISL_SURF_USAGE_STORAGE_BIT)
180
return dev->mocs.internal;
181
182
if (usage & (ISL_SURF_USAGE_CONSTANT_BUFFER_BIT |
183
ISL_SURF_USAGE_RENDER_TARGET_BIT |
184
ISL_SURF_USAGE_TEXTURE_BIT))
185
return dev->mocs.l1_hdc_l3_llc;
186
}
187
188
return dev->mocs.internal;
189
}
190
191
void
192
isl_device_init(struct isl_device *dev,
193
const struct intel_device_info *info,
194
bool has_bit6_swizzling)
195
{
196
/* Gfx8+ don't have bit6 swizzling, ensure callsite is not confused. */
197
assert(!(has_bit6_swizzling && info->ver >= 8));
198
199
dev->info = info;
200
dev->use_separate_stencil = ISL_GFX_VER(dev) >= 6;
201
dev->has_bit6_swizzling = has_bit6_swizzling;
202
203
/* The ISL_DEV macros may be defined in the CFLAGS, thus hardcoding some
204
* device properties at buildtime. Verify that the macros with the device
205
* properties chosen during runtime.
206
*/
207
ISL_GFX_VER_SANITIZE(dev);
208
ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(dev);
209
210
/* Did we break hiz or stencil? */
211
if (ISL_DEV_USE_SEPARATE_STENCIL(dev))
212
assert(info->has_hiz_and_separate_stencil);
213
if (info->must_use_separate_stencil)
214
assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
215
216
dev->ss.size = RENDER_SURFACE_STATE_length(info) * 4;
217
dev->ss.align = isl_align(dev->ss.size, 32);
218
219
dev->ss.clear_color_state_size =
220
isl_align(CLEAR_COLOR_length(info) * 4, 64);
221
dev->ss.clear_color_state_offset =
222
RENDER_SURFACE_STATE_ClearValueAddress_start(info) / 32 * 4;
223
224
dev->ss.clear_value_size =
225
isl_align(RENDER_SURFACE_STATE_RedClearColor_bits(info) +
226
RENDER_SURFACE_STATE_GreenClearColor_bits(info) +
227
RENDER_SURFACE_STATE_BlueClearColor_bits(info) +
228
RENDER_SURFACE_STATE_AlphaClearColor_bits(info), 32) / 8;
229
230
dev->ss.clear_value_offset =
231
RENDER_SURFACE_STATE_RedClearColor_start(info) / 32 * 4;
232
233
assert(RENDER_SURFACE_STATE_SurfaceBaseAddress_start(info) % 8 == 0);
234
dev->ss.addr_offset =
235
RENDER_SURFACE_STATE_SurfaceBaseAddress_start(info) / 8;
236
237
/* The "Auxiliary Surface Base Address" field starts a bit higher up
238
* because the bottom 12 bits are used for other things. Round down to
239
* the nearest dword before.
240
*/
241
dev->ss.aux_addr_offset =
242
(RENDER_SURFACE_STATE_AuxiliarySurfaceBaseAddress_start(info) & ~31) / 8;
243
244
dev->ds.size = _3DSTATE_DEPTH_BUFFER_length(info) * 4;
245
assert(_3DSTATE_DEPTH_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
246
dev->ds.depth_offset =
247
_3DSTATE_DEPTH_BUFFER_SurfaceBaseAddress_start(info) / 8;
248
249
if (dev->use_separate_stencil) {
250
dev->ds.size += _3DSTATE_STENCIL_BUFFER_length(info) * 4 +
251
_3DSTATE_HIER_DEPTH_BUFFER_length(info) * 4 +
252
_3DSTATE_CLEAR_PARAMS_length(info) * 4;
253
254
assert(_3DSTATE_STENCIL_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
255
dev->ds.stencil_offset =
256
_3DSTATE_DEPTH_BUFFER_length(info) * 4 +
257
_3DSTATE_STENCIL_BUFFER_SurfaceBaseAddress_start(info) / 8;
258
259
assert(_3DSTATE_HIER_DEPTH_BUFFER_SurfaceBaseAddress_start(info) % 8 == 0);
260
dev->ds.hiz_offset =
261
_3DSTATE_DEPTH_BUFFER_length(info) * 4 +
262
_3DSTATE_STENCIL_BUFFER_length(info) * 4 +
263
_3DSTATE_HIER_DEPTH_BUFFER_SurfaceBaseAddress_start(info) / 8;
264
} else {
265
dev->ds.stencil_offset = 0;
266
dev->ds.hiz_offset = 0;
267
}
268
269
if (ISL_GFX_VERX10(dev) == 120) {
270
dev->ds.size += GFX12_MI_LOAD_REGISTER_IMM_length * 4 * 2;
271
}
272
273
isl_device_setup_mocs(dev);
274
}
275
276
/**
277
* @brief Query the set of multisamples supported by the device.
278
*
279
* This function always returns non-zero, as ISL_SAMPLE_COUNT_1_BIT is always
280
* supported.
281
*/
282
isl_sample_count_mask_t ATTRIBUTE_CONST
283
isl_device_get_sample_counts(struct isl_device *dev)
284
{
285
if (ISL_GFX_VER(dev) >= 9) {
286
return ISL_SAMPLE_COUNT_1_BIT |
287
ISL_SAMPLE_COUNT_2_BIT |
288
ISL_SAMPLE_COUNT_4_BIT |
289
ISL_SAMPLE_COUNT_8_BIT |
290
ISL_SAMPLE_COUNT_16_BIT;
291
} else if (ISL_GFX_VER(dev) >= 8) {
292
return ISL_SAMPLE_COUNT_1_BIT |
293
ISL_SAMPLE_COUNT_2_BIT |
294
ISL_SAMPLE_COUNT_4_BIT |
295
ISL_SAMPLE_COUNT_8_BIT;
296
} else if (ISL_GFX_VER(dev) >= 7) {
297
return ISL_SAMPLE_COUNT_1_BIT |
298
ISL_SAMPLE_COUNT_4_BIT |
299
ISL_SAMPLE_COUNT_8_BIT;
300
} else if (ISL_GFX_VER(dev) >= 6) {
301
return ISL_SAMPLE_COUNT_1_BIT |
302
ISL_SAMPLE_COUNT_4_BIT;
303
} else {
304
return ISL_SAMPLE_COUNT_1_BIT;
305
}
306
}
307
308
/**
309
* Returns an isl_tile_info representation of the given isl_tiling when
310
* combined with a format of the given size.
311
*
312
* @param[out] info is written only on success
313
*/
314
void
315
isl_tiling_get_info(enum isl_tiling tiling,
316
uint32_t format_bpb,
317
struct isl_tile_info *tile_info)
318
{
319
const uint32_t bs = format_bpb / 8;
320
struct isl_extent4d logical_el;
321
struct isl_extent2d phys_B;
322
323
if (tiling != ISL_TILING_LINEAR && !isl_is_pow2(format_bpb)) {
324
/* It is possible to have non-power-of-two formats in a tiled buffer.
325
* The easiest way to handle this is to treat the tile as if it is three
326
* times as wide. This way no pixel will ever cross a tile boundary.
327
* This really only works on legacy X and Y tiling formats.
328
*/
329
assert(tiling == ISL_TILING_X || tiling == ISL_TILING_Y0);
330
assert(bs % 3 == 0 && isl_is_pow2(format_bpb / 3));
331
isl_tiling_get_info(tiling, format_bpb / 3, tile_info);
332
return;
333
}
334
335
switch (tiling) {
336
case ISL_TILING_LINEAR:
337
assert(bs > 0);
338
logical_el = isl_extent4d(1, 1, 1, 1);
339
phys_B = isl_extent2d(bs, 1);
340
break;
341
342
case ISL_TILING_X:
343
assert(bs > 0);
344
logical_el = isl_extent4d(512 / bs, 8, 1, 1);
345
phys_B = isl_extent2d(512, 8);
346
break;
347
348
case ISL_TILING_Y0:
349
assert(bs > 0);
350
logical_el = isl_extent4d(128 / bs, 32, 1, 1);
351
phys_B = isl_extent2d(128, 32);
352
break;
353
354
case ISL_TILING_W:
355
assert(bs == 1);
356
logical_el = isl_extent4d(64, 64, 1, 1);
357
/* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfacePitch:
358
*
359
* "If the surface is a stencil buffer (and thus has Tile Mode set
360
* to TILEMODE_WMAJOR), the pitch must be set to 2x the value
361
* computed based on width, as the stencil buffer is stored with two
362
* rows interleaved."
363
*
364
* This, together with the fact that stencil buffers are referred to as
365
* being Y-tiled in the PRMs for older hardware implies that the
366
* physical size of a W-tile is actually the same as for a Y-tile.
367
*/
368
phys_B = isl_extent2d(128, 32);
369
break;
370
371
case ISL_TILING_Yf:
372
case ISL_TILING_Ys: {
373
bool is_Ys = tiling == ISL_TILING_Ys;
374
375
assert(bs > 0);
376
unsigned width = 1 << (6 + (ffs(bs) / 2) + (2 * is_Ys));
377
unsigned height = 1 << (6 - (ffs(bs) / 2) + (2 * is_Ys));
378
379
logical_el = isl_extent4d(width / bs, height, 1, 1);
380
phys_B = isl_extent2d(width, height);
381
break;
382
}
383
384
case ISL_TILING_HIZ:
385
/* HiZ buffers are required to have ISL_FORMAT_HIZ which is an 8x4
386
* 128bpb format. The tiling has the same physical dimensions as
387
* Y-tiling but actually has two HiZ columns per Y-tiled column.
388
*/
389
assert(bs == 16);
390
logical_el = isl_extent4d(16, 16, 1, 1);
391
phys_B = isl_extent2d(128, 32);
392
break;
393
394
case ISL_TILING_CCS:
395
/* CCS surfaces are required to have one of the GENX_CCS_* formats which
396
* have a block size of 1 or 2 bits per block and each CCS element
397
* corresponds to one cache-line pair in the main surface. From the Sky
398
* Lake PRM Vol. 12 in the section on planes:
399
*
400
* "The Color Control Surface (CCS) contains the compression status
401
* of the cache-line pairs. The compression state of the cache-line
402
* pair is specified by 2 bits in the CCS. Each CCS cache-line
403
* represents an area on the main surface of 16x16 sets of 128 byte
404
* Y-tiled cache-line-pairs. CCS is always Y tiled."
405
*
406
* The CCS being Y-tiled implies that it's an 8x8 grid of cache-lines.
407
* Since each cache line corresponds to a 16x16 set of cache-line pairs,
408
* that yields total tile area of 128x128 cache-line pairs or CCS
409
* elements. On older hardware, each CCS element is 1 bit and the tile
410
* is 128x256 elements.
411
*/
412
assert(format_bpb == 1 || format_bpb == 2);
413
logical_el = isl_extent4d(128, 256 / format_bpb, 1, 1);
414
phys_B = isl_extent2d(128, 32);
415
break;
416
417
case ISL_TILING_GFX12_CCS:
418
/* From the Bspec, Gen Graphics > Gfx12 > Memory Data Formats > Memory
419
* Compression > Memory Compression - Gfx12:
420
*
421
* 4 bits of auxiliary plane data are required for 2 cachelines of
422
* main surface data. This results in a single cacheline of auxiliary
423
* plane data mapping to 4 4K pages of main surface data for the 4K
424
* pages (tile Y ) and 1 64K Tile Ys page.
425
*
426
* The Y-tiled pairing bit of 9 shown in the table below that Bspec
427
* section expresses that the 2 cachelines of main surface data are
428
* horizontally adjacent.
429
*
430
* TODO: Handle Ys, Yf and their pairing bits.
431
*
432
* Therefore, each CCS cacheline represents a 512Bx32 row area and each
433
* element represents a 32Bx4 row area.
434
*/
435
assert(format_bpb == 4);
436
logical_el = isl_extent4d(16, 8, 1, 1);
437
phys_B = isl_extent2d(64, 1);
438
break;
439
440
default:
441
unreachable("not reached");
442
} /* end switch */
443
444
*tile_info = (struct isl_tile_info) {
445
.tiling = tiling,
446
.format_bpb = format_bpb,
447
.logical_extent_el = logical_el,
448
.phys_extent_B = phys_B,
449
};
450
}
451
452
bool
453
isl_color_value_is_zero(union isl_color_value value,
454
enum isl_format format)
455
{
456
const struct isl_format_layout *fmtl = isl_format_get_layout(format);
457
458
#define RETURN_FALSE_IF_NOT_0(c, i) \
459
if (fmtl->channels.c.bits && value.u32[i] != 0) \
460
return false
461
462
RETURN_FALSE_IF_NOT_0(r, 0);
463
RETURN_FALSE_IF_NOT_0(g, 1);
464
RETURN_FALSE_IF_NOT_0(b, 2);
465
RETURN_FALSE_IF_NOT_0(a, 3);
466
467
#undef RETURN_FALSE_IF_NOT_0
468
469
return true;
470
}
471
472
bool
473
isl_color_value_is_zero_one(union isl_color_value value,
474
enum isl_format format)
475
{
476
const struct isl_format_layout *fmtl = isl_format_get_layout(format);
477
478
#define RETURN_FALSE_IF_NOT_0_1(c, i, field) \
479
if (fmtl->channels.c.bits && value.field[i] != 0 && value.field[i] != 1) \
480
return false
481
482
if (isl_format_has_int_channel(format)) {
483
RETURN_FALSE_IF_NOT_0_1(r, 0, u32);
484
RETURN_FALSE_IF_NOT_0_1(g, 1, u32);
485
RETURN_FALSE_IF_NOT_0_1(b, 2, u32);
486
RETURN_FALSE_IF_NOT_0_1(a, 3, u32);
487
} else {
488
RETURN_FALSE_IF_NOT_0_1(r, 0, f32);
489
RETURN_FALSE_IF_NOT_0_1(g, 1, f32);
490
RETURN_FALSE_IF_NOT_0_1(b, 2, f32);
491
RETURN_FALSE_IF_NOT_0_1(a, 3, f32);
492
}
493
494
#undef RETURN_FALSE_IF_NOT_0_1
495
496
return true;
497
}
498
499
/**
500
* @param[out] tiling is set only on success
501
*/
502
static bool
503
isl_surf_choose_tiling(const struct isl_device *dev,
504
const struct isl_surf_init_info *restrict info,
505
enum isl_tiling *tiling)
506
{
507
isl_tiling_flags_t tiling_flags = info->tiling_flags;
508
509
/* HiZ surfaces always use the HiZ tiling */
510
if (info->usage & ISL_SURF_USAGE_HIZ_BIT) {
511
assert(info->format == ISL_FORMAT_HIZ);
512
assert(tiling_flags == ISL_TILING_HIZ_BIT);
513
*tiling = isl_tiling_flag_to_enum(tiling_flags);
514
return true;
515
}
516
517
/* CCS surfaces always use the CCS tiling */
518
if (info->usage & ISL_SURF_USAGE_CCS_BIT) {
519
assert(isl_format_get_layout(info->format)->txc == ISL_TXC_CCS);
520
UNUSED bool ivb_ccs = ISL_GFX_VER(dev) < 12 &&
521
tiling_flags == ISL_TILING_CCS_BIT;
522
UNUSED bool tgl_ccs = ISL_GFX_VER(dev) >= 12 &&
523
tiling_flags == ISL_TILING_GFX12_CCS_BIT;
524
assert(ivb_ccs != tgl_ccs);
525
*tiling = isl_tiling_flag_to_enum(tiling_flags);
526
return true;
527
}
528
529
if (ISL_GFX_VER(dev) >= 6) {
530
isl_gfx6_filter_tiling(dev, info, &tiling_flags);
531
} else {
532
isl_gfx4_filter_tiling(dev, info, &tiling_flags);
533
}
534
535
#define CHOOSE(__tiling) \
536
do { \
537
if (tiling_flags & (1u << (__tiling))) { \
538
*tiling = (__tiling); \
539
return true; \
540
} \
541
} while (0)
542
543
/* Of the tiling modes remaining, choose the one that offers the best
544
* performance.
545
*/
546
547
if (info->dim == ISL_SURF_DIM_1D) {
548
/* Prefer linear for 1D surfaces because they do not benefit from
549
* tiling. To the contrary, tiling leads to wasted memory and poor
550
* memory locality due to the swizzling and alignment restrictions
551
* required in tiled surfaces.
552
*/
553
CHOOSE(ISL_TILING_LINEAR);
554
}
555
556
CHOOSE(ISL_TILING_Ys);
557
CHOOSE(ISL_TILING_Yf);
558
CHOOSE(ISL_TILING_Y0);
559
CHOOSE(ISL_TILING_X);
560
CHOOSE(ISL_TILING_W);
561
CHOOSE(ISL_TILING_LINEAR);
562
563
#undef CHOOSE
564
565
/* No tiling mode accomodates the inputs. */
566
return false;
567
}
568
569
static bool
570
isl_choose_msaa_layout(const struct isl_device *dev,
571
const struct isl_surf_init_info *info,
572
enum isl_tiling tiling,
573
enum isl_msaa_layout *msaa_layout)
574
{
575
if (ISL_GFX_VER(dev) >= 8) {
576
return isl_gfx8_choose_msaa_layout(dev, info, tiling, msaa_layout);
577
} else if (ISL_GFX_VER(dev) >= 7) {
578
return isl_gfx7_choose_msaa_layout(dev, info, tiling, msaa_layout);
579
} else if (ISL_GFX_VER(dev) >= 6) {
580
return isl_gfx6_choose_msaa_layout(dev, info, tiling, msaa_layout);
581
} else {
582
return isl_gfx4_choose_msaa_layout(dev, info, tiling, msaa_layout);
583
}
584
}
585
586
struct isl_extent2d
587
isl_get_interleaved_msaa_px_size_sa(uint32_t samples)
588
{
589
assert(isl_is_pow2(samples));
590
591
/* From the Broadwell PRM >> Volume 5: Memory Views >> Computing Mip Level
592
* Sizes (p133):
593
*
594
* If the surface is multisampled and it is a depth or stencil surface
595
* or Multisampled Surface StorageFormat in SURFACE_STATE is
596
* MSFMT_DEPTH_STENCIL, W_L and H_L must be adjusted as follows before
597
* proceeding: [...]
598
*/
599
return (struct isl_extent2d) {
600
.width = 1 << ((ffs(samples) - 0) / 2),
601
.height = 1 << ((ffs(samples) - 1) / 2),
602
};
603
}
604
605
static void
606
isl_msaa_interleaved_scale_px_to_sa(uint32_t samples,
607
uint32_t *width, uint32_t *height)
608
{
609
const struct isl_extent2d px_size_sa =
610
isl_get_interleaved_msaa_px_size_sa(samples);
611
612
if (width)
613
*width = isl_align(*width, 2) * px_size_sa.width;
614
if (height)
615
*height = isl_align(*height, 2) * px_size_sa.height;
616
}
617
618
static enum isl_array_pitch_span
619
isl_choose_array_pitch_span(const struct isl_device *dev,
620
const struct isl_surf_init_info *restrict info,
621
enum isl_dim_layout dim_layout,
622
const struct isl_extent4d *phys_level0_sa)
623
{
624
switch (dim_layout) {
625
case ISL_DIM_LAYOUT_GFX9_1D:
626
case ISL_DIM_LAYOUT_GFX4_2D:
627
if (ISL_GFX_VER(dev) >= 8) {
628
/* QPitch becomes programmable in Broadwell. So choose the
629
* most compact QPitch possible in order to conserve memory.
630
*
631
* From the Broadwell PRM >> Volume 2d: Command Reference: Structures
632
* >> RENDER_SURFACE_STATE Surface QPitch (p325):
633
*
634
* - Software must ensure that this field is set to a value
635
* sufficiently large such that the array slices in the surface
636
* do not overlap. Refer to the Memory Data Formats section for
637
* information on how surfaces are stored in memory.
638
*
639
* - This field specifies the distance in rows between array
640
* slices. It is used only in the following cases:
641
*
642
* - Surface Array is enabled OR
643
* - Number of Mulitsamples is not NUMSAMPLES_1 and
644
* Multisampled Surface Storage Format set to MSFMT_MSS OR
645
* - Surface Type is SURFTYPE_CUBE
646
*/
647
return ISL_ARRAY_PITCH_SPAN_COMPACT;
648
} else if (ISL_GFX_VER(dev) >= 7) {
649
/* Note that Ivybridge introduces
650
* RENDER_SURFACE_STATE.SurfaceArraySpacing, which provides the
651
* driver more control over the QPitch.
652
*/
653
654
if (phys_level0_sa->array_len == 1) {
655
/* The hardware will never use the QPitch. So choose the most
656
* compact QPitch possible in order to conserve memory.
657
*/
658
return ISL_ARRAY_PITCH_SPAN_COMPACT;
659
}
660
661
if (isl_surf_usage_is_depth_or_stencil(info->usage) ||
662
(info->usage & ISL_SURF_USAGE_HIZ_BIT)) {
663
/* From the Ivybridge PRM >> Volume 1 Part 1: Graphics Core >>
664
* Section 6.18.4.7: Surface Arrays (p112):
665
*
666
* If Surface Array Spacing is set to ARYSPC_FULL (note that
667
* the depth buffer and stencil buffer have an implied value of
668
* ARYSPC_FULL):
669
*/
670
return ISL_ARRAY_PITCH_SPAN_FULL;
671
}
672
673
if (info->levels == 1) {
674
/* We are able to set RENDER_SURFACE_STATE.SurfaceArraySpacing
675
* to ARYSPC_LOD0.
676
*/
677
return ISL_ARRAY_PITCH_SPAN_COMPACT;
678
}
679
680
return ISL_ARRAY_PITCH_SPAN_FULL;
681
} else if ((ISL_GFX_VER(dev) == 5 || ISL_GFX_VER(dev) == 6) &&
682
ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
683
isl_surf_usage_is_stencil(info->usage)) {
684
/* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
685
* Graphics Core >> Section 7.18.3.7: Surface Arrays:
686
*
687
* The separate stencil buffer does not support mip mapping, thus
688
* the storage for LODs other than LOD 0 is not needed.
689
*/
690
assert(info->levels == 1);
691
return ISL_ARRAY_PITCH_SPAN_COMPACT;
692
} else {
693
if ((ISL_GFX_VER(dev) == 5 || ISL_GFX_VER(dev) == 6) &&
694
ISL_DEV_USE_SEPARATE_STENCIL(dev) &&
695
isl_surf_usage_is_stencil(info->usage)) {
696
/* [ILK-SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
697
* Graphics Core >> Section 7.18.3.7: Surface Arrays:
698
*
699
* The separate stencil buffer does not support mip mapping,
700
* thus the storage for LODs other than LOD 0 is not needed.
701
*/
702
assert(info->levels == 1);
703
assert(phys_level0_sa->array_len == 1);
704
return ISL_ARRAY_PITCH_SPAN_COMPACT;
705
}
706
707
if (phys_level0_sa->array_len == 1) {
708
/* The hardware will never use the QPitch. So choose the most
709
* compact QPitch possible in order to conserve memory.
710
*/
711
return ISL_ARRAY_PITCH_SPAN_COMPACT;
712
}
713
714
return ISL_ARRAY_PITCH_SPAN_FULL;
715
}
716
717
case ISL_DIM_LAYOUT_GFX4_3D:
718
/* The hardware will never use the QPitch. So choose the most
719
* compact QPitch possible in order to conserve memory.
720
*/
721
return ISL_ARRAY_PITCH_SPAN_COMPACT;
722
723
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
724
/* Each array image in the gfx6 stencil of HiZ surface is compact in the
725
* sense that every LOD is a compact array of the same size as LOD0.
726
*/
727
return ISL_ARRAY_PITCH_SPAN_COMPACT;
728
}
729
730
unreachable("bad isl_dim_layout");
731
return ISL_ARRAY_PITCH_SPAN_FULL;
732
}
733
734
static void
735
isl_choose_image_alignment_el(const struct isl_device *dev,
736
const struct isl_surf_init_info *restrict info,
737
enum isl_tiling tiling,
738
enum isl_dim_layout dim_layout,
739
enum isl_msaa_layout msaa_layout,
740
struct isl_extent3d *image_align_el)
741
{
742
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
743
if (fmtl->txc == ISL_TXC_MCS) {
744
assert(tiling == ISL_TILING_Y0);
745
746
/*
747
* IvyBrigde PRM Vol 2, Part 1, "11.7 MCS Buffer for Render Target(s)":
748
*
749
* Height, width, and layout of MCS buffer in this case must match with
750
* Render Target height, width, and layout. MCS buffer is tiledY.
751
*
752
* To avoid wasting memory, choose the smallest alignment possible:
753
* HALIGN_4 and VALIGN_4.
754
*/
755
*image_align_el = isl_extent3d(4, 4, 1);
756
return;
757
} else if (info->format == ISL_FORMAT_HIZ) {
758
assert(ISL_GFX_VER(dev) >= 6);
759
if (ISL_GFX_VER(dev) == 6) {
760
/* HiZ surfaces on Sandy Bridge are packed tightly. */
761
*image_align_el = isl_extent3d(1, 1, 1);
762
} else if (ISL_GFX_VER(dev) < 12) {
763
/* On gfx7+, HiZ surfaces are always aligned to 16x8 pixels in the
764
* primary surface which works out to 2x2 HiZ elments.
765
*/
766
*image_align_el = isl_extent3d(2, 2, 1);
767
} else {
768
/* On gfx12+, HiZ surfaces are always aligned to 16x16 pixels in the
769
* primary surface which works out to 2x4 HiZ elments.
770
* TODO: Verify
771
*/
772
*image_align_el = isl_extent3d(2, 4, 1);
773
}
774
return;
775
}
776
777
if (ISL_GFX_VER(dev) >= 12) {
778
isl_gfx12_choose_image_alignment_el(dev, info, tiling, dim_layout,
779
msaa_layout, image_align_el);
780
} else if (ISL_GFX_VER(dev) >= 9) {
781
isl_gfx9_choose_image_alignment_el(dev, info, tiling, dim_layout,
782
msaa_layout, image_align_el);
783
} else if (ISL_GFX_VER(dev) >= 8) {
784
isl_gfx8_choose_image_alignment_el(dev, info, tiling, dim_layout,
785
msaa_layout, image_align_el);
786
} else if (ISL_GFX_VER(dev) >= 7) {
787
isl_gfx7_choose_image_alignment_el(dev, info, tiling, dim_layout,
788
msaa_layout, image_align_el);
789
} else if (ISL_GFX_VER(dev) >= 6) {
790
isl_gfx6_choose_image_alignment_el(dev, info, tiling, dim_layout,
791
msaa_layout, image_align_el);
792
} else {
793
isl_gfx4_choose_image_alignment_el(dev, info, tiling, dim_layout,
794
msaa_layout, image_align_el);
795
}
796
}
797
798
static enum isl_dim_layout
799
isl_surf_choose_dim_layout(const struct isl_device *dev,
800
enum isl_surf_dim logical_dim,
801
enum isl_tiling tiling,
802
isl_surf_usage_flags_t usage)
803
{
804
/* Sandy bridge needs a special layout for HiZ and stencil. */
805
if (ISL_GFX_VER(dev) == 6 &&
806
(tiling == ISL_TILING_W || tiling == ISL_TILING_HIZ))
807
return ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ;
808
809
if (ISL_GFX_VER(dev) >= 9) {
810
switch (logical_dim) {
811
case ISL_SURF_DIM_1D:
812
/* From the Sky Lake PRM Vol. 5, "1D Surfaces":
813
*
814
* One-dimensional surfaces use a tiling mode of linear.
815
* Technically, they are not tiled resources, but the Tiled
816
* Resource Mode field in RENDER_SURFACE_STATE is still used to
817
* indicate the alignment requirements for this linear surface
818
* (See 1D Alignment requirements for how 4K and 64KB Tiled
819
* Resource Modes impact alignment). Alternatively, a 1D surface
820
* can be defined as a 2D tiled surface (e.g. TileY or TileX) with
821
* a height of 0.
822
*
823
* In other words, ISL_DIM_LAYOUT_GFX9_1D is only used for linear
824
* surfaces and, for tiled surfaces, ISL_DIM_LAYOUT_GFX4_2D is used.
825
*/
826
if (tiling == ISL_TILING_LINEAR)
827
return ISL_DIM_LAYOUT_GFX9_1D;
828
else
829
return ISL_DIM_LAYOUT_GFX4_2D;
830
case ISL_SURF_DIM_2D:
831
case ISL_SURF_DIM_3D:
832
return ISL_DIM_LAYOUT_GFX4_2D;
833
}
834
} else {
835
switch (logical_dim) {
836
case ISL_SURF_DIM_1D:
837
case ISL_SURF_DIM_2D:
838
/* From the G45 PRM Vol. 1a, "6.17.4.1 Hardware Cube Map Layout":
839
*
840
* The cube face textures are stored in the same way as 3D surfaces
841
* are stored (see section 6.17.5 for details). For cube surfaces,
842
* however, the depth is equal to the number of faces (always 6) and
843
* is not reduced for each MIP.
844
*/
845
if (ISL_GFX_VER(dev) == 4 && (usage & ISL_SURF_USAGE_CUBE_BIT))
846
return ISL_DIM_LAYOUT_GFX4_3D;
847
848
return ISL_DIM_LAYOUT_GFX4_2D;
849
case ISL_SURF_DIM_3D:
850
return ISL_DIM_LAYOUT_GFX4_3D;
851
}
852
}
853
854
unreachable("bad isl_surf_dim");
855
return ISL_DIM_LAYOUT_GFX4_2D;
856
}
857
858
/**
859
* Calculate the physical extent of the surface's first level, in units of
860
* surface samples.
861
*/
862
static void
863
isl_calc_phys_level0_extent_sa(const struct isl_device *dev,
864
const struct isl_surf_init_info *restrict info,
865
enum isl_dim_layout dim_layout,
866
enum isl_tiling tiling,
867
enum isl_msaa_layout msaa_layout,
868
struct isl_extent4d *phys_level0_sa)
869
{
870
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
871
872
if (isl_format_is_planar(info->format))
873
unreachable("Planar formats unsupported");
874
875
switch (info->dim) {
876
case ISL_SURF_DIM_1D:
877
assert(info->height == 1);
878
assert(info->depth == 1);
879
assert(info->samples == 1);
880
881
switch (dim_layout) {
882
case ISL_DIM_LAYOUT_GFX4_3D:
883
unreachable("bad isl_dim_layout");
884
885
case ISL_DIM_LAYOUT_GFX9_1D:
886
case ISL_DIM_LAYOUT_GFX4_2D:
887
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
888
*phys_level0_sa = (struct isl_extent4d) {
889
.w = info->width,
890
.h = 1,
891
.d = 1,
892
.a = info->array_len,
893
};
894
break;
895
}
896
break;
897
898
case ISL_SURF_DIM_2D:
899
if (ISL_GFX_VER(dev) == 4 && (info->usage & ISL_SURF_USAGE_CUBE_BIT))
900
assert(dim_layout == ISL_DIM_LAYOUT_GFX4_3D);
901
else
902
assert(dim_layout == ISL_DIM_LAYOUT_GFX4_2D ||
903
dim_layout == ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ);
904
905
if (tiling == ISL_TILING_Ys && info->samples > 1)
906
isl_finishme("%s:%s: multisample TileYs layout", __FILE__, __func__);
907
908
switch (msaa_layout) {
909
case ISL_MSAA_LAYOUT_NONE:
910
assert(info->depth == 1);
911
assert(info->samples == 1);
912
913
*phys_level0_sa = (struct isl_extent4d) {
914
.w = info->width,
915
.h = info->height,
916
.d = 1,
917
.a = info->array_len,
918
};
919
break;
920
921
case ISL_MSAA_LAYOUT_ARRAY:
922
assert(info->depth == 1);
923
assert(info->levels == 1);
924
assert(isl_format_supports_multisampling(dev->info, info->format));
925
assert(fmtl->bw == 1 && fmtl->bh == 1);
926
927
*phys_level0_sa = (struct isl_extent4d) {
928
.w = info->width,
929
.h = info->height,
930
.d = 1,
931
.a = info->array_len * info->samples,
932
};
933
break;
934
935
case ISL_MSAA_LAYOUT_INTERLEAVED:
936
assert(info->depth == 1);
937
assert(info->levels == 1);
938
assert(isl_format_supports_multisampling(dev->info, info->format));
939
940
*phys_level0_sa = (struct isl_extent4d) {
941
.w = info->width,
942
.h = info->height,
943
.d = 1,
944
.a = info->array_len,
945
};
946
947
isl_msaa_interleaved_scale_px_to_sa(info->samples,
948
&phys_level0_sa->w,
949
&phys_level0_sa->h);
950
break;
951
}
952
break;
953
954
case ISL_SURF_DIM_3D:
955
assert(info->array_len == 1);
956
assert(info->samples == 1);
957
958
if (fmtl->bd > 1) {
959
isl_finishme("%s:%s: compression block with depth > 1",
960
__FILE__, __func__);
961
}
962
963
switch (dim_layout) {
964
case ISL_DIM_LAYOUT_GFX9_1D:
965
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
966
unreachable("bad isl_dim_layout");
967
968
case ISL_DIM_LAYOUT_GFX4_2D:
969
assert(ISL_GFX_VER(dev) >= 9);
970
971
*phys_level0_sa = (struct isl_extent4d) {
972
.w = info->width,
973
.h = info->height,
974
.d = 1,
975
.a = info->depth,
976
};
977
break;
978
979
case ISL_DIM_LAYOUT_GFX4_3D:
980
assert(ISL_GFX_VER(dev) < 9);
981
*phys_level0_sa = (struct isl_extent4d) {
982
.w = info->width,
983
.h = info->height,
984
.d = info->depth,
985
.a = 1,
986
};
987
break;
988
}
989
break;
990
}
991
}
992
993
/**
994
* Calculate the pitch between physical array slices, in units of rows of
995
* surface elements.
996
*/
997
static uint32_t
998
isl_calc_array_pitch_el_rows_gfx4_2d(
999
const struct isl_device *dev,
1000
const struct isl_surf_init_info *restrict info,
1001
const struct isl_tile_info *tile_info,
1002
const struct isl_extent3d *image_align_sa,
1003
const struct isl_extent4d *phys_level0_sa,
1004
enum isl_array_pitch_span array_pitch_span,
1005
const struct isl_extent2d *phys_slice0_sa)
1006
{
1007
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1008
uint32_t pitch_sa_rows = 0;
1009
1010
switch (array_pitch_span) {
1011
case ISL_ARRAY_PITCH_SPAN_COMPACT:
1012
pitch_sa_rows = isl_align_npot(phys_slice0_sa->h, image_align_sa->h);
1013
break;
1014
case ISL_ARRAY_PITCH_SPAN_FULL: {
1015
/* The QPitch equation is found in the Broadwell PRM >> Volume 5:
1016
* Memory Views >> Common Surface Formats >> Surface Layout >> 2D
1017
* Surfaces >> Surface Arrays.
1018
*/
1019
uint32_t H0_sa = phys_level0_sa->h;
1020
uint32_t H1_sa = isl_minify(H0_sa, 1);
1021
1022
uint32_t h0_sa = isl_align_npot(H0_sa, image_align_sa->h);
1023
uint32_t h1_sa = isl_align_npot(H1_sa, image_align_sa->h);
1024
1025
uint32_t m;
1026
if (ISL_GFX_VER(dev) >= 7) {
1027
/* The QPitch equation changed slightly in Ivybridge. */
1028
m = 12;
1029
} else {
1030
m = 11;
1031
}
1032
1033
pitch_sa_rows = h0_sa + h1_sa + (m * image_align_sa->h);
1034
1035
if (ISL_GFX_VER(dev) == 6 && info->samples > 1 &&
1036
(info->height % 4 == 1)) {
1037
/* [SNB] Errata from the Sandy Bridge PRM >> Volume 4 Part 1:
1038
* Graphics Core >> Section 7.18.3.7: Surface Arrays:
1039
*
1040
* [SNB] Errata: Sampler MSAA Qpitch will be 4 greater than
1041
* the value calculated in the equation above , for every
1042
* other odd Surface Height starting from 1 i.e. 1,5,9,13.
1043
*
1044
* XXX(chadv): Is the errata natural corollary of the physical
1045
* layout of interleaved samples?
1046
*/
1047
pitch_sa_rows += 4;
1048
}
1049
1050
pitch_sa_rows = isl_align_npot(pitch_sa_rows, fmtl->bh);
1051
} /* end case */
1052
break;
1053
}
1054
1055
assert(pitch_sa_rows % fmtl->bh == 0);
1056
uint32_t pitch_el_rows = pitch_sa_rows / fmtl->bh;
1057
1058
if (ISL_GFX_VER(dev) >= 9 && ISL_GFX_VER(dev) <= 11 &&
1059
fmtl->txc == ISL_TXC_CCS) {
1060
/*
1061
* From the Sky Lake PRM Vol 7, "MCS Buffer for Render Target(s)" (p. 632):
1062
*
1063
* "Mip-mapped and arrayed surfaces are supported with MCS buffer
1064
* layout with these alignments in the RT space: Horizontal
1065
* Alignment = 128 and Vertical Alignment = 64."
1066
*
1067
* From the Sky Lake PRM Vol. 2d, "RENDER_SURFACE_STATE" (p. 435):
1068
*
1069
* "For non-multisampled render target's CCS auxiliary surface,
1070
* QPitch must be computed with Horizontal Alignment = 128 and
1071
* Surface Vertical Alignment = 256. These alignments are only for
1072
* CCS buffer and not for associated render target."
1073
*
1074
* The first restriction is already handled by isl_choose_image_alignment_el
1075
* but the second restriction, which is an extension of the first, only
1076
* applies to qpitch and must be applied here.
1077
*
1078
* The second restriction disappears on Gfx12.
1079
*/
1080
assert(fmtl->bh == 4);
1081
pitch_el_rows = isl_align(pitch_el_rows, 256 / 4);
1082
}
1083
1084
if (ISL_GFX_VER(dev) >= 9 &&
1085
info->dim == ISL_SURF_DIM_3D &&
1086
tile_info->tiling != ISL_TILING_LINEAR) {
1087
/* From the Skylake BSpec >> RENDER_SURFACE_STATE >> Surface QPitch:
1088
*
1089
* Tile Mode != Linear: This field must be set to an integer multiple
1090
* of the tile height
1091
*/
1092
pitch_el_rows = isl_align(pitch_el_rows, tile_info->logical_extent_el.height);
1093
}
1094
1095
return pitch_el_rows;
1096
}
1097
1098
/**
1099
* A variant of isl_calc_phys_slice0_extent_sa() specific to
1100
* ISL_DIM_LAYOUT_GFX4_2D.
1101
*/
1102
static void
1103
isl_calc_phys_slice0_extent_sa_gfx4_2d(
1104
const struct isl_device *dev,
1105
const struct isl_surf_init_info *restrict info,
1106
enum isl_msaa_layout msaa_layout,
1107
const struct isl_extent3d *image_align_sa,
1108
const struct isl_extent4d *phys_level0_sa,
1109
struct isl_extent2d *phys_slice0_sa)
1110
{
1111
assert(phys_level0_sa->depth == 1);
1112
1113
if (info->levels == 1) {
1114
/* Do not pad the surface to the image alignment.
1115
*
1116
* For tiled surfaces, using a reduced alignment here avoids wasting CPU
1117
* cycles on the below mipmap layout caluclations. Reducing the
1118
* alignment here is safe because we later align the row pitch and array
1119
* pitch to the tile boundary. It is safe even for
1120
* ISL_MSAA_LAYOUT_INTERLEAVED, because phys_level0_sa is already scaled
1121
* to accomodate the interleaved samples.
1122
*
1123
* For linear surfaces, reducing the alignment here permits us to later
1124
* choose an arbitrary, non-aligned row pitch. If the surface backs
1125
* a VkBuffer, then an arbitrary pitch may be needed to accomodate
1126
* VkBufferImageCopy::bufferRowLength.
1127
*/
1128
*phys_slice0_sa = (struct isl_extent2d) {
1129
.w = phys_level0_sa->w,
1130
.h = phys_level0_sa->h,
1131
};
1132
return;
1133
}
1134
1135
uint32_t slice_top_w = 0;
1136
uint32_t slice_bottom_w = 0;
1137
uint32_t slice_left_h = 0;
1138
uint32_t slice_right_h = 0;
1139
1140
uint32_t W0 = phys_level0_sa->w;
1141
uint32_t H0 = phys_level0_sa->h;
1142
1143
for (uint32_t l = 0; l < info->levels; ++l) {
1144
uint32_t W = isl_minify(W0, l);
1145
uint32_t H = isl_minify(H0, l);
1146
1147
uint32_t w = isl_align_npot(W, image_align_sa->w);
1148
uint32_t h = isl_align_npot(H, image_align_sa->h);
1149
1150
if (l == 0) {
1151
slice_top_w = w;
1152
slice_left_h = h;
1153
slice_right_h = h;
1154
} else if (l == 1) {
1155
slice_bottom_w = w;
1156
slice_left_h += h;
1157
} else if (l == 2) {
1158
slice_bottom_w += w;
1159
slice_right_h += h;
1160
} else {
1161
slice_right_h += h;
1162
}
1163
}
1164
1165
*phys_slice0_sa = (struct isl_extent2d) {
1166
.w = MAX(slice_top_w, slice_bottom_w),
1167
.h = MAX(slice_left_h, slice_right_h),
1168
};
1169
}
1170
1171
static void
1172
isl_calc_phys_total_extent_el_gfx4_2d(
1173
const struct isl_device *dev,
1174
const struct isl_surf_init_info *restrict info,
1175
const struct isl_tile_info *tile_info,
1176
enum isl_msaa_layout msaa_layout,
1177
const struct isl_extent3d *image_align_sa,
1178
const struct isl_extent4d *phys_level0_sa,
1179
enum isl_array_pitch_span array_pitch_span,
1180
uint32_t *array_pitch_el_rows,
1181
struct isl_extent4d *phys_total_el)
1182
{
1183
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1184
1185
struct isl_extent2d phys_slice0_sa;
1186
isl_calc_phys_slice0_extent_sa_gfx4_2d(dev, info, msaa_layout,
1187
image_align_sa, phys_level0_sa,
1188
&phys_slice0_sa);
1189
*array_pitch_el_rows =
1190
isl_calc_array_pitch_el_rows_gfx4_2d(dev, info, tile_info,
1191
image_align_sa, phys_level0_sa,
1192
array_pitch_span,
1193
&phys_slice0_sa);
1194
*phys_total_el = (struct isl_extent4d) {
1195
.w = isl_align_div_npot(phys_slice0_sa.w, fmtl->bw),
1196
.h = *array_pitch_el_rows * (phys_level0_sa->array_len - 1) +
1197
isl_align_div_npot(phys_slice0_sa.h, fmtl->bh),
1198
.d = 1,
1199
.a = 1,
1200
};
1201
}
1202
1203
/**
1204
* A variant of isl_calc_phys_slice0_extent_sa() specific to
1205
* ISL_DIM_LAYOUT_GFX4_3D.
1206
*/
1207
static void
1208
isl_calc_phys_total_extent_el_gfx4_3d(
1209
const struct isl_device *dev,
1210
const struct isl_surf_init_info *restrict info,
1211
const struct isl_extent3d *image_align_sa,
1212
const struct isl_extent4d *phys_level0_sa,
1213
uint32_t *array_pitch_el_rows,
1214
struct isl_extent4d *phys_total_el)
1215
{
1216
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1217
1218
assert(info->samples == 1);
1219
1220
if (info->dim != ISL_SURF_DIM_3D) {
1221
/* From the G45 PRM Vol. 1a, "6.17.4.1 Hardware Cube Map Layout":
1222
*
1223
* The cube face textures are stored in the same way as 3D surfaces
1224
* are stored (see section 6.17.5 for details). For cube surfaces,
1225
* however, the depth is equal to the number of faces (always 6) and
1226
* is not reduced for each MIP.
1227
*/
1228
assert(ISL_GFX_VER(dev) == 4);
1229
assert(info->usage & ISL_SURF_USAGE_CUBE_BIT);
1230
assert(phys_level0_sa->array_len == 6);
1231
} else {
1232
assert(phys_level0_sa->array_len == 1);
1233
}
1234
1235
uint32_t total_w = 0;
1236
uint32_t total_h = 0;
1237
1238
uint32_t W0 = phys_level0_sa->w;
1239
uint32_t H0 = phys_level0_sa->h;
1240
uint32_t D0 = phys_level0_sa->d;
1241
uint32_t A0 = phys_level0_sa->a;
1242
1243
for (uint32_t l = 0; l < info->levels; ++l) {
1244
uint32_t level_w = isl_align_npot(isl_minify(W0, l), image_align_sa->w);
1245
uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa->h);
1246
uint32_t level_d = info->dim == ISL_SURF_DIM_3D ? isl_minify(D0, l) : A0;
1247
1248
uint32_t max_layers_horiz = MIN(level_d, 1u << l);
1249
uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
1250
1251
total_w = MAX(total_w, level_w * max_layers_horiz);
1252
total_h += level_h * max_layers_vert;
1253
}
1254
1255
/* GFX4_3D layouts don't really have an array pitch since each LOD has a
1256
* different number of horizontal and vertical layers. We have to set it
1257
* to something, so at least make it true for LOD0.
1258
*/
1259
*array_pitch_el_rows =
1260
isl_align_npot(phys_level0_sa->h, image_align_sa->h) / fmtl->bw;
1261
*phys_total_el = (struct isl_extent4d) {
1262
.w = isl_assert_div(total_w, fmtl->bw),
1263
.h = isl_assert_div(total_h, fmtl->bh),
1264
.d = 1,
1265
.a = 1,
1266
};
1267
}
1268
1269
/**
1270
* A variant of isl_calc_phys_slice0_extent_sa() specific to
1271
* ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ.
1272
*/
1273
static void
1274
isl_calc_phys_total_extent_el_gfx6_stencil_hiz(
1275
const struct isl_device *dev,
1276
const struct isl_surf_init_info *restrict info,
1277
const struct isl_tile_info *tile_info,
1278
const struct isl_extent3d *image_align_sa,
1279
const struct isl_extent4d *phys_level0_sa,
1280
uint32_t *array_pitch_el_rows,
1281
struct isl_extent4d *phys_total_el)
1282
{
1283
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1284
1285
const struct isl_extent2d tile_extent_sa = {
1286
.w = tile_info->logical_extent_el.w * fmtl->bw,
1287
.h = tile_info->logical_extent_el.h * fmtl->bh,
1288
};
1289
/* Tile size is a multiple of image alignment */
1290
assert(tile_extent_sa.w % image_align_sa->w == 0);
1291
assert(tile_extent_sa.h % image_align_sa->h == 0);
1292
1293
const uint32_t W0 = phys_level0_sa->w;
1294
const uint32_t H0 = phys_level0_sa->h;
1295
1296
/* Each image has the same height as LOD0 because the hardware thinks
1297
* everything is LOD0
1298
*/
1299
const uint32_t H = isl_align(H0, image_align_sa->h) * phys_level0_sa->a;
1300
1301
uint32_t total_top_w = 0;
1302
uint32_t total_bottom_w = 0;
1303
uint32_t total_h = 0;
1304
1305
for (uint32_t l = 0; l < info->levels; ++l) {
1306
const uint32_t W = isl_minify(W0, l);
1307
1308
const uint32_t w = isl_align(W, tile_extent_sa.w);
1309
const uint32_t h = isl_align(H, tile_extent_sa.h);
1310
1311
if (l == 0) {
1312
total_top_w = w;
1313
total_h = h;
1314
} else if (l == 1) {
1315
total_bottom_w = w;
1316
total_h += h;
1317
} else {
1318
total_bottom_w += w;
1319
}
1320
}
1321
1322
*array_pitch_el_rows =
1323
isl_assert_div(isl_align(H0, image_align_sa->h), fmtl->bh);
1324
*phys_total_el = (struct isl_extent4d) {
1325
.w = isl_assert_div(MAX(total_top_w, total_bottom_w), fmtl->bw),
1326
.h = isl_assert_div(total_h, fmtl->bh),
1327
.d = 1,
1328
.a = 1,
1329
};
1330
}
1331
1332
/**
1333
* A variant of isl_calc_phys_slice0_extent_sa() specific to
1334
* ISL_DIM_LAYOUT_GFX9_1D.
1335
*/
1336
static void
1337
isl_calc_phys_total_extent_el_gfx9_1d(
1338
const struct isl_device *dev,
1339
const struct isl_surf_init_info *restrict info,
1340
const struct isl_extent3d *image_align_sa,
1341
const struct isl_extent4d *phys_level0_sa,
1342
uint32_t *array_pitch_el_rows,
1343
struct isl_extent4d *phys_total_el)
1344
{
1345
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1346
1347
assert(phys_level0_sa->height == 1);
1348
assert(phys_level0_sa->depth == 1);
1349
assert(info->samples == 1);
1350
assert(image_align_sa->w >= fmtl->bw);
1351
1352
uint32_t slice_w = 0;
1353
const uint32_t W0 = phys_level0_sa->w;
1354
1355
for (uint32_t l = 0; l < info->levels; ++l) {
1356
uint32_t W = isl_minify(W0, l);
1357
uint32_t w = isl_align_npot(W, image_align_sa->w);
1358
1359
slice_w += w;
1360
}
1361
1362
*array_pitch_el_rows = 1;
1363
*phys_total_el = (struct isl_extent4d) {
1364
.w = isl_assert_div(slice_w, fmtl->bw),
1365
.h = phys_level0_sa->array_len,
1366
.d = 1,
1367
.a = 1,
1368
};
1369
}
1370
1371
/**
1372
* Calculate the two-dimensional total physical extent of the surface, in
1373
* units of surface elements.
1374
*/
1375
static void
1376
isl_calc_phys_total_extent_el(const struct isl_device *dev,
1377
const struct isl_surf_init_info *restrict info,
1378
const struct isl_tile_info *tile_info,
1379
enum isl_dim_layout dim_layout,
1380
enum isl_msaa_layout msaa_layout,
1381
const struct isl_extent3d *image_align_sa,
1382
const struct isl_extent4d *phys_level0_sa,
1383
enum isl_array_pitch_span array_pitch_span,
1384
uint32_t *array_pitch_el_rows,
1385
struct isl_extent4d *phys_total_el)
1386
{
1387
switch (dim_layout) {
1388
case ISL_DIM_LAYOUT_GFX9_1D:
1389
assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
1390
isl_calc_phys_total_extent_el_gfx9_1d(dev, info,
1391
image_align_sa, phys_level0_sa,
1392
array_pitch_el_rows,
1393
phys_total_el);
1394
return;
1395
case ISL_DIM_LAYOUT_GFX4_2D:
1396
isl_calc_phys_total_extent_el_gfx4_2d(dev, info, tile_info, msaa_layout,
1397
image_align_sa, phys_level0_sa,
1398
array_pitch_span,
1399
array_pitch_el_rows,
1400
phys_total_el);
1401
return;
1402
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
1403
assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
1404
isl_calc_phys_total_extent_el_gfx6_stencil_hiz(dev, info, tile_info,
1405
image_align_sa,
1406
phys_level0_sa,
1407
array_pitch_el_rows,
1408
phys_total_el);
1409
return;
1410
case ISL_DIM_LAYOUT_GFX4_3D:
1411
assert(array_pitch_span == ISL_ARRAY_PITCH_SPAN_COMPACT);
1412
isl_calc_phys_total_extent_el_gfx4_3d(dev, info,
1413
image_align_sa, phys_level0_sa,
1414
array_pitch_el_rows,
1415
phys_total_el);
1416
return;
1417
}
1418
1419
unreachable("invalid value for dim_layout");
1420
}
1421
1422
static uint32_t
1423
isl_calc_row_pitch_alignment(const struct isl_device *dev,
1424
const struct isl_surf_init_info *surf_info,
1425
const struct isl_tile_info *tile_info)
1426
{
1427
if (tile_info->tiling != ISL_TILING_LINEAR) {
1428
/* According to BSpec: 44930, Gfx12's CCS-compressed surface pitches must
1429
* be 512B-aligned. CCS is only support on Y tilings.
1430
*
1431
* Only consider 512B alignment when :
1432
* - AUX is not explicitly disabled
1433
* - the caller has specified no pitch
1434
*
1435
* isl_surf_get_ccs_surf() will check that the main surface alignment
1436
* matches CCS expectations.
1437
*/
1438
if (ISL_GFX_VER(dev) >= 12 &&
1439
isl_format_supports_ccs_e(dev->info, surf_info->format) &&
1440
tile_info->tiling != ISL_TILING_X &&
1441
!(surf_info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT) &&
1442
surf_info->row_pitch_B == 0) {
1443
return isl_align(tile_info->phys_extent_B.width, 512);
1444
}
1445
1446
return tile_info->phys_extent_B.width;
1447
}
1448
1449
/* From the Broadwel PRM >> Volume 2d: Command Reference: Structures >>
1450
* RENDER_SURFACE_STATE Surface Pitch (p349):
1451
*
1452
* - For linear render target surfaces and surfaces accessed with the
1453
* typed data port messages, the pitch must be a multiple of the
1454
* element size for non-YUV surface formats. Pitch must be
1455
* a multiple of 2 * element size for YUV surface formats.
1456
*
1457
* - [Requirements for SURFTYPE_BUFFER and SURFTYPE_STRBUF, which we
1458
* ignore because isl doesn't do buffers.]
1459
*
1460
* - For other linear surfaces, the pitch can be any multiple of
1461
* bytes.
1462
*/
1463
const struct isl_format_layout *fmtl = isl_format_get_layout(surf_info->format);
1464
const uint32_t bs = fmtl->bpb / 8;
1465
uint32_t alignment;
1466
1467
if (surf_info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
1468
if (isl_format_is_yuv(surf_info->format)) {
1469
alignment = 2 * bs;
1470
} else {
1471
alignment = bs;
1472
}
1473
} else {
1474
alignment = 1;
1475
}
1476
1477
/* From the Broadwell PRM >> Volume 2c: Command Reference: Registers >>
1478
* PRI_STRIDE Stride (p1254):
1479
*
1480
* "When using linear memory, this must be at least 64 byte aligned."
1481
*
1482
* However, when displaying on NVIDIA and recent AMD GPUs via PRIME,
1483
* we need a larger pitch of 256 bytes. We do that just in case.
1484
*/
1485
if (surf_info->usage & ISL_SURF_USAGE_DISPLAY_BIT)
1486
alignment = isl_align(alignment, 256);
1487
1488
return alignment;
1489
}
1490
1491
static uint32_t
1492
isl_calc_linear_min_row_pitch(const struct isl_device *dev,
1493
const struct isl_surf_init_info *info,
1494
const struct isl_extent4d *phys_total_el,
1495
uint32_t alignment_B)
1496
{
1497
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1498
const uint32_t bs = fmtl->bpb / 8;
1499
1500
return isl_align_npot(bs * phys_total_el->w, alignment_B);
1501
}
1502
1503
static uint32_t
1504
isl_calc_tiled_min_row_pitch(const struct isl_device *dev,
1505
const struct isl_surf_init_info *surf_info,
1506
const struct isl_tile_info *tile_info,
1507
const struct isl_extent4d *phys_total_el,
1508
uint32_t alignment_B)
1509
{
1510
const struct isl_format_layout *fmtl = isl_format_get_layout(surf_info->format);
1511
1512
assert(fmtl->bpb % tile_info->format_bpb == 0);
1513
1514
const uint32_t tile_el_scale = fmtl->bpb / tile_info->format_bpb;
1515
const uint32_t total_w_tl =
1516
isl_align_div(phys_total_el->w * tile_el_scale,
1517
tile_info->logical_extent_el.width);
1518
1519
/* In some cases the alignment of the pitch might be > to the tile size
1520
* (for example Gfx12 CCS requires 512B alignment while the tile's width
1521
* can be 128B), so align the row pitch to the alignment.
1522
*/
1523
assert(alignment_B >= tile_info->phys_extent_B.width);
1524
return isl_align(total_w_tl * tile_info->phys_extent_B.width, alignment_B);
1525
}
1526
1527
static uint32_t
1528
isl_calc_min_row_pitch(const struct isl_device *dev,
1529
const struct isl_surf_init_info *surf_info,
1530
const struct isl_tile_info *tile_info,
1531
const struct isl_extent4d *phys_total_el,
1532
uint32_t alignment_B)
1533
{
1534
if (tile_info->tiling == ISL_TILING_LINEAR) {
1535
return isl_calc_linear_min_row_pitch(dev, surf_info, phys_total_el,
1536
alignment_B);
1537
} else {
1538
return isl_calc_tiled_min_row_pitch(dev, surf_info, tile_info,
1539
phys_total_el, alignment_B);
1540
}
1541
}
1542
1543
/**
1544
* Is `pitch` in the valid range for a hardware bitfield, if the bitfield's
1545
* size is `bits` bits?
1546
*
1547
* Hardware pitch fields are offset by 1. For example, if the size of
1548
* RENDER_SURFACE_STATE::SurfacePitch is B bits, then the range of valid
1549
* pitches is [1, 2^b] inclusive. If the surface pitch is N, then
1550
* RENDER_SURFACE_STATE::SurfacePitch must be set to N-1.
1551
*/
1552
static bool
1553
pitch_in_range(uint32_t n, uint32_t bits)
1554
{
1555
assert(n != 0);
1556
return likely(bits != 0 && 1 <= n && n <= (1 << bits));
1557
}
1558
1559
static bool
1560
isl_calc_row_pitch(const struct isl_device *dev,
1561
const struct isl_surf_init_info *surf_info,
1562
const struct isl_tile_info *tile_info,
1563
enum isl_dim_layout dim_layout,
1564
const struct isl_extent4d *phys_total_el,
1565
uint32_t *out_row_pitch_B)
1566
{
1567
uint32_t alignment_B =
1568
isl_calc_row_pitch_alignment(dev, surf_info, tile_info);
1569
1570
const uint32_t min_row_pitch_B =
1571
isl_calc_min_row_pitch(dev, surf_info, tile_info, phys_total_el,
1572
alignment_B);
1573
1574
if (surf_info->row_pitch_B != 0) {
1575
if (surf_info->row_pitch_B < min_row_pitch_B)
1576
return false;
1577
1578
if (surf_info->row_pitch_B % alignment_B != 0)
1579
return false;
1580
}
1581
1582
const uint32_t row_pitch_B =
1583
surf_info->row_pitch_B != 0 ? surf_info->row_pitch_B : min_row_pitch_B;
1584
1585
const uint32_t row_pitch_tl = row_pitch_B / tile_info->phys_extent_B.width;
1586
1587
if (row_pitch_B == 0)
1588
return false;
1589
1590
if (dim_layout == ISL_DIM_LAYOUT_GFX9_1D) {
1591
/* SurfacePitch is ignored for this layout. */
1592
goto done;
1593
}
1594
1595
if ((surf_info->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
1596
ISL_SURF_USAGE_TEXTURE_BIT |
1597
ISL_SURF_USAGE_STORAGE_BIT)) &&
1598
!pitch_in_range(row_pitch_B, RENDER_SURFACE_STATE_SurfacePitch_bits(dev->info)))
1599
return false;
1600
1601
if ((surf_info->usage & (ISL_SURF_USAGE_CCS_BIT |
1602
ISL_SURF_USAGE_MCS_BIT)) &&
1603
!pitch_in_range(row_pitch_tl, RENDER_SURFACE_STATE_AuxiliarySurfacePitch_bits(dev->info)))
1604
return false;
1605
1606
if ((surf_info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&
1607
!pitch_in_range(row_pitch_B, _3DSTATE_DEPTH_BUFFER_SurfacePitch_bits(dev->info)))
1608
return false;
1609
1610
if ((surf_info->usage & ISL_SURF_USAGE_HIZ_BIT) &&
1611
!pitch_in_range(row_pitch_B, _3DSTATE_HIER_DEPTH_BUFFER_SurfacePitch_bits(dev->info)))
1612
return false;
1613
1614
const uint32_t stencil_pitch_bits = dev->use_separate_stencil ?
1615
_3DSTATE_STENCIL_BUFFER_SurfacePitch_bits(dev->info) :
1616
_3DSTATE_DEPTH_BUFFER_SurfacePitch_bits(dev->info);
1617
1618
if ((surf_info->usage & ISL_SURF_USAGE_STENCIL_BIT) &&
1619
!pitch_in_range(row_pitch_B, stencil_pitch_bits))
1620
return false;
1621
1622
done:
1623
*out_row_pitch_B = row_pitch_B;
1624
return true;
1625
}
1626
1627
bool
1628
isl_surf_init_s(const struct isl_device *dev,
1629
struct isl_surf *surf,
1630
const struct isl_surf_init_info *restrict info)
1631
{
1632
const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1633
1634
const struct isl_extent4d logical_level0_px = {
1635
.w = info->width,
1636
.h = info->height,
1637
.d = info->depth,
1638
.a = info->array_len,
1639
};
1640
1641
enum isl_tiling tiling;
1642
if (!isl_surf_choose_tiling(dev, info, &tiling))
1643
return false;
1644
1645
struct isl_tile_info tile_info;
1646
isl_tiling_get_info(tiling, fmtl->bpb, &tile_info);
1647
1648
const enum isl_dim_layout dim_layout =
1649
isl_surf_choose_dim_layout(dev, info->dim, tiling, info->usage);
1650
1651
enum isl_msaa_layout msaa_layout;
1652
if (!isl_choose_msaa_layout(dev, info, tiling, &msaa_layout))
1653
return false;
1654
1655
struct isl_extent3d image_align_el;
1656
isl_choose_image_alignment_el(dev, info, tiling, dim_layout, msaa_layout,
1657
&image_align_el);
1658
1659
struct isl_extent3d image_align_sa =
1660
isl_extent3d_el_to_sa(info->format, image_align_el);
1661
1662
struct isl_extent4d phys_level0_sa;
1663
isl_calc_phys_level0_extent_sa(dev, info, dim_layout, tiling, msaa_layout,
1664
&phys_level0_sa);
1665
1666
enum isl_array_pitch_span array_pitch_span =
1667
isl_choose_array_pitch_span(dev, info, dim_layout, &phys_level0_sa);
1668
1669
uint32_t array_pitch_el_rows;
1670
struct isl_extent4d phys_total_el;
1671
isl_calc_phys_total_extent_el(dev, info, &tile_info,
1672
dim_layout, msaa_layout,
1673
&image_align_sa, &phys_level0_sa,
1674
array_pitch_span, &array_pitch_el_rows,
1675
&phys_total_el);
1676
1677
uint32_t row_pitch_B;
1678
if (!isl_calc_row_pitch(dev, info, &tile_info, dim_layout,
1679
&phys_total_el, &row_pitch_B))
1680
return false;
1681
1682
uint32_t base_alignment_B;
1683
uint64_t size_B;
1684
if (tiling == ISL_TILING_LINEAR) {
1685
/* LINEAR tiling has no concept of intra-tile arrays */
1686
assert(phys_total_el.d == 1 && phys_total_el.a == 1);
1687
1688
size_B = (uint64_t) row_pitch_B * phys_total_el.h;
1689
1690
/* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfaceBaseAddress:
1691
*
1692
* "The Base Address for linear render target surfaces and surfaces
1693
* accessed with the typed surface read/write data port messages must
1694
* be element-size aligned, for non-YUV surface formats, or a
1695
* multiple of 2 element-sizes for YUV surface formats. Other linear
1696
* surfaces have no alignment requirements (byte alignment is
1697
* sufficient.)"
1698
*/
1699
base_alignment_B = MAX(1, info->min_alignment_B);
1700
if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) {
1701
if (isl_format_is_yuv(info->format)) {
1702
base_alignment_B = MAX(base_alignment_B, fmtl->bpb / 4);
1703
} else {
1704
base_alignment_B = MAX(base_alignment_B, fmtl->bpb / 8);
1705
}
1706
}
1707
base_alignment_B = isl_round_up_to_power_of_two(base_alignment_B);
1708
1709
/* From the Skylake PRM Vol 2c, PLANE_STRIDE::Stride:
1710
*
1711
* "For Linear memory, this field specifies the stride in chunks of
1712
* 64 bytes (1 cache line)."
1713
*/
1714
if (isl_surf_usage_is_display(info->usage))
1715
base_alignment_B = MAX(base_alignment_B, 64);
1716
} else {
1717
/* Pitches must make sense with the tiling */
1718
assert(row_pitch_B % tile_info.phys_extent_B.width == 0);
1719
1720
uint32_t array_slices, array_pitch_tl_rows;
1721
if (phys_total_el.d > 1) {
1722
assert(phys_total_el.a == 1);
1723
array_pitch_tl_rows = isl_assert_div(array_pitch_el_rows,
1724
tile_info.logical_extent_el.h);
1725
array_slices = isl_align_div(phys_total_el.d,
1726
tile_info.logical_extent_el.d);
1727
} else if (phys_total_el.a > 1) {
1728
assert(phys_total_el.d == 1);
1729
array_pitch_tl_rows = isl_assert_div(array_pitch_el_rows,
1730
tile_info.logical_extent_el.h);
1731
array_slices = isl_align_div(phys_total_el.a,
1732
tile_info.logical_extent_el.a);
1733
assert(array_pitch_el_rows % tile_info.logical_extent_el.h == 0);
1734
} else {
1735
assert(phys_total_el.d == 1 && phys_total_el.a == 1);
1736
array_pitch_tl_rows = 0;
1737
array_slices = 1;
1738
}
1739
1740
const uint32_t total_h_tl =
1741
(array_slices - 1) * array_pitch_tl_rows +
1742
isl_align_div(phys_total_el.h, tile_info.logical_extent_el.height);
1743
1744
size_B = (uint64_t) total_h_tl * tile_info.phys_extent_B.height * row_pitch_B;
1745
1746
const uint32_t tile_size_B = tile_info.phys_extent_B.width *
1747
tile_info.phys_extent_B.height;
1748
assert(isl_is_pow2(info->min_alignment_B) && isl_is_pow2(tile_size_B));
1749
base_alignment_B = MAX(info->min_alignment_B, tile_size_B);
1750
1751
/* The diagram in the Bspec section Memory Compression - Gfx12, shows
1752
* that the CCS is indexed in 256B chunks. However, the
1753
* PLANE_AUX_DIST::Auxiliary Surface Distance field is in units of 4K
1754
* pages. We currently don't assign the usage field like we do for main
1755
* surfaces, so just use 4K for now.
1756
*/
1757
if (tiling == ISL_TILING_GFX12_CCS)
1758
base_alignment_B = MAX(base_alignment_B, 4096);
1759
1760
/* Gfx12+ requires that images be 64K-aligned if they're going to used
1761
* with CCS. This is because the Aux translation table maps main
1762
* surface addresses to aux addresses at a 64K (in the main surface)
1763
* granularity. Because we don't know for sure in ISL if a surface will
1764
* use CCS, we have to guess based on the DISABLE_AUX usage bit. The
1765
* one thing we do know is that we haven't enable CCS on linear images
1766
* yet so we can avoid the extra alignment there.
1767
*/
1768
if (ISL_GFX_VER(dev) >= 12 &&
1769
!(info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)) {
1770
base_alignment_B = MAX(base_alignment_B, 64 * 1024);
1771
}
1772
}
1773
1774
if (ISL_GFX_VER(dev) < 9) {
1775
/* From the Broadwell PRM Vol 5, Surface Layout:
1776
*
1777
* "In addition to restrictions on maximum height, width, and depth,
1778
* surfaces are also restricted to a maximum size in bytes. This
1779
* maximum is 2 GB for all products and all surface types."
1780
*
1781
* This comment is applicable to all Pre-gfx9 platforms.
1782
*/
1783
if (size_B > (uint64_t) 1 << 31)
1784
return false;
1785
} else if (ISL_GFX_VER(dev) < 11) {
1786
/* From the Skylake PRM Vol 5, Maximum Surface Size in Bytes:
1787
* "In addition to restrictions on maximum height, width, and depth,
1788
* surfaces are also restricted to a maximum size of 2^38 bytes.
1789
* All pixels within the surface must be contained within 2^38 bytes
1790
* of the base address."
1791
*/
1792
if (size_B > (uint64_t) 1 << 38)
1793
return false;
1794
} else {
1795
/* gfx11+ platforms raised this limit to 2^44 bytes. */
1796
if (size_B > (uint64_t) 1 << 44)
1797
return false;
1798
}
1799
1800
*surf = (struct isl_surf) {
1801
.dim = info->dim,
1802
.dim_layout = dim_layout,
1803
.msaa_layout = msaa_layout,
1804
.tiling = tiling,
1805
.format = info->format,
1806
1807
.levels = info->levels,
1808
.samples = info->samples,
1809
1810
.image_alignment_el = image_align_el,
1811
.logical_level0_px = logical_level0_px,
1812
.phys_level0_sa = phys_level0_sa,
1813
1814
.size_B = size_B,
1815
.alignment_B = base_alignment_B,
1816
.row_pitch_B = row_pitch_B,
1817
.array_pitch_el_rows = array_pitch_el_rows,
1818
.array_pitch_span = array_pitch_span,
1819
1820
.usage = info->usage,
1821
};
1822
1823
return true;
1824
}
1825
1826
void
1827
isl_surf_get_tile_info(const struct isl_surf *surf,
1828
struct isl_tile_info *tile_info)
1829
{
1830
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1831
isl_tiling_get_info(surf->tiling, fmtl->bpb, tile_info);
1832
}
1833
1834
bool
1835
isl_surf_get_hiz_surf(const struct isl_device *dev,
1836
const struct isl_surf *surf,
1837
struct isl_surf *hiz_surf)
1838
{
1839
assert(ISL_GFX_VER(dev) >= 5 && ISL_DEV_USE_SEPARATE_STENCIL(dev));
1840
1841
if (!isl_surf_usage_is_depth(surf->usage))
1842
return false;
1843
1844
/* HiZ only works with Y-tiled depth buffers */
1845
if (!isl_tiling_is_any_y(surf->tiling))
1846
return false;
1847
1848
/* On SNB+, compressed depth buffers cannot be interleaved with stencil. */
1849
switch (surf->format) {
1850
case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
1851
if (isl_surf_usage_is_depth_and_stencil(surf->usage)) {
1852
assert(ISL_GFX_VER(dev) == 5);
1853
unreachable("This should work, but is untested");
1854
}
1855
FALLTHROUGH;
1856
case ISL_FORMAT_R16_UNORM:
1857
case ISL_FORMAT_R32_FLOAT:
1858
break;
1859
case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
1860
if (ISL_GFX_VER(dev) == 5) {
1861
assert(isl_surf_usage_is_depth_and_stencil(surf->usage));
1862
unreachable("This should work, but is untested");
1863
}
1864
FALLTHROUGH;
1865
default:
1866
return false;
1867
}
1868
1869
/* Multisampled depth is always interleaved */
1870
assert(surf->msaa_layout == ISL_MSAA_LAYOUT_NONE ||
1871
surf->msaa_layout == ISL_MSAA_LAYOUT_INTERLEAVED);
1872
1873
/* From the Broadwell PRM Vol. 7, "Hierarchical Depth Buffer":
1874
*
1875
* "The Surface Type, Height, Width, Depth, Minimum Array Element, Render
1876
* Target View Extent, and Depth Coordinate Offset X/Y of the
1877
* hierarchical depth buffer are inherited from the depth buffer. The
1878
* height and width of the hierarchical depth buffer that must be
1879
* allocated are computed by the following formulas, where HZ is the
1880
* hierarchical depth buffer and Z is the depth buffer. The Z_Height,
1881
* Z_Width, and Z_Depth values given in these formulas are those present
1882
* in 3DSTATE_DEPTH_BUFFER incremented by one.
1883
*
1884
* "The value of Z_Height and Z_Width must each be multiplied by 2 before
1885
* being applied to the table below if Number of Multisamples is set to
1886
* NUMSAMPLES_4. The value of Z_Height must be multiplied by 2 and
1887
* Z_Width must be multiplied by 4 before being applied to the table
1888
* below if Number of Multisamples is set to NUMSAMPLES_8."
1889
*
1890
* In the Sky Lake PRM, the second paragraph is replaced with this:
1891
*
1892
* "The Z_Height and Z_Width values must equal those present in
1893
* 3DSTATE_DEPTH_BUFFER incremented by one."
1894
*
1895
* In other words, on Sandy Bridge through Broadwell, each 128-bit HiZ
1896
* block corresponds to a region of 8x4 samples in the primary depth
1897
* surface. On Sky Lake, on the other hand, each HiZ block corresponds to
1898
* a region of 8x4 pixels in the primary depth surface regardless of the
1899
* number of samples. The dimensions of a HiZ block in both pixels and
1900
* samples are given in the table below:
1901
*
1902
* | SNB - BDW | SKL+
1903
* ------+-----------+-------------
1904
* 1x | 8 x 4 sa | 8 x 4 sa
1905
* MSAA | 8 x 4 px | 8 x 4 px
1906
* ------+-----------+-------------
1907
* 2x | 8 x 4 sa | 16 x 4 sa
1908
* MSAA | 4 x 4 px | 8 x 4 px
1909
* ------+-----------+-------------
1910
* 4x | 8 x 4 sa | 16 x 8 sa
1911
* MSAA | 4 x 2 px | 8 x 4 px
1912
* ------+-----------+-------------
1913
* 8x | 8 x 4 sa | 32 x 8 sa
1914
* MSAA | 2 x 2 px | 8 x 4 px
1915
* ------+-----------+-------------
1916
* 16x | N/A | 32 x 16 sa
1917
* MSAA | N/A | 8 x 4 px
1918
* ------+-----------+-------------
1919
*
1920
* There are a number of different ways that this discrepency could be
1921
* handled. The way we have chosen is to simply make MSAA HiZ have the
1922
* same number of samples as the parent surface pre-Sky Lake and always be
1923
* single-sampled on Sky Lake and above. Since the block sizes of
1924
* compressed formats are given in samples, this neatly handles everything
1925
* without the need for additional HiZ formats with different block sizes
1926
* on SKL+.
1927
*/
1928
const unsigned samples = ISL_GFX_VER(dev) >= 9 ? 1 : surf->samples;
1929
1930
return isl_surf_init(dev, hiz_surf,
1931
.dim = surf->dim,
1932
.format = ISL_FORMAT_HIZ,
1933
.width = surf->logical_level0_px.width,
1934
.height = surf->logical_level0_px.height,
1935
.depth = surf->logical_level0_px.depth,
1936
.levels = surf->levels,
1937
.array_len = surf->logical_level0_px.array_len,
1938
.samples = samples,
1939
.usage = ISL_SURF_USAGE_HIZ_BIT,
1940
.tiling_flags = ISL_TILING_HIZ_BIT);
1941
}
1942
1943
bool
1944
isl_surf_get_mcs_surf(const struct isl_device *dev,
1945
const struct isl_surf *surf,
1946
struct isl_surf *mcs_surf)
1947
{
1948
/* It must be multisampled with an array layout */
1949
if (surf->msaa_layout != ISL_MSAA_LAYOUT_ARRAY)
1950
return false;
1951
1952
if (mcs_surf->size_B > 0)
1953
return false;
1954
1955
/* The following are true of all multisampled surfaces */
1956
assert(surf->samples > 1);
1957
assert(surf->dim == ISL_SURF_DIM_2D);
1958
assert(surf->levels == 1);
1959
assert(surf->logical_level0_px.depth == 1);
1960
1961
/* From the Ivy Bridge PRM, Vol4 Part1 p77 ("MCS Enable"):
1962
*
1963
* This field must be set to 0 for all SINT MSRTs when all RT channels
1964
* are not written
1965
*
1966
* In practice this means that we have to disable MCS for all signed
1967
* integer MSAA buffers. The alternative, to disable MCS only when one
1968
* of the render target channels is disabled, is impractical because it
1969
* would require converting between CMS and UMS MSAA layouts on the fly,
1970
* which is expensive.
1971
*/
1972
if (ISL_GFX_VER(dev) == 7 && isl_format_has_sint_channel(surf->format))
1973
return false;
1974
1975
/* The "Auxiliary Surface Pitch" field in RENDER_SURFACE_STATE is only 9
1976
* bits which means the maximum pitch of a compression surface is 512
1977
* tiles or 64KB (since MCS is always Y-tiled). Since a 16x MCS buffer is
1978
* 64bpp, this gives us a maximum width of 8192 pixels. We can create
1979
* larger multisampled surfaces, we just can't compress them. For 2x, 4x,
1980
* and 8x, we have enough room for the full 16k supported by the hardware.
1981
*/
1982
if (surf->samples == 16 && surf->logical_level0_px.width > 8192)
1983
return false;
1984
1985
enum isl_format mcs_format;
1986
switch (surf->samples) {
1987
case 2: mcs_format = ISL_FORMAT_MCS_2X; break;
1988
case 4: mcs_format = ISL_FORMAT_MCS_4X; break;
1989
case 8: mcs_format = ISL_FORMAT_MCS_8X; break;
1990
case 16: mcs_format = ISL_FORMAT_MCS_16X; break;
1991
default:
1992
unreachable("Invalid sample count");
1993
}
1994
1995
return isl_surf_init(dev, mcs_surf,
1996
.dim = ISL_SURF_DIM_2D,
1997
.format = mcs_format,
1998
.width = surf->logical_level0_px.width,
1999
.height = surf->logical_level0_px.height,
2000
.depth = 1,
2001
.levels = 1,
2002
.array_len = surf->logical_level0_px.array_len,
2003
.samples = 1, /* MCS surfaces are really single-sampled */
2004
.usage = ISL_SURF_USAGE_MCS_BIT,
2005
.tiling_flags = ISL_TILING_Y0_BIT);
2006
}
2007
2008
bool
2009
isl_surf_supports_ccs(const struct isl_device *dev,
2010
const struct isl_surf *surf,
2011
const struct isl_surf *hiz_or_mcs_surf)
2012
{
2013
/* CCS support does not exist prior to Gfx7 */
2014
if (ISL_GFX_VER(dev) <= 6)
2015
return false;
2016
2017
/* Wa_22011186057: Disable compression on ADL-P A0 */
2018
if (dev->info->is_alderlake && dev->info->gt == 2 &&
2019
dev->info->revision == 0)
2020
return false;
2021
2022
if (surf->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)
2023
return false;
2024
2025
if (isl_format_is_compressed(surf->format))
2026
return false;
2027
2028
if (!isl_is_pow2(isl_format_get_layout(surf->format)->bpb))
2029
return false;
2030
2031
/* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
2032
* Target(s)", beneath the "Fast Color Clear" bullet (p326):
2033
*
2034
* - Support is limited to tiled render targets.
2035
*
2036
* From the Skylake documentation, it is made clear that X-tiling is no
2037
* longer supported:
2038
*
2039
* - MCS and Lossless compression is supported for
2040
* TiledY/TileYs/TileYf non-MSRTs only.
2041
*
2042
* From the BSpec (44930) for Gfx12:
2043
*
2044
* Linear CCS is only allowed for Untyped Buffers but only via HDC
2045
* Data-Port messages.
2046
*
2047
* We never use untyped messages on surfaces created by ISL on Gfx9+ so
2048
* this means linear is out on Gfx12+ as well.
2049
*/
2050
if (surf->tiling == ISL_TILING_LINEAR)
2051
return false;
2052
2053
if (ISL_GFX_VER(dev) >= 12) {
2054
if (isl_surf_usage_is_stencil(surf->usage)) {
2055
/* HiZ and MCS aren't allowed with stencil */
2056
assert(hiz_or_mcs_surf == NULL || hiz_or_mcs_surf->size_B == 0);
2057
2058
/* Multi-sampled stencil cannot have CCS */
2059
if (surf->samples > 1)
2060
return false;
2061
} else if (isl_surf_usage_is_depth(surf->usage)) {
2062
const struct isl_surf *hiz_surf = hiz_or_mcs_surf;
2063
2064
/* With depth surfaces, HIZ is required for CCS. */
2065
if (hiz_surf == NULL || hiz_surf->size_B == 0)
2066
return false;
2067
2068
assert(hiz_surf->usage & ISL_SURF_USAGE_HIZ_BIT);
2069
assert(hiz_surf->tiling == ISL_TILING_HIZ);
2070
assert(hiz_surf->format == ISL_FORMAT_HIZ);
2071
} else if (surf->samples > 1) {
2072
const struct isl_surf *mcs_surf = hiz_or_mcs_surf;
2073
2074
/* With multisampled color, CCS requires MCS */
2075
if (mcs_surf == NULL || mcs_surf->size_B == 0)
2076
return false;
2077
2078
assert(mcs_surf->usage & ISL_SURF_USAGE_MCS_BIT);
2079
assert(isl_tiling_is_any_y(mcs_surf->tiling));
2080
assert(isl_format_is_mcs(mcs_surf->format));
2081
} else {
2082
/* Single-sampled color can't have MCS or HiZ */
2083
assert(hiz_or_mcs_surf == NULL || hiz_or_mcs_surf->size_B == 0);
2084
}
2085
2086
/* On Gfx12, all CCS-compressed surface pitches must be multiples of
2087
* 512B.
2088
*/
2089
if (surf->row_pitch_B % 512 != 0)
2090
return false;
2091
2092
/* According to Wa_1406738321, 3D textures need a blit to a new
2093
* surface in order to perform a resolve. For now, just disable CCS.
2094
*/
2095
if (surf->dim == ISL_SURF_DIM_3D) {
2096
isl_finishme("%s:%s: CCS for 3D textures is disabled, but a workaround"
2097
" is available.", __FILE__, __func__);
2098
return false;
2099
}
2100
2101
/* Wa_1207137018
2102
*
2103
* TODO: implement following workaround currently covered by the
2104
* restriction above. If following conditions are met:
2105
*
2106
* - RENDER_SURFACE_STATE.Surface Type == 3D
2107
* - RENDER_SURFACE_STATE.Auxiliary Surface Mode != AUX_NONE
2108
* - RENDER_SURFACE_STATE.Tiled ResourceMode is TYF or TYS
2109
*
2110
* Set the value of RENDER_SURFACE_STATE.Mip Tail Start LOD to a mip
2111
* that larger than those present in the surface (i.e. 15)
2112
*/
2113
2114
/* TODO: Handle the other tiling formats */
2115
if (surf->tiling != ISL_TILING_Y0)
2116
return false;
2117
} else {
2118
/* ISL_GFX_VER(dev) < 12 */
2119
if (surf->samples > 1)
2120
return false;
2121
2122
/* CCS is only for color images on Gfx7-11 */
2123
if (isl_surf_usage_is_depth_or_stencil(surf->usage))
2124
return false;
2125
2126
/* We're single-sampled color so having HiZ or MCS makes no sense */
2127
assert(hiz_or_mcs_surf == NULL || hiz_or_mcs_surf->size_B == 0);
2128
2129
/* The PRM doesn't say this explicitly, but fast-clears don't appear to
2130
* work for 3D textures until gfx9 where the layout of 3D textures
2131
* changes to match 2D array textures.
2132
*/
2133
if (ISL_GFX_VER(dev) <= 8 && surf->dim != ISL_SURF_DIM_2D)
2134
return false;
2135
2136
/* From the HSW PRM Volume 7: 3D-Media-GPGPU, page 652 (Color Clear of
2137
* Non-MultiSampler Render Target Restrictions):
2138
*
2139
* "Support is for non-mip-mapped and non-array surface types only."
2140
*
2141
* This restriction is lifted on gfx8+. Technically, it may be possible
2142
* to create a CCS for an arrayed or mipmapped image and only enable
2143
* CCS_D when rendering to the base slice. However, there is no
2144
* documentation tell us what the hardware would do in that case or what
2145
* it does if you walk off the bases slice. (Does it ignore CCS or does
2146
* it start scribbling over random memory?) We play it safe and just
2147
* follow the docs and don't allow CCS_D for arrayed or mip-mapped
2148
* surfaces.
2149
*/
2150
if (ISL_GFX_VER(dev) <= 7 &&
2151
(surf->levels > 1 || surf->logical_level0_px.array_len > 1))
2152
return false;
2153
2154
/* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
2155
* Target(s)", beneath the "Fast Color Clear" bullet (p326):
2156
*
2157
* - MCS buffer for non-MSRT is supported only for RT formats 32bpp,
2158
* 64bpp, and 128bpp.
2159
*/
2160
if (isl_format_get_layout(surf->format)->bpb < 32)
2161
return false;
2162
2163
/* From the Skylake documentation, it is made clear that X-tiling is no
2164
* longer supported:
2165
*
2166
* - MCS and Lossless compression is supported for
2167
* TiledY/TileYs/TileYf non-MSRTs only.
2168
*/
2169
if (ISL_GFX_VER(dev) >= 9 && !isl_tiling_is_any_y(surf->tiling))
2170
return false;
2171
}
2172
2173
return true;
2174
}
2175
2176
bool
2177
isl_surf_get_ccs_surf(const struct isl_device *dev,
2178
const struct isl_surf *surf,
2179
const struct isl_surf *hiz_or_mcs_surf,
2180
struct isl_surf *ccs_surf,
2181
uint32_t row_pitch_B)
2182
{
2183
if (!isl_surf_supports_ccs(dev, surf, hiz_or_mcs_surf))
2184
return false;
2185
2186
if (ISL_GFX_VER(dev) >= 12) {
2187
enum isl_format ccs_format;
2188
switch (isl_format_get_layout(surf->format)->bpb) {
2189
case 8: ccs_format = ISL_FORMAT_GFX12_CCS_8BPP_Y0; break;
2190
case 16: ccs_format = ISL_FORMAT_GFX12_CCS_16BPP_Y0; break;
2191
case 32: ccs_format = ISL_FORMAT_GFX12_CCS_32BPP_Y0; break;
2192
case 64: ccs_format = ISL_FORMAT_GFX12_CCS_64BPP_Y0; break;
2193
case 128: ccs_format = ISL_FORMAT_GFX12_CCS_128BPP_Y0; break;
2194
default:
2195
return false;
2196
}
2197
2198
/* On Gfx12, the CCS is a scaled-down version of the main surface. We
2199
* model this as the CCS compressing a 2D-view of the entire surface.
2200
*/
2201
const bool ok =
2202
isl_surf_init(dev, ccs_surf,
2203
.dim = ISL_SURF_DIM_2D,
2204
.format = ccs_format,
2205
.width = isl_surf_get_row_pitch_el(surf),
2206
.height = surf->size_B / surf->row_pitch_B,
2207
.depth = 1,
2208
.levels = 1,
2209
.array_len = 1,
2210
.samples = 1,
2211
.row_pitch_B = row_pitch_B,
2212
.usage = ISL_SURF_USAGE_CCS_BIT,
2213
.tiling_flags = ISL_TILING_GFX12_CCS_BIT);
2214
assert(!ok || ccs_surf->size_B == surf->size_B / 256);
2215
return ok;
2216
} else {
2217
enum isl_format ccs_format;
2218
if (ISL_GFX_VER(dev) >= 9) {
2219
switch (isl_format_get_layout(surf->format)->bpb) {
2220
case 32: ccs_format = ISL_FORMAT_GFX9_CCS_32BPP; break;
2221
case 64: ccs_format = ISL_FORMAT_GFX9_CCS_64BPP; break;
2222
case 128: ccs_format = ISL_FORMAT_GFX9_CCS_128BPP; break;
2223
default: unreachable("Unsupported CCS format");
2224
return false;
2225
}
2226
} else if (surf->tiling == ISL_TILING_Y0) {
2227
switch (isl_format_get_layout(surf->format)->bpb) {
2228
case 32: ccs_format = ISL_FORMAT_GFX7_CCS_32BPP_Y; break;
2229
case 64: ccs_format = ISL_FORMAT_GFX7_CCS_64BPP_Y; break;
2230
case 128: ccs_format = ISL_FORMAT_GFX7_CCS_128BPP_Y; break;
2231
default: unreachable("Unsupported CCS format");
2232
}
2233
} else if (surf->tiling == ISL_TILING_X) {
2234
switch (isl_format_get_layout(surf->format)->bpb) {
2235
case 32: ccs_format = ISL_FORMAT_GFX7_CCS_32BPP_X; break;
2236
case 64: ccs_format = ISL_FORMAT_GFX7_CCS_64BPP_X; break;
2237
case 128: ccs_format = ISL_FORMAT_GFX7_CCS_128BPP_X; break;
2238
default: unreachable("Unsupported CCS format");
2239
}
2240
} else {
2241
unreachable("Invalid tiling format");
2242
}
2243
2244
return isl_surf_init(dev, ccs_surf,
2245
.dim = surf->dim,
2246
.format = ccs_format,
2247
.width = surf->logical_level0_px.width,
2248
.height = surf->logical_level0_px.height,
2249
.depth = surf->logical_level0_px.depth,
2250
.levels = surf->levels,
2251
.array_len = surf->logical_level0_px.array_len,
2252
.samples = 1,
2253
.row_pitch_B = row_pitch_B,
2254
.usage = ISL_SURF_USAGE_CCS_BIT,
2255
.tiling_flags = ISL_TILING_CCS_BIT);
2256
}
2257
}
2258
2259
#define isl_genX_call(dev, func, ...) \
2260
switch (ISL_GFX_VERX10(dev)) { \
2261
case 40: \
2262
isl_gfx4_##func(__VA_ARGS__); \
2263
break; \
2264
case 45: \
2265
/* G45 surface state is the same as gfx5 */ \
2266
case 50: \
2267
isl_gfx5_##func(__VA_ARGS__); \
2268
break; \
2269
case 60: \
2270
isl_gfx6_##func(__VA_ARGS__); \
2271
break; \
2272
case 70: \
2273
isl_gfx7_##func(__VA_ARGS__); \
2274
break; \
2275
case 75: \
2276
isl_gfx75_##func(__VA_ARGS__); \
2277
break; \
2278
case 80: \
2279
isl_gfx8_##func(__VA_ARGS__); \
2280
break; \
2281
case 90: \
2282
isl_gfx9_##func(__VA_ARGS__); \
2283
break; \
2284
case 110: \
2285
isl_gfx11_##func(__VA_ARGS__); \
2286
break; \
2287
case 120: \
2288
isl_gfx12_##func(__VA_ARGS__); \
2289
break; \
2290
case 125: \
2291
isl_gfx125_##func(__VA_ARGS__); \
2292
break; \
2293
default: \
2294
assert(!"Unknown hardware generation"); \
2295
}
2296
2297
void
2298
isl_surf_fill_state_s(const struct isl_device *dev, void *state,
2299
const struct isl_surf_fill_state_info *restrict info)
2300
{
2301
#ifndef NDEBUG
2302
isl_surf_usage_flags_t _base_usage =
2303
info->view->usage & (ISL_SURF_USAGE_RENDER_TARGET_BIT |
2304
ISL_SURF_USAGE_TEXTURE_BIT |
2305
ISL_SURF_USAGE_STORAGE_BIT);
2306
/* They may only specify one of the above bits at a time */
2307
assert(__builtin_popcount(_base_usage) == 1);
2308
/* The only other allowed bit is ISL_SURF_USAGE_CUBE_BIT */
2309
assert((info->view->usage & ~ISL_SURF_USAGE_CUBE_BIT) == _base_usage);
2310
#endif
2311
2312
if (info->surf->dim == ISL_SURF_DIM_3D) {
2313
assert(info->view->base_array_layer + info->view->array_len <=
2314
info->surf->logical_level0_px.depth);
2315
} else {
2316
assert(info->view->base_array_layer + info->view->array_len <=
2317
info->surf->logical_level0_px.array_len);
2318
}
2319
2320
isl_genX_call(dev, surf_fill_state_s, dev, state, info);
2321
}
2322
2323
void
2324
isl_buffer_fill_state_s(const struct isl_device *dev, void *state,
2325
const struct isl_buffer_fill_state_info *restrict info)
2326
{
2327
isl_genX_call(dev, buffer_fill_state_s, dev, state, info);
2328
}
2329
2330
void
2331
isl_null_fill_state_s(const struct isl_device *dev, void *state,
2332
const struct isl_null_fill_state_info *restrict info)
2333
{
2334
isl_genX_call(dev, null_fill_state, state, info);
2335
}
2336
2337
void
2338
isl_emit_depth_stencil_hiz_s(const struct isl_device *dev, void *batch,
2339
const struct isl_depth_stencil_hiz_emit_info *restrict info)
2340
{
2341
if (info->depth_surf && info->stencil_surf) {
2342
if (!dev->info->has_hiz_and_separate_stencil) {
2343
assert(info->depth_surf == info->stencil_surf);
2344
assert(info->depth_address == info->stencil_address);
2345
}
2346
assert(info->depth_surf->dim == info->stencil_surf->dim);
2347
}
2348
2349
if (info->depth_surf) {
2350
assert((info->depth_surf->usage & ISL_SURF_USAGE_DEPTH_BIT));
2351
if (info->depth_surf->dim == ISL_SURF_DIM_3D) {
2352
assert(info->view->base_array_layer + info->view->array_len <=
2353
info->depth_surf->logical_level0_px.depth);
2354
} else {
2355
assert(info->view->base_array_layer + info->view->array_len <=
2356
info->depth_surf->logical_level0_px.array_len);
2357
}
2358
}
2359
2360
if (info->stencil_surf) {
2361
assert((info->stencil_surf->usage & ISL_SURF_USAGE_STENCIL_BIT));
2362
if (info->stencil_surf->dim == ISL_SURF_DIM_3D) {
2363
assert(info->view->base_array_layer + info->view->array_len <=
2364
info->stencil_surf->logical_level0_px.depth);
2365
} else {
2366
assert(info->view->base_array_layer + info->view->array_len <=
2367
info->stencil_surf->logical_level0_px.array_len);
2368
}
2369
}
2370
2371
isl_genX_call(dev, emit_depth_stencil_hiz_s, dev, batch, info);
2372
}
2373
2374
/**
2375
* A variant of isl_surf_get_image_offset_sa() specific to
2376
* ISL_DIM_LAYOUT_GFX4_2D.
2377
*/
2378
static void
2379
get_image_offset_sa_gfx4_2d(const struct isl_surf *surf,
2380
uint32_t level, uint32_t logical_array_layer,
2381
uint32_t *x_offset_sa,
2382
uint32_t *y_offset_sa)
2383
{
2384
assert(level < surf->levels);
2385
if (surf->dim == ISL_SURF_DIM_3D)
2386
assert(logical_array_layer < surf->logical_level0_px.depth);
2387
else
2388
assert(logical_array_layer < surf->logical_level0_px.array_len);
2389
2390
const struct isl_extent3d image_align_sa =
2391
isl_surf_get_image_alignment_sa(surf);
2392
2393
const uint32_t W0 = surf->phys_level0_sa.width;
2394
const uint32_t H0 = surf->phys_level0_sa.height;
2395
2396
const uint32_t phys_layer = logical_array_layer *
2397
(surf->msaa_layout == ISL_MSAA_LAYOUT_ARRAY ? surf->samples : 1);
2398
2399
uint32_t x = 0;
2400
uint32_t y = phys_layer * isl_surf_get_array_pitch_sa_rows(surf);
2401
2402
for (uint32_t l = 0; l < level; ++l) {
2403
if (l == 1) {
2404
uint32_t W = isl_minify(W0, l);
2405
x += isl_align_npot(W, image_align_sa.w);
2406
} else {
2407
uint32_t H = isl_minify(H0, l);
2408
y += isl_align_npot(H, image_align_sa.h);
2409
}
2410
}
2411
2412
*x_offset_sa = x;
2413
*y_offset_sa = y;
2414
}
2415
2416
/**
2417
* A variant of isl_surf_get_image_offset_sa() specific to
2418
* ISL_DIM_LAYOUT_GFX4_3D.
2419
*/
2420
static void
2421
get_image_offset_sa_gfx4_3d(const struct isl_surf *surf,
2422
uint32_t level, uint32_t logical_z_offset_px,
2423
uint32_t *x_offset_sa,
2424
uint32_t *y_offset_sa)
2425
{
2426
assert(level < surf->levels);
2427
if (surf->dim == ISL_SURF_DIM_3D) {
2428
assert(surf->phys_level0_sa.array_len == 1);
2429
assert(logical_z_offset_px < isl_minify(surf->phys_level0_sa.depth, level));
2430
} else {
2431
assert(surf->dim == ISL_SURF_DIM_2D);
2432
assert(surf->usage & ISL_SURF_USAGE_CUBE_BIT);
2433
assert(surf->phys_level0_sa.array_len == 6);
2434
assert(logical_z_offset_px < surf->phys_level0_sa.array_len);
2435
}
2436
2437
const struct isl_extent3d image_align_sa =
2438
isl_surf_get_image_alignment_sa(surf);
2439
2440
const uint32_t W0 = surf->phys_level0_sa.width;
2441
const uint32_t H0 = surf->phys_level0_sa.height;
2442
const uint32_t D0 = surf->phys_level0_sa.depth;
2443
const uint32_t AL = surf->phys_level0_sa.array_len;
2444
2445
uint32_t x = 0;
2446
uint32_t y = 0;
2447
2448
for (uint32_t l = 0; l < level; ++l) {
2449
const uint32_t level_h = isl_align_npot(isl_minify(H0, l), image_align_sa.h);
2450
const uint32_t level_d =
2451
isl_align_npot(surf->dim == ISL_SURF_DIM_3D ? isl_minify(D0, l) : AL,
2452
image_align_sa.d);
2453
const uint32_t max_layers_vert = isl_align(level_d, 1u << l) / (1u << l);
2454
2455
y += level_h * max_layers_vert;
2456
}
2457
2458
const uint32_t level_w = isl_align_npot(isl_minify(W0, level), image_align_sa.w);
2459
const uint32_t level_h = isl_align_npot(isl_minify(H0, level), image_align_sa.h);
2460
const uint32_t level_d =
2461
isl_align_npot(surf->dim == ISL_SURF_DIM_3D ? isl_minify(D0, level) : AL,
2462
image_align_sa.d);
2463
2464
const uint32_t max_layers_horiz = MIN(level_d, 1u << level);
2465
2466
x += level_w * (logical_z_offset_px % max_layers_horiz);
2467
y += level_h * (logical_z_offset_px / max_layers_horiz);
2468
2469
*x_offset_sa = x;
2470
*y_offset_sa = y;
2471
}
2472
2473
static void
2474
get_image_offset_sa_gfx6_stencil_hiz(const struct isl_surf *surf,
2475
uint32_t level,
2476
uint32_t logical_array_layer,
2477
uint32_t *x_offset_sa,
2478
uint32_t *y_offset_sa)
2479
{
2480
assert(level < surf->levels);
2481
assert(surf->logical_level0_px.depth == 1);
2482
assert(logical_array_layer < surf->logical_level0_px.array_len);
2483
2484
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2485
2486
const struct isl_extent3d image_align_sa =
2487
isl_surf_get_image_alignment_sa(surf);
2488
2489
struct isl_tile_info tile_info;
2490
isl_tiling_get_info(surf->tiling, fmtl->bpb, &tile_info);
2491
const struct isl_extent2d tile_extent_sa = {
2492
.w = tile_info.logical_extent_el.w * fmtl->bw,
2493
.h = tile_info.logical_extent_el.h * fmtl->bh,
2494
};
2495
/* Tile size is a multiple of image alignment */
2496
assert(tile_extent_sa.w % image_align_sa.w == 0);
2497
assert(tile_extent_sa.h % image_align_sa.h == 0);
2498
2499
const uint32_t W0 = surf->phys_level0_sa.w;
2500
const uint32_t H0 = surf->phys_level0_sa.h;
2501
2502
/* Each image has the same height as LOD0 because the hardware thinks
2503
* everything is LOD0
2504
*/
2505
const uint32_t H = isl_align(H0, image_align_sa.h);
2506
2507
/* Quick sanity check for consistency */
2508
if (surf->phys_level0_sa.array_len > 1)
2509
assert(surf->array_pitch_el_rows == isl_assert_div(H, fmtl->bh));
2510
2511
uint32_t x = 0, y = 0;
2512
for (uint32_t l = 0; l < level; ++l) {
2513
const uint32_t W = isl_minify(W0, l);
2514
2515
const uint32_t w = isl_align(W, tile_extent_sa.w);
2516
const uint32_t h = isl_align(H * surf->phys_level0_sa.a,
2517
tile_extent_sa.h);
2518
2519
if (l == 0) {
2520
y += h;
2521
} else {
2522
x += w;
2523
}
2524
}
2525
2526
y += H * logical_array_layer;
2527
2528
*x_offset_sa = x;
2529
*y_offset_sa = y;
2530
}
2531
2532
/**
2533
* A variant of isl_surf_get_image_offset_sa() specific to
2534
* ISL_DIM_LAYOUT_GFX9_1D.
2535
*/
2536
static void
2537
get_image_offset_sa_gfx9_1d(const struct isl_surf *surf,
2538
uint32_t level, uint32_t layer,
2539
uint32_t *x_offset_sa,
2540
uint32_t *y_offset_sa)
2541
{
2542
assert(level < surf->levels);
2543
assert(layer < surf->phys_level0_sa.array_len);
2544
assert(surf->phys_level0_sa.height == 1);
2545
assert(surf->phys_level0_sa.depth == 1);
2546
assert(surf->samples == 1);
2547
2548
const uint32_t W0 = surf->phys_level0_sa.width;
2549
const struct isl_extent3d image_align_sa =
2550
isl_surf_get_image_alignment_sa(surf);
2551
2552
uint32_t x = 0;
2553
2554
for (uint32_t l = 0; l < level; ++l) {
2555
uint32_t W = isl_minify(W0, l);
2556
uint32_t w = isl_align_npot(W, image_align_sa.w);
2557
2558
x += w;
2559
}
2560
2561
*x_offset_sa = x;
2562
*y_offset_sa = layer * isl_surf_get_array_pitch_sa_rows(surf);
2563
}
2564
2565
/**
2566
* Calculate the offset, in units of surface samples, to a subimage in the
2567
* surface.
2568
*
2569
* @invariant level < surface levels
2570
* @invariant logical_array_layer < logical array length of surface
2571
* @invariant logical_z_offset_px < logical depth of surface at level
2572
*/
2573
void
2574
isl_surf_get_image_offset_sa(const struct isl_surf *surf,
2575
uint32_t level,
2576
uint32_t logical_array_layer,
2577
uint32_t logical_z_offset_px,
2578
uint32_t *x_offset_sa,
2579
uint32_t *y_offset_sa,
2580
uint32_t *z_offset_sa,
2581
uint32_t *array_offset)
2582
{
2583
assert(level < surf->levels);
2584
assert(logical_array_layer < surf->logical_level0_px.array_len);
2585
assert(logical_z_offset_px
2586
< isl_minify(surf->logical_level0_px.depth, level));
2587
2588
switch (surf->dim_layout) {
2589
case ISL_DIM_LAYOUT_GFX9_1D:
2590
get_image_offset_sa_gfx9_1d(surf, level, logical_array_layer,
2591
x_offset_sa, y_offset_sa);
2592
*z_offset_sa = 0;
2593
*array_offset = 0;
2594
break;
2595
case ISL_DIM_LAYOUT_GFX4_2D:
2596
get_image_offset_sa_gfx4_2d(surf, level, logical_array_layer
2597
+ logical_z_offset_px,
2598
x_offset_sa, y_offset_sa);
2599
*z_offset_sa = 0;
2600
*array_offset = 0;
2601
break;
2602
case ISL_DIM_LAYOUT_GFX4_3D:
2603
get_image_offset_sa_gfx4_3d(surf, level, logical_array_layer +
2604
logical_z_offset_px,
2605
x_offset_sa, y_offset_sa);
2606
*z_offset_sa = 0;
2607
*array_offset = 0;
2608
break;
2609
case ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ:
2610
get_image_offset_sa_gfx6_stencil_hiz(surf, level, logical_array_layer +
2611
logical_z_offset_px,
2612
x_offset_sa, y_offset_sa);
2613
*z_offset_sa = 0;
2614
*array_offset = 0;
2615
break;
2616
2617
default:
2618
unreachable("not reached");
2619
}
2620
}
2621
2622
void
2623
isl_surf_get_image_offset_el(const struct isl_surf *surf,
2624
uint32_t level,
2625
uint32_t logical_array_layer,
2626
uint32_t logical_z_offset_px,
2627
uint32_t *x_offset_el,
2628
uint32_t *y_offset_el,
2629
uint32_t *z_offset_el,
2630
uint32_t *array_offset)
2631
{
2632
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2633
2634
assert(level < surf->levels);
2635
assert(logical_array_layer < surf->logical_level0_px.array_len);
2636
assert(logical_z_offset_px
2637
< isl_minify(surf->logical_level0_px.depth, level));
2638
2639
uint32_t x_offset_sa, y_offset_sa, z_offset_sa;
2640
isl_surf_get_image_offset_sa(surf, level,
2641
logical_array_layer,
2642
logical_z_offset_px,
2643
&x_offset_sa,
2644
&y_offset_sa,
2645
&z_offset_sa,
2646
array_offset);
2647
2648
*x_offset_el = x_offset_sa / fmtl->bw;
2649
*y_offset_el = y_offset_sa / fmtl->bh;
2650
*z_offset_el = z_offset_sa / fmtl->bd;
2651
}
2652
2653
void
2654
isl_surf_get_image_offset_B_tile_sa(const struct isl_surf *surf,
2655
uint32_t level,
2656
uint32_t logical_array_layer,
2657
uint32_t logical_z_offset_px,
2658
uint32_t *offset_B,
2659
uint32_t *x_offset_sa,
2660
uint32_t *y_offset_sa)
2661
{
2662
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2663
2664
uint32_t x_offset_el, y_offset_el;
2665
isl_surf_get_image_offset_B_tile_el(surf, level,
2666
logical_array_layer,
2667
logical_z_offset_px,
2668
offset_B,
2669
&x_offset_el,
2670
&y_offset_el);
2671
2672
if (x_offset_sa) {
2673
*x_offset_sa = x_offset_el * fmtl->bw;
2674
} else {
2675
assert(x_offset_el == 0);
2676
}
2677
2678
if (y_offset_sa) {
2679
*y_offset_sa = y_offset_el * fmtl->bh;
2680
} else {
2681
assert(y_offset_el == 0);
2682
}
2683
}
2684
2685
void
2686
isl_surf_get_image_offset_B_tile_el(const struct isl_surf *surf,
2687
uint32_t level,
2688
uint32_t logical_array_layer,
2689
uint32_t logical_z_offset_px,
2690
uint32_t *offset_B,
2691
uint32_t *x_offset_el,
2692
uint32_t *y_offset_el)
2693
{
2694
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2695
2696
uint32_t total_x_offset_el, total_y_offset_el;
2697
uint32_t total_z_offset_el, total_array_offset;
2698
isl_surf_get_image_offset_el(surf, level, logical_array_layer,
2699
logical_z_offset_px,
2700
&total_x_offset_el,
2701
&total_y_offset_el,
2702
&total_z_offset_el,
2703
&total_array_offset);
2704
2705
uint32_t z_offset_el, array_offset;
2706
isl_tiling_get_intratile_offset_el(surf->tiling, fmtl->bpb,
2707
surf->row_pitch_B,
2708
surf->array_pitch_el_rows,
2709
total_x_offset_el,
2710
total_y_offset_el,
2711
total_z_offset_el,
2712
total_array_offset,
2713
offset_B,
2714
x_offset_el,
2715
y_offset_el,
2716
&z_offset_el,
2717
&array_offset);
2718
assert(z_offset_el == 0);
2719
assert(array_offset == 0);
2720
}
2721
2722
void
2723
isl_surf_get_image_range_B_tile(const struct isl_surf *surf,
2724
uint32_t level,
2725
uint32_t logical_array_layer,
2726
uint32_t logical_z_offset_px,
2727
uint32_t *start_tile_B,
2728
uint32_t *end_tile_B)
2729
{
2730
uint32_t start_x_offset_el, start_y_offset_el;
2731
uint32_t start_z_offset_el, start_array_slice;
2732
isl_surf_get_image_offset_el(surf, level, logical_array_layer,
2733
logical_z_offset_px,
2734
&start_x_offset_el,
2735
&start_y_offset_el,
2736
&start_z_offset_el,
2737
&start_array_slice);
2738
2739
/* Compute the size of the subimage in surface elements */
2740
const uint32_t subimage_w_sa = isl_minify(surf->phys_level0_sa.w, level);
2741
const uint32_t subimage_h_sa = isl_minify(surf->phys_level0_sa.h, level);
2742
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
2743
const uint32_t subimage_w_el = isl_align_div_npot(subimage_w_sa, fmtl->bw);
2744
const uint32_t subimage_h_el = isl_align_div_npot(subimage_h_sa, fmtl->bh);
2745
2746
/* Find the last pixel */
2747
uint32_t end_x_offset_el = start_x_offset_el + subimage_w_el - 1;
2748
uint32_t end_y_offset_el = start_y_offset_el + subimage_h_el - 1;
2749
2750
/* We only consider one Z or array slice */
2751
const uint32_t end_z_offset_el = start_z_offset_el;
2752
const uint32_t end_array_slice = start_array_slice;
2753
2754
UNUSED uint32_t x_offset_el, y_offset_el, z_offset_el, array_slice;
2755
isl_tiling_get_intratile_offset_el(surf->tiling, fmtl->bpb,
2756
surf->row_pitch_B,
2757
surf->array_pitch_el_rows,
2758
start_x_offset_el,
2759
start_y_offset_el,
2760
start_z_offset_el,
2761
start_array_slice,
2762
start_tile_B,
2763
&x_offset_el,
2764
&y_offset_el,
2765
&z_offset_el,
2766
&array_slice);
2767
2768
isl_tiling_get_intratile_offset_el(surf->tiling, fmtl->bpb,
2769
surf->row_pitch_B,
2770
surf->array_pitch_el_rows,
2771
end_x_offset_el,
2772
end_y_offset_el,
2773
end_z_offset_el,
2774
end_array_slice,
2775
end_tile_B,
2776
&x_offset_el,
2777
&y_offset_el,
2778
&z_offset_el,
2779
&array_slice);
2780
2781
/* We want the range we return to be exclusive but the tile containing the
2782
* last pixel (what we just calculated) is inclusive. Add one.
2783
*/
2784
(*end_tile_B)++;
2785
2786
assert(*end_tile_B <= surf->size_B);
2787
}
2788
2789
void
2790
isl_surf_get_image_surf(const struct isl_device *dev,
2791
const struct isl_surf *surf,
2792
uint32_t level,
2793
uint32_t logical_array_layer,
2794
uint32_t logical_z_offset_px,
2795
struct isl_surf *image_surf,
2796
uint32_t *offset_B,
2797
uint32_t *x_offset_sa,
2798
uint32_t *y_offset_sa)
2799
{
2800
isl_surf_get_image_offset_B_tile_sa(surf,
2801
level,
2802
logical_array_layer,
2803
logical_z_offset_px,
2804
offset_B,
2805
x_offset_sa,
2806
y_offset_sa);
2807
2808
/* Even for cube maps there will be only single face, therefore drop the
2809
* corresponding flag if present.
2810
*/
2811
const isl_surf_usage_flags_t usage =
2812
surf->usage & (~ISL_SURF_USAGE_CUBE_BIT);
2813
2814
bool ok UNUSED;
2815
ok = isl_surf_init(dev, image_surf,
2816
.dim = ISL_SURF_DIM_2D,
2817
.format = surf->format,
2818
.width = isl_minify(surf->logical_level0_px.w, level),
2819
.height = isl_minify(surf->logical_level0_px.h, level),
2820
.depth = 1,
2821
.levels = 1,
2822
.array_len = 1,
2823
.samples = surf->samples,
2824
.row_pitch_B = surf->row_pitch_B,
2825
.usage = usage,
2826
.tiling_flags = (1 << surf->tiling));
2827
assert(ok);
2828
}
2829
2830
bool
2831
isl_surf_get_uncompressed_surf(const struct isl_device *dev,
2832
const struct isl_surf *surf,
2833
const struct isl_view *view,
2834
struct isl_surf *ucompr_surf,
2835
struct isl_view *ucompr_view,
2836
uint32_t *offset_B,
2837
uint32_t *x_offset_el,
2838
uint32_t *y_offset_el)
2839
{
2840
const struct isl_format_layout *fmtl =
2841
isl_format_get_layout(surf->format);
2842
const enum isl_format view_format = view->format;
2843
2844
assert(fmtl->bw > 1 || fmtl->bh > 1 || fmtl->bd > 1);
2845
assert(isl_format_is_compressed(surf->format));
2846
assert(!isl_format_is_compressed(view->format));
2847
assert(isl_format_get_layout(view->format)->bpb == fmtl->bpb);
2848
assert(view->levels == 1);
2849
2850
const uint32_t view_width =
2851
isl_minify(surf->logical_level0_px.width, view->base_level);
2852
const uint32_t view_height =
2853
isl_minify(surf->logical_level0_px.height, view->base_level);
2854
2855
const uint32_t ucompr_width = isl_align_div_npot(view_width, fmtl->bw);
2856
const uint32_t ucompr_height = isl_align_div_npot(view_height, fmtl->bh);
2857
2858
/* If we ever enable 3D block formats, we'll need to re-think this */
2859
assert(fmtl->bd == 1);
2860
2861
uint32_t x_offset_sa = 0, y_offset_sa = 0;
2862
if (view->array_len > 1) {
2863
/* The Skylake PRM Vol. 2d, "RENDER_SURFACE_STATE::X Offset" says:
2864
*
2865
* "If Surface Array is enabled, this field must be zero."
2866
*
2867
* The PRMs for other hardware have similar text. This is also tricky
2868
* to handle with things like BLORP's SW offsetting because the
2869
* increased surface size required for the offset may result in an image
2870
* height greater than qpitch.
2871
*/
2872
if (view->base_level > 0)
2873
return false;
2874
2875
/* On Haswell and earlier, RENDER_SURFACE_STATE doesn't have a QPitch
2876
* field; it only has "array pitch span" which means the QPitch is
2877
* automatically calculated. Since we're smashing the surface format
2878
* (block formats are subtly different) and the number of miplevels,
2879
* that calculation will get thrown off. This means we can't do arrays
2880
* even at LOD0
2881
*
2882
* On Broadwell, we do have a QPitch field which we can control.
2883
* However, HALIGN and VALIGN are specified in pixels and are
2884
* hard-coded to align to exactly the block size of the compressed
2885
* texture. This means that, when reinterpreted as a non-compressed
2886
* the QPitch may be anything but the HW requires it to be properly
2887
* aligned.
2888
*/
2889
if (ISL_GFX_VER(dev) < 9)
2890
return false;
2891
2892
*ucompr_surf = *surf;
2893
ucompr_surf->levels = 1;
2894
2895
/* The surface mostly stays as-is; there is no offset */
2896
*offset_B = 0;
2897
2898
/* The view remains the same */
2899
*ucompr_view = *view;
2900
} else {
2901
/* If only one array slice is requested, directly offset to that slice.
2902
* We could, in theory, still use arrays in some cases but BLORP isn't
2903
* prepared for this and everyone who calls this function should be
2904
* prepared to handle an X/Y offset.
2905
*/
2906
isl_surf_get_image_surf(dev, surf,
2907
view->base_level,
2908
surf->dim == ISL_SURF_DIM_3D ?
2909
0 : view->base_array_layer,
2910
surf->dim == ISL_SURF_DIM_3D ?
2911
view->base_array_layer : 0,
2912
ucompr_surf,
2913
offset_B, &x_offset_sa, &y_offset_sa);
2914
2915
/* The newly created image represents the one subimage we're
2916
* referencing with this view so it only has one array slice and
2917
* miplevel.
2918
*/
2919
*ucompr_view = *view;
2920
ucompr_view->base_array_layer = 0;
2921
ucompr_view->base_level = 0;
2922
}
2923
2924
ucompr_surf->format = view_format;
2925
2926
/* We're making an uncompressed view here. The image dimensions
2927
* need to be scaled down by the block size.
2928
*/
2929
assert(ucompr_surf->logical_level0_px.width == view_width);
2930
assert(ucompr_surf->logical_level0_px.height == view_height);
2931
ucompr_surf->logical_level0_px.width = ucompr_width;
2932
ucompr_surf->logical_level0_px.height = ucompr_height;
2933
ucompr_surf->phys_level0_sa = isl_surf_get_phys_level0_el(surf);
2934
2935
*x_offset_el = isl_assert_div(x_offset_sa, fmtl->bw);
2936
*y_offset_el = isl_assert_div(y_offset_sa, fmtl->bh);
2937
2938
return true;
2939
}
2940
2941
void
2942
isl_tiling_get_intratile_offset_el(enum isl_tiling tiling,
2943
uint32_t bpb,
2944
uint32_t row_pitch_B,
2945
uint32_t array_pitch_el_rows,
2946
uint32_t total_x_offset_el,
2947
uint32_t total_y_offset_el,
2948
uint32_t total_z_offset_el,
2949
uint32_t total_array_offset,
2950
uint32_t *base_address_offset,
2951
uint32_t *x_offset_el,
2952
uint32_t *y_offset_el,
2953
uint32_t *z_offset_el,
2954
uint32_t *array_offset)
2955
{
2956
if (tiling == ISL_TILING_LINEAR) {
2957
assert(bpb % 8 == 0);
2958
assert(total_z_offset_el == 0 && total_array_offset == 0);
2959
*base_address_offset = total_y_offset_el * row_pitch_B +
2960
total_x_offset_el * (bpb / 8);
2961
*x_offset_el = 0;
2962
*y_offset_el = 0;
2963
*z_offset_el = 0;
2964
*array_offset = 0;
2965
return;
2966
}
2967
2968
struct isl_tile_info tile_info;
2969
isl_tiling_get_info(tiling, bpb, &tile_info);
2970
2971
/* Pitches must make sense with the tiling */
2972
assert(row_pitch_B % tile_info.phys_extent_B.width == 0);
2973
if (tile_info.logical_extent_el.d > 1 || tile_info.logical_extent_el.a > 1)
2974
assert(array_pitch_el_rows % tile_info.logical_extent_el.h == 0);
2975
2976
/* For non-power-of-two formats, we need the address to be both tile and
2977
* element-aligned. The easiest way to achieve this is to work with a tile
2978
* that is three times as wide as the regular tile.
2979
*
2980
* The tile info returned by get_tile_info has a logical size that is an
2981
* integer number of tile_info.format_bpb size elements. To scale the
2982
* tile, we scale up the physical width and then treat the logical tile
2983
* size as if it has bpb size elements.
2984
*/
2985
const uint32_t tile_el_scale = bpb / tile_info.format_bpb;
2986
tile_info.phys_extent_B.width *= tile_el_scale;
2987
2988
/* Compute the offset into the tile */
2989
*x_offset_el = total_x_offset_el % tile_info.logical_extent_el.w;
2990
*y_offset_el = total_y_offset_el % tile_info.logical_extent_el.h;
2991
*z_offset_el = total_z_offset_el % tile_info.logical_extent_el.d;
2992
*array_offset = total_array_offset % tile_info.logical_extent_el.a;
2993
2994
/* Compute the offset of the tile in units of whole tiles */
2995
uint32_t x_offset_tl = total_x_offset_el / tile_info.logical_extent_el.w;
2996
uint32_t y_offset_tl = total_y_offset_el / tile_info.logical_extent_el.h;
2997
uint32_t z_offset_tl = total_z_offset_el / tile_info.logical_extent_el.d;
2998
uint32_t a_offset_tl = total_array_offset / tile_info.logical_extent_el.a;
2999
3000
/* Compute an array pitch in number of tiles */
3001
uint32_t array_pitch_tl_rows =
3002
array_pitch_el_rows / tile_info.logical_extent_el.h;
3003
3004
/* Add the Z and array offset to the Y offset to get a 2D offset */
3005
y_offset_tl += (z_offset_tl + a_offset_tl) * array_pitch_tl_rows;
3006
3007
*base_address_offset =
3008
y_offset_tl * tile_info.phys_extent_B.h * row_pitch_B +
3009
x_offset_tl * tile_info.phys_extent_B.h * tile_info.phys_extent_B.w;
3010
}
3011
3012
uint32_t
3013
isl_surf_get_depth_format(const struct isl_device *dev,
3014
const struct isl_surf *surf)
3015
{
3016
/* Support for separate stencil buffers began in gfx5. Support for
3017
* interleaved depthstencil buffers ceased in gfx7. The intermediate gens,
3018
* those that supported separate and interleaved stencil, were gfx5 and
3019
* gfx6.
3020
*
3021
* For a list of all available formats, see the Sandybridge PRM >> Volume
3022
* 2 Part 1: 3D/Media - 3D Pipeline >> 3DSTATE_DEPTH_BUFFER >> Surface
3023
* Format (p321).
3024
*/
3025
3026
bool has_stencil = surf->usage & ISL_SURF_USAGE_STENCIL_BIT;
3027
3028
assert(surf->usage & ISL_SURF_USAGE_DEPTH_BIT);
3029
3030
if (has_stencil)
3031
assert(ISL_GFX_VER(dev) < 7);
3032
3033
switch (surf->format) {
3034
default:
3035
unreachable("bad isl depth format");
3036
case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
3037
assert(ISL_GFX_VER(dev) < 7);
3038
return 0; /* D32_FLOAT_S8X24_UINT */
3039
case ISL_FORMAT_R32_FLOAT:
3040
assert(!has_stencil);
3041
return 1; /* D32_FLOAT */
3042
case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
3043
if (has_stencil) {
3044
assert(ISL_GFX_VER(dev) < 7);
3045
return 2; /* D24_UNORM_S8_UINT */
3046
} else {
3047
assert(ISL_GFX_VER(dev) >= 5);
3048
return 3; /* D24_UNORM_X8_UINT */
3049
}
3050
case ISL_FORMAT_R16_UNORM:
3051
assert(!has_stencil);
3052
return 5; /* D16_UNORM */
3053
}
3054
}
3055
3056
bool
3057
isl_swizzle_supports_rendering(const struct intel_device_info *devinfo,
3058
struct isl_swizzle swizzle)
3059
{
3060
if (devinfo->is_haswell) {
3061
/* From the Haswell PRM,
3062
* RENDER_SURFACE_STATE::Shader Channel Select Red
3063
*
3064
* "The Shader channel selects also define which shader channels are
3065
* written to which surface channel. If the Shader channel select is
3066
* SCS_ZERO or SCS_ONE then it is not written to the surface. If the
3067
* shader channel select is SCS_RED it is written to the surface red
3068
* channel and so on. If more than one shader channel select is set
3069
* to the same surface channel only the first shader channel in RGBA
3070
* order will be written."
3071
*/
3072
return true;
3073
} else if (devinfo->ver <= 7) {
3074
/* Ivy Bridge and early doesn't have any swizzling */
3075
return isl_swizzle_is_identity(swizzle);
3076
} else {
3077
/* From the Sky Lake PRM Vol. 2d,
3078
* RENDER_SURFACE_STATE::Shader Channel Select Red
3079
*
3080
* "For Render Target, Red, Green and Blue Shader Channel Selects
3081
* MUST be such that only valid components can be swapped i.e. only
3082
* change the order of components in the pixel. Any other values for
3083
* these Shader Channel Select fields are not valid for Render
3084
* Targets. This also means that there MUST not be multiple shader
3085
* channels mapped to the same RT channel."
3086
*
3087
* From the Sky Lake PRM Vol. 2d,
3088
* RENDER_SURFACE_STATE::Shader Channel Select Alpha
3089
*
3090
* "For Render Target, this field MUST be programmed to
3091
* value = SCS_ALPHA."
3092
*/
3093
return (swizzle.r == ISL_CHANNEL_SELECT_RED ||
3094
swizzle.r == ISL_CHANNEL_SELECT_GREEN ||
3095
swizzle.r == ISL_CHANNEL_SELECT_BLUE) &&
3096
(swizzle.g == ISL_CHANNEL_SELECT_RED ||
3097
swizzle.g == ISL_CHANNEL_SELECT_GREEN ||
3098
swizzle.g == ISL_CHANNEL_SELECT_BLUE) &&
3099
(swizzle.b == ISL_CHANNEL_SELECT_RED ||
3100
swizzle.b == ISL_CHANNEL_SELECT_GREEN ||
3101
swizzle.b == ISL_CHANNEL_SELECT_BLUE) &&
3102
swizzle.r != swizzle.g &&
3103
swizzle.r != swizzle.b &&
3104
swizzle.g != swizzle.b &&
3105
swizzle.a == ISL_CHANNEL_SELECT_ALPHA;
3106
}
3107
}
3108
3109
static enum isl_channel_select
3110
swizzle_select(enum isl_channel_select chan, struct isl_swizzle swizzle)
3111
{
3112
switch (chan) {
3113
case ISL_CHANNEL_SELECT_ZERO:
3114
case ISL_CHANNEL_SELECT_ONE:
3115
return chan;
3116
case ISL_CHANNEL_SELECT_RED:
3117
return swizzle.r;
3118
case ISL_CHANNEL_SELECT_GREEN:
3119
return swizzle.g;
3120
case ISL_CHANNEL_SELECT_BLUE:
3121
return swizzle.b;
3122
case ISL_CHANNEL_SELECT_ALPHA:
3123
return swizzle.a;
3124
default:
3125
unreachable("Invalid swizzle component");
3126
}
3127
}
3128
3129
/**
3130
* Returns the single swizzle that is equivalent to applying the two given
3131
* swizzles in sequence.
3132
*/
3133
struct isl_swizzle
3134
isl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second)
3135
{
3136
return (struct isl_swizzle) {
3137
.r = swizzle_select(first.r, second),
3138
.g = swizzle_select(first.g, second),
3139
.b = swizzle_select(first.b, second),
3140
.a = swizzle_select(first.a, second),
3141
};
3142
}
3143
3144
/**
3145
* Returns a swizzle that is the pseudo-inverse of this swizzle.
3146
*/
3147
struct isl_swizzle
3148
isl_swizzle_invert(struct isl_swizzle swizzle)
3149
{
3150
/* Default to zero for channels which do not show up in the swizzle */
3151
enum isl_channel_select chans[4] = {
3152
ISL_CHANNEL_SELECT_ZERO,
3153
ISL_CHANNEL_SELECT_ZERO,
3154
ISL_CHANNEL_SELECT_ZERO,
3155
ISL_CHANNEL_SELECT_ZERO,
3156
};
3157
3158
/* We go in ABGR order so that, if there are any duplicates, the first one
3159
* is taken if you look at it in RGBA order. This is what Haswell hardware
3160
* does for render target swizzles.
3161
*/
3162
if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)
3163
chans[swizzle.a - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_ALPHA;
3164
if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)
3165
chans[swizzle.b - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_BLUE;
3166
if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)
3167
chans[swizzle.g - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_GREEN;
3168
if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)
3169
chans[swizzle.r - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_RED;
3170
3171
return (struct isl_swizzle) { chans[0], chans[1], chans[2], chans[3] };
3172
}
3173
3174
/** Applies an inverse swizzle to a color value */
3175
union isl_color_value
3176
isl_color_value_swizzle_inv(union isl_color_value src,
3177
struct isl_swizzle swizzle)
3178
{
3179
union isl_color_value dst = { .u32 = { 0, } };
3180
3181
/* We assign colors in ABGR order so that the first one will be taken in
3182
* RGBA precedence order. According to the PRM docs for shader channel
3183
* select, this matches Haswell hardware behavior.
3184
*/
3185
if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)
3186
dst.u32[swizzle.a - ISL_CHANNEL_SELECT_RED] = src.u32[3];
3187
if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)
3188
dst.u32[swizzle.b - ISL_CHANNEL_SELECT_RED] = src.u32[2];
3189
if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)
3190
dst.u32[swizzle.g - ISL_CHANNEL_SELECT_RED] = src.u32[1];
3191
if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)
3192
dst.u32[swizzle.r - ISL_CHANNEL_SELECT_RED] = src.u32[0];
3193
3194
return dst;
3195
}
3196
3197
uint8_t
3198
isl_format_get_aux_map_encoding(enum isl_format format)
3199
{
3200
switch(format) {
3201
case ISL_FORMAT_R32G32B32A32_FLOAT: return 0x11;
3202
case ISL_FORMAT_R32G32B32X32_FLOAT: return 0x11;
3203
case ISL_FORMAT_R32G32B32A32_SINT: return 0x12;
3204
case ISL_FORMAT_R32G32B32A32_UINT: return 0x13;
3205
case ISL_FORMAT_R16G16B16A16_UNORM: return 0x14;
3206
case ISL_FORMAT_R16G16B16A16_SNORM: return 0x15;
3207
case ISL_FORMAT_R16G16B16A16_SINT: return 0x16;
3208
case ISL_FORMAT_R16G16B16A16_UINT: return 0x17;
3209
case ISL_FORMAT_R16G16B16A16_FLOAT: return 0x10;
3210
case ISL_FORMAT_R16G16B16X16_FLOAT: return 0x10;
3211
case ISL_FORMAT_R32G32_FLOAT: return 0x11;
3212
case ISL_FORMAT_R32G32_SINT: return 0x12;
3213
case ISL_FORMAT_R32G32_UINT: return 0x13;
3214
case ISL_FORMAT_B8G8R8A8_UNORM: return 0xA;
3215
case ISL_FORMAT_B8G8R8X8_UNORM: return 0xA;
3216
case ISL_FORMAT_B8G8R8A8_UNORM_SRGB: return 0xA;
3217
case ISL_FORMAT_B8G8R8X8_UNORM_SRGB: return 0xA;
3218
case ISL_FORMAT_R10G10B10A2_UNORM: return 0x18;
3219
case ISL_FORMAT_R10G10B10A2_UNORM_SRGB: return 0x18;
3220
case ISL_FORMAT_R10G10B10_FLOAT_A2_UNORM: return 0x19;
3221
case ISL_FORMAT_R10G10B10A2_UINT: return 0x1A;
3222
case ISL_FORMAT_R8G8B8A8_UNORM: return 0xA;
3223
case ISL_FORMAT_R8G8B8A8_UNORM_SRGB: return 0xA;
3224
case ISL_FORMAT_R8G8B8A8_SNORM: return 0x1B;
3225
case ISL_FORMAT_R8G8B8A8_SINT: return 0x1C;
3226
case ISL_FORMAT_R8G8B8A8_UINT: return 0x1D;
3227
case ISL_FORMAT_R16G16_UNORM: return 0x14;
3228
case ISL_FORMAT_R16G16_SNORM: return 0x15;
3229
case ISL_FORMAT_R16G16_SINT: return 0x16;
3230
case ISL_FORMAT_R16G16_UINT: return 0x17;
3231
case ISL_FORMAT_R16G16_FLOAT: return 0x10;
3232
case ISL_FORMAT_B10G10R10A2_UNORM: return 0x18;
3233
case ISL_FORMAT_B10G10R10A2_UNORM_SRGB: return 0x18;
3234
case ISL_FORMAT_R11G11B10_FLOAT: return 0x1E;
3235
case ISL_FORMAT_R32_SINT: return 0x12;
3236
case ISL_FORMAT_R32_UINT: return 0x13;
3237
case ISL_FORMAT_R32_FLOAT: return 0x11;
3238
case ISL_FORMAT_R24_UNORM_X8_TYPELESS: return 0x13;
3239
case ISL_FORMAT_B5G6R5_UNORM: return 0xA;
3240
case ISL_FORMAT_B5G6R5_UNORM_SRGB: return 0xA;
3241
case ISL_FORMAT_B5G5R5A1_UNORM: return 0xA;
3242
case ISL_FORMAT_B5G5R5A1_UNORM_SRGB: return 0xA;
3243
case ISL_FORMAT_B4G4R4A4_UNORM: return 0xA;
3244
case ISL_FORMAT_B4G4R4A4_UNORM_SRGB: return 0xA;
3245
case ISL_FORMAT_R8G8_UNORM: return 0xA;
3246
case ISL_FORMAT_R8G8_SNORM: return 0x1B;
3247
case ISL_FORMAT_R8G8_SINT: return 0x1C;
3248
case ISL_FORMAT_R8G8_UINT: return 0x1D;
3249
case ISL_FORMAT_R16_UNORM: return 0x14;
3250
case ISL_FORMAT_R16_SNORM: return 0x15;
3251
case ISL_FORMAT_R16_SINT: return 0x16;
3252
case ISL_FORMAT_R16_UINT: return 0x17;
3253
case ISL_FORMAT_R16_FLOAT: return 0x10;
3254
case ISL_FORMAT_B5G5R5X1_UNORM: return 0xA;
3255
case ISL_FORMAT_B5G5R5X1_UNORM_SRGB: return 0xA;
3256
case ISL_FORMAT_A1B5G5R5_UNORM: return 0xA;
3257
case ISL_FORMAT_A4B4G4R4_UNORM: return 0xA;
3258
case ISL_FORMAT_R8_UNORM: return 0xA;
3259
case ISL_FORMAT_R8_SNORM: return 0x1B;
3260
case ISL_FORMAT_R8_SINT: return 0x1C;
3261
case ISL_FORMAT_R8_UINT: return 0x1D;
3262
case ISL_FORMAT_A8_UNORM: return 0xA;
3263
case ISL_FORMAT_PLANAR_420_8: return 0xF;
3264
case ISL_FORMAT_PLANAR_420_10: return 0x7;
3265
case ISL_FORMAT_PLANAR_420_12: return 0x8;
3266
case ISL_FORMAT_PLANAR_420_16: return 0x8;
3267
case ISL_FORMAT_YCRCB_NORMAL: return 0x3;
3268
case ISL_FORMAT_YCRCB_SWAPY: return 0xB;
3269
default:
3270
unreachable("Unsupported aux-map format!");
3271
return 0;
3272
}
3273
}
3274
3275