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