Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_resource.c
4565 views
1
/*
2
* Copyright © 2017 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 shall be included
12
* in all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
* DEALINGS IN THE SOFTWARE.
21
*/
22
23
/**
24
* @file iris_resource.c
25
*
26
* Resources are images, buffers, and other objects used by the GPU.
27
*
28
* XXX: explain resources
29
*/
30
31
#include <stdio.h>
32
#include <errno.h>
33
#include "pipe/p_defines.h"
34
#include "pipe/p_state.h"
35
#include "pipe/p_context.h"
36
#include "pipe/p_screen.h"
37
#include "util/os_memory.h"
38
#include "util/u_cpu_detect.h"
39
#include "util/u_inlines.h"
40
#include "util/format/u_format.h"
41
#include "util/u_memory.h"
42
#include "util/u_threaded_context.h"
43
#include "util/u_transfer.h"
44
#include "util/u_transfer_helper.h"
45
#include "util/u_upload_mgr.h"
46
#include "util/ralloc.h"
47
#include "iris_batch.h"
48
#include "iris_context.h"
49
#include "iris_resource.h"
50
#include "iris_screen.h"
51
#include "intel/common/intel_aux_map.h"
52
#include "intel/dev/intel_debug.h"
53
#include "isl/isl.h"
54
#include "drm-uapi/drm_fourcc.h"
55
#include "drm-uapi/i915_drm.h"
56
57
enum modifier_priority {
58
MODIFIER_PRIORITY_INVALID = 0,
59
MODIFIER_PRIORITY_LINEAR,
60
MODIFIER_PRIORITY_X,
61
MODIFIER_PRIORITY_Y,
62
MODIFIER_PRIORITY_Y_CCS,
63
MODIFIER_PRIORITY_Y_GFX12_RC_CCS,
64
MODIFIER_PRIORITY_Y_GFX12_RC_CCS_CC,
65
};
66
67
static const uint64_t priority_to_modifier[] = {
68
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
69
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
70
[MODIFIER_PRIORITY_X] = I915_FORMAT_MOD_X_TILED,
71
[MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
72
[MODIFIER_PRIORITY_Y_CCS] = I915_FORMAT_MOD_Y_TILED_CCS,
73
[MODIFIER_PRIORITY_Y_GFX12_RC_CCS] = I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS,
74
[MODIFIER_PRIORITY_Y_GFX12_RC_CCS_CC] = I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC,
75
};
76
77
static bool
78
modifier_is_supported(const struct intel_device_info *devinfo,
79
enum pipe_format pfmt, unsigned bind,
80
uint64_t modifier)
81
{
82
/* Check for basic device support. */
83
switch (modifier) {
84
case DRM_FORMAT_MOD_LINEAR:
85
case I915_FORMAT_MOD_X_TILED:
86
break;
87
case I915_FORMAT_MOD_Y_TILED:
88
if (devinfo->ver <= 8 && (bind & PIPE_BIND_SCANOUT))
89
return false;
90
break;
91
case I915_FORMAT_MOD_Y_TILED_CCS:
92
if (devinfo->ver <= 8 || devinfo->ver >= 12)
93
return false;
94
break;
95
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
96
case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
97
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
98
if (devinfo->ver != 12)
99
return false;
100
break;
101
case DRM_FORMAT_MOD_INVALID:
102
default:
103
return false;
104
}
105
106
/* Check remaining requirements. */
107
switch (modifier) {
108
case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
109
if (pfmt != PIPE_FORMAT_BGRA8888_UNORM &&
110
pfmt != PIPE_FORMAT_RGBA8888_UNORM &&
111
pfmt != PIPE_FORMAT_BGRX8888_UNORM &&
112
pfmt != PIPE_FORMAT_RGBX8888_UNORM &&
113
pfmt != PIPE_FORMAT_NV12 &&
114
pfmt != PIPE_FORMAT_P010 &&
115
pfmt != PIPE_FORMAT_P012 &&
116
pfmt != PIPE_FORMAT_P016 &&
117
pfmt != PIPE_FORMAT_YUYV &&
118
pfmt != PIPE_FORMAT_UYVY) {
119
return false;
120
}
121
break;
122
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
123
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
124
case I915_FORMAT_MOD_Y_TILED_CCS: {
125
if (INTEL_DEBUG & DEBUG_NO_RBC)
126
return false;
127
128
enum isl_format rt_format =
129
iris_format_for_usage(devinfo, pfmt,
130
ISL_SURF_USAGE_RENDER_TARGET_BIT).fmt;
131
132
if (rt_format == ISL_FORMAT_UNSUPPORTED ||
133
!isl_format_supports_ccs_e(devinfo, rt_format))
134
return false;
135
break;
136
}
137
default:
138
break;
139
}
140
141
return true;
142
}
143
144
static uint64_t
145
select_best_modifier(struct intel_device_info *devinfo,
146
const struct pipe_resource *templ,
147
const uint64_t *modifiers,
148
int count)
149
{
150
enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
151
152
for (int i = 0; i < count; i++) {
153
if (!modifier_is_supported(devinfo, templ->format, templ->bind,
154
modifiers[i]))
155
continue;
156
157
switch (modifiers[i]) {
158
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
159
prio = MAX2(prio, MODIFIER_PRIORITY_Y_GFX12_RC_CCS_CC);
160
break;
161
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
162
prio = MAX2(prio, MODIFIER_PRIORITY_Y_GFX12_RC_CCS);
163
break;
164
case I915_FORMAT_MOD_Y_TILED_CCS:
165
prio = MAX2(prio, MODIFIER_PRIORITY_Y_CCS);
166
break;
167
case I915_FORMAT_MOD_Y_TILED:
168
prio = MAX2(prio, MODIFIER_PRIORITY_Y);
169
break;
170
case I915_FORMAT_MOD_X_TILED:
171
prio = MAX2(prio, MODIFIER_PRIORITY_X);
172
break;
173
case DRM_FORMAT_MOD_LINEAR:
174
prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
175
break;
176
case DRM_FORMAT_MOD_INVALID:
177
default:
178
break;
179
}
180
}
181
182
return priority_to_modifier[prio];
183
}
184
185
static inline bool is_modifier_external_only(enum pipe_format pfmt,
186
uint64_t modifier)
187
{
188
/* Only allow external usage for the following cases: YUV formats
189
* and the media-compression modifier. The render engine lacks
190
* support for rendering to a media-compressed surface if the
191
* compression ratio is large enough. By requiring external usage
192
* of media-compressed surfaces, resolves are avoided.
193
*/
194
return util_format_is_yuv(pfmt) ||
195
modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
196
}
197
198
static void
199
iris_query_dmabuf_modifiers(struct pipe_screen *pscreen,
200
enum pipe_format pfmt,
201
int max,
202
uint64_t *modifiers,
203
unsigned int *external_only,
204
int *count)
205
{
206
struct iris_screen *screen = (void *) pscreen;
207
const struct intel_device_info *devinfo = &screen->devinfo;
208
209
uint64_t all_modifiers[] = {
210
DRM_FORMAT_MOD_LINEAR,
211
I915_FORMAT_MOD_X_TILED,
212
I915_FORMAT_MOD_Y_TILED,
213
I915_FORMAT_MOD_Y_TILED_CCS,
214
I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS,
215
I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS,
216
I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC,
217
};
218
219
int supported_mods = 0;
220
221
for (int i = 0; i < ARRAY_SIZE(all_modifiers); i++) {
222
if (!modifier_is_supported(devinfo, pfmt, 0, all_modifiers[i]))
223
continue;
224
225
if (supported_mods < max) {
226
if (modifiers)
227
modifiers[supported_mods] = all_modifiers[i];
228
229
if (external_only) {
230
external_only[supported_mods] =
231
is_modifier_external_only(pfmt, all_modifiers[i]);
232
}
233
}
234
235
supported_mods++;
236
}
237
238
*count = supported_mods;
239
}
240
241
static bool
242
iris_is_dmabuf_modifier_supported(struct pipe_screen *pscreen,
243
uint64_t modifier, enum pipe_format pfmt,
244
bool *external_only)
245
{
246
struct iris_screen *screen = (void *) pscreen;
247
const struct intel_device_info *devinfo = &screen->devinfo;
248
249
if (modifier_is_supported(devinfo, pfmt, 0, modifier)) {
250
if (external_only)
251
*external_only = is_modifier_external_only(pfmt, modifier);
252
253
return true;
254
}
255
256
return false;
257
}
258
259
static unsigned int
260
iris_get_dmabuf_modifier_planes(struct pipe_screen *pscreen, uint64_t modifier,
261
enum pipe_format format)
262
{
263
unsigned int planes = util_format_get_num_planes(format);
264
265
switch (modifier) {
266
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
267
return 3;
268
case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
269
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
270
case I915_FORMAT_MOD_Y_TILED_CCS:
271
return 2 * planes;
272
default:
273
return planes;
274
}
275
}
276
277
enum isl_format
278
iris_image_view_get_format(struct iris_context *ice,
279
const struct pipe_image_view *img)
280
{
281
struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
282
const struct intel_device_info *devinfo = &screen->devinfo;
283
284
isl_surf_usage_flags_t usage = ISL_SURF_USAGE_STORAGE_BIT;
285
enum isl_format isl_fmt =
286
iris_format_for_usage(devinfo, img->format, usage).fmt;
287
288
if (img->shader_access & PIPE_IMAGE_ACCESS_READ) {
289
/* On Gfx8, try to use typed surfaces reads (which support a
290
* limited number of formats), and if not possible, fall back
291
* to untyped reads.
292
*/
293
if (devinfo->ver == 8 &&
294
!isl_has_matching_typed_storage_image_format(devinfo, isl_fmt))
295
return ISL_FORMAT_RAW;
296
else
297
return isl_lower_storage_image_format(devinfo, isl_fmt);
298
}
299
300
return isl_fmt;
301
}
302
303
static struct pipe_memory_object *
304
iris_memobj_create_from_handle(struct pipe_screen *pscreen,
305
struct winsys_handle *whandle,
306
bool dedicated)
307
{
308
struct iris_screen *screen = (struct iris_screen *)pscreen;
309
struct iris_memory_object *memobj = CALLOC_STRUCT(iris_memory_object);
310
struct iris_bo *bo;
311
312
if (!memobj)
313
return NULL;
314
315
switch (whandle->type) {
316
case WINSYS_HANDLE_TYPE_SHARED:
317
bo = iris_bo_gem_create_from_name(screen->bufmgr, "winsys image",
318
whandle->handle);
319
break;
320
case WINSYS_HANDLE_TYPE_FD:
321
bo = iris_bo_import_dmabuf(screen->bufmgr, whandle->handle);
322
break;
323
default:
324
unreachable("invalid winsys handle type");
325
}
326
327
if (!bo) {
328
free(memobj);
329
return NULL;
330
}
331
332
memobj->b.dedicated = dedicated;
333
memobj->bo = bo;
334
memobj->format = whandle->format;
335
memobj->stride = whandle->stride;
336
337
return &memobj->b;
338
}
339
340
static void
341
iris_memobj_destroy(struct pipe_screen *pscreen,
342
struct pipe_memory_object *pmemobj)
343
{
344
struct iris_memory_object *memobj = (struct iris_memory_object *)pmemobj;
345
346
iris_bo_unreference(memobj->bo);
347
free(memobj);
348
}
349
350
struct pipe_resource *
351
iris_resource_get_separate_stencil(struct pipe_resource *p_res)
352
{
353
/* For packed depth-stencil, we treat depth as the primary resource
354
* and store S8 as the "second plane" resource.
355
*/
356
if (p_res->next && p_res->next->format == PIPE_FORMAT_S8_UINT)
357
return p_res->next;
358
359
return NULL;
360
361
}
362
363
static void
364
iris_resource_set_separate_stencil(struct pipe_resource *p_res,
365
struct pipe_resource *stencil)
366
{
367
assert(util_format_has_depth(util_format_description(p_res->format)));
368
pipe_resource_reference(&p_res->next, stencil);
369
}
370
371
void
372
iris_get_depth_stencil_resources(struct pipe_resource *res,
373
struct iris_resource **out_z,
374
struct iris_resource **out_s)
375
{
376
if (!res) {
377
*out_z = NULL;
378
*out_s = NULL;
379
return;
380
}
381
382
if (res->format != PIPE_FORMAT_S8_UINT) {
383
*out_z = (void *) res;
384
*out_s = (void *) iris_resource_get_separate_stencil(res);
385
} else {
386
*out_z = NULL;
387
*out_s = (void *) res;
388
}
389
}
390
391
void
392
iris_resource_disable_aux(struct iris_resource *res)
393
{
394
iris_bo_unreference(res->aux.bo);
395
iris_bo_unreference(res->aux.clear_color_bo);
396
free(res->aux.state);
397
398
res->aux.usage = ISL_AUX_USAGE_NONE;
399
res->aux.possible_usages = 1 << ISL_AUX_USAGE_NONE;
400
res->aux.sampler_usages = 1 << ISL_AUX_USAGE_NONE;
401
res->aux.surf.size_B = 0;
402
res->aux.bo = NULL;
403
res->aux.extra_aux.surf.size_B = 0;
404
res->aux.clear_color_bo = NULL;
405
res->aux.state = NULL;
406
}
407
408
static uint32_t
409
iris_resource_alloc_flags(const struct iris_screen *screen,
410
const struct pipe_resource *templ)
411
{
412
if (templ->flags & IRIS_RESOURCE_FLAG_DEVICE_MEM)
413
return 0;
414
415
uint32_t flags = 0;
416
417
switch (templ->usage) {
418
case PIPE_USAGE_STAGING:
419
flags |= BO_ALLOC_SMEM | BO_ALLOC_COHERENT;
420
break;
421
case PIPE_USAGE_STREAM:
422
flags |= BO_ALLOC_SMEM;
423
break;
424
case PIPE_USAGE_DYNAMIC:
425
case PIPE_USAGE_DEFAULT:
426
case PIPE_USAGE_IMMUTABLE:
427
/* Use LMEM for these if possible */
428
break;
429
}
430
431
if (templ->flags & (PIPE_RESOURCE_FLAG_MAP_COHERENT |
432
PIPE_RESOURCE_FLAG_MAP_PERSISTENT))
433
flags |= BO_ALLOC_SMEM;
434
435
return flags;
436
}
437
438
static void
439
iris_resource_destroy(struct pipe_screen *screen,
440
struct pipe_resource *p_res)
441
{
442
struct iris_resource *res = (struct iris_resource *) p_res;
443
444
if (p_res->target == PIPE_BUFFER)
445
util_range_destroy(&res->valid_buffer_range);
446
447
iris_resource_disable_aux(res);
448
449
threaded_resource_deinit(p_res);
450
iris_bo_unreference(res->bo);
451
iris_pscreen_unref(res->orig_screen);
452
453
free(res);
454
}
455
456
static struct iris_resource *
457
iris_alloc_resource(struct pipe_screen *pscreen,
458
const struct pipe_resource *templ)
459
{
460
struct iris_resource *res = calloc(1, sizeof(struct iris_resource));
461
if (!res)
462
return NULL;
463
464
res->base.b = *templ;
465
res->base.b.screen = pscreen;
466
res->orig_screen = iris_pscreen_ref(pscreen);
467
pipe_reference_init(&res->base.b.reference, 1);
468
threaded_resource_init(&res->base.b);
469
470
res->aux.possible_usages = 1 << ISL_AUX_USAGE_NONE;
471
res->aux.sampler_usages = 1 << ISL_AUX_USAGE_NONE;
472
473
if (templ->target == PIPE_BUFFER)
474
util_range_init(&res->valid_buffer_range);
475
476
return res;
477
}
478
479
unsigned
480
iris_get_num_logical_layers(const struct iris_resource *res, unsigned level)
481
{
482
if (res->surf.dim == ISL_SURF_DIM_3D)
483
return minify(res->surf.logical_level0_px.depth, level);
484
else
485
return res->surf.logical_level0_px.array_len;
486
}
487
488
static enum isl_aux_state **
489
create_aux_state_map(struct iris_resource *res, enum isl_aux_state initial)
490
{
491
assert(res->aux.state == NULL);
492
493
uint32_t total_slices = 0;
494
for (uint32_t level = 0; level < res->surf.levels; level++)
495
total_slices += iris_get_num_logical_layers(res, level);
496
497
const size_t per_level_array_size =
498
res->surf.levels * sizeof(enum isl_aux_state *);
499
500
/* We're going to allocate a single chunk of data for both the per-level
501
* reference array and the arrays of aux_state. This makes cleanup
502
* significantly easier.
503
*/
504
const size_t total_size =
505
per_level_array_size + total_slices * sizeof(enum isl_aux_state);
506
507
void *data = malloc(total_size);
508
if (!data)
509
return NULL;
510
511
enum isl_aux_state **per_level_arr = data;
512
enum isl_aux_state *s = data + per_level_array_size;
513
for (uint32_t level = 0; level < res->surf.levels; level++) {
514
per_level_arr[level] = s;
515
const unsigned level_layers = iris_get_num_logical_layers(res, level);
516
for (uint32_t a = 0; a < level_layers; a++)
517
*(s++) = initial;
518
}
519
assert((void *)s == data + total_size);
520
521
return per_level_arr;
522
}
523
524
static unsigned
525
iris_get_aux_clear_color_state_size(struct iris_screen *screen)
526
{
527
const struct intel_device_info *devinfo = &screen->devinfo;
528
return devinfo->ver >= 10 ? screen->isl_dev.ss.clear_color_state_size : 0;
529
}
530
531
static void
532
map_aux_addresses(struct iris_screen *screen, struct iris_resource *res,
533
enum isl_format format, unsigned plane)
534
{
535
const struct intel_device_info *devinfo = &screen->devinfo;
536
if (devinfo->ver >= 12 && isl_aux_usage_has_ccs(res->aux.usage)) {
537
void *aux_map_ctx = iris_bufmgr_get_aux_map_context(screen->bufmgr);
538
assert(aux_map_ctx);
539
const unsigned aux_offset = res->aux.extra_aux.surf.size_B > 0 ?
540
res->aux.extra_aux.offset : res->aux.offset;
541
const uint64_t format_bits =
542
intel_aux_map_format_bits(res->surf.tiling, format, plane);
543
intel_aux_map_add_mapping(aux_map_ctx, res->bo->gtt_offset + res->offset,
544
res->aux.bo->gtt_offset + aux_offset,
545
res->surf.size_B, format_bits);
546
res->bo->aux_map_address = res->aux.bo->gtt_offset;
547
}
548
}
549
550
static bool
551
want_ccs_e_for_format(const struct intel_device_info *devinfo,
552
enum isl_format format)
553
{
554
if (!isl_format_supports_ccs_e(devinfo, format))
555
return false;
556
557
const struct isl_format_layout *fmtl = isl_format_get_layout(format);
558
559
/* CCS_E seems to significantly hurt performance with 32-bit floating
560
* point formats. For example, Paraview's "Wavelet Volume" case uses
561
* both R32_FLOAT and R32G32B32A32_FLOAT, and enabling CCS_E for those
562
* formats causes a 62% FPS drop.
563
*
564
* However, many benchmarks seem to use 16-bit float with no issues.
565
*/
566
if (fmtl->channels.r.bits == 32 && fmtl->channels.r.type == ISL_SFLOAT)
567
return false;
568
569
return true;
570
}
571
572
static enum isl_surf_dim
573
target_to_isl_surf_dim(enum pipe_texture_target target)
574
{
575
switch (target) {
576
case PIPE_BUFFER:
577
case PIPE_TEXTURE_1D:
578
case PIPE_TEXTURE_1D_ARRAY:
579
return ISL_SURF_DIM_1D;
580
case PIPE_TEXTURE_2D:
581
case PIPE_TEXTURE_CUBE:
582
case PIPE_TEXTURE_RECT:
583
case PIPE_TEXTURE_2D_ARRAY:
584
case PIPE_TEXTURE_CUBE_ARRAY:
585
return ISL_SURF_DIM_2D;
586
case PIPE_TEXTURE_3D:
587
return ISL_SURF_DIM_3D;
588
case PIPE_MAX_TEXTURE_TYPES:
589
break;
590
}
591
unreachable("invalid texture type");
592
}
593
594
static bool
595
iris_resource_configure_main(const struct iris_screen *screen,
596
struct iris_resource *res,
597
const struct pipe_resource *templ,
598
uint64_t modifier, uint32_t row_pitch_B)
599
{
600
res->mod_info = isl_drm_modifier_get_info(modifier);
601
602
if (modifier != DRM_FORMAT_MOD_INVALID && res->mod_info == NULL)
603
return false;
604
605
isl_tiling_flags_t tiling_flags = 0;
606
607
if (res->mod_info != NULL) {
608
tiling_flags = 1 << res->mod_info->tiling;
609
} else if (templ->usage == PIPE_USAGE_STAGING ||
610
templ->bind & (PIPE_BIND_LINEAR | PIPE_BIND_CURSOR)) {
611
tiling_flags = ISL_TILING_LINEAR_BIT;
612
} else if (templ->bind & PIPE_BIND_SCANOUT) {
613
tiling_flags = screen->devinfo.has_tiling_uapi ?
614
ISL_TILING_X_BIT : ISL_TILING_LINEAR_BIT;
615
} else {
616
tiling_flags = ISL_TILING_ANY_MASK;
617
}
618
619
isl_surf_usage_flags_t usage = 0;
620
621
if (templ->usage == PIPE_USAGE_STAGING)
622
usage |= ISL_SURF_USAGE_STAGING_BIT;
623
624
if (templ->bind & PIPE_BIND_RENDER_TARGET)
625
usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT;
626
627
if (templ->bind & PIPE_BIND_SAMPLER_VIEW)
628
usage |= ISL_SURF_USAGE_TEXTURE_BIT;
629
630
if (templ->bind & PIPE_BIND_SHADER_IMAGE)
631
usage |= ISL_SURF_USAGE_STORAGE_BIT;
632
633
if (templ->bind & PIPE_BIND_SCANOUT)
634
usage |= ISL_SURF_USAGE_DISPLAY_BIT;
635
636
if (templ->target == PIPE_TEXTURE_CUBE ||
637
templ->target == PIPE_TEXTURE_CUBE_ARRAY) {
638
usage |= ISL_SURF_USAGE_CUBE_BIT;
639
}
640
641
if (templ->usage != PIPE_USAGE_STAGING &&
642
util_format_is_depth_or_stencil(templ->format)) {
643
644
/* Should be handled by u_transfer_helper */
645
assert(!util_format_is_depth_and_stencil(templ->format));
646
647
usage |= templ->format == PIPE_FORMAT_S8_UINT ?
648
ISL_SURF_USAGE_STENCIL_BIT : ISL_SURF_USAGE_DEPTH_BIT;
649
}
650
651
const enum isl_format format =
652
iris_format_for_usage(&screen->devinfo, templ->format, usage).fmt;
653
654
const struct isl_surf_init_info init_info = {
655
.dim = target_to_isl_surf_dim(templ->target),
656
.format = format,
657
.width = templ->width0,
658
.height = templ->height0,
659
.depth = templ->depth0,
660
.levels = templ->last_level + 1,
661
.array_len = templ->array_size,
662
.samples = MAX2(templ->nr_samples, 1),
663
.min_alignment_B = 0,
664
.row_pitch_B = row_pitch_B,
665
.usage = usage,
666
.tiling_flags = tiling_flags
667
};
668
669
if (!isl_surf_init_s(&screen->isl_dev, &res->surf, &init_info))
670
return false;
671
672
res->internal_format = templ->format;
673
674
return true;
675
}
676
677
static bool
678
iris_get_ccs_surf(const struct isl_device *dev,
679
const struct isl_surf *surf,
680
struct isl_surf *aux_surf,
681
struct isl_surf *extra_aux_surf,
682
uint32_t row_pitch_B)
683
{
684
assert(extra_aux_surf->size_B == 0);
685
686
struct isl_surf *ccs_surf;
687
const struct isl_surf *hiz_or_mcs_surf;
688
if (aux_surf->size_B > 0) {
689
assert(aux_surf->usage & (ISL_SURF_USAGE_HIZ_BIT |
690
ISL_SURF_USAGE_MCS_BIT));
691
hiz_or_mcs_surf = aux_surf;
692
ccs_surf = extra_aux_surf;
693
} else {
694
hiz_or_mcs_surf = NULL;
695
ccs_surf = aux_surf;
696
}
697
698
return isl_surf_get_ccs_surf(dev, surf, hiz_or_mcs_surf,
699
ccs_surf, row_pitch_B);
700
}
701
702
/**
703
* Configure aux for the resource, but don't allocate it. For images which
704
* might be shared with modifiers, we must allocate the image and aux data in
705
* a single bo.
706
*
707
* Returns false on unexpected error (e.g. allocation failed, or invalid
708
* configuration result).
709
*/
710
static bool
711
iris_resource_configure_aux(struct iris_screen *screen,
712
struct iris_resource *res, bool imported)
713
{
714
const struct intel_device_info *devinfo = &screen->devinfo;
715
716
/* Try to create the auxiliary surfaces allowed by the modifier or by
717
* the user if no modifier is specified.
718
*/
719
assert(!res->mod_info ||
720
res->mod_info->aux_usage == ISL_AUX_USAGE_NONE ||
721
res->mod_info->aux_usage == ISL_AUX_USAGE_CCS_E ||
722
res->mod_info->aux_usage == ISL_AUX_USAGE_GFX12_CCS_E ||
723
res->mod_info->aux_usage == ISL_AUX_USAGE_MC);
724
725
const bool has_mcs = !res->mod_info &&
726
isl_surf_get_mcs_surf(&screen->isl_dev, &res->surf, &res->aux.surf);
727
728
const bool has_hiz = !res->mod_info && !(INTEL_DEBUG & DEBUG_NO_HIZ) &&
729
isl_surf_get_hiz_surf(&screen->isl_dev, &res->surf, &res->aux.surf);
730
731
const bool has_ccs =
732
((!res->mod_info && !(INTEL_DEBUG & DEBUG_NO_RBC)) ||
733
(res->mod_info && res->mod_info->aux_usage != ISL_AUX_USAGE_NONE)) &&
734
iris_get_ccs_surf(&screen->isl_dev, &res->surf, &res->aux.surf,
735
&res->aux.extra_aux.surf, 0);
736
737
/* Having both HIZ and MCS is impossible. */
738
assert(!has_mcs || !has_hiz);
739
740
if (res->mod_info && has_ccs) {
741
/* Only allow a CCS modifier if the aux was created successfully. */
742
res->aux.possible_usages |= 1 << res->mod_info->aux_usage;
743
} else if (has_mcs) {
744
res->aux.possible_usages |=
745
1 << (has_ccs ? ISL_AUX_USAGE_MCS_CCS : ISL_AUX_USAGE_MCS);
746
} else if (has_hiz) {
747
if (!has_ccs) {
748
res->aux.possible_usages |= 1 << ISL_AUX_USAGE_HIZ;
749
} else if (res->surf.samples == 1 &&
750
(res->surf.usage & ISL_SURF_USAGE_TEXTURE_BIT)) {
751
/* If this resource is single-sampled and will be used as a texture,
752
* put the HiZ surface in write-through mode so that we can sample
753
* from it.
754
*/
755
res->aux.possible_usages |= 1 << ISL_AUX_USAGE_HIZ_CCS_WT;
756
} else {
757
res->aux.possible_usages |= 1 << ISL_AUX_USAGE_HIZ_CCS;
758
}
759
} else if (has_ccs && isl_surf_usage_is_stencil(res->surf.usage)) {
760
res->aux.possible_usages |= 1 << ISL_AUX_USAGE_STC_CCS;
761
} else if (has_ccs) {
762
if (want_ccs_e_for_format(devinfo, res->surf.format)) {
763
res->aux.possible_usages |= devinfo->ver < 12 ?
764
1 << ISL_AUX_USAGE_CCS_E : 1 << ISL_AUX_USAGE_GFX12_CCS_E;
765
} else if (isl_format_supports_ccs_d(devinfo, res->surf.format)) {
766
res->aux.possible_usages |= 1 << ISL_AUX_USAGE_CCS_D;
767
}
768
}
769
770
res->aux.usage = util_last_bit(res->aux.possible_usages) - 1;
771
772
if (!has_hiz || iris_sample_with_depth_aux(devinfo, res))
773
res->aux.sampler_usages = res->aux.possible_usages;
774
775
enum isl_aux_state initial_state;
776
assert(!res->aux.bo);
777
778
switch (res->aux.usage) {
779
case ISL_AUX_USAGE_NONE:
780
/* Update relevant fields to indicate that aux is disabled. */
781
iris_resource_disable_aux(res);
782
783
/* Having no aux buffer is only okay if there's no modifier with aux. */
784
return !res->mod_info || res->mod_info->aux_usage == ISL_AUX_USAGE_NONE;
785
case ISL_AUX_USAGE_HIZ:
786
case ISL_AUX_USAGE_HIZ_CCS:
787
case ISL_AUX_USAGE_HIZ_CCS_WT:
788
initial_state = ISL_AUX_STATE_AUX_INVALID;
789
break;
790
case ISL_AUX_USAGE_MCS:
791
case ISL_AUX_USAGE_MCS_CCS:
792
/* The Ivybridge PRM, Vol 2 Part 1 p326 says:
793
*
794
* "When MCS buffer is enabled and bound to MSRT, it is required
795
* that it is cleared prior to any rendering."
796
*
797
* Since we only use the MCS buffer for rendering, we just clear it
798
* immediately on allocation. The clear value for MCS buffers is all
799
* 1's, so we simply memset it to 0xff.
800
*/
801
initial_state = ISL_AUX_STATE_CLEAR;
802
break;
803
case ISL_AUX_USAGE_CCS_D:
804
case ISL_AUX_USAGE_CCS_E:
805
case ISL_AUX_USAGE_GFX12_CCS_E:
806
case ISL_AUX_USAGE_STC_CCS:
807
case ISL_AUX_USAGE_MC:
808
/* When CCS_E is used, we need to ensure that the CCS starts off in
809
* a valid state. From the Sky Lake PRM, "MCS Buffer for Render
810
* Target(s)":
811
*
812
* "If Software wants to enable Color Compression without Fast
813
* clear, Software needs to initialize MCS with zeros."
814
*
815
* A CCS value of 0 indicates that the corresponding block is in the
816
* pass-through state which is what we want.
817
*
818
* For CCS_D, do the same thing. On Gfx9+, this avoids having any
819
* undefined bits in the aux buffer.
820
*/
821
if (imported) {
822
assert(res->aux.usage != ISL_AUX_USAGE_STC_CCS);
823
initial_state =
824
isl_drm_modifier_get_default_aux_state(res->mod_info->modifier);
825
} else {
826
initial_state = ISL_AUX_STATE_PASS_THROUGH;
827
}
828
break;
829
default:
830
unreachable("Unsupported aux mode");
831
}
832
833
/* Create the aux_state for the auxiliary buffer. */
834
res->aux.state = create_aux_state_map(res, initial_state);
835
if (!res->aux.state)
836
return false;
837
838
return true;
839
}
840
841
/**
842
* Initialize the aux buffer contents.
843
*
844
* Returns false on unexpected error (e.g. mapping a BO failed).
845
*/
846
static bool
847
iris_resource_init_aux_buf(struct iris_resource *res,
848
unsigned clear_color_state_size)
849
{
850
void *map = iris_bo_map(NULL, res->aux.bo, MAP_WRITE | MAP_RAW);
851
852
if (!map)
853
return false;
854
855
if (iris_resource_get_aux_state(res, 0, 0) != ISL_AUX_STATE_AUX_INVALID) {
856
/* See iris_resource_configure_aux for the memset_value rationale. */
857
uint8_t memset_value = isl_aux_usage_has_mcs(res->aux.usage) ? 0xFF : 0;
858
memset((char*)map + res->aux.offset, memset_value,
859
res->aux.surf.size_B);
860
}
861
862
memset((char*)map + res->aux.extra_aux.offset,
863
0, res->aux.extra_aux.surf.size_B);
864
865
/* Zero the indirect clear color to match ::fast_clear_color. */
866
memset((char *)map + res->aux.clear_color_offset, 0,
867
clear_color_state_size);
868
869
iris_bo_unmap(res->aux.bo);
870
871
if (clear_color_state_size > 0) {
872
res->aux.clear_color_bo = res->aux.bo;
873
iris_bo_reference(res->aux.clear_color_bo);
874
}
875
876
return true;
877
}
878
879
static void
880
import_aux_info(struct iris_resource *res,
881
const struct iris_resource *aux_res)
882
{
883
assert(aux_res->aux.surf.row_pitch_B && aux_res->aux.offset);
884
assert(res->bo == aux_res->aux.bo);
885
assert(res->aux.surf.row_pitch_B == aux_res->aux.surf.row_pitch_B);
886
assert(res->bo->size >= aux_res->aux.offset + res->aux.surf.size_B);
887
888
iris_bo_reference(aux_res->aux.bo);
889
res->aux.bo = aux_res->aux.bo;
890
res->aux.offset = aux_res->aux.offset;
891
}
892
893
void
894
iris_resource_finish_aux_import(struct pipe_screen *pscreen,
895
struct iris_resource *res)
896
{
897
struct iris_screen *screen = (struct iris_screen *)pscreen;
898
assert(iris_resource_unfinished_aux_import(res));
899
900
/* Create an array of resources. Combining main and aux planes is easier
901
* with indexing as opposed to scanning the linked list.
902
*/
903
struct iris_resource *r[4] = { NULL, };
904
unsigned num_planes = 0;
905
unsigned num_main_planes = 0;
906
for (struct pipe_resource *p_res = &res->base.b; p_res; p_res = p_res->next) {
907
r[num_planes] = (struct iris_resource *)p_res;
908
num_main_planes += r[num_planes++]->bo != NULL;
909
}
910
911
/* Get an ISL format to use with the aux-map. */
912
enum isl_format format;
913
switch (res->external_format) {
914
case PIPE_FORMAT_NV12: format = ISL_FORMAT_PLANAR_420_8; break;
915
case PIPE_FORMAT_P010: format = ISL_FORMAT_PLANAR_420_10; break;
916
case PIPE_FORMAT_P012: format = ISL_FORMAT_PLANAR_420_12; break;
917
case PIPE_FORMAT_P016: format = ISL_FORMAT_PLANAR_420_16; break;
918
case PIPE_FORMAT_YUYV: format = ISL_FORMAT_YCRCB_NORMAL; break;
919
case PIPE_FORMAT_UYVY: format = ISL_FORMAT_YCRCB_SWAPY; break;
920
default: format = res->surf.format; break;
921
}
922
923
/* Combine main and aux plane information. */
924
if (num_main_planes == 1 && num_planes == 2) {
925
import_aux_info(r[0], r[1]);
926
map_aux_addresses(screen, r[0], format, 0);
927
928
/* Add on a clear color BO. */
929
if (iris_get_aux_clear_color_state_size(screen) > 0) {
930
res->aux.clear_color_bo =
931
iris_bo_alloc(screen->bufmgr, "clear color_buffer",
932
iris_get_aux_clear_color_state_size(screen), 1,
933
IRIS_MEMZONE_OTHER, BO_ALLOC_ZEROED);
934
}
935
} else if (num_main_planes == 1 && num_planes == 3) {
936
import_aux_info(r[0], r[1]);
937
map_aux_addresses(screen, r[0], format, 0);
938
939
/* Import the clear color BO. */
940
iris_bo_reference(r[2]->aux.clear_color_bo);
941
r[0]->aux.clear_color_bo = r[2]->aux.clear_color_bo;
942
r[0]->aux.clear_color_offset = r[2]->aux.clear_color_offset;
943
memcpy(res->aux.clear_color.f32,
944
iris_bo_map(NULL, res->aux.clear_color_bo, MAP_READ|MAP_RAW) +
945
res->aux.clear_color_offset, sizeof(res->aux.clear_color.f32));
946
} else if (num_main_planes == 2 && num_planes == 4) {
947
import_aux_info(r[0], r[2]);
948
import_aux_info(r[1], r[3]);
949
map_aux_addresses(screen, r[0], format, 0);
950
map_aux_addresses(screen, r[1], format, 1);
951
} else {
952
/* Gallium has lowered a single main plane into two. */
953
assert(num_main_planes == 2 && num_planes == 3);
954
assert(isl_format_is_yuv(format) && !isl_format_is_planar(format));
955
import_aux_info(r[0], r[2]);
956
import_aux_info(r[1], r[2]);
957
map_aux_addresses(screen, r[0], format, 0);
958
}
959
}
960
961
static struct pipe_resource *
962
iris_resource_create_for_buffer(struct pipe_screen *pscreen,
963
const struct pipe_resource *templ)
964
{
965
struct iris_screen *screen = (struct iris_screen *)pscreen;
966
struct iris_resource *res = iris_alloc_resource(pscreen, templ);
967
968
assert(templ->target == PIPE_BUFFER);
969
assert(templ->height0 <= 1);
970
assert(templ->depth0 <= 1);
971
assert(templ->format == PIPE_FORMAT_NONE ||
972
util_format_get_blocksize(templ->format) == 1);
973
974
res->internal_format = templ->format;
975
res->surf.tiling = ISL_TILING_LINEAR;
976
977
enum iris_memory_zone memzone = IRIS_MEMZONE_OTHER;
978
const char *name = templ->target == PIPE_BUFFER ? "buffer" : "miptree";
979
if (templ->flags & IRIS_RESOURCE_FLAG_SHADER_MEMZONE) {
980
memzone = IRIS_MEMZONE_SHADER;
981
name = "shader kernels";
982
} else if (templ->flags & IRIS_RESOURCE_FLAG_SURFACE_MEMZONE) {
983
memzone = IRIS_MEMZONE_SURFACE;
984
name = "surface state";
985
} else if (templ->flags & IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE) {
986
memzone = IRIS_MEMZONE_DYNAMIC;
987
name = "dynamic state";
988
} else if (templ->flags & IRIS_RESOURCE_FLAG_BINDLESS_MEMZONE) {
989
memzone = IRIS_MEMZONE_BINDLESS;
990
name = "bindless surface state";
991
}
992
993
unsigned flags = iris_resource_alloc_flags(screen, templ);
994
995
res->bo =
996
iris_bo_alloc(screen->bufmgr, name, templ->width0, 1, memzone, flags);
997
998
if (!res->bo) {
999
iris_resource_destroy(pscreen, &res->base.b);
1000
return NULL;
1001
}
1002
1003
if (templ->bind & PIPE_BIND_SHARED) {
1004
iris_bo_mark_exported(res->bo);
1005
res->base.is_shared = true;
1006
}
1007
1008
return &res->base.b;
1009
}
1010
1011
static struct pipe_resource *
1012
iris_resource_create_with_modifiers(struct pipe_screen *pscreen,
1013
const struct pipe_resource *templ,
1014
const uint64_t *modifiers,
1015
int modifiers_count)
1016
{
1017
struct iris_screen *screen = (struct iris_screen *)pscreen;
1018
struct intel_device_info *devinfo = &screen->devinfo;
1019
struct iris_resource *res = iris_alloc_resource(pscreen, templ);
1020
1021
if (!res)
1022
return NULL;
1023
1024
uint64_t modifier =
1025
select_best_modifier(devinfo, templ, modifiers, modifiers_count);
1026
1027
if (modifier == DRM_FORMAT_MOD_INVALID && modifiers_count > 0) {
1028
fprintf(stderr, "Unsupported modifier, resource creation failed.\n");
1029
goto fail;
1030
}
1031
1032
UNUSED const bool isl_surf_created_successfully =
1033
iris_resource_configure_main(screen, res, templ, modifier, 0);
1034
assert(isl_surf_created_successfully);
1035
1036
const char *name = "miptree";
1037
enum iris_memory_zone memzone = IRIS_MEMZONE_OTHER;
1038
1039
unsigned int flags = iris_resource_alloc_flags(screen, templ);
1040
1041
/* These are for u_upload_mgr buffers only */
1042
assert(!(templ->flags & (IRIS_RESOURCE_FLAG_SHADER_MEMZONE |
1043
IRIS_RESOURCE_FLAG_SURFACE_MEMZONE |
1044
IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE |
1045
IRIS_RESOURCE_FLAG_BINDLESS_MEMZONE)));
1046
1047
if (!iris_resource_configure_aux(screen, res, false))
1048
goto fail;
1049
1050
/* Modifiers require the aux data to be in the same buffer as the main
1051
* surface, but we combine them even when a modifier is not being used.
1052
*/
1053
uint64_t bo_size = res->surf.size_B;
1054
1055
/* Allocate space for the aux buffer. */
1056
if (res->aux.surf.size_B > 0) {
1057
res->aux.offset = ALIGN(bo_size, res->aux.surf.alignment_B);
1058
bo_size = res->aux.offset + res->aux.surf.size_B;
1059
}
1060
1061
/* Allocate space for the extra aux buffer. */
1062
if (res->aux.extra_aux.surf.size_B > 0) {
1063
res->aux.extra_aux.offset =
1064
ALIGN(bo_size, res->aux.extra_aux.surf.alignment_B);
1065
bo_size = res->aux.extra_aux.offset + res->aux.extra_aux.surf.size_B;
1066
}
1067
1068
/* Allocate space for the indirect clear color.
1069
*
1070
* Also add some padding to make sure the fast clear color state buffer
1071
* starts at a 4K alignment. We believe that 256B might be enough, but due
1072
* to lack of testing we will leave this as 4K for now.
1073
*/
1074
if (res->aux.surf.size_B > 0) {
1075
res->aux.clear_color_offset = ALIGN(bo_size, 4096);
1076
bo_size = res->aux.clear_color_offset +
1077
iris_get_aux_clear_color_state_size(screen);
1078
}
1079
1080
uint32_t alignment = MAX2(4096, res->surf.alignment_B);
1081
res->bo =
1082
iris_bo_alloc(screen->bufmgr, name, bo_size, alignment, memzone, flags);
1083
1084
if (!res->bo)
1085
goto fail;
1086
1087
if (res->aux.surf.size_B > 0) {
1088
res->aux.bo = res->bo;
1089
iris_bo_reference(res->aux.bo);
1090
unsigned clear_color_state_size =
1091
iris_get_aux_clear_color_state_size(screen);
1092
if (!iris_resource_init_aux_buf(res, clear_color_state_size))
1093
goto fail;
1094
map_aux_addresses(screen, res, res->surf.format, 0);
1095
}
1096
1097
if (templ->bind & PIPE_BIND_SHARED) {
1098
iris_bo_mark_exported(res->bo);
1099
res->base.is_shared = true;
1100
}
1101
1102
return &res->base.b;
1103
1104
fail:
1105
fprintf(stderr, "XXX: resource creation failed\n");
1106
iris_resource_destroy(pscreen, &res->base.b);
1107
return NULL;
1108
}
1109
1110
static struct pipe_resource *
1111
iris_resource_create(struct pipe_screen *pscreen,
1112
const struct pipe_resource *templ)
1113
{
1114
if (templ->target == PIPE_BUFFER)
1115
return iris_resource_create_for_buffer(pscreen, templ);
1116
else
1117
return iris_resource_create_with_modifiers(pscreen, templ, NULL, 0);
1118
}
1119
1120
static uint64_t
1121
tiling_to_modifier(uint32_t tiling)
1122
{
1123
static const uint64_t map[] = {
1124
[I915_TILING_NONE] = DRM_FORMAT_MOD_LINEAR,
1125
[I915_TILING_X] = I915_FORMAT_MOD_X_TILED,
1126
[I915_TILING_Y] = I915_FORMAT_MOD_Y_TILED,
1127
};
1128
1129
assert(tiling < ARRAY_SIZE(map));
1130
1131
return map[tiling];
1132
}
1133
1134
static struct pipe_resource *
1135
iris_resource_from_user_memory(struct pipe_screen *pscreen,
1136
const struct pipe_resource *templ,
1137
void *user_memory)
1138
{
1139
struct iris_screen *screen = (struct iris_screen *)pscreen;
1140
struct iris_bufmgr *bufmgr = screen->bufmgr;
1141
struct iris_resource *res = iris_alloc_resource(pscreen, templ);
1142
if (!res)
1143
return NULL;
1144
1145
assert(templ->target == PIPE_BUFFER);
1146
1147
res->internal_format = templ->format;
1148
res->base.is_user_ptr = true;
1149
res->bo = iris_bo_create_userptr(bufmgr, "user",
1150
user_memory, templ->width0,
1151
IRIS_MEMZONE_OTHER);
1152
if (!res->bo) {
1153
iris_resource_destroy(pscreen, &res->base.b);
1154
return NULL;
1155
}
1156
1157
util_range_add(&res->base.b, &res->valid_buffer_range, 0, templ->width0);
1158
1159
return &res->base.b;
1160
}
1161
1162
static bool
1163
mod_plane_is_clear_color(uint64_t modifier, uint32_t plane)
1164
{
1165
ASSERTED const struct isl_drm_modifier_info *mod_info =
1166
isl_drm_modifier_get_info(modifier);
1167
assert(mod_info);
1168
1169
switch (modifier) {
1170
case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1171
assert(mod_info->supports_clear_color);
1172
return plane == 2;
1173
default:
1174
assert(!mod_info->supports_clear_color);
1175
return false;
1176
}
1177
}
1178
1179
static struct pipe_resource *
1180
iris_resource_from_handle(struct pipe_screen *pscreen,
1181
const struct pipe_resource *templ,
1182
struct winsys_handle *whandle,
1183
unsigned usage)
1184
{
1185
assert(templ->target != PIPE_BUFFER);
1186
1187
struct iris_screen *screen = (struct iris_screen *)pscreen;
1188
struct iris_bufmgr *bufmgr = screen->bufmgr;
1189
struct iris_resource *res = iris_alloc_resource(pscreen, templ);
1190
if (!res)
1191
return NULL;
1192
1193
switch (whandle->type) {
1194
case WINSYS_HANDLE_TYPE_FD:
1195
res->bo = iris_bo_import_dmabuf(bufmgr, whandle->handle);
1196
break;
1197
case WINSYS_HANDLE_TYPE_SHARED:
1198
res->bo = iris_bo_gem_create_from_name(bufmgr, "winsys image",
1199
whandle->handle);
1200
break;
1201
default:
1202
unreachable("invalid winsys handle type");
1203
}
1204
if (!res->bo)
1205
goto fail;
1206
1207
res->offset = whandle->offset;
1208
res->external_format = whandle->format;
1209
1210
/* Create a surface for each plane specified by the external format. */
1211
if (whandle->plane < util_format_get_num_planes(whandle->format)) {
1212
uint64_t modifier = whandle->modifier;
1213
1214
if (whandle->modifier == DRM_FORMAT_MOD_INVALID) {
1215
/* We don't have a modifier; match whatever GEM_GET_TILING says */
1216
uint32_t tiling;
1217
iris_gem_get_tiling(res->bo, &tiling);
1218
modifier = tiling_to_modifier(tiling);
1219
}
1220
1221
UNUSED const bool isl_surf_created_successfully =
1222
iris_resource_configure_main(screen, res, templ, modifier,
1223
whandle->stride);
1224
assert(isl_surf_created_successfully);
1225
1226
UNUSED const bool ok = iris_resource_configure_aux(screen, res, true);
1227
assert(ok);
1228
/* The gallium dri layer will create a separate plane resource for the
1229
* aux image. iris_resource_finish_aux_import will merge the separate aux
1230
* parameters back into a single iris_resource.
1231
*/
1232
} else if (mod_plane_is_clear_color(whandle->modifier, whandle->plane)) {
1233
res->aux.clear_color_offset = whandle->offset;
1234
res->aux.clear_color_bo = res->bo;
1235
res->bo = NULL;
1236
} else {
1237
/* Save modifier import information to reconstruct later. After import,
1238
* this will be available under a second image accessible from the main
1239
* image with res->base.next. See iris_resource_finish_aux_import.
1240
*/
1241
res->aux.surf.row_pitch_B = whandle->stride;
1242
res->aux.offset = whandle->offset;
1243
res->aux.bo = res->bo;
1244
res->bo = NULL;
1245
}
1246
1247
return &res->base.b;
1248
1249
fail:
1250
iris_resource_destroy(pscreen, &res->base.b);
1251
return NULL;
1252
}
1253
1254
static struct pipe_resource *
1255
iris_resource_from_memobj(struct pipe_screen *pscreen,
1256
const struct pipe_resource *templ,
1257
struct pipe_memory_object *pmemobj,
1258
uint64_t offset)
1259
{
1260
struct iris_screen *screen = (struct iris_screen *)pscreen;
1261
struct iris_memory_object *memobj = (struct iris_memory_object *)pmemobj;
1262
struct iris_resource *res = iris_alloc_resource(pscreen, templ);
1263
1264
if (!res)
1265
return NULL;
1266
1267
if (templ->flags & PIPE_RESOURCE_FLAG_TEXTURING_MORE_LIKELY) {
1268
UNUSED const bool isl_surf_created_successfully =
1269
iris_resource_configure_main(screen, res, templ, DRM_FORMAT_MOD_INVALID, 0);
1270
assert(isl_surf_created_successfully);
1271
}
1272
1273
res->bo = memobj->bo;
1274
res->offset = offset;
1275
res->external_format = memobj->format;
1276
1277
iris_bo_reference(memobj->bo);
1278
1279
return &res->base.b;
1280
}
1281
1282
static void
1283
iris_flush_resource(struct pipe_context *ctx, struct pipe_resource *resource)
1284
{
1285
struct iris_context *ice = (struct iris_context *)ctx;
1286
struct iris_resource *res = (void *) resource;
1287
const struct isl_drm_modifier_info *mod = res->mod_info;
1288
1289
iris_resource_prepare_access(ice, res,
1290
0, INTEL_REMAINING_LEVELS,
1291
0, INTEL_REMAINING_LAYERS,
1292
mod ? mod->aux_usage : ISL_AUX_USAGE_NONE,
1293
mod ? mod->supports_clear_color : false);
1294
1295
if (!res->mod_info && res->aux.usage != ISL_AUX_USAGE_NONE) {
1296
/* flush_resource may be used to prepare an image for sharing external
1297
* to the driver (e.g. via eglCreateImage). To account for this, make
1298
* sure to get rid of any compression that a consumer wouldn't know how
1299
* to handle.
1300
*/
1301
for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
1302
if (iris_batch_references(&ice->batches[i], res->bo))
1303
iris_batch_flush(&ice->batches[i]);
1304
}
1305
1306
iris_resource_disable_aux(res);
1307
}
1308
}
1309
1310
static void
1311
iris_resource_disable_aux_on_first_query(struct pipe_resource *resource,
1312
unsigned usage)
1313
{
1314
struct iris_resource *res = (struct iris_resource *)resource;
1315
bool mod_with_aux =
1316
res->mod_info && res->mod_info->aux_usage != ISL_AUX_USAGE_NONE;
1317
1318
/* Disable aux usage if explicit flush not set and this is the first time
1319
* we are dealing with this resource and the resource was not created with
1320
* a modifier with aux.
1321
*/
1322
if (!mod_with_aux &&
1323
(!(usage & PIPE_HANDLE_USAGE_EXPLICIT_FLUSH) && res->aux.usage != 0) &&
1324
p_atomic_read(&resource->reference.count) == 1) {
1325
iris_resource_disable_aux(res);
1326
}
1327
}
1328
1329
static bool
1330
iris_resource_get_param(struct pipe_screen *pscreen,
1331
struct pipe_context *context,
1332
struct pipe_resource *resource,
1333
unsigned plane,
1334
unsigned layer,
1335
unsigned level,
1336
enum pipe_resource_param param,
1337
unsigned handle_usage,
1338
uint64_t *value)
1339
{
1340
struct iris_screen *screen = (struct iris_screen *)pscreen;
1341
struct iris_resource *res = (struct iris_resource *)resource;
1342
bool mod_with_aux =
1343
res->mod_info && res->mod_info->aux_usage != ISL_AUX_USAGE_NONE;
1344
bool wants_aux = mod_with_aux && plane > 0;
1345
bool result;
1346
unsigned handle;
1347
1348
if (iris_resource_unfinished_aux_import(res))
1349
iris_resource_finish_aux_import(pscreen, res);
1350
1351
struct iris_bo *bo = wants_aux ? res->aux.bo : res->bo;
1352
1353
iris_resource_disable_aux_on_first_query(resource, handle_usage);
1354
1355
switch (param) {
1356
case PIPE_RESOURCE_PARAM_NPLANES:
1357
if (mod_with_aux) {
1358
*value = iris_get_dmabuf_modifier_planes(pscreen,
1359
res->mod_info->modifier,
1360
res->external_format);
1361
} else {
1362
unsigned count = 0;
1363
for (struct pipe_resource *cur = resource; cur; cur = cur->next)
1364
count++;
1365
*value = count;
1366
}
1367
return true;
1368
case PIPE_RESOURCE_PARAM_STRIDE:
1369
*value = wants_aux ? res->aux.surf.row_pitch_B : res->surf.row_pitch_B;
1370
return true;
1371
case PIPE_RESOURCE_PARAM_OFFSET:
1372
*value = wants_aux ?
1373
mod_plane_is_clear_color(res->mod_info->modifier, plane) ?
1374
res->aux.clear_color_offset : res->aux.offset : 0;
1375
return true;
1376
case PIPE_RESOURCE_PARAM_MODIFIER:
1377
*value = res->mod_info ? res->mod_info->modifier :
1378
tiling_to_modifier(isl_tiling_to_i915_tiling(res->surf.tiling));
1379
return true;
1380
case PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED:
1381
if (!wants_aux)
1382
iris_gem_set_tiling(bo, &res->surf);
1383
1384
result = iris_bo_flink(bo, &handle) == 0;
1385
if (result)
1386
*value = handle;
1387
return result;
1388
case PIPE_RESOURCE_PARAM_HANDLE_TYPE_KMS: {
1389
if (!wants_aux)
1390
iris_gem_set_tiling(bo, &res->surf);
1391
1392
/* Because we share the same drm file across multiple iris_screen, when
1393
* we export a GEM handle we must make sure it is valid in the DRM file
1394
* descriptor the caller is using (this is the FD given at screen
1395
* creation).
1396
*/
1397
uint32_t handle;
1398
if (iris_bo_export_gem_handle_for_device(bo, screen->winsys_fd, &handle))
1399
return false;
1400
*value = handle;
1401
return true;
1402
}
1403
1404
case PIPE_RESOURCE_PARAM_HANDLE_TYPE_FD:
1405
if (!wants_aux)
1406
iris_gem_set_tiling(bo, &res->surf);
1407
1408
result = iris_bo_export_dmabuf(bo, (int *) &handle) == 0;
1409
if (result)
1410
*value = handle;
1411
return result;
1412
default:
1413
return false;
1414
}
1415
}
1416
1417
static bool
1418
iris_resource_get_handle(struct pipe_screen *pscreen,
1419
struct pipe_context *unused_ctx,
1420
struct pipe_resource *resource,
1421
struct winsys_handle *whandle,
1422
unsigned usage)
1423
{
1424
struct iris_screen *screen = (struct iris_screen *) pscreen;
1425
struct iris_resource *res = (struct iris_resource *)resource;
1426
bool mod_with_aux =
1427
res->mod_info && res->mod_info->aux_usage != ISL_AUX_USAGE_NONE;
1428
1429
/* if ctx is ever used, do ctx = threaded_context_unwrap_sync(ctx) */
1430
1431
iris_resource_disable_aux_on_first_query(resource, usage);
1432
1433
struct iris_bo *bo;
1434
if (res->mod_info &&
1435
mod_plane_is_clear_color(res->mod_info->modifier, whandle->plane)) {
1436
bo = res->aux.clear_color_bo;
1437
whandle->offset = res->aux.clear_color_offset;
1438
} else if (mod_with_aux && whandle->plane > 0) {
1439
bo = res->aux.bo;
1440
whandle->stride = res->aux.surf.row_pitch_B;
1441
whandle->offset = res->aux.offset;
1442
} else {
1443
/* If this is a buffer, stride should be 0 - no need to special case */
1444
whandle->stride = res->surf.row_pitch_B;
1445
bo = res->bo;
1446
}
1447
1448
whandle->format = res->external_format;
1449
whandle->modifier =
1450
res->mod_info ? res->mod_info->modifier
1451
: tiling_to_modifier(isl_tiling_to_i915_tiling(res->surf.tiling));
1452
1453
#ifndef NDEBUG
1454
enum isl_aux_usage allowed_usage =
1455
usage & PIPE_HANDLE_USAGE_EXPLICIT_FLUSH ? res->aux.usage :
1456
res->mod_info ? res->mod_info->aux_usage : ISL_AUX_USAGE_NONE;
1457
1458
if (res->aux.usage != allowed_usage) {
1459
enum isl_aux_state aux_state = iris_resource_get_aux_state(res, 0, 0);
1460
assert(aux_state == ISL_AUX_STATE_RESOLVED ||
1461
aux_state == ISL_AUX_STATE_PASS_THROUGH);
1462
}
1463
#endif
1464
1465
switch (whandle->type) {
1466
case WINSYS_HANDLE_TYPE_SHARED:
1467
iris_gem_set_tiling(bo, &res->surf);
1468
return iris_bo_flink(bo, &whandle->handle) == 0;
1469
case WINSYS_HANDLE_TYPE_KMS: {
1470
iris_gem_set_tiling(bo, &res->surf);
1471
1472
/* Because we share the same drm file across multiple iris_screen, when
1473
* we export a GEM handle we must make sure it is valid in the DRM file
1474
* descriptor the caller is using (this is the FD given at screen
1475
* creation).
1476
*/
1477
uint32_t handle;
1478
if (iris_bo_export_gem_handle_for_device(bo, screen->winsys_fd, &handle))
1479
return false;
1480
whandle->handle = handle;
1481
return true;
1482
}
1483
case WINSYS_HANDLE_TYPE_FD:
1484
iris_gem_set_tiling(bo, &res->surf);
1485
return iris_bo_export_dmabuf(bo, (int *) &whandle->handle) == 0;
1486
}
1487
1488
return false;
1489
}
1490
1491
static bool
1492
resource_is_busy(struct iris_context *ice,
1493
struct iris_resource *res)
1494
{
1495
bool busy = iris_bo_busy(res->bo);
1496
1497
for (int i = 0; i < IRIS_BATCH_COUNT; i++)
1498
busy |= iris_batch_references(&ice->batches[i], res->bo);
1499
1500
return busy;
1501
}
1502
1503
void
1504
iris_replace_buffer_storage(struct pipe_context *ctx,
1505
struct pipe_resource *p_dst,
1506
struct pipe_resource *p_src,
1507
unsigned num_rebinds,
1508
uint32_t rebind_mask,
1509
uint32_t delete_buffer_id)
1510
{
1511
struct iris_screen *screen = (void *) ctx->screen;
1512
struct iris_context *ice = (void *) ctx;
1513
struct iris_resource *dst = (void *) p_dst;
1514
struct iris_resource *src = (void *) p_src;
1515
1516
assert(memcmp(&dst->surf, &src->surf, sizeof(dst->surf)) == 0);
1517
1518
struct iris_bo *old_bo = dst->bo;
1519
1520
/* Swap out the backing storage */
1521
iris_bo_reference(src->bo);
1522
dst->bo = src->bo;
1523
1524
/* Rebind the buffer, replacing any state referring to the old BO's
1525
* address, and marking state dirty so it's reemitted.
1526
*/
1527
screen->vtbl.rebind_buffer(ice, dst);
1528
1529
iris_bo_unreference(old_bo);
1530
}
1531
1532
static void
1533
iris_invalidate_resource(struct pipe_context *ctx,
1534
struct pipe_resource *resource)
1535
{
1536
struct iris_screen *screen = (void *) ctx->screen;
1537
struct iris_context *ice = (void *) ctx;
1538
struct iris_resource *res = (void *) resource;
1539
1540
if (resource->target != PIPE_BUFFER)
1541
return;
1542
1543
/* If it's already invalidated, don't bother doing anything. */
1544
if (res->valid_buffer_range.start > res->valid_buffer_range.end)
1545
return;
1546
1547
if (!resource_is_busy(ice, res)) {
1548
/* The resource is idle, so just mark that it contains no data and
1549
* keep using the same underlying buffer object.
1550
*/
1551
util_range_set_empty(&res->valid_buffer_range);
1552
return;
1553
}
1554
1555
/* Otherwise, try and replace the backing storage with a new BO. */
1556
1557
/* We can't reallocate memory we didn't allocate in the first place. */
1558
if (res->bo->userptr)
1559
return;
1560
1561
struct iris_bo *old_bo = res->bo;
1562
struct iris_bo *new_bo =
1563
iris_bo_alloc(screen->bufmgr, res->bo->name, resource->width0, 1,
1564
iris_memzone_for_address(old_bo->gtt_offset), 0);
1565
if (!new_bo)
1566
return;
1567
1568
/* Swap out the backing storage */
1569
res->bo = new_bo;
1570
1571
/* Rebind the buffer, replacing any state referring to the old BO's
1572
* address, and marking state dirty so it's reemitted.
1573
*/
1574
screen->vtbl.rebind_buffer(ice, res);
1575
1576
util_range_set_empty(&res->valid_buffer_range);
1577
1578
iris_bo_unreference(old_bo);
1579
}
1580
1581
static void
1582
iris_flush_staging_region(struct pipe_transfer *xfer,
1583
const struct pipe_box *flush_box)
1584
{
1585
if (!(xfer->usage & PIPE_MAP_WRITE))
1586
return;
1587
1588
struct iris_transfer *map = (void *) xfer;
1589
1590
struct pipe_box src_box = *flush_box;
1591
1592
/* Account for extra alignment padding in staging buffer */
1593
if (xfer->resource->target == PIPE_BUFFER)
1594
src_box.x += xfer->box.x % IRIS_MAP_BUFFER_ALIGNMENT;
1595
1596
struct pipe_box dst_box = (struct pipe_box) {
1597
.x = xfer->box.x + flush_box->x,
1598
.y = xfer->box.y + flush_box->y,
1599
.z = xfer->box.z + flush_box->z,
1600
.width = flush_box->width,
1601
.height = flush_box->height,
1602
.depth = flush_box->depth,
1603
};
1604
1605
iris_copy_region(map->blorp, map->batch, xfer->resource, xfer->level,
1606
dst_box.x, dst_box.y, dst_box.z, map->staging, 0,
1607
&src_box);
1608
}
1609
1610
static void
1611
iris_unmap_copy_region(struct iris_transfer *map)
1612
{
1613
iris_resource_destroy(map->staging->screen, map->staging);
1614
1615
map->ptr = NULL;
1616
}
1617
1618
static void
1619
iris_map_copy_region(struct iris_transfer *map)
1620
{
1621
struct pipe_screen *pscreen = &map->batch->screen->base;
1622
struct pipe_transfer *xfer = &map->base.b;
1623
struct pipe_box *box = &xfer->box;
1624
struct iris_resource *res = (void *) xfer->resource;
1625
1626
unsigned extra = xfer->resource->target == PIPE_BUFFER ?
1627
box->x % IRIS_MAP_BUFFER_ALIGNMENT : 0;
1628
1629
struct pipe_resource templ = (struct pipe_resource) {
1630
.usage = PIPE_USAGE_STAGING,
1631
.width0 = box->width + extra,
1632
.height0 = box->height,
1633
.depth0 = 1,
1634
.nr_samples = xfer->resource->nr_samples,
1635
.nr_storage_samples = xfer->resource->nr_storage_samples,
1636
.array_size = box->depth,
1637
.format = res->internal_format,
1638
};
1639
1640
if (xfer->resource->target == PIPE_BUFFER)
1641
templ.target = PIPE_BUFFER;
1642
else if (templ.array_size > 1)
1643
templ.target = PIPE_TEXTURE_2D_ARRAY;
1644
else
1645
templ.target = PIPE_TEXTURE_2D;
1646
1647
map->staging = iris_resource_create(pscreen, &templ);
1648
assert(map->staging);
1649
1650
if (templ.target != PIPE_BUFFER) {
1651
struct isl_surf *surf = &((struct iris_resource *) map->staging)->surf;
1652
xfer->stride = isl_surf_get_row_pitch_B(surf);
1653
xfer->layer_stride = isl_surf_get_array_pitch(surf);
1654
}
1655
1656
if (!(xfer->usage & PIPE_MAP_DISCARD_RANGE)) {
1657
iris_copy_region(map->blorp, map->batch, map->staging, 0, extra, 0, 0,
1658
xfer->resource, xfer->level, box);
1659
/* Ensure writes to the staging BO land before we map it below. */
1660
iris_emit_pipe_control_flush(map->batch,
1661
"transfer read: flush before mapping",
1662
PIPE_CONTROL_RENDER_TARGET_FLUSH |
1663
PIPE_CONTROL_TILE_CACHE_FLUSH |
1664
PIPE_CONTROL_CS_STALL);
1665
}
1666
1667
struct iris_bo *staging_bo = iris_resource_bo(map->staging);
1668
1669
if (iris_batch_references(map->batch, staging_bo))
1670
iris_batch_flush(map->batch);
1671
1672
map->ptr =
1673
iris_bo_map(map->dbg, staging_bo, xfer->usage & MAP_FLAGS) + extra;
1674
1675
map->unmap = iris_unmap_copy_region;
1676
}
1677
1678
static void
1679
get_image_offset_el(const struct isl_surf *surf, unsigned level, unsigned z,
1680
unsigned *out_x0_el, unsigned *out_y0_el)
1681
{
1682
ASSERTED uint32_t z0_el, a0_el;
1683
if (surf->dim == ISL_SURF_DIM_3D) {
1684
isl_surf_get_image_offset_el(surf, level, 0, z,
1685
out_x0_el, out_y0_el, &z0_el, &a0_el);
1686
} else {
1687
isl_surf_get_image_offset_el(surf, level, z, 0,
1688
out_x0_el, out_y0_el, &z0_el, &a0_el);
1689
}
1690
assert(z0_el == 0 && a0_el == 0);
1691
}
1692
1693
/**
1694
* Get pointer offset into stencil buffer.
1695
*
1696
* The stencil buffer is W tiled. Since the GTT is incapable of W fencing, we
1697
* must decode the tile's layout in software.
1698
*
1699
* See
1700
* - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.2.1 W-Major Tile
1701
* Format.
1702
* - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.3 Tiling Algorithm
1703
*
1704
* Even though the returned offset is always positive, the return type is
1705
* signed due to
1706
* commit e8b1c6d6f55f5be3bef25084fdd8b6127517e137
1707
* mesa: Fix return type of _mesa_get_format_bytes() (#37351)
1708
*/
1709
static intptr_t
1710
s8_offset(uint32_t stride, uint32_t x, uint32_t y)
1711
{
1712
uint32_t tile_size = 4096;
1713
uint32_t tile_width = 64;
1714
uint32_t tile_height = 64;
1715
uint32_t row_size = 64 * stride / 2; /* Two rows are interleaved. */
1716
1717
uint32_t tile_x = x / tile_width;
1718
uint32_t tile_y = y / tile_height;
1719
1720
/* The byte's address relative to the tile's base addres. */
1721
uint32_t byte_x = x % tile_width;
1722
uint32_t byte_y = y % tile_height;
1723
1724
uintptr_t u = tile_y * row_size
1725
+ tile_x * tile_size
1726
+ 512 * (byte_x / 8)
1727
+ 64 * (byte_y / 8)
1728
+ 32 * ((byte_y / 4) % 2)
1729
+ 16 * ((byte_x / 4) % 2)
1730
+ 8 * ((byte_y / 2) % 2)
1731
+ 4 * ((byte_x / 2) % 2)
1732
+ 2 * (byte_y % 2)
1733
+ 1 * (byte_x % 2);
1734
1735
return u;
1736
}
1737
1738
static void
1739
iris_unmap_s8(struct iris_transfer *map)
1740
{
1741
struct pipe_transfer *xfer = &map->base.b;
1742
const struct pipe_box *box = &xfer->box;
1743
struct iris_resource *res = (struct iris_resource *) xfer->resource;
1744
struct isl_surf *surf = &res->surf;
1745
1746
if (xfer->usage & PIPE_MAP_WRITE) {
1747
uint8_t *untiled_s8_map = map->ptr;
1748
uint8_t *tiled_s8_map =
1749
iris_bo_map(map->dbg, res->bo, (xfer->usage | MAP_RAW) & MAP_FLAGS);
1750
1751
for (int s = 0; s < box->depth; s++) {
1752
unsigned x0_el, y0_el;
1753
get_image_offset_el(surf, xfer->level, box->z + s, &x0_el, &y0_el);
1754
1755
for (uint32_t y = 0; y < box->height; y++) {
1756
for (uint32_t x = 0; x < box->width; x++) {
1757
ptrdiff_t offset = s8_offset(surf->row_pitch_B,
1758
x0_el + box->x + x,
1759
y0_el + box->y + y);
1760
tiled_s8_map[offset] =
1761
untiled_s8_map[s * xfer->layer_stride + y * xfer->stride + x];
1762
}
1763
}
1764
}
1765
}
1766
1767
free(map->buffer);
1768
}
1769
1770
static void
1771
iris_map_s8(struct iris_transfer *map)
1772
{
1773
struct pipe_transfer *xfer = &map->base.b;
1774
const struct pipe_box *box = &xfer->box;
1775
struct iris_resource *res = (struct iris_resource *) xfer->resource;
1776
struct isl_surf *surf = &res->surf;
1777
1778
xfer->stride = surf->row_pitch_B;
1779
xfer->layer_stride = xfer->stride * box->height;
1780
1781
/* The tiling and detiling functions require that the linear buffer has
1782
* a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
1783
* over-allocate the linear buffer to get the proper alignment.
1784
*/
1785
map->buffer = map->ptr = malloc(xfer->layer_stride * box->depth);
1786
assert(map->buffer);
1787
1788
/* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no
1789
* INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless
1790
* invalidate is set, since we'll be writing the whole rectangle from our
1791
* temporary buffer back out.
1792
*/
1793
if (!(xfer->usage & PIPE_MAP_DISCARD_RANGE)) {
1794
uint8_t *untiled_s8_map = map->ptr;
1795
uint8_t *tiled_s8_map =
1796
iris_bo_map(map->dbg, res->bo, (xfer->usage | MAP_RAW) & MAP_FLAGS);
1797
1798
for (int s = 0; s < box->depth; s++) {
1799
unsigned x0_el, y0_el;
1800
get_image_offset_el(surf, xfer->level, box->z + s, &x0_el, &y0_el);
1801
1802
for (uint32_t y = 0; y < box->height; y++) {
1803
for (uint32_t x = 0; x < box->width; x++) {
1804
ptrdiff_t offset = s8_offset(surf->row_pitch_B,
1805
x0_el + box->x + x,
1806
y0_el + box->y + y);
1807
untiled_s8_map[s * xfer->layer_stride + y * xfer->stride + x] =
1808
tiled_s8_map[offset];
1809
}
1810
}
1811
}
1812
}
1813
1814
map->unmap = iris_unmap_s8;
1815
}
1816
1817
/* Compute extent parameters for use with tiled_memcpy functions.
1818
* xs are in units of bytes and ys are in units of strides.
1819
*/
1820
static inline void
1821
tile_extents(const struct isl_surf *surf,
1822
const struct pipe_box *box,
1823
unsigned level, int z,
1824
unsigned *x1_B, unsigned *x2_B,
1825
unsigned *y1_el, unsigned *y2_el)
1826
{
1827
const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1828
const unsigned cpp = fmtl->bpb / 8;
1829
1830
assert(box->x % fmtl->bw == 0);
1831
assert(box->y % fmtl->bh == 0);
1832
1833
unsigned x0_el, y0_el;
1834
get_image_offset_el(surf, level, box->z + z, &x0_el, &y0_el);
1835
1836
*x1_B = (box->x / fmtl->bw + x0_el) * cpp;
1837
*y1_el = box->y / fmtl->bh + y0_el;
1838
*x2_B = (DIV_ROUND_UP(box->x + box->width, fmtl->bw) + x0_el) * cpp;
1839
*y2_el = DIV_ROUND_UP(box->y + box->height, fmtl->bh) + y0_el;
1840
}
1841
1842
static void
1843
iris_unmap_tiled_memcpy(struct iris_transfer *map)
1844
{
1845
struct pipe_transfer *xfer = &map->base.b;
1846
const struct pipe_box *box = &xfer->box;
1847
struct iris_resource *res = (struct iris_resource *) xfer->resource;
1848
struct isl_surf *surf = &res->surf;
1849
1850
const bool has_swizzling = false;
1851
1852
if (xfer->usage & PIPE_MAP_WRITE) {
1853
char *dst =
1854
iris_bo_map(map->dbg, res->bo, (xfer->usage | MAP_RAW) & MAP_FLAGS);
1855
1856
for (int s = 0; s < box->depth; s++) {
1857
unsigned x1, x2, y1, y2;
1858
tile_extents(surf, box, xfer->level, s, &x1, &x2, &y1, &y2);
1859
1860
void *ptr = map->ptr + s * xfer->layer_stride;
1861
1862
isl_memcpy_linear_to_tiled(x1, x2, y1, y2, dst, ptr,
1863
surf->row_pitch_B, xfer->stride,
1864
has_swizzling, surf->tiling, ISL_MEMCPY);
1865
}
1866
}
1867
os_free_aligned(map->buffer);
1868
map->buffer = map->ptr = NULL;
1869
}
1870
1871
static void
1872
iris_map_tiled_memcpy(struct iris_transfer *map)
1873
{
1874
struct pipe_transfer *xfer = &map->base.b;
1875
const struct pipe_box *box = &xfer->box;
1876
struct iris_resource *res = (struct iris_resource *) xfer->resource;
1877
struct isl_surf *surf = &res->surf;
1878
1879
xfer->stride = ALIGN(surf->row_pitch_B, 16);
1880
xfer->layer_stride = xfer->stride * box->height;
1881
1882
unsigned x1, x2, y1, y2;
1883
tile_extents(surf, box, xfer->level, 0, &x1, &x2, &y1, &y2);
1884
1885
/* The tiling and detiling functions require that the linear buffer has
1886
* a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
1887
* over-allocate the linear buffer to get the proper alignment.
1888
*/
1889
map->buffer =
1890
os_malloc_aligned(xfer->layer_stride * box->depth, 16);
1891
assert(map->buffer);
1892
map->ptr = (char *)map->buffer + (x1 & 0xf);
1893
1894
const bool has_swizzling = false;
1895
1896
if (!(xfer->usage & PIPE_MAP_DISCARD_RANGE)) {
1897
char *src =
1898
iris_bo_map(map->dbg, res->bo, (xfer->usage | MAP_RAW) & MAP_FLAGS);
1899
1900
for (int s = 0; s < box->depth; s++) {
1901
unsigned x1, x2, y1, y2;
1902
tile_extents(surf, box, xfer->level, s, &x1, &x2, &y1, &y2);
1903
1904
/* Use 's' rather than 'box->z' to rebase the first slice to 0. */
1905
void *ptr = map->ptr + s * xfer->layer_stride;
1906
1907
isl_memcpy_tiled_to_linear(x1, x2, y1, y2, ptr, src, xfer->stride,
1908
surf->row_pitch_B, has_swizzling,
1909
surf->tiling, ISL_MEMCPY_STREAMING_LOAD);
1910
}
1911
}
1912
1913
map->unmap = iris_unmap_tiled_memcpy;
1914
}
1915
1916
static void
1917
iris_map_direct(struct iris_transfer *map)
1918
{
1919
struct pipe_transfer *xfer = &map->base.b;
1920
struct pipe_box *box = &xfer->box;
1921
struct iris_resource *res = (struct iris_resource *) xfer->resource;
1922
1923
void *ptr = iris_bo_map(map->dbg, res->bo, xfer->usage & MAP_FLAGS);
1924
1925
if (res->base.b.target == PIPE_BUFFER) {
1926
xfer->stride = 0;
1927
xfer->layer_stride = 0;
1928
1929
map->ptr = ptr + box->x;
1930
} else {
1931
struct isl_surf *surf = &res->surf;
1932
const struct isl_format_layout *fmtl =
1933
isl_format_get_layout(surf->format);
1934
const unsigned cpp = fmtl->bpb / 8;
1935
unsigned x0_el, y0_el;
1936
1937
get_image_offset_el(surf, xfer->level, box->z, &x0_el, &y0_el);
1938
1939
xfer->stride = isl_surf_get_row_pitch_B(surf);
1940
xfer->layer_stride = isl_surf_get_array_pitch(surf);
1941
1942
map->ptr = ptr + (y0_el + box->y) * xfer->stride + (x0_el + box->x) * cpp;
1943
}
1944
}
1945
1946
static bool
1947
can_promote_to_async(const struct iris_resource *res,
1948
const struct pipe_box *box,
1949
enum pipe_map_flags usage)
1950
{
1951
/* If we're writing to a section of the buffer that hasn't even been
1952
* initialized with useful data, then we can safely promote this write
1953
* to be unsynchronized. This helps the common pattern of appending data.
1954
*/
1955
return res->base.b.target == PIPE_BUFFER && (usage & PIPE_MAP_WRITE) &&
1956
!(usage & TC_TRANSFER_MAP_NO_INFER_UNSYNCHRONIZED) &&
1957
!util_ranges_intersect(&res->valid_buffer_range, box->x,
1958
box->x + box->width);
1959
}
1960
1961
static void *
1962
iris_transfer_map(struct pipe_context *ctx,
1963
struct pipe_resource *resource,
1964
unsigned level,
1965
enum pipe_map_flags usage,
1966
const struct pipe_box *box,
1967
struct pipe_transfer **ptransfer)
1968
{
1969
struct iris_context *ice = (struct iris_context *)ctx;
1970
struct iris_resource *res = (struct iris_resource *)resource;
1971
struct isl_surf *surf = &res->surf;
1972
1973
if (iris_resource_unfinished_aux_import(res))
1974
iris_resource_finish_aux_import(ctx->screen, res);
1975
1976
if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE) {
1977
/* Replace the backing storage with a fresh buffer for non-async maps */
1978
if (!(usage & (PIPE_MAP_UNSYNCHRONIZED |
1979
TC_TRANSFER_MAP_NO_INVALIDATE)))
1980
iris_invalidate_resource(ctx, resource);
1981
1982
/* If we can discard the whole resource, we can discard the range. */
1983
usage |= PIPE_MAP_DISCARD_RANGE;
1984
}
1985
1986
if (!(usage & PIPE_MAP_UNSYNCHRONIZED) &&
1987
can_promote_to_async(res, box, usage)) {
1988
usage |= PIPE_MAP_UNSYNCHRONIZED;
1989
}
1990
1991
/* Avoid using GPU copies for persistent/coherent buffers, as the idea
1992
* there is to access them simultaneously on the CPU & GPU. This also
1993
* avoids trying to use GPU copies for our u_upload_mgr buffers which
1994
* contain state we're constructing for a GPU draw call, which would
1995
* kill us with infinite stack recursion.
1996
*/
1997
if (usage & (PIPE_MAP_PERSISTENT | PIPE_MAP_COHERENT))
1998
usage |= PIPE_MAP_DIRECTLY;
1999
2000
/* We cannot provide a direct mapping of tiled resources, and we
2001
* may not be able to mmap imported BOs since they may come from
2002
* other devices that I915_GEM_MMAP cannot work with.
2003
*/
2004
if ((usage & PIPE_MAP_DIRECTLY) &&
2005
(surf->tiling != ISL_TILING_LINEAR || res->bo->imported))
2006
return NULL;
2007
2008
bool map_would_stall = false;
2009
2010
if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
2011
map_would_stall =
2012
resource_is_busy(ice, res) ||
2013
iris_has_invalid_primary(res, level, 1, box->z, box->depth);
2014
2015
if (map_would_stall && (usage & PIPE_MAP_DONTBLOCK) &&
2016
(usage & PIPE_MAP_DIRECTLY))
2017
return NULL;
2018
}
2019
2020
struct iris_transfer *map;
2021
2022
if (usage & TC_TRANSFER_MAP_THREADED_UNSYNC)
2023
map = slab_alloc(&ice->transfer_pool_unsync);
2024
else
2025
map = slab_alloc(&ice->transfer_pool);
2026
2027
if (!map)
2028
return NULL;
2029
2030
struct pipe_transfer *xfer = &map->base.b;
2031
2032
memset(map, 0, sizeof(*map));
2033
map->dbg = &ice->dbg;
2034
2035
pipe_resource_reference(&xfer->resource, resource);
2036
xfer->level = level;
2037
xfer->usage = usage;
2038
xfer->box = *box;
2039
*ptransfer = xfer;
2040
2041
map->dest_had_defined_contents =
2042
util_ranges_intersect(&res->valid_buffer_range, box->x,
2043
box->x + box->width);
2044
2045
if (usage & PIPE_MAP_WRITE)
2046
util_range_add(&res->base.b, &res->valid_buffer_range, box->x, box->x + box->width);
2047
2048
if (!res->bo->imported) {
2049
/* GPU copies are not useful for buffer reads. Instead of stalling to
2050
* read from the original buffer, we'd simply copy it to a temporary...
2051
* then stall (a bit longer) to read from that buffer.
2052
*
2053
* Images are less clear-cut. Resolves can be destructive, removing
2054
* some of the underlying compression, so we'd rather blit the data to
2055
* a linear temporary and map that, to avoid the resolve.
2056
*/
2057
if (!(usage & PIPE_MAP_DISCARD_RANGE) &&
2058
!iris_has_invalid_primary(res, level, 1, box->z, box->depth)) {
2059
usage |= PIPE_MAP_DIRECTLY;
2060
}
2061
2062
const struct isl_format_layout *fmtl =
2063
isl_format_get_layout(surf->format);
2064
if (fmtl->txc == ISL_TXC_ASTC)
2065
usage |= PIPE_MAP_DIRECTLY;
2066
2067
/* We can map directly if it wouldn't stall, there's no compression,
2068
* and we aren't doing an uncached read.
2069
*/
2070
if (!map_would_stall &&
2071
!isl_aux_usage_has_compression(res->aux.usage) &&
2072
!((usage & PIPE_MAP_READ) && res->bo->mmap_mode != IRIS_MMAP_WB)) {
2073
usage |= PIPE_MAP_DIRECTLY;
2074
}
2075
}
2076
2077
if (!(usage & PIPE_MAP_DIRECTLY)) {
2078
/* If we need a synchronous mapping and the resource is busy, or needs
2079
* resolving, we copy to/from a linear temporary buffer using the GPU.
2080
*/
2081
map->batch = &ice->batches[IRIS_BATCH_RENDER];
2082
map->blorp = &ice->blorp;
2083
iris_map_copy_region(map);
2084
} else {
2085
/* Otherwise we're free to map on the CPU. */
2086
2087
if (resource->target != PIPE_BUFFER) {
2088
iris_resource_access_raw(ice, res, level, box->z, box->depth,
2089
usage & PIPE_MAP_WRITE);
2090
}
2091
2092
if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
2093
for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
2094
if (iris_batch_references(&ice->batches[i], res->bo))
2095
iris_batch_flush(&ice->batches[i]);
2096
}
2097
}
2098
2099
if (surf->tiling == ISL_TILING_W) {
2100
/* TODO: Teach iris_map_tiled_memcpy about W-tiling... */
2101
iris_map_s8(map);
2102
} else if (surf->tiling != ISL_TILING_LINEAR) {
2103
iris_map_tiled_memcpy(map);
2104
} else {
2105
iris_map_direct(map);
2106
}
2107
}
2108
2109
return map->ptr;
2110
}
2111
2112
static void
2113
iris_transfer_flush_region(struct pipe_context *ctx,
2114
struct pipe_transfer *xfer,
2115
const struct pipe_box *box)
2116
{
2117
struct iris_context *ice = (struct iris_context *)ctx;
2118
struct iris_resource *res = (struct iris_resource *) xfer->resource;
2119
struct iris_transfer *map = (void *) xfer;
2120
2121
if (map->staging)
2122
iris_flush_staging_region(xfer, box);
2123
2124
uint32_t history_flush = 0;
2125
2126
if (res->base.b.target == PIPE_BUFFER) {
2127
if (map->staging)
2128
history_flush |= PIPE_CONTROL_RENDER_TARGET_FLUSH |
2129
PIPE_CONTROL_TILE_CACHE_FLUSH;
2130
2131
if (map->dest_had_defined_contents)
2132
history_flush |= iris_flush_bits_for_history(ice, res);
2133
2134
util_range_add(&res->base.b, &res->valid_buffer_range, box->x, box->x + box->width);
2135
}
2136
2137
if (history_flush & ~PIPE_CONTROL_CS_STALL) {
2138
for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
2139
struct iris_batch *batch = &ice->batches[i];
2140
if (batch->contains_draw || batch->cache.render->entries) {
2141
iris_batch_maybe_flush(batch, 24);
2142
iris_emit_pipe_control_flush(batch,
2143
"cache history: transfer flush",
2144
history_flush);
2145
}
2146
}
2147
}
2148
2149
/* Make sure we flag constants dirty even if there's no need to emit
2150
* any PIPE_CONTROLs to a batch.
2151
*/
2152
iris_dirty_for_history(ice, res);
2153
}
2154
2155
static void
2156
iris_transfer_unmap(struct pipe_context *ctx, struct pipe_transfer *xfer)
2157
{
2158
struct iris_context *ice = (struct iris_context *)ctx;
2159
struct iris_transfer *map = (void *) xfer;
2160
2161
if (!(xfer->usage & (PIPE_MAP_FLUSH_EXPLICIT |
2162
PIPE_MAP_COHERENT))) {
2163
struct pipe_box flush_box = {
2164
.x = 0, .y = 0, .z = 0,
2165
.width = xfer->box.width,
2166
.height = xfer->box.height,
2167
.depth = xfer->box.depth,
2168
};
2169
iris_transfer_flush_region(ctx, xfer, &flush_box);
2170
}
2171
2172
if (map->unmap)
2173
map->unmap(map);
2174
2175
pipe_resource_reference(&xfer->resource, NULL);
2176
2177
/* transfer_unmap is always called from the driver thread, so we have to
2178
* use transfer_pool, not transfer_pool_unsync. Freeing an object into a
2179
* different pool is allowed, however.
2180
*/
2181
slab_free(&ice->transfer_pool, map);
2182
}
2183
2184
/**
2185
* The pipe->texture_subdata() driver hook.
2186
*
2187
* Mesa's state tracker takes this path whenever possible, even with
2188
* PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER set.
2189
*/
2190
static void
2191
iris_texture_subdata(struct pipe_context *ctx,
2192
struct pipe_resource *resource,
2193
unsigned level,
2194
unsigned usage,
2195
const struct pipe_box *box,
2196
const void *data,
2197
unsigned stride,
2198
unsigned layer_stride)
2199
{
2200
struct iris_context *ice = (struct iris_context *)ctx;
2201
struct iris_resource *res = (struct iris_resource *)resource;
2202
const struct isl_surf *surf = &res->surf;
2203
2204
assert(resource->target != PIPE_BUFFER);
2205
2206
if (iris_resource_unfinished_aux_import(res))
2207
iris_resource_finish_aux_import(ctx->screen, res);
2208
2209
/* Just use the transfer-based path for linear buffers - it will already
2210
* do a direct mapping, or a simple linear staging buffer.
2211
*
2212
* Linear staging buffers appear to be better than tiled ones, too, so
2213
* take that path if we need the GPU to perform color compression, or
2214
* stall-avoidance blits.
2215
*/
2216
if (surf->tiling == ISL_TILING_LINEAR ||
2217
isl_aux_usage_has_compression(res->aux.usage) ||
2218
resource_is_busy(ice, res)) {
2219
return u_default_texture_subdata(ctx, resource, level, usage, box,
2220
data, stride, layer_stride);
2221
}
2222
2223
/* No state trackers pass any flags other than PIPE_MAP_WRITE */
2224
2225
iris_resource_access_raw(ice, res, level, box->z, box->depth, true);
2226
2227
for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
2228
if (iris_batch_references(&ice->batches[i], res->bo))
2229
iris_batch_flush(&ice->batches[i]);
2230
}
2231
2232
uint8_t *dst = iris_bo_map(&ice->dbg, res->bo, MAP_WRITE | MAP_RAW);
2233
2234
for (int s = 0; s < box->depth; s++) {
2235
const uint8_t *src = data + s * layer_stride;
2236
2237
if (surf->tiling == ISL_TILING_W) {
2238
unsigned x0_el, y0_el;
2239
get_image_offset_el(surf, level, box->z + s, &x0_el, &y0_el);
2240
2241
for (unsigned y = 0; y < box->height; y++) {
2242
for (unsigned x = 0; x < box->width; x++) {
2243
ptrdiff_t offset = s8_offset(surf->row_pitch_B,
2244
x0_el + box->x + x,
2245
y0_el + box->y + y);
2246
dst[offset] = src[y * stride + x];
2247
}
2248
}
2249
} else {
2250
unsigned x1, x2, y1, y2;
2251
2252
tile_extents(surf, box, level, s, &x1, &x2, &y1, &y2);
2253
2254
isl_memcpy_linear_to_tiled(x1, x2, y1, y2,
2255
(void *)dst, (void *)src,
2256
surf->row_pitch_B, stride,
2257
false, surf->tiling, ISL_MEMCPY);
2258
}
2259
}
2260
}
2261
2262
/**
2263
* Mark state dirty that needs to be re-emitted when a resource is written.
2264
*/
2265
void
2266
iris_dirty_for_history(struct iris_context *ice,
2267
struct iris_resource *res)
2268
{
2269
uint64_t stage_dirty = 0ull;
2270
2271
if (res->bind_history & PIPE_BIND_CONSTANT_BUFFER) {
2272
stage_dirty |= ((uint64_t)res->bind_stages)
2273
<< IRIS_SHIFT_FOR_STAGE_DIRTY_CONSTANTS;
2274
}
2275
2276
ice->state.stage_dirty |= stage_dirty;
2277
}
2278
2279
/**
2280
* Produce a set of PIPE_CONTROL bits which ensure data written to a
2281
* resource becomes visible, and any stale read cache data is invalidated.
2282
*/
2283
uint32_t
2284
iris_flush_bits_for_history(struct iris_context *ice,
2285
struct iris_resource *res)
2286
{
2287
struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
2288
2289
uint32_t flush = PIPE_CONTROL_CS_STALL;
2290
2291
if (res->bind_history & PIPE_BIND_CONSTANT_BUFFER) {
2292
flush |= PIPE_CONTROL_CONST_CACHE_INVALIDATE;
2293
flush |= screen->compiler->indirect_ubos_use_sampler ?
2294
PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE :
2295
PIPE_CONTROL_DATA_CACHE_FLUSH;
2296
}
2297
2298
if (res->bind_history & PIPE_BIND_SAMPLER_VIEW)
2299
flush |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE;
2300
2301
if (res->bind_history & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER))
2302
flush |= PIPE_CONTROL_VF_CACHE_INVALIDATE;
2303
2304
if (res->bind_history & (PIPE_BIND_SHADER_BUFFER | PIPE_BIND_SHADER_IMAGE))
2305
flush |= PIPE_CONTROL_DATA_CACHE_FLUSH;
2306
2307
return flush;
2308
}
2309
2310
void
2311
iris_flush_and_dirty_for_history(struct iris_context *ice,
2312
struct iris_batch *batch,
2313
struct iris_resource *res,
2314
uint32_t extra_flags,
2315
const char *reason)
2316
{
2317
if (res->base.b.target != PIPE_BUFFER)
2318
return;
2319
2320
uint32_t flush = iris_flush_bits_for_history(ice, res) | extra_flags;
2321
2322
iris_emit_pipe_control_flush(batch, reason, flush);
2323
2324
iris_dirty_for_history(ice, res);
2325
}
2326
2327
bool
2328
iris_resource_set_clear_color(struct iris_context *ice,
2329
struct iris_resource *res,
2330
union isl_color_value color)
2331
{
2332
if (memcmp(&res->aux.clear_color, &color, sizeof(color)) != 0) {
2333
res->aux.clear_color = color;
2334
return true;
2335
}
2336
2337
return false;
2338
}
2339
2340
union isl_color_value
2341
iris_resource_get_clear_color(const struct iris_resource *res,
2342
struct iris_bo **clear_color_bo,
2343
uint64_t *clear_color_offset)
2344
{
2345
assert(res->aux.bo);
2346
2347
if (clear_color_bo)
2348
*clear_color_bo = res->aux.clear_color_bo;
2349
if (clear_color_offset)
2350
*clear_color_offset = res->aux.clear_color_offset;
2351
return res->aux.clear_color;
2352
}
2353
2354
static enum pipe_format
2355
iris_resource_get_internal_format(struct pipe_resource *p_res)
2356
{
2357
struct iris_resource *res = (void *) p_res;
2358
return res->internal_format;
2359
}
2360
2361
static const struct u_transfer_vtbl transfer_vtbl = {
2362
.resource_create = iris_resource_create,
2363
.resource_destroy = iris_resource_destroy,
2364
.transfer_map = iris_transfer_map,
2365
.transfer_unmap = iris_transfer_unmap,
2366
.transfer_flush_region = iris_transfer_flush_region,
2367
.get_internal_format = iris_resource_get_internal_format,
2368
.set_stencil = iris_resource_set_separate_stencil,
2369
.get_stencil = iris_resource_get_separate_stencil,
2370
};
2371
2372
void
2373
iris_init_screen_resource_functions(struct pipe_screen *pscreen)
2374
{
2375
pscreen->query_dmabuf_modifiers = iris_query_dmabuf_modifiers;
2376
pscreen->is_dmabuf_modifier_supported = iris_is_dmabuf_modifier_supported;
2377
pscreen->get_dmabuf_modifier_planes = iris_get_dmabuf_modifier_planes;
2378
pscreen->resource_create_with_modifiers =
2379
iris_resource_create_with_modifiers;
2380
pscreen->resource_create = u_transfer_helper_resource_create;
2381
pscreen->resource_from_user_memory = iris_resource_from_user_memory;
2382
pscreen->resource_from_handle = iris_resource_from_handle;
2383
pscreen->resource_from_memobj = iris_resource_from_memobj;
2384
pscreen->resource_get_handle = iris_resource_get_handle;
2385
pscreen->resource_get_param = iris_resource_get_param;
2386
pscreen->resource_destroy = u_transfer_helper_resource_destroy;
2387
pscreen->memobj_create_from_handle = iris_memobj_create_from_handle;
2388
pscreen->memobj_destroy = iris_memobj_destroy;
2389
pscreen->transfer_helper =
2390
u_transfer_helper_create(&transfer_vtbl, true, true, false, true);
2391
}
2392
2393
void
2394
iris_init_resource_functions(struct pipe_context *ctx)
2395
{
2396
ctx->flush_resource = iris_flush_resource;
2397
ctx->invalidate_resource = iris_invalidate_resource;
2398
ctx->buffer_map = u_transfer_helper_transfer_map;
2399
ctx->texture_map = u_transfer_helper_transfer_map;
2400
ctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
2401
ctx->buffer_unmap = u_transfer_helper_transfer_unmap;
2402
ctx->texture_unmap = u_transfer_helper_transfer_unmap;
2403
ctx->buffer_subdata = u_default_buffer_subdata;
2404
ctx->texture_subdata = iris_texture_subdata;
2405
}
2406
2407