cce24b287298a8274e9dbf9aa7f5f6aaf9e372ec
[mesa.git] / src / gallium / drivers / iris / iris_resource.c
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/u_format.h"
41 #include "util/u_transfer.h"
42 #include "util/u_transfer_helper.h"
43 #include "util/u_upload_mgr.h"
44 #include "util/ralloc.h"
45 #include "iris_batch.h"
46 #include "iris_context.h"
47 #include "iris_resource.h"
48 #include "iris_screen.h"
49 #include "intel/common/gen_debug.h"
50 #include "isl/isl.h"
51 #include "drm-uapi/drm_fourcc.h"
52 #include "drm-uapi/i915_drm.h"
53
54 enum modifier_priority {
55 MODIFIER_PRIORITY_INVALID = 0,
56 MODIFIER_PRIORITY_LINEAR,
57 MODIFIER_PRIORITY_X,
58 MODIFIER_PRIORITY_Y,
59 MODIFIER_PRIORITY_Y_CCS,
60 };
61
62 static const uint64_t priority_to_modifier[] = {
63 [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
64 [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
65 [MODIFIER_PRIORITY_X] = I915_FORMAT_MOD_X_TILED,
66 [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
67 [MODIFIER_PRIORITY_Y_CCS] = I915_FORMAT_MOD_Y_TILED_CCS,
68 };
69
70 static bool
71 modifier_is_supported(const struct gen_device_info *devinfo,
72 uint64_t modifier)
73 {
74 /* XXX: do something real */
75 switch (modifier) {
76 case I915_FORMAT_MOD_Y_TILED:
77 case I915_FORMAT_MOD_X_TILED:
78 case DRM_FORMAT_MOD_LINEAR:
79 return true;
80 case I915_FORMAT_MOD_Y_TILED_CCS:
81 case DRM_FORMAT_MOD_INVALID:
82 default:
83 return false;
84 }
85 }
86
87 static uint64_t
88 select_best_modifier(struct gen_device_info *devinfo,
89 const uint64_t *modifiers,
90 int count)
91 {
92 enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
93
94 for (int i = 0; i < count; i++) {
95 if (!modifier_is_supported(devinfo, modifiers[i]))
96 continue;
97
98 switch (modifiers[i]) {
99 case I915_FORMAT_MOD_Y_TILED_CCS:
100 prio = MAX2(prio, MODIFIER_PRIORITY_Y_CCS);
101 break;
102 case I915_FORMAT_MOD_Y_TILED:
103 prio = MAX2(prio, MODIFIER_PRIORITY_Y);
104 break;
105 case I915_FORMAT_MOD_X_TILED:
106 prio = MAX2(prio, MODIFIER_PRIORITY_X);
107 break;
108 case DRM_FORMAT_MOD_LINEAR:
109 prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
110 break;
111 case DRM_FORMAT_MOD_INVALID:
112 default:
113 break;
114 }
115 }
116
117 return priority_to_modifier[prio];
118 }
119
120 static enum isl_surf_dim
121 target_to_isl_surf_dim(enum pipe_texture_target target)
122 {
123 switch (target) {
124 case PIPE_BUFFER:
125 case PIPE_TEXTURE_1D:
126 case PIPE_TEXTURE_1D_ARRAY:
127 return ISL_SURF_DIM_1D;
128 case PIPE_TEXTURE_2D:
129 case PIPE_TEXTURE_CUBE:
130 case PIPE_TEXTURE_RECT:
131 case PIPE_TEXTURE_2D_ARRAY:
132 case PIPE_TEXTURE_CUBE_ARRAY:
133 return ISL_SURF_DIM_2D;
134 case PIPE_TEXTURE_3D:
135 return ISL_SURF_DIM_3D;
136 case PIPE_MAX_TEXTURE_TYPES:
137 break;
138 }
139 unreachable("invalid texture type");
140 }
141
142 static isl_surf_usage_flags_t
143 pipe_bind_to_isl_usage(unsigned bindings)
144 {
145 isl_surf_usage_flags_t usage = 0;
146
147 if (bindings & PIPE_BIND_RENDER_TARGET)
148 usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT;
149
150 if (bindings & PIPE_BIND_SAMPLER_VIEW)
151 usage |= ISL_SURF_USAGE_TEXTURE_BIT;
152
153 if (bindings & (PIPE_BIND_SHADER_IMAGE | PIPE_BIND_SHADER_BUFFER))
154 usage |= ISL_SURF_USAGE_STORAGE_BIT;
155
156 if (bindings & PIPE_BIND_DISPLAY_TARGET)
157 usage |= ISL_SURF_USAGE_DISPLAY_BIT;
158
159 return usage;
160 }
161
162 struct pipe_resource *
163 iris_resource_get_separate_stencil(struct pipe_resource *p_res)
164 {
165 /* For packed depth-stencil, we treat depth as the primary resource
166 * and store S8 as the "second plane" resource.
167 */
168 return p_res->next;
169 }
170
171 static void
172 iris_resource_set_separate_stencil(struct pipe_resource *p_res,
173 struct pipe_resource *stencil)
174 {
175 assert(util_format_has_depth(util_format_description(p_res->format)));
176 pipe_resource_reference(&p_res->next, stencil);
177 }
178
179 void
180 iris_get_depth_stencil_resources(struct pipe_resource *res,
181 struct iris_resource **out_z,
182 struct iris_resource **out_s)
183 {
184 if (!res) {
185 *out_z = NULL;
186 *out_s = NULL;
187 return;
188 }
189
190 if (res->format != PIPE_FORMAT_S8_UINT) {
191 *out_z = (void *) res;
192 *out_s = (void *) iris_resource_get_separate_stencil(res);
193 } else {
194 *out_z = NULL;
195 *out_s = (void *) res;
196 }
197 }
198
199 void
200 iris_resource_disable_aux(struct iris_resource *res)
201 {
202 iris_bo_unreference(res->aux.bo);
203 free(res->aux.state);
204
205 // XXX: clear color BO
206
207 res->aux.usage = ISL_AUX_USAGE_NONE;
208 res->aux.possible_usages = 1 << ISL_AUX_USAGE_NONE;
209 res->aux.surf.size_B = 0;
210 res->aux.bo = NULL;
211 res->aux.state = NULL;
212 }
213
214 static void
215 iris_resource_destroy(struct pipe_screen *screen,
216 struct pipe_resource *resource)
217 {
218 struct iris_resource *res = (struct iris_resource *)resource;
219
220 iris_resource_disable_aux(res);
221
222 iris_bo_unreference(res->bo);
223 free(res);
224 }
225
226 static struct iris_resource *
227 iris_alloc_resource(struct pipe_screen *pscreen,
228 const struct pipe_resource *templ)
229 {
230 struct iris_resource *res = calloc(1, sizeof(struct iris_resource));
231 if (!res)
232 return NULL;
233
234 res->base = *templ;
235 res->base.screen = pscreen;
236 pipe_reference_init(&res->base.reference, 1);
237
238 res->aux.possible_usages = 1 << ISL_AUX_USAGE_NONE;
239
240 return res;
241 }
242
243 unsigned
244 iris_get_num_logical_layers(const struct iris_resource *res, unsigned level)
245 {
246 if (res->surf.dim == ISL_SURF_DIM_3D)
247 return minify(res->surf.logical_level0_px.depth, level);
248 else
249 return res->surf.logical_level0_px.array_len;
250 }
251
252 static enum isl_aux_state **
253 create_aux_state_map(struct iris_resource *res, enum isl_aux_state initial)
254 {
255 uint32_t total_slices = 0;
256 for (uint32_t level = 0; level < res->surf.levels; level++)
257 total_slices += iris_get_num_logical_layers(res, level);
258
259 const size_t per_level_array_size =
260 res->surf.levels * sizeof(enum isl_aux_state *);
261
262 /* We're going to allocate a single chunk of data for both the per-level
263 * reference array and the arrays of aux_state. This makes cleanup
264 * significantly easier.
265 */
266 const size_t total_size =
267 per_level_array_size + total_slices * sizeof(enum isl_aux_state);
268
269 void *data = malloc(total_size);
270 if (!data)
271 return NULL;
272
273 enum isl_aux_state **per_level_arr = data;
274 enum isl_aux_state *s = data + per_level_array_size;
275 for (uint32_t level = 0; level < res->surf.levels; level++) {
276 per_level_arr[level] = s;
277 const unsigned level_layers = iris_get_num_logical_layers(res, level);
278 for (uint32_t a = 0; a < level_layers; a++)
279 *(s++) = initial;
280 }
281 assert((void *)s == data + total_size);
282
283 return per_level_arr;
284 }
285
286 /**
287 * Allocate the initial aux surface for a resource based on aux.usage
288 */
289 static bool
290 iris_resource_alloc_aux(struct iris_screen *screen, struct iris_resource *res)
291 {
292 struct isl_device *isl_dev = &screen->isl_dev;
293 enum isl_aux_state initial_state;
294 UNUSED bool ok = false;
295 uint8_t memset_value = 0;
296 uint32_t alloc_flags = 0;
297
298 assert(!res->aux.bo);
299
300 switch (res->aux.usage) {
301 case ISL_AUX_USAGE_NONE:
302 res->aux.surf.size_B = 0;
303 break;
304 case ISL_AUX_USAGE_HIZ:
305 initial_state = ISL_AUX_STATE_AUX_INVALID;
306 memset_value = 0;
307 ok = isl_surf_get_hiz_surf(isl_dev, &res->surf, &res->aux.surf);
308 break;
309 case ISL_AUX_USAGE_MCS:
310 /* The Ivybridge PRM, Vol 2 Part 1 p326 says:
311 *
312 * "When MCS buffer is enabled and bound to MSRT, it is required
313 * that it is cleared prior to any rendering."
314 *
315 * Since we only use the MCS buffer for rendering, we just clear it
316 * immediately on allocation. The clear value for MCS buffers is all
317 * 1's, so we simply memset it to 0xff.
318 */
319 initial_state = ISL_AUX_STATE_CLEAR;
320 memset_value = 0xFF;
321 ok = isl_surf_get_mcs_surf(isl_dev, &res->surf, &res->aux.surf);
322 break;
323 case ISL_AUX_USAGE_CCS_D:
324 case ISL_AUX_USAGE_CCS_E:
325 /* When CCS_E is used, we need to ensure that the CCS starts off in
326 * a valid state. From the Sky Lake PRM, "MCS Buffer for Render
327 * Target(s)":
328 *
329 * "If Software wants to enable Color Compression without Fast
330 * clear, Software needs to initialize MCS with zeros."
331 *
332 * A CCS value of 0 indicates that the corresponding block is in the
333 * pass-through state which is what we want.
334 *
335 * For CCS_D, do the same thing. On Gen9+, this avoids having any
336 * undefined bits in the aux buffer.
337 */
338 initial_state = ISL_AUX_STATE_PASS_THROUGH;
339 alloc_flags |= BO_ALLOC_ZEROED;
340 ok = isl_surf_get_ccs_surf(isl_dev, &res->surf, &res->aux.surf, 0);
341 break;
342 }
343
344 /* No work is needed for a zero-sized auxiliary buffer. */
345 if (res->aux.surf.size_B == 0)
346 return true;
347
348 /* Assert that ISL gave us a valid aux surf */
349 assert(ok);
350
351 /* Create the aux_state for the auxiliary buffer. */
352 res->aux.state = create_aux_state_map(res, initial_state);
353 if (!res->aux.state)
354 return false;
355
356 /* Allocate the auxiliary buffer. ISL has stricter set of alignment rules
357 * the drm allocator. Therefore, one can pass the ISL dimensions in terms
358 * of bytes instead of trying to recalculate based on different format
359 * block sizes.
360 */
361 res->aux.bo = iris_bo_alloc_tiled(screen->bufmgr, "aux buffer",
362 res->aux.surf.size_B,
363 IRIS_MEMZONE_OTHER, I915_TILING_Y,
364 res->aux.surf.row_pitch_B, alloc_flags);
365 if (!res->aux.bo)
366 return false;
367
368 /* Optionally, initialize the auxiliary data to the desired value. */
369 if (memset_value != 0) {
370 void *map = iris_bo_map(NULL, res->aux.bo, MAP_WRITE | MAP_RAW);
371 if (!map)
372 return false;
373
374 memset(map, memset_value, res->aux.surf.size_B);
375 iris_bo_unmap(res->aux.bo);
376 }
377
378 if (res->aux.usage == ISL_AUX_USAGE_HIZ) {
379 for (unsigned level = 0; level < res->surf.levels; ++level) {
380 uint32_t width = u_minify(res->surf.phys_level0_sa.width, level);
381 uint32_t height = u_minify(res->surf.phys_level0_sa.height, level);
382
383 /* Disable HiZ for LOD > 0 unless the width/height are 8x4 aligned.
384 * For LOD == 0, we can grow the dimensions to make it work.
385 */
386 if (level == 0 || ((width & 7) == 0 && (height & 3) == 0))
387 res->aux.has_hiz |= 1 << level;
388 }
389 }
390
391 return true;
392 }
393
394 static bool
395 supports_mcs(const struct isl_surf *surf)
396 {
397 /* MCS compression only applies to multisampled resources. */
398 if (surf->samples <= 1)
399 return false;
400
401 /* See isl_surf_get_mcs_surf for details. */
402 if (surf->samples == 16 && surf->logical_level0_px.width > 8192)
403 return false;
404
405 /* Depth and stencil buffers use the IMS (interleaved) layout. */
406 if (isl_surf_usage_is_depth_or_stencil(surf->usage))
407 return false;
408
409 return true;
410 }
411
412 static bool
413 supports_ccs(const struct gen_device_info *devinfo,
414 const struct isl_surf *surf)
415 {
416 /* Gen9+ only supports CCS for Y-tiled buffers. */
417 if (surf->tiling != ISL_TILING_Y0)
418 return false;
419
420 /* CCS only supports singlesampled resources. */
421 if (surf->samples > 1)
422 return false;
423
424 /* The PRM doesn't say this explicitly, but fast-clears don't appear to
425 * work for 3D textures until Gen9 where the layout of 3D textures changes
426 * to match 2D array textures.
427 */
428 if (devinfo->gen < 9 && surf->dim != ISL_SURF_DIM_2D)
429 return false;
430
431 /* Note: still need to check the format! */
432
433 return true;
434 }
435
436 static struct pipe_resource *
437 iris_resource_create_for_buffer(struct pipe_screen *pscreen,
438 const struct pipe_resource *templ)
439 {
440 struct iris_screen *screen = (struct iris_screen *)pscreen;
441 struct iris_resource *res = iris_alloc_resource(pscreen, templ);
442
443 assert(templ->target == PIPE_BUFFER);
444 assert(templ->height0 <= 1);
445 assert(templ->depth0 <= 1);
446 assert(templ->format == PIPE_FORMAT_NONE ||
447 util_format_get_blocksize(templ->format) == 1);
448
449 res->internal_format = templ->format;
450 res->surf.tiling = ISL_TILING_LINEAR;
451
452 enum iris_memory_zone memzone = IRIS_MEMZONE_OTHER;
453 const char *name = templ->target == PIPE_BUFFER ? "buffer" : "miptree";
454 if (templ->flags & IRIS_RESOURCE_FLAG_SHADER_MEMZONE) {
455 memzone = IRIS_MEMZONE_SHADER;
456 name = "shader kernels";
457 } else if (templ->flags & IRIS_RESOURCE_FLAG_SURFACE_MEMZONE) {
458 memzone = IRIS_MEMZONE_SURFACE;
459 name = "surface state";
460 } else if (templ->flags & IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE) {
461 memzone = IRIS_MEMZONE_DYNAMIC;
462 name = "dynamic state";
463 }
464
465 res->bo = iris_bo_alloc(screen->bufmgr, name, templ->width0, memzone);
466 if (!res->bo) {
467 iris_resource_destroy(pscreen, &res->base);
468 return NULL;
469 }
470
471 return &res->base;
472 }
473
474 static struct pipe_resource *
475 iris_resource_create_with_modifiers(struct pipe_screen *pscreen,
476 const struct pipe_resource *templ,
477 const uint64_t *modifiers,
478 int modifiers_count)
479 {
480 struct iris_screen *screen = (struct iris_screen *)pscreen;
481 struct gen_device_info *devinfo = &screen->devinfo;
482 struct iris_resource *res = iris_alloc_resource(pscreen, templ);
483
484 if (!res)
485 return NULL;
486
487 const struct util_format_description *format_desc =
488 util_format_description(templ->format);
489 const bool has_depth = util_format_has_depth(format_desc);
490 uint64_t modifier =
491 select_best_modifier(devinfo, modifiers, modifiers_count);
492
493 isl_tiling_flags_t tiling_flags = ISL_TILING_ANY_MASK;
494
495 if (modifier != DRM_FORMAT_MOD_INVALID) {
496 res->mod_info = isl_drm_modifier_get_info(modifier);
497
498 tiling_flags = 1 << res->mod_info->tiling;
499 } else {
500 if (modifiers_count > 0) {
501 fprintf(stderr, "Unsupported modifier, resource creation failed.\n");
502 return NULL;
503 }
504
505 /* No modifiers - we can select our own tiling. */
506
507 if (has_depth) {
508 /* Depth must be Y-tiled */
509 tiling_flags = ISL_TILING_Y0_BIT;
510 } else if (templ->format == PIPE_FORMAT_S8_UINT) {
511 /* Stencil must be W-tiled */
512 tiling_flags = ISL_TILING_W_BIT;
513 } else if (templ->target == PIPE_BUFFER ||
514 templ->target == PIPE_TEXTURE_1D ||
515 templ->target == PIPE_TEXTURE_1D_ARRAY) {
516 /* Use linear for buffers and 1D textures */
517 tiling_flags = ISL_TILING_LINEAR_BIT;
518 }
519
520 /* Use linear for staging buffers */
521 if (templ->usage == PIPE_USAGE_STAGING ||
522 templ->bind & (PIPE_BIND_LINEAR | PIPE_BIND_CURSOR) )
523 tiling_flags = ISL_TILING_LINEAR_BIT;
524 }
525
526 isl_surf_usage_flags_t usage = pipe_bind_to_isl_usage(templ->bind);
527
528 if (templ->target == PIPE_TEXTURE_CUBE ||
529 templ->target == PIPE_TEXTURE_CUBE_ARRAY)
530 usage |= ISL_SURF_USAGE_CUBE_BIT;
531
532 if (templ->usage != PIPE_USAGE_STAGING) {
533 if (templ->format == PIPE_FORMAT_S8_UINT)
534 usage |= ISL_SURF_USAGE_STENCIL_BIT;
535 else if (has_depth)
536 usage |= ISL_SURF_USAGE_DEPTH_BIT;
537 }
538
539 enum pipe_format pfmt = templ->format;
540 res->internal_format = pfmt;
541
542 /* Should be handled by u_transfer_helper */
543 assert(!util_format_is_depth_and_stencil(pfmt));
544
545 struct iris_format_info fmt = iris_format_for_usage(devinfo, pfmt, usage);
546 assert(fmt.fmt != ISL_FORMAT_UNSUPPORTED);
547
548 UNUSED const bool isl_surf_created_successfully =
549 isl_surf_init(&screen->isl_dev, &res->surf,
550 .dim = target_to_isl_surf_dim(templ->target),
551 .format = fmt.fmt,
552 .width = templ->width0,
553 .height = templ->height0,
554 .depth = templ->depth0,
555 .levels = templ->last_level + 1,
556 .array_len = templ->array_size,
557 .samples = MAX2(templ->nr_samples, 1),
558 .min_alignment_B = 0,
559 .row_pitch_B = 0,
560 .usage = usage,
561 .tiling_flags = tiling_flags);
562 assert(isl_surf_created_successfully);
563
564 if (res->mod_info) {
565 res->aux.possible_usages |= 1 << res->mod_info->aux_usage;
566 } else if (res->surf.samples > 1) {
567 if (supports_mcs(&res->surf))
568 res->aux.possible_usages |= 1 << ISL_AUX_USAGE_MCS;
569 } else {
570 if (has_depth) {
571 res->aux.possible_usages |= 1 << ISL_AUX_USAGE_HIZ;
572 } else if (supports_ccs(devinfo, &res->surf)) {
573 if (isl_format_supports_ccs_e(devinfo, res->surf.format))
574 res->aux.possible_usages |= 1 << ISL_AUX_USAGE_CCS_E;
575 else if (isl_format_supports_ccs_d(devinfo, res->surf.format))
576 res->aux.possible_usages |= 1 << ISL_AUX_USAGE_CCS_D;
577 }
578 }
579
580 // XXX: we don't actually do aux yet
581 res->aux.possible_usages = 1 << ISL_AUX_USAGE_NONE;
582
583 res->aux.usage = util_last_bit(res->aux.possible_usages) - 1;
584
585 const char *name = "miptree";
586 enum iris_memory_zone memzone = IRIS_MEMZONE_OTHER;
587
588 /* These are for u_upload_mgr buffers only */
589 assert(!(templ->flags & (IRIS_RESOURCE_FLAG_SHADER_MEMZONE |
590 IRIS_RESOURCE_FLAG_SURFACE_MEMZONE |
591 IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE)));
592
593 res->bo = iris_bo_alloc_tiled(screen->bufmgr, name, res->surf.size_B,
594 memzone,
595 isl_tiling_to_i915_tiling(res->surf.tiling),
596 res->surf.row_pitch_B, 0);
597
598 if (!res->bo)
599 goto fail;
600
601 if (!iris_resource_alloc_aux(screen, res))
602 goto fail;
603
604 return &res->base;
605
606 fail:
607 fprintf(stderr, "XXX: resource creation failed\n");
608 iris_resource_destroy(pscreen, &res->base);
609 return NULL;
610
611 }
612
613 static struct pipe_resource *
614 iris_resource_create(struct pipe_screen *pscreen,
615 const struct pipe_resource *templ)
616 {
617 if (templ->target == PIPE_BUFFER)
618 return iris_resource_create_for_buffer(pscreen, templ);
619 else
620 return iris_resource_create_with_modifiers(pscreen, templ, NULL, 0);
621 }
622
623 static uint64_t
624 tiling_to_modifier(uint32_t tiling)
625 {
626 static const uint64_t map[] = {
627 [I915_TILING_NONE] = DRM_FORMAT_MOD_LINEAR,
628 [I915_TILING_X] = I915_FORMAT_MOD_X_TILED,
629 [I915_TILING_Y] = I915_FORMAT_MOD_Y_TILED,
630 };
631
632 assert(tiling < ARRAY_SIZE(map));
633
634 return map[tiling];
635 }
636
637 static struct pipe_resource *
638 iris_resource_from_user_memory(struct pipe_screen *pscreen,
639 const struct pipe_resource *templ,
640 void *user_memory)
641 {
642 struct iris_screen *screen = (struct iris_screen *)pscreen;
643 struct iris_bufmgr *bufmgr = screen->bufmgr;
644 struct iris_resource *res = iris_alloc_resource(pscreen, templ);
645 if (!res)
646 return NULL;
647
648 assert(templ->target == PIPE_BUFFER);
649
650 res->internal_format = templ->format;
651 res->bo = iris_bo_create_userptr(bufmgr, "user",
652 user_memory, templ->width0,
653 IRIS_MEMZONE_OTHER);
654 if (!res->bo) {
655 free(res);
656 return NULL;
657 }
658
659 return &res->base;
660 }
661
662 static struct pipe_resource *
663 iris_resource_from_handle(struct pipe_screen *pscreen,
664 const struct pipe_resource *templ,
665 struct winsys_handle *whandle,
666 unsigned usage)
667 {
668 struct iris_screen *screen = (struct iris_screen *)pscreen;
669 struct gen_device_info *devinfo = &screen->devinfo;
670 struct iris_bufmgr *bufmgr = screen->bufmgr;
671 struct iris_resource *res = iris_alloc_resource(pscreen, templ);
672 if (!res)
673 return NULL;
674
675 if (whandle->offset != 0) {
676 dbg_printf("Attempt to import unsupported winsys offset %u\n",
677 whandle->offset);
678 goto fail;
679 }
680
681 switch (whandle->type) {
682 case WINSYS_HANDLE_TYPE_FD:
683 res->bo = iris_bo_import_dmabuf(bufmgr, whandle->handle);
684 break;
685 case WINSYS_HANDLE_TYPE_SHARED:
686 res->bo = iris_bo_gem_create_from_name(bufmgr, "winsys image",
687 whandle->handle);
688 break;
689 default:
690 unreachable("invalid winsys handle type");
691 }
692 if (!res->bo)
693 return NULL;
694
695 uint64_t modifier = whandle->modifier;
696 if (modifier == DRM_FORMAT_MOD_INVALID) {
697 modifier = tiling_to_modifier(res->bo->tiling_mode);
698 }
699 res->mod_info = isl_drm_modifier_get_info(modifier);
700 assert(res->mod_info);
701
702 isl_surf_usage_flags_t isl_usage = pipe_bind_to_isl_usage(templ->bind);
703
704 const struct iris_format_info fmt =
705 iris_format_for_usage(devinfo, templ->format, isl_usage);
706 res->internal_format = templ->format;
707
708 if (templ->target == PIPE_BUFFER) {
709 res->surf.tiling = ISL_TILING_LINEAR;
710 } else {
711 isl_surf_init(&screen->isl_dev, &res->surf,
712 .dim = target_to_isl_surf_dim(templ->target),
713 .format = fmt.fmt,
714 .width = templ->width0,
715 .height = templ->height0,
716 .depth = templ->depth0,
717 .levels = templ->last_level + 1,
718 .array_len = templ->array_size,
719 .samples = MAX2(templ->nr_samples, 1),
720 .min_alignment_B = 0,
721 .row_pitch_B = whandle->stride,
722 .usage = isl_usage,
723 .tiling_flags = 1 << res->mod_info->tiling);
724
725 assert(res->bo->tiling_mode ==
726 isl_tiling_to_i915_tiling(res->surf.tiling));
727
728 // XXX: create_ccs_buf_for_image?
729 if (!iris_resource_alloc_aux(screen, res))
730 goto fail;
731 }
732
733 return &res->base;
734
735 fail:
736 iris_resource_destroy(pscreen, &res->base);
737 return NULL;
738 }
739
740 static boolean
741 iris_resource_get_handle(struct pipe_screen *pscreen,
742 struct pipe_context *ctx,
743 struct pipe_resource *resource,
744 struct winsys_handle *whandle,
745 unsigned usage)
746 {
747 struct iris_context *ice = (struct iris_context *)ctx;
748 struct iris_resource *res = (struct iris_resource *)resource;
749
750 /* If this is a buffer, stride should be 0 - no need to special case */
751 whandle->stride = res->surf.row_pitch_B;
752 whandle->modifier =
753 res->mod_info ? res->mod_info->modifier
754 : tiling_to_modifier(res->bo->tiling_mode);
755
756 if (!res->mod_info || res->mod_info->aux_usage != res->aux.usage) {
757 struct iris_batch *render_batch = &ice->batches[IRIS_BATCH_RENDER];
758 iris_resource_prepare_access(ice, render_batch, res,
759 0, INTEL_REMAINING_LEVELS,
760 0, INTEL_REMAINING_LAYERS,
761 ISL_AUX_USAGE_NONE, false);
762 iris_resource_disable_aux(res);
763 }
764
765 switch (whandle->type) {
766 case WINSYS_HANDLE_TYPE_SHARED:
767 return iris_bo_flink(res->bo, &whandle->handle) == 0;
768 case WINSYS_HANDLE_TYPE_KMS:
769 whandle->handle = iris_bo_export_gem_handle(res->bo);
770 return true;
771 case WINSYS_HANDLE_TYPE_FD:
772 return iris_bo_export_dmabuf(res->bo, (int *) &whandle->handle) == 0;
773 }
774
775 return false;
776 }
777
778 static void
779 get_image_offset_el(struct isl_surf *surf, unsigned level, unsigned z,
780 unsigned *out_x0_el, unsigned *out_y0_el)
781 {
782 if (surf->dim == ISL_SURF_DIM_3D) {
783 isl_surf_get_image_offset_el(surf, level, 0, z, out_x0_el, out_y0_el);
784 } else {
785 isl_surf_get_image_offset_el(surf, level, z, 0, out_x0_el, out_y0_el);
786 }
787 }
788
789 /**
790 * Get pointer offset into stencil buffer.
791 *
792 * The stencil buffer is W tiled. Since the GTT is incapable of W fencing, we
793 * must decode the tile's layout in software.
794 *
795 * See
796 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.2.1 W-Major Tile
797 * Format.
798 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.3 Tiling Algorithm
799 *
800 * Even though the returned offset is always positive, the return type is
801 * signed due to
802 * commit e8b1c6d6f55f5be3bef25084fdd8b6127517e137
803 * mesa: Fix return type of _mesa_get_format_bytes() (#37351)
804 */
805 static intptr_t
806 s8_offset(uint32_t stride, uint32_t x, uint32_t y, bool swizzled)
807 {
808 uint32_t tile_size = 4096;
809 uint32_t tile_width = 64;
810 uint32_t tile_height = 64;
811 uint32_t row_size = 64 * stride / 2; /* Two rows are interleaved. */
812
813 uint32_t tile_x = x / tile_width;
814 uint32_t tile_y = y / tile_height;
815
816 /* The byte's address relative to the tile's base addres. */
817 uint32_t byte_x = x % tile_width;
818 uint32_t byte_y = y % tile_height;
819
820 uintptr_t u = tile_y * row_size
821 + tile_x * tile_size
822 + 512 * (byte_x / 8)
823 + 64 * (byte_y / 8)
824 + 32 * ((byte_y / 4) % 2)
825 + 16 * ((byte_x / 4) % 2)
826 + 8 * ((byte_y / 2) % 2)
827 + 4 * ((byte_x / 2) % 2)
828 + 2 * (byte_y % 2)
829 + 1 * (byte_x % 2);
830
831 if (swizzled) {
832 /* adjust for bit6 swizzling */
833 if (((byte_x / 8) % 2) == 1) {
834 if (((byte_y / 8) % 2) == 0) {
835 u += 64;
836 } else {
837 u -= 64;
838 }
839 }
840 }
841
842 return u;
843 }
844
845 static void
846 iris_unmap_s8(struct iris_transfer *map)
847 {
848 struct pipe_transfer *xfer = &map->base;
849 struct iris_resource *res = (struct iris_resource *) xfer->resource;
850 struct isl_surf *surf = &res->surf;
851 const bool has_swizzling = false;
852
853 if (xfer->usage & PIPE_TRANSFER_WRITE) {
854 uint8_t *untiled_s8_map = map->ptr;
855 uint8_t *tiled_s8_map =
856 iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
857
858 struct pipe_box box = xfer->box;
859
860 for (int s = 0; s < box.depth; s++) {
861 unsigned x0_el, y0_el;
862 get_image_offset_el(surf, xfer->level, box.z, &x0_el, &y0_el);
863
864 for (uint32_t y = 0; y < box.height; y++) {
865 for (uint32_t x = 0; x < box.width; x++) {
866 ptrdiff_t offset = s8_offset(surf->row_pitch_B,
867 x0_el + box.x + x,
868 y0_el + box.y + y,
869 has_swizzling);
870 tiled_s8_map[offset] =
871 untiled_s8_map[s * xfer->layer_stride + y * xfer->stride + x];
872 }
873 }
874
875 box.z++;
876 }
877 }
878
879 free(map->buffer);
880 }
881
882 static void
883 iris_map_s8(struct iris_transfer *map)
884 {
885 struct pipe_transfer *xfer = &map->base;
886 struct iris_resource *res = (struct iris_resource *) xfer->resource;
887 struct isl_surf *surf = &res->surf;
888
889 xfer->stride = surf->row_pitch_B;
890 xfer->layer_stride = xfer->stride * xfer->box.height;
891
892 /* The tiling and detiling functions require that the linear buffer has
893 * a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
894 * over-allocate the linear buffer to get the proper alignment.
895 */
896 map->buffer = map->ptr = malloc(xfer->layer_stride * xfer->box.depth);
897 assert(map->buffer);
898
899 const bool has_swizzling = false;
900
901 /* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no
902 * INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless
903 * invalidate is set, since we'll be writing the whole rectangle from our
904 * temporary buffer back out.
905 */
906 if (!(xfer->usage & PIPE_TRANSFER_DISCARD_RANGE)) {
907 uint8_t *untiled_s8_map = map->ptr;
908 uint8_t *tiled_s8_map =
909 iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
910
911 struct pipe_box box = xfer->box;
912
913 for (int s = 0; s < box.depth; s++) {
914 unsigned x0_el, y0_el;
915 get_image_offset_el(surf, xfer->level, box.z, &x0_el, &y0_el);
916
917 for (uint32_t y = 0; y < box.height; y++) {
918 for (uint32_t x = 0; x < box.width; x++) {
919 ptrdiff_t offset = s8_offset(surf->row_pitch_B,
920 x0_el + box.x + x,
921 y0_el + box.y + y,
922 has_swizzling);
923 untiled_s8_map[s * xfer->layer_stride + y * xfer->stride + x] =
924 tiled_s8_map[offset];
925 }
926 }
927
928 box.z++;
929 }
930 }
931
932 map->unmap = iris_unmap_s8;
933 }
934
935 /* Compute extent parameters for use with tiled_memcpy functions.
936 * xs are in units of bytes and ys are in units of strides.
937 */
938 static inline void
939 tile_extents(struct isl_surf *surf,
940 const struct pipe_box *box,
941 unsigned level,
942 unsigned *x1_B, unsigned *x2_B,
943 unsigned *y1_el, unsigned *y2_el)
944 {
945 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
946 const unsigned cpp = fmtl->bpb / 8;
947
948 assert(box->x % fmtl->bw == 0);
949 assert(box->y % fmtl->bh == 0);
950
951 unsigned x0_el, y0_el;
952 get_image_offset_el(surf, level, box->z, &x0_el, &y0_el);
953
954 *x1_B = (box->x / fmtl->bw + x0_el) * cpp;
955 *y1_el = box->y / fmtl->bh + y0_el;
956 *x2_B = (DIV_ROUND_UP(box->x + box->width, fmtl->bw) + x0_el) * cpp;
957 *y2_el = DIV_ROUND_UP(box->y + box->height, fmtl->bh) + y0_el;
958 }
959
960 static void
961 iris_unmap_tiled_memcpy(struct iris_transfer *map)
962 {
963 struct pipe_transfer *xfer = &map->base;
964 struct pipe_box box = xfer->box;
965 struct iris_resource *res = (struct iris_resource *) xfer->resource;
966 struct isl_surf *surf = &res->surf;
967
968 const bool has_swizzling = false;
969
970 if (xfer->usage & PIPE_TRANSFER_WRITE) {
971 char *dst = iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
972
973 for (int s = 0; s < box.depth; s++) {
974 unsigned x1, x2, y1, y2;
975 tile_extents(surf, &box, xfer->level, &x1, &x2, &y1, &y2);
976
977 void *ptr = map->ptr + s * xfer->layer_stride;
978
979 isl_memcpy_linear_to_tiled(x1, x2, y1, y2, dst, ptr,
980 surf->row_pitch_B, xfer->stride,
981 has_swizzling, surf->tiling, ISL_MEMCPY);
982 box.z++;
983 }
984 }
985 os_free_aligned(map->buffer);
986 map->buffer = map->ptr = NULL;
987 }
988
989 static void
990 iris_map_tiled_memcpy(struct iris_transfer *map)
991 {
992 struct pipe_transfer *xfer = &map->base;
993 struct iris_resource *res = (struct iris_resource *) xfer->resource;
994 struct isl_surf *surf = &res->surf;
995
996 xfer->stride = ALIGN(surf->row_pitch_B, 16);
997 xfer->layer_stride = xfer->stride * xfer->box.height;
998
999 unsigned x1, x2, y1, y2;
1000 tile_extents(surf, &xfer->box, xfer->level, &x1, &x2, &y1, &y2);
1001
1002 /* The tiling and detiling functions require that the linear buffer has
1003 * a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
1004 * over-allocate the linear buffer to get the proper alignment.
1005 */
1006 map->buffer =
1007 os_malloc_aligned(xfer->layer_stride * xfer->box.depth, 16);
1008 assert(map->buffer);
1009 map->ptr = (char *)map->buffer + (x1 & 0xf);
1010
1011 const bool has_swizzling = false;
1012
1013 // XXX: PIPE_TRANSFER_READ?
1014 if (!(xfer->usage & PIPE_TRANSFER_DISCARD_RANGE)) {
1015 char *src = iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
1016
1017 struct pipe_box box = xfer->box;
1018
1019 for (int s = 0; s < box.depth; s++) {
1020 unsigned x1, x2, y1, y2;
1021 tile_extents(surf, &box, xfer->level, &x1, &x2, &y1, &y2);
1022
1023 /* Use 's' rather than 'box.z' to rebase the first slice to 0. */
1024 void *ptr = map->ptr + s * xfer->layer_stride;
1025
1026 isl_memcpy_tiled_to_linear(x1, x2, y1, y2, ptr, src, xfer->stride,
1027 surf->row_pitch_B, has_swizzling,
1028 surf->tiling, ISL_MEMCPY);
1029 box.z++;
1030 }
1031 }
1032
1033 map->unmap = iris_unmap_tiled_memcpy;
1034 }
1035
1036 static void
1037 iris_map_direct(struct iris_transfer *map)
1038 {
1039 struct pipe_transfer *xfer = &map->base;
1040 struct pipe_box *box = &xfer->box;
1041 struct iris_resource *res = (struct iris_resource *) xfer->resource;
1042
1043 void *ptr = iris_bo_map(map->dbg, res->bo, xfer->usage);
1044
1045 if (res->base.target == PIPE_BUFFER) {
1046 xfer->stride = 0;
1047 xfer->layer_stride = 0;
1048
1049 map->ptr = ptr + box->x;
1050 } else {
1051 struct isl_surf *surf = &res->surf;
1052 const struct isl_format_layout *fmtl =
1053 isl_format_get_layout(surf->format);
1054 const unsigned cpp = fmtl->bpb / 8;
1055 unsigned x0_el, y0_el;
1056
1057 get_image_offset_el(surf, xfer->level, box->z, &x0_el, &y0_el);
1058
1059 xfer->stride = isl_surf_get_row_pitch_B(surf);
1060 xfer->layer_stride = isl_surf_get_array_pitch(surf);
1061
1062 map->ptr = ptr + (y0_el + box->y) * xfer->stride + (x0_el + box->x) * cpp;
1063 }
1064 }
1065
1066 static void *
1067 iris_transfer_map(struct pipe_context *ctx,
1068 struct pipe_resource *resource,
1069 unsigned level,
1070 enum pipe_transfer_usage usage,
1071 const struct pipe_box *box,
1072 struct pipe_transfer **ptransfer)
1073 {
1074 struct iris_context *ice = (struct iris_context *)ctx;
1075 struct iris_resource *res = (struct iris_resource *)resource;
1076 struct isl_surf *surf = &res->surf;
1077
1078 /* If we can discard the whole resource, we can also discard the
1079 * subrange being accessed.
1080 */
1081 if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE)
1082 usage |= PIPE_TRANSFER_DISCARD_RANGE;
1083
1084 if (surf->tiling != ISL_TILING_LINEAR &&
1085 (usage & PIPE_TRANSFER_MAP_DIRECTLY))
1086 return NULL;
1087
1088 if (resource->target != PIPE_BUFFER) {
1089 iris_resource_access_raw(ice, &ice->batches[IRIS_BATCH_RENDER], res,
1090 level, box->z, box->depth,
1091 usage & PIPE_TRANSFER_WRITE);
1092 }
1093
1094 if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
1095 for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
1096 if (iris_batch_references(&ice->batches[i], res->bo))
1097 iris_batch_flush(&ice->batches[i]);
1098 }
1099 }
1100
1101 if ((usage & PIPE_TRANSFER_DONTBLOCK) && iris_bo_busy(res->bo))
1102 return NULL;
1103
1104 struct iris_transfer *map = slab_alloc(&ice->transfer_pool);
1105 struct pipe_transfer *xfer = &map->base;
1106
1107 if (!map)
1108 return NULL;
1109
1110 memset(map, 0, sizeof(*map));
1111 map->dbg = &ice->dbg;
1112
1113 pipe_resource_reference(&xfer->resource, resource);
1114 xfer->level = level;
1115 xfer->usage = usage;
1116 xfer->box = *box;
1117 *ptransfer = xfer;
1118
1119 xfer->usage &= (PIPE_TRANSFER_READ |
1120 PIPE_TRANSFER_WRITE |
1121 PIPE_TRANSFER_UNSYNCHRONIZED |
1122 PIPE_TRANSFER_PERSISTENT |
1123 PIPE_TRANSFER_COHERENT |
1124 PIPE_TRANSFER_DISCARD_RANGE);
1125
1126 if (surf->tiling == ISL_TILING_W) {
1127 // XXX: just teach iris_map_tiled_memcpy about W tiling...
1128 iris_map_s8(map);
1129 } else if (surf->tiling != ISL_TILING_LINEAR) {
1130 iris_map_tiled_memcpy(map);
1131 } else {
1132 iris_map_direct(map);
1133 }
1134
1135 return map->ptr;
1136 }
1137
1138 static void
1139 iris_transfer_flush_region(struct pipe_context *ctx,
1140 struct pipe_transfer *xfer,
1141 const struct pipe_box *box)
1142 {
1143 struct iris_context *ice = (struct iris_context *)ctx;
1144 struct iris_resource *res = (struct iris_resource *) xfer->resource;
1145
1146
1147 // XXX: don't emit flushes in both engines...? we may also need to flush
1148 // even if there isn't a draw yet - may still be stale data in caches...
1149 for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
1150 if (ice->batches[i].contains_draw) {
1151 iris_batch_maybe_flush(&ice->batches[i], 24);
1152 iris_flush_and_dirty_for_history(ice, &ice->batches[i], res);
1153 }
1154 }
1155 }
1156
1157 static void
1158 iris_transfer_unmap(struct pipe_context *ctx, struct pipe_transfer *xfer)
1159 {
1160 struct iris_context *ice = (struct iris_context *)ctx;
1161 struct iris_transfer *map = (void *) xfer;
1162 struct iris_resource *res = (struct iris_resource *) xfer->resource;
1163
1164 if (map->unmap)
1165 map->unmap(map);
1166
1167 // XXX: don't emit flushes in both engines...?
1168 for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
1169 if (ice->batches[i].contains_draw) {
1170 iris_batch_maybe_flush(&ice->batches[i], 24);
1171 iris_flush_and_dirty_for_history(ice, &ice->batches[i], res);
1172 }
1173 }
1174
1175 pipe_resource_reference(&xfer->resource, NULL);
1176 slab_free(&ice->transfer_pool, map);
1177 }
1178
1179 static void
1180 iris_flush_resource(struct pipe_context *ctx, struct pipe_resource *resource)
1181 {
1182 }
1183
1184 void
1185 iris_flush_and_dirty_for_history(struct iris_context *ice,
1186 struct iris_batch *batch,
1187 struct iris_resource *res)
1188 {
1189 if (res->base.target != PIPE_BUFFER)
1190 return;
1191
1192 unsigned flush = PIPE_CONTROL_CS_STALL;
1193
1194 /* We've likely used the rendering engine (i.e. BLORP) to write to this
1195 * surface. Flush the render cache so the data actually lands.
1196 */
1197 if (batch->name != IRIS_BATCH_COMPUTE)
1198 flush |= PIPE_CONTROL_RENDER_TARGET_FLUSH;
1199
1200 uint64_t dirty = 0ull;
1201
1202 if (res->bind_history & PIPE_BIND_CONSTANT_BUFFER) {
1203 flush |= PIPE_CONTROL_CONST_CACHE_INVALIDATE |
1204 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE;
1205 dirty |= IRIS_DIRTY_CONSTANTS_VS |
1206 IRIS_DIRTY_CONSTANTS_TCS |
1207 IRIS_DIRTY_CONSTANTS_TES |
1208 IRIS_DIRTY_CONSTANTS_GS |
1209 IRIS_DIRTY_CONSTANTS_FS |
1210 IRIS_DIRTY_CONSTANTS_CS |
1211 IRIS_ALL_DIRTY_BINDINGS;
1212 }
1213
1214 if (res->bind_history & PIPE_BIND_SAMPLER_VIEW)
1215 flush |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE;
1216
1217 if (res->bind_history & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER))
1218 flush |= PIPE_CONTROL_VF_CACHE_INVALIDATE;
1219
1220 if (res->bind_history & (PIPE_BIND_SHADER_BUFFER | PIPE_BIND_SHADER_IMAGE))
1221 flush |= PIPE_CONTROL_DATA_CACHE_FLUSH;
1222
1223 iris_emit_pipe_control_flush(batch, flush);
1224
1225 ice->state.dirty |= dirty;
1226 }
1227
1228 static enum pipe_format
1229 iris_resource_get_internal_format(struct pipe_resource *p_res)
1230 {
1231 struct iris_resource *res = (void *) p_res;
1232 return res->internal_format;
1233 }
1234
1235 static const struct u_transfer_vtbl transfer_vtbl = {
1236 .resource_create = iris_resource_create,
1237 .resource_destroy = iris_resource_destroy,
1238 .transfer_map = iris_transfer_map,
1239 .transfer_unmap = iris_transfer_unmap,
1240 .transfer_flush_region = iris_transfer_flush_region,
1241 .get_internal_format = iris_resource_get_internal_format,
1242 .set_stencil = iris_resource_set_separate_stencil,
1243 .get_stencil = iris_resource_get_separate_stencil,
1244 };
1245
1246 void
1247 iris_init_screen_resource_functions(struct pipe_screen *pscreen)
1248 {
1249 pscreen->resource_create_with_modifiers =
1250 iris_resource_create_with_modifiers;
1251 pscreen->resource_create = u_transfer_helper_resource_create;
1252 pscreen->resource_from_user_memory = iris_resource_from_user_memory;
1253 pscreen->resource_from_handle = iris_resource_from_handle;
1254 pscreen->resource_get_handle = iris_resource_get_handle;
1255 pscreen->resource_destroy = u_transfer_helper_resource_destroy;
1256 pscreen->transfer_helper =
1257 u_transfer_helper_create(&transfer_vtbl, true, true, false, true);
1258 }
1259
1260 void
1261 iris_init_resource_functions(struct pipe_context *ctx)
1262 {
1263 ctx->flush_resource = iris_flush_resource;
1264 ctx->transfer_map = u_transfer_helper_transfer_map;
1265 ctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
1266 ctx->transfer_unmap = u_transfer_helper_transfer_unmap;
1267 ctx->buffer_subdata = u_default_buffer_subdata;
1268 ctx->texture_subdata = u_default_texture_subdata;
1269 }