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
->tiling
= 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
->tiling
= 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 case PIPE_TEXTURE_RECT
:
364 if (!i9x5_special_layout(tex
))
365 i915_texture_layout_2d(tex
);
367 case PIPE_TEXTURE_3D
:
368 i915_texture_layout_3d(tex
);
370 case PIPE_TEXTURE_CUBE
:
371 i9x5_texture_layout_cube(tex
);
383 * i945 layout functions
388 i945_texture_layout_2d(struct i915_texture
*tex
)
390 struct pipe_resource
*pt
= &tex
->b
.b
;
391 int align_x
= 4, align_y
= 2;
395 unsigned width
= pt
->width0
;
396 unsigned height
= pt
->height0
;
397 unsigned nblocksx
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
398 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->height0
);
400 if (util_format_is_s3tc(pt
->format
)) {
405 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
407 /* May need to adjust pitch to accomodate the placement of
408 * the 2nd mipmap level. This occurs when the alignment
409 * constraints of mipmap placement push the right edge of the
410 * 2nd mipmap level out past the width of its parent.
412 if (pt
->last_level
> 0) {
413 unsigned mip1_nblocksx
=
414 align_nblocksx(pt
->format
, u_minify(pt
->width0
, 1), align_x
) +
415 util_format_get_nblocksx(pt
->format
, u_minify(pt
->width0
, 2));
417 if (mip1_nblocksx
> nblocksx
)
418 tex
->stride
= mip1_nblocksx
* util_format_get_blocksize(pt
->format
);
421 /* Pitch must be a whole number of dwords
423 tex
->stride
= align(tex
->stride
, 64);
424 tex
->total_nblocksy
= 0;
426 for (level
= 0; level
<= pt
->last_level
; level
++) {
427 i915_texture_set_level_info(tex
, level
, 1);
428 i915_texture_set_image_offset(tex
, level
, 0, x
, y
);
430 /* Because the images are packed better, the final offset
431 * might not be the maximal one:
433 tex
->total_nblocksy
= MAX2(tex
->total_nblocksy
, y
+ nblocksy
);
435 /* Layout_below: step right after second mipmap level.
443 width
= u_minify(width
, 1);
444 height
= u_minify(height
, 1);
445 nblocksx
= align_nblocksx(pt
->format
, width
, align_x
);
446 nblocksy
= align_nblocksy(pt
->format
, height
, align_y
);
451 i945_texture_layout_3d(struct i915_texture
*tex
)
453 struct pipe_resource
*pt
= &tex
->b
.b
;
454 unsigned width
= pt
->width0
;
455 unsigned height
= pt
->height0
;
456 unsigned depth
= pt
->depth0
;
457 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->width0
);
458 unsigned pack_x_pitch
, pack_x_nr
;
459 unsigned pack_y_pitch
;
462 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
463 tex
->total_nblocksy
= 0;
465 pack_y_pitch
= MAX2(nblocksy
, 2);
466 pack_x_pitch
= tex
->stride
/ util_format_get_blocksize(pt
->format
);
469 for (level
= 0; level
<= pt
->last_level
; level
++) {
474 i915_texture_set_level_info(tex
, level
, depth
);
476 for (q
= 0; q
< depth
;) {
477 for (j
= 0; j
< pack_x_nr
&& q
< depth
; j
++, q
++) {
478 i915_texture_set_image_offset(tex
, level
, q
, x
, y
+ tex
->total_nblocksy
);
486 tex
->total_nblocksy
+= y
;
488 if (pack_x_pitch
> 4) {
491 assert(pack_x_pitch
* pack_x_nr
* util_format_get_blocksize(pt
->format
) <= tex
->stride
);
494 if (pack_y_pitch
> 2) {
498 width
= u_minify(width
, 1);
499 height
= u_minify(height
, 1);
500 depth
= u_minify(depth
, 1);
501 nblocksy
= util_format_get_nblocksy(pt
->format
, height
);
506 i945_texture_layout_cube(struct i915_texture
*tex
)
508 struct pipe_resource
*pt
= &tex
->b
.b
;
509 const unsigned nblocks
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
510 const unsigned dim
= pt
->width0
;
514 assert(pt
->width0
== pt
->height0
); /* cubemap images are square */
515 assert(util_next_power_of_two(pt
->width0
) == pt
->width0
); /* npot only */
516 assert(util_format_is_s3tc(pt
->format
)); /* compressed only */
519 * Depending on the size of the largest images, pitch can be
520 * determined either by the old-style packing of cubemap faces,
521 * or the final row of 4x4, 2x2 and 1x1 faces below this.
526 if (pt
->width0
>= 64)
527 tex
->stride
= nblocks
* 2 * util_format_get_blocksize(pt
->format
);
529 tex
->stride
= 14 * 2 * util_format_get_blocksize(pt
->format
);
532 * Something similary apply for height as well.
535 tex
->total_nblocksy
= nblocks
* 4 + 1;
537 tex
->total_nblocksy
= 1;
539 /* Set all the levels to effectively occupy the whole rectangular region */
540 for (level
= 0; level
<= pt
->last_level
; level
++)
541 i915_texture_set_level_info(tex
, level
, 6);
543 for (face
= 0; face
< 6; face
++) {
544 /* all calculations in pixels */
545 unsigned total_height
= tex
->total_nblocksy
* 4;
546 unsigned x
= initial_offsets
[face
][0] * dim
;
547 unsigned y
= initial_offsets
[face
][1] * dim
;
550 if (dim
== 4 && face
>= 4) {
552 y
= tex
->total_nblocksy
* 4 - 4; /* 4 = 1 block */
553 } else if (dim
< 4 && (face
> 0)) {
555 y
= total_height
- 4;
558 for (level
= 0; level
<= pt
->last_level
; level
++) {
559 i915_texture_set_image_offset(tex
, level
, face
,
560 util_format_get_nblocksx(pt
->format
, x
),
561 util_format_get_nblocksy(pt
->format
, y
));
568 case PIPE_TEX_FACE_POS_X
:
569 case PIPE_TEX_FACE_NEG_X
:
570 x
+= step_offsets
[face
][0] * d
;
571 y
+= step_offsets
[face
][1] * d
;
573 case PIPE_TEX_FACE_POS_Y
:
574 case PIPE_TEX_FACE_NEG_Y
:
578 case PIPE_TEX_FACE_POS_Z
:
579 case PIPE_TEX_FACE_NEG_Z
:
580 y
= total_height
- 4;
586 y
= total_height
- 4;
587 x
= bottom_offsets
[face
];
593 x
+= step_offsets
[face
][0] * d
;
594 y
+= step_offsets
[face
][1] * d
;
602 i945_texture_layout(struct i915_texture
* tex
)
604 struct pipe_resource
*pt
= &tex
->b
.b
;
606 switch (pt
->target
) {
607 case PIPE_TEXTURE_1D
:
608 case PIPE_TEXTURE_2D
:
609 case PIPE_TEXTURE_RECT
:
610 if (!i9x5_special_layout(tex
))
611 i945_texture_layout_2d(tex
);
613 case PIPE_TEXTURE_3D
:
614 i945_texture_layout_3d(tex
);
616 case PIPE_TEXTURE_CUBE
:
617 if (!util_format_is_s3tc(pt
->format
))
618 i9x5_texture_layout_cube(tex
);
620 i945_texture_layout_cube(tex
);
633 * Screen texture functions
639 i915_texture_get_handle(struct pipe_screen
* screen
,
640 struct pipe_resource
*texture
,
641 struct winsys_handle
*whandle
)
643 struct i915_screen
*is
= i915_screen(screen
);
644 struct i915_texture
*tex
= i915_texture(texture
);
645 struct i915_winsys
*iws
= is
->iws
;
647 return iws
->buffer_get_handle(iws
, tex
->buffer
, whandle
, tex
->stride
);
652 i915_texture_destroy(struct pipe_screen
*screen
,
653 struct pipe_resource
*pt
)
655 struct i915_texture
*tex
= i915_texture(pt
);
656 struct i915_winsys
*iws
= i915_screen(screen
)->iws
;
659 iws
->buffer_destroy(iws
, tex
->buffer
);
661 for (i
= 0; i
< Elements(tex
->image_offset
); i
++)
662 if (tex
->image_offset
[i
])
663 FREE(tex
->image_offset
[i
]);
668 static struct pipe_transfer
*
669 i915_texture_get_transfer(struct pipe_context
*context
,
670 struct pipe_resource
*resource
,
671 struct pipe_subresource sr
,
673 const struct pipe_box
*box
)
675 struct i915_texture
*tex
= i915_texture(resource
);
676 struct pipe_transfer
*transfer
= CALLOC_STRUCT(pipe_transfer
);
677 if (transfer
== NULL
)
680 transfer
->resource
= resource
;
682 transfer
->usage
= usage
;
683 transfer
->box
= *box
;
684 transfer
->stride
= tex
->stride
;
691 i915_texture_transfer_map(struct pipe_context
*pipe
,
692 struct pipe_transfer
*transfer
)
694 struct pipe_resource
*resource
= transfer
->resource
;
695 struct i915_texture
*tex
= i915_texture(resource
);
696 struct i915_winsys
*iws
= i915_screen(pipe
->screen
)->iws
;
697 struct pipe_subresource sr
= transfer
->sr
;
698 struct pipe_box
*box
= &transfer
->box
;
699 enum pipe_format format
= resource
->format
;
703 if (resource
->target
== PIPE_TEXTURE_CUBE
) {
704 offset
= tex
->image_offset
[sr
.level
][sr
.face
];
705 } else if (resource
->target
== PIPE_TEXTURE_3D
) {
706 offset
= tex
->image_offset
[sr
.level
][box
->z
];
708 offset
= tex
->image_offset
[sr
.level
][0];
709 assert(sr
.face
== 0);
713 map
= iws
->buffer_map(iws
, tex
->buffer
,
714 (transfer
->usage
& PIPE_TRANSFER_WRITE
) ? TRUE
: FALSE
);
718 return map
+ offset
+
719 box
->y
/ util_format_get_blockheight(format
) * transfer
->stride
+
720 box
->x
/ util_format_get_blockwidth(format
) * util_format_get_blocksize(format
);
724 i915_texture_transfer_unmap(struct pipe_context
*pipe
,
725 struct pipe_transfer
*transfer
)
727 struct i915_texture
*tex
= i915_texture(transfer
->resource
);
728 struct i915_winsys
*iws
= i915_screen(tex
->b
.b
.screen
)->iws
;
729 iws
->buffer_unmap(iws
, tex
->buffer
);
734 struct u_resource_vtbl i915_texture_vtbl
=
736 i915_texture_get_handle
, /* get_handle */
737 i915_texture_destroy
, /* resource_destroy */
738 NULL
, /* is_resource_referenced */
739 i915_texture_get_transfer
, /* get_transfer */
740 u_default_transfer_destroy
, /* transfer_destroy */
741 i915_texture_transfer_map
, /* transfer_map */
742 u_default_transfer_flush_region
, /* transfer_flush_region */
743 i915_texture_transfer_unmap
, /* transfer_unmap */
744 u_default_transfer_inline_write
/* transfer_inline_write */
750 struct pipe_resource
*
751 i915_texture_create(struct pipe_screen
*screen
,
752 const struct pipe_resource
*template)
754 struct i915_screen
*is
= i915_screen(screen
);
755 struct i915_winsys
*iws
= is
->iws
;
756 struct i915_texture
*tex
= CALLOC_STRUCT(i915_texture
);
758 unsigned buf_usage
= 0;
763 tex
->b
.b
= *template;
764 tex
->b
.vtbl
= &i915_texture_vtbl
;
765 pipe_reference_init(&tex
->b
.b
.reference
, 1);
766 tex
->b
.b
.screen
= screen
;
769 if (!i945_texture_layout(tex
))
772 if (!i915_texture_layout(tex
))
776 tex_size
= tex
->stride
* tex
->total_nblocksy
;
778 /* for scanouts and cursors, cursors arn't scanouts */
780 /* XXX: use a custom flag for cursors, don't rely on magically
781 * guessing that this is Xorg asking for a cursor
783 if ((template->bind
& PIPE_BIND_SCANOUT
) && template->width0
!= 64)
784 buf_usage
= I915_NEW_SCANOUT
;
786 buf_usage
= I915_NEW_TEXTURE
;
788 tex
->buffer
= iws
->buffer_create(iws
, tex_size
, 64, buf_usage
);
792 /* setup any hw fences */
794 iws
->buffer_set_fence_reg(iws
, tex
->buffer
, tex
->stride
, tex
->tiling
);
799 void *ptr
= ws
->buffer_map(ws
, tex
->buffer
,
800 PIPE_BUFFER_USAGE_CPU_WRITE
);
801 memset(ptr
, 0x80, tex_size
);
802 ws
->buffer_unmap(ws
, tex
->buffer
);
805 I915_DBG(DBG_TEXTURE
, "%s: %p size %u, stride %u, blocks (%u, %u)\n", __func__
,
806 tex
, (unsigned int)tex_size
, tex
->stride
,
807 tex
->stride
/ util_format_get_blocksize(tex
->b
.b
.format
),
808 tex
->total_nblocksy
);
817 struct pipe_resource
*
818 i915_texture_from_handle(struct pipe_screen
* screen
,
819 const struct pipe_resource
*template,
820 struct winsys_handle
*whandle
)
822 struct i915_screen
*is
= i915_screen(screen
);
823 struct i915_texture
*tex
;
824 struct i915_winsys
*iws
= is
->iws
;
825 struct i915_winsys_buffer
*buffer
;
830 buffer
= iws
->buffer_from_handle(iws
, whandle
, &stride
);
832 /* Only supports one type */
833 if ((template->target
!= PIPE_TEXTURE_2D
&&
834 template->target
!= PIPE_TEXTURE_RECT
) ||
835 template->last_level
!= 0 ||
836 template->depth0
!= 1) {
840 tex
= CALLOC_STRUCT(i915_texture
);
844 tex
->b
.b
= *template;
845 tex
->b
.vtbl
= &i915_texture_vtbl
;
846 pipe_reference_init(&tex
->b
.b
.reference
, 1);
847 tex
->b
.b
.screen
= screen
;
849 tex
->stride
= stride
;
850 tex
->total_nblocksy
= align_nblocksy(tex
->b
.b
.format
, tex
->b
.b
.height0
, 8);
852 i915_texture_set_level_info(tex
, 0, 1);
853 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
855 tex
->buffer
= buffer
;
857 I915_DBG(DBG_TEXTURE
, "%s: %p stride %u, blocks (%ux%u)\n", __func__
,
859 tex
->stride
/ util_format_get_blocksize(tex
->b
.b
.format
),
860 tex
->total_nblocksy
);