1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
30 * Michel Dänzer <michel@tungstengraphics.com>
33 #include "pipe/p_state.h"
34 #include "pipe/p_context.h"
35 #include "pipe/p_defines.h"
36 #include "util/u_inlines.h"
37 #include "util/u_format.h"
38 #include "util/u_math.h"
39 #include "util/u_memory.h"
41 #include "i915_context.h"
42 #include "i915_resource.h"
43 #include "i915_screen.h"
44 #include "i915_winsys.h"
45 #include "i915_debug.h"
48 #define DEBUG_TEXTURES 0
51 * Helper function and arrays
56 * Initial offset for Cube map.
58 static const int initial_offsets
[6][2] = {
59 [PIPE_TEX_FACE_POS_X
] = {0, 0},
60 [PIPE_TEX_FACE_POS_Y
] = {1, 0},
61 [PIPE_TEX_FACE_POS_Z
] = {1, 1},
62 [PIPE_TEX_FACE_NEG_X
] = {0, 2},
63 [PIPE_TEX_FACE_NEG_Y
] = {1, 2},
64 [PIPE_TEX_FACE_NEG_Z
] = {1, 3},
68 * Step offsets for Cube map.
70 static const int step_offsets
[6][2] = {
71 [PIPE_TEX_FACE_POS_X
] = { 0, 2},
72 [PIPE_TEX_FACE_POS_Y
] = {-1, 2},
73 [PIPE_TEX_FACE_POS_Z
] = {-1, 1},
74 [PIPE_TEX_FACE_NEG_X
] = { 0, 2},
75 [PIPE_TEX_FACE_NEG_Y
] = {-1, 2},
76 [PIPE_TEX_FACE_NEG_Z
] = {-1, 1},
80 * For compressed level 2
82 static const int bottom_offsets
[6] = {
83 [PIPE_TEX_FACE_POS_X
] = 16 + 0 * 8,
84 [PIPE_TEX_FACE_POS_Y
] = 16 + 1 * 8,
85 [PIPE_TEX_FACE_POS_Z
] = 16 + 2 * 8,
86 [PIPE_TEX_FACE_NEG_X
] = 16 + 3 * 8,
87 [PIPE_TEX_FACE_NEG_Y
] = 16 + 4 * 8,
88 [PIPE_TEX_FACE_NEG_Z
] = 16 + 5 * 8,
91 static INLINE
unsigned
92 align_nblocksx(enum pipe_format format
, unsigned width
, unsigned align_to
)
94 return align(util_format_get_nblocksx(format
, width
), align_to
);
97 static INLINE
unsigned
98 align_nblocksy(enum pipe_format format
, unsigned width
, unsigned align_to
)
100 return align(util_format_get_nblocksy(format
, width
), align_to
);
103 static INLINE
unsigned
104 get_pot_stride(enum pipe_format format
, unsigned width
)
106 return util_next_power_of_two(util_format_get_stride(format
, width
));
110 * More advanced helper funcs
115 i915_texture_set_level_info(struct i915_texture
*tex
,
116 unsigned level
, unsigned nr_images
)
118 assert(level
< Elements(tex
->nr_images
));
120 assert(!tex
->image_offset
[level
]);
122 tex
->nr_images
[level
] = nr_images
;
123 tex
->image_offset
[level
] = (unsigned *) MALLOC(nr_images
* sizeof(unsigned));
124 tex
->image_offset
[level
][0] = 0;
128 i915_texture_set_image_offset(struct i915_texture
*tex
,
129 unsigned level
, unsigned img
,
130 unsigned x
, unsigned y
)
132 /* for the first image and level make sure offset is zero */
133 assert(!(img
== 0 && level
== 0) || (x
== 0 && y
== 0));
134 assert(img
< tex
->nr_images
[level
]);
136 tex
->image_offset
[level
][img
] = y
* tex
->stride
+ x
* util_format_get_blocksize(tex
->b
.b
.format
);
139 debug_printf("%s: %p level %u, img %u (%u, %u) %p\n", __FUNCTION__
,
140 tex
, level
, img
, x
, y
,
141 (void*)(uintptr_t)tex
->image_offset
[level
][img
]);
147 * Shared layout functions
152 * Special case to deal with scanout textures.
155 i9x5_scanout_layout(struct i915_texture
*tex
)
157 struct pipe_resource
*pt
= &tex
->b
.b
;
159 if (pt
->last_level
> 0 || util_format_get_blocksize(pt
->format
) != 4)
162 i915_texture_set_level_info(tex
, 0, 1);
163 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
165 if (pt
->width0
>= 240) {
166 tex
->stride
= get_pot_stride(pt
->format
, pt
->width0
);
167 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
168 tex
->hw_tiled
= I915_TILE_X
;
169 } else if (pt
->width0
== 64 && pt
->height0
== 64) {
170 tex
->stride
= get_pot_stride(pt
->format
, pt
->width0
);
171 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
177 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
178 pt
->width0
, pt
->height0
, util_format_get_blocksize(pt
->format
),
179 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
186 * Special case to deal with shared textures.
189 i9x5_display_target_layout(struct i915_texture
*tex
)
191 struct pipe_resource
*pt
= &tex
->b
.b
;
193 if (pt
->last_level
> 0 || util_format_get_blocksize(pt
->format
) != 4)
196 /* fallback to normal textures for small textures */
197 if (pt
->width0
< 240)
200 i915_texture_set_level_info(tex
, 0, 1);
201 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
203 tex
->stride
= get_pot_stride(pt
->format
, pt
->width0
);
204 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
205 tex
->hw_tiled
= I915_TILE_X
;
208 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
209 pt
->width0
, pt
->height0
, util_format_get_blocksize(pt
->format
),
210 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
217 * Helper function for special layouts
220 i9x5_special_layout(struct i915_texture
*tex
)
222 struct pipe_resource
*pt
= &tex
->b
.b
;
224 /* Scanouts needs special care */
225 if (pt
->bind
& PIPE_BIND_SCANOUT
)
226 if (i9x5_scanout_layout(tex
))
229 /* Shared buffers needs to be compatible with X servers
231 * XXX: need a better name than shared for this if it is to be part
232 * of core gallium, and probably move the flag to resource.flags,
233 * rather than bindings.
235 if (pt
->bind
& (PIPE_BIND_SHARED
| PIPE_BIND_DISPLAY_TARGET
))
236 if (i9x5_display_target_layout(tex
))
243 * Cube layout used on i915 and for non-compressed textures on i945.
246 i9x5_texture_layout_cube(struct i915_texture
*tex
)
248 struct pipe_resource
*pt
= &tex
->b
.b
;
249 const unsigned nblocks
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
253 assert(pt
->width0
== pt
->height0
); /* cubemap images are square */
255 /* double pitch for cube layouts */
256 tex
->stride
= align(nblocks
* util_format_get_blocksize(pt
->format
) * 2, 4);
257 tex
->total_nblocksy
= nblocks
* 4;
259 for (level
= 0; level
<= pt
->last_level
; level
++)
260 i915_texture_set_level_info(tex
, level
, 6);
262 for (face
= 0; face
< 6; face
++) {
263 unsigned x
= initial_offsets
[face
][0] * nblocks
;
264 unsigned y
= initial_offsets
[face
][1] * nblocks
;
265 unsigned d
= nblocks
;
267 for (level
= 0; level
<= pt
->last_level
; level
++) {
268 i915_texture_set_image_offset(tex
, level
, face
, x
, y
);
270 x
+= step_offsets
[face
][0] * d
;
271 y
+= step_offsets
[face
][1] * d
;
278 * i915 layout functions
283 i915_texture_layout_2d(struct i915_texture
*tex
)
285 struct pipe_resource
*pt
= &tex
->b
.b
;
287 unsigned width
= pt
->width0
;
288 unsigned height
= pt
->height0
;
289 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->width0
);
290 unsigned align_y
= 2;
292 if (util_format_is_s3tc(pt
->format
))
295 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
296 tex
->total_nblocksy
= 0;
298 for (level
= 0; level
<= pt
->last_level
; level
++) {
299 i915_texture_set_level_info(tex
, level
, 1);
300 i915_texture_set_image_offset(tex
, level
, 0, 0, tex
->total_nblocksy
);
302 tex
->total_nblocksy
+= nblocksy
;
304 width
= u_minify(width
, 1);
305 height
= u_minify(height
, 1);
306 nblocksy
= align_nblocksy(pt
->format
, height
, align_y
);
311 i915_texture_layout_3d(struct i915_texture
*tex
)
313 struct pipe_resource
*pt
= &tex
->b
.b
;
316 unsigned width
= pt
->width0
;
317 unsigned height
= pt
->height0
;
318 unsigned depth
= pt
->depth0
;
319 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->height0
);
320 unsigned stack_nblocksy
= 0;
322 /* Calculate the size of a single slice.
324 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
326 /* XXX: hardware expects/requires 9 levels at minimum.
328 for (level
= 0; level
<= MAX2(8, pt
->last_level
); level
++) {
329 i915_texture_set_level_info(tex
, level
, depth
);
331 stack_nblocksy
+= MAX2(2, nblocksy
);
333 width
= u_minify(width
, 1);
334 height
= u_minify(height
, 1);
335 nblocksy
= util_format_get_nblocksy(pt
->format
, height
);
338 /* Fixup depth image_offsets:
340 for (level
= 0; level
<= pt
->last_level
; level
++) {
342 for (i
= 0; i
< depth
; i
++)
343 i915_texture_set_image_offset(tex
, level
, i
, 0, i
* stack_nblocksy
);
345 depth
= u_minify(depth
, 1);
348 /* Multiply slice size by texture depth for total size. It's
349 * remarkable how wasteful of memory the i915 texture layouts
350 * are. They are largely fixed in the i945.
352 tex
->total_nblocksy
= stack_nblocksy
* pt
->depth0
;
356 i915_texture_layout(struct i915_texture
* tex
)
358 struct pipe_resource
*pt
= &tex
->b
.b
;
360 switch (pt
->target
) {
361 case PIPE_TEXTURE_1D
:
362 case PIPE_TEXTURE_2D
:
363 if (!i9x5_special_layout(tex
))
364 i915_texture_layout_2d(tex
);
366 case PIPE_TEXTURE_3D
:
367 i915_texture_layout_3d(tex
);
369 case PIPE_TEXTURE_CUBE
:
370 i9x5_texture_layout_cube(tex
);
382 * i945 layout functions
387 i945_texture_layout_2d(struct i915_texture
*tex
)
389 struct pipe_resource
*pt
= &tex
->b
.b
;
390 int align_x
= 4, align_y
= 2;
394 unsigned width
= pt
->width0
;
395 unsigned height
= pt
->height0
;
396 unsigned nblocksx
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
397 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->height0
);
399 if (util_format_is_s3tc(pt
->format
)) {
404 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
406 /* May need to adjust pitch to accomodate the placement of
407 * the 2nd mipmap level. This occurs when the alignment
408 * constraints of mipmap placement push the right edge of the
409 * 2nd mipmap level out past the width of its parent.
411 if (pt
->last_level
> 0) {
412 unsigned mip1_nblocksx
=
413 align_nblocksx(pt
->format
, u_minify(pt
->width0
, 1), align_x
) +
414 util_format_get_nblocksx(pt
->format
, u_minify(pt
->width0
, 2));
416 if (mip1_nblocksx
> nblocksx
)
417 tex
->stride
= mip1_nblocksx
* util_format_get_blocksize(pt
->format
);
420 /* Pitch must be a whole number of dwords
422 tex
->stride
= align(tex
->stride
, 64);
423 tex
->total_nblocksy
= 0;
425 for (level
= 0; level
<= pt
->last_level
; level
++) {
426 i915_texture_set_level_info(tex
, level
, 1);
427 i915_texture_set_image_offset(tex
, level
, 0, x
, y
);
429 /* Because the images are packed better, the final offset
430 * might not be the maximal one:
432 tex
->total_nblocksy
= MAX2(tex
->total_nblocksy
, y
+ nblocksy
);
434 /* Layout_below: step right after second mipmap level.
442 width
= u_minify(width
, 1);
443 height
= u_minify(height
, 1);
444 nblocksx
= align_nblocksx(pt
->format
, width
, align_x
);
445 nblocksy
= align_nblocksy(pt
->format
, height
, align_y
);
450 i945_texture_layout_3d(struct i915_texture
*tex
)
452 struct pipe_resource
*pt
= &tex
->b
.b
;
453 unsigned width
= pt
->width0
;
454 unsigned height
= pt
->height0
;
455 unsigned depth
= pt
->depth0
;
456 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->width0
);
457 unsigned pack_x_pitch
, pack_x_nr
;
458 unsigned pack_y_pitch
;
461 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
462 tex
->total_nblocksy
= 0;
464 pack_y_pitch
= MAX2(nblocksy
, 2);
465 pack_x_pitch
= tex
->stride
/ util_format_get_blocksize(pt
->format
);
468 for (level
= 0; level
<= pt
->last_level
; level
++) {
473 i915_texture_set_level_info(tex
, level
, depth
);
475 for (q
= 0; q
< depth
;) {
476 for (j
= 0; j
< pack_x_nr
&& q
< depth
; j
++, q
++) {
477 i915_texture_set_image_offset(tex
, level
, q
, x
, y
+ tex
->total_nblocksy
);
485 tex
->total_nblocksy
+= y
;
487 if (pack_x_pitch
> 4) {
490 assert(pack_x_pitch
* pack_x_nr
* util_format_get_blocksize(pt
->format
) <= tex
->stride
);
493 if (pack_y_pitch
> 2) {
497 width
= u_minify(width
, 1);
498 height
= u_minify(height
, 1);
499 depth
= u_minify(depth
, 1);
500 nblocksy
= util_format_get_nblocksy(pt
->format
, height
);
505 i945_texture_layout_cube(struct i915_texture
*tex
)
507 struct pipe_resource
*pt
= &tex
->b
.b
;
508 const unsigned nblocks
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
509 const unsigned dim
= pt
->width0
;
513 assert(pt
->width0
== pt
->height0
); /* cubemap images are square */
514 assert(util_next_power_of_two(pt
->width0
) == pt
->width0
); /* npot only */
515 assert(util_format_is_s3tc(pt
->format
)); /* compressed only */
518 * Depending on the size of the largest images, pitch can be
519 * determined either by the old-style packing of cubemap faces,
520 * or the final row of 4x4, 2x2 and 1x1 faces below this.
525 if (pt
->width0
>= 64)
526 tex
->stride
= nblocks
* 2 * util_format_get_blocksize(pt
->format
);
528 tex
->stride
= 14 * 2 * util_format_get_blocksize(pt
->format
);
531 * Something similary apply for height as well.
534 tex
->total_nblocksy
= nblocks
* 4 + 1;
536 tex
->total_nblocksy
= 1;
538 /* Set all the levels to effectively occupy the whole rectangular region */
539 for (level
= 0; level
<= pt
->last_level
; level
++)
540 i915_texture_set_level_info(tex
, level
, 6);
542 for (face
= 0; face
< 6; face
++) {
543 /* all calculations in pixels */
544 unsigned total_height
= tex
->total_nblocksy
* 4;
545 unsigned x
= initial_offsets
[face
][0] * dim
;
546 unsigned y
= initial_offsets
[face
][1] * dim
;
549 if (dim
== 4 && face
>= 4) {
551 y
= tex
->total_nblocksy
* 4 - 4; /* 4 = 1 block */
552 } else if (dim
< 4 && (face
> 0)) {
554 y
= total_height
- 4;
557 for (level
= 0; level
<= pt
->last_level
; level
++) {
558 i915_texture_set_image_offset(tex
, level
, face
,
559 util_format_get_nblocksx(pt
->format
, x
),
560 util_format_get_nblocksy(pt
->format
, y
));
567 case PIPE_TEX_FACE_POS_X
:
568 case PIPE_TEX_FACE_NEG_X
:
569 x
+= step_offsets
[face
][0] * d
;
570 y
+= step_offsets
[face
][1] * d
;
572 case PIPE_TEX_FACE_POS_Y
:
573 case PIPE_TEX_FACE_NEG_Y
:
577 case PIPE_TEX_FACE_POS_Z
:
578 case PIPE_TEX_FACE_NEG_Z
:
579 y
= total_height
- 4;
585 y
= total_height
- 4;
586 x
= bottom_offsets
[face
];
592 x
+= step_offsets
[face
][0] * d
;
593 y
+= step_offsets
[face
][1] * d
;
601 i945_texture_layout(struct i915_texture
* tex
)
603 struct pipe_resource
*pt
= &tex
->b
.b
;
605 switch (pt
->target
) {
606 case PIPE_TEXTURE_1D
:
607 case PIPE_TEXTURE_2D
:
608 if (!i9x5_special_layout(tex
))
609 i945_texture_layout_2d(tex
);
611 case PIPE_TEXTURE_3D
:
612 i945_texture_layout_3d(tex
);
614 case PIPE_TEXTURE_CUBE
:
615 if (!util_format_is_s3tc(pt
->format
))
616 i9x5_texture_layout_cube(tex
);
618 i945_texture_layout_cube(tex
);
631 * Screen texture functions
637 i915_texture_get_handle(struct pipe_screen
* screen
,
638 struct pipe_resource
*texture
,
639 struct winsys_handle
*whandle
)
641 struct i915_screen
*is
= i915_screen(screen
);
642 struct i915_texture
*tex
= i915_texture(texture
);
643 struct i915_winsys
*iws
= is
->iws
;
645 return iws
->buffer_get_handle(iws
, tex
->buffer
, whandle
, tex
->stride
);
650 i915_texture_destroy(struct pipe_screen
*screen
,
651 struct pipe_resource
*pt
)
653 struct i915_texture
*tex
= i915_texture(pt
);
654 struct i915_winsys
*iws
= i915_screen(screen
)->iws
;
657 iws
->buffer_destroy(iws
, tex
->buffer
);
659 for (i
= 0; i
< Elements(tex
->image_offset
); i
++)
660 if (tex
->image_offset
[i
])
661 FREE(tex
->image_offset
[i
]);
666 static struct pipe_transfer
*
667 i915_texture_get_transfer(struct pipe_context
*context
,
668 struct pipe_resource
*resource
,
669 struct pipe_subresource sr
,
671 const struct pipe_box
*box
)
673 struct i915_texture
*tex
= i915_texture(resource
);
674 struct pipe_transfer
*transfer
= CALLOC_STRUCT(pipe_transfer
);
675 if (transfer
== NULL
)
678 transfer
->resource
= resource
;
680 transfer
->usage
= usage
;
681 transfer
->box
= *box
;
682 transfer
->stride
= tex
->stride
;
689 i915_texture_transfer_map(struct pipe_context
*pipe
,
690 struct pipe_transfer
*transfer
)
692 struct pipe_resource
*resource
= transfer
->resource
;
693 struct i915_texture
*tex
= i915_texture(resource
);
694 struct i915_winsys
*iws
= i915_screen(pipe
->screen
)->iws
;
695 struct pipe_subresource sr
= transfer
->sr
;
696 struct pipe_box
*box
= &transfer
->box
;
697 enum pipe_format format
= resource
->format
;
701 if (resource
->target
== PIPE_TEXTURE_CUBE
) {
702 offset
= tex
->image_offset
[sr
.level
][sr
.face
];
703 } else if (resource
->target
== PIPE_TEXTURE_3D
) {
704 offset
= tex
->image_offset
[sr
.level
][box
->z
];
706 offset
= tex
->image_offset
[sr
.level
][0];
707 assert(sr
.face
== 0);
711 map
= iws
->buffer_map(iws
, tex
->buffer
,
712 (transfer
->usage
& PIPE_TRANSFER_WRITE
) ? TRUE
: FALSE
);
716 return map
+ offset
+
717 box
->y
/ util_format_get_blockheight(format
) * transfer
->stride
+
718 box
->x
/ util_format_get_blockwidth(format
) * util_format_get_blocksize(format
);
722 i915_texture_transfer_unmap(struct pipe_context
*pipe
,
723 struct pipe_transfer
*transfer
)
725 struct i915_texture
*tex
= i915_texture(transfer
->resource
);
726 struct i915_winsys
*iws
= i915_screen(tex
->b
.b
.screen
)->iws
;
727 iws
->buffer_unmap(iws
, tex
->buffer
);
732 struct u_resource_vtbl i915_texture_vtbl
=
734 i915_texture_get_handle
, /* get_handle */
735 i915_texture_destroy
, /* resource_destroy */
736 NULL
, /* is_resource_referenced */
737 i915_texture_get_transfer
, /* get_transfer */
738 u_default_transfer_destroy
, /* transfer_destroy */
739 i915_texture_transfer_map
, /* transfer_map */
740 u_default_transfer_flush_region
, /* transfer_flush_region */
741 i915_texture_transfer_unmap
, /* transfer_unmap */
742 u_default_transfer_inline_write
/* transfer_inline_write */
748 struct pipe_resource
*
749 i915_texture_create(struct pipe_screen
*screen
,
750 const struct pipe_resource
*template)
752 struct i915_screen
*is
= i915_screen(screen
);
753 struct i915_winsys
*iws
= is
->iws
;
754 struct i915_texture
*tex
= CALLOC_STRUCT(i915_texture
);
756 unsigned buf_usage
= 0;
761 tex
->b
.b
= *template;
762 tex
->b
.vtbl
= &i915_texture_vtbl
;
763 pipe_reference_init(&tex
->b
.b
.reference
, 1);
764 tex
->b
.b
.screen
= screen
;
767 if (!i945_texture_layout(tex
))
770 if (!i915_texture_layout(tex
))
774 tex_size
= tex
->stride
* tex
->total_nblocksy
;
776 /* for scanouts and cursors, cursors arn't scanouts */
778 /* XXX: use a custom flag for cursors, don't rely on magically
779 * guessing that this is Xorg asking for a cursor
781 if ((template->bind
& PIPE_BIND_SCANOUT
) && template->width0
!= 64)
782 buf_usage
= I915_NEW_SCANOUT
;
784 buf_usage
= I915_NEW_TEXTURE
;
786 tex
->buffer
= iws
->buffer_create(iws
, tex_size
, 64, buf_usage
);
790 /* setup any hw fences */
792 assert(tex
->sw_tiled
== I915_TILE_NONE
);
793 iws
->buffer_set_fence_reg(iws
, tex
->buffer
, tex
->stride
, tex
->hw_tiled
);
798 void *ptr
= ws
->buffer_map(ws
, tex
->buffer
,
799 PIPE_BUFFER_USAGE_CPU_WRITE
);
800 memset(ptr
, 0x80, tex_size
);
801 ws
->buffer_unmap(ws
, tex
->buffer
);
804 I915_DBG(DBG_TEXTURE
, "%s: %p size %u, stride %u, blocks (%u, %u)\n", __func__
,
805 tex
, (unsigned int)tex_size
, tex
->stride
,
806 tex
->stride
/ util_format_get_blocksize(tex
->b
.b
.format
),
807 tex
->total_nblocksy
);
816 struct pipe_resource
*
817 i915_texture_from_handle(struct pipe_screen
* screen
,
818 const struct pipe_resource
*template,
819 struct winsys_handle
*whandle
)
821 struct i915_screen
*is
= i915_screen(screen
);
822 struct i915_texture
*tex
;
823 struct i915_winsys
*iws
= is
->iws
;
824 struct i915_winsys_buffer
*buffer
;
829 buffer
= iws
->buffer_from_handle(iws
, whandle
, &stride
);
831 /* Only supports one type */
832 if (template->target
!= PIPE_TEXTURE_2D
||
833 template->last_level
!= 0 ||
834 template->depth0
!= 1) {
838 tex
= CALLOC_STRUCT(i915_texture
);
842 tex
->b
.b
= *template;
843 tex
->b
.vtbl
= &i915_texture_vtbl
;
844 pipe_reference_init(&tex
->b
.b
.reference
, 1);
845 tex
->b
.b
.screen
= screen
;
847 tex
->stride
= stride
;
849 i915_texture_set_level_info(tex
, 0, 1);
850 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
852 tex
->buffer
= buffer
;
854 I915_DBG(DBG_TEXTURE
, "%s: %p stride %u, blocks (%ux%u)\n", __func__
,
856 tex
->stride
/ util_format_get_blocksize(tex
->b
.b
.format
),
857 tex
->total_nblocksy
);