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
));
109 static INLINE
const char*
110 get_tiling_string(enum i915_winsys_buffer_tile tile
)
127 * More advanced helper funcs
132 i915_texture_set_level_info(struct i915_texture
*tex
,
133 unsigned level
, unsigned nr_images
)
135 assert(level
< Elements(tex
->nr_images
));
137 assert(!tex
->image_offset
[level
]);
139 tex
->nr_images
[level
] = nr_images
;
140 tex
->image_offset
[level
] = MALLOC(nr_images
* sizeof(struct offset_pair
));
141 tex
->image_offset
[level
][0].nblocksx
= 0;
142 tex
->image_offset
[level
][0].nblocksy
= 0;
145 INLINE
unsigned i915_texture_offset(struct i915_texture
*tex
,
146 unsigned level
, unsigned layer
)
149 x
= tex
->image_offset
[level
][layer
].nblocksx
150 * util_format_get_blocksize(tex
->b
.b
.format
);
151 y
= tex
->image_offset
[level
][layer
].nblocksy
;
153 return y
* tex
->stride
+ x
;
157 i915_texture_set_image_offset(struct i915_texture
*tex
,
158 unsigned level
, unsigned img
,
159 unsigned nblocksx
, unsigned nblocksy
)
161 /* for the first image and level make sure offset is zero */
162 assert(!(img
== 0 && level
== 0) || (nblocksx
== 0 && nblocksy
== 0));
163 assert(img
< tex
->nr_images
[level
]);
165 tex
->image_offset
[level
][img
].nblocksx
= nblocksx
;
166 tex
->image_offset
[level
][img
].nblocksy
= nblocksy
;
169 debug_printf("%s: %p level %u, img %u (%u, %u)\n", __FUNCTION__
,
170 tex
, level
, img
, x
, y
);
174 static enum i915_winsys_buffer_tile
175 i915_texture_tiling(struct pipe_resource
*pt
)
178 return I915_TILE_NONE
;
180 if (pt
->target
== PIPE_TEXTURE_1D
)
181 return I915_TILE_NONE
;
183 if (util_format_is_s3tc(pt
->format
))
184 /* XXX X-tiling might make sense */
185 return I915_TILE_NONE
;
192 * Shared layout functions
197 * Special case to deal with scanout textures.
200 i9x5_scanout_layout(struct i915_texture
*tex
)
202 struct pipe_resource
*pt
= &tex
->b
.b
;
204 if (pt
->last_level
> 0 || util_format_get_blocksize(pt
->format
) != 4)
207 i915_texture_set_level_info(tex
, 0, 1);
208 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
210 if (pt
->width0
>= 240) {
211 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 64);
212 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
213 tex
->tiling
= I915_TILE_X
;
214 /* special case for cursors */
215 } else if (pt
->width0
== 64 && pt
->height0
== 64) {
216 tex
->stride
= get_pot_stride(pt
->format
, pt
->width0
);
217 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
223 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
224 pt
->width0
, pt
->height0
, util_format_get_blocksize(pt
->format
),
225 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
232 * Special case to deal with shared textures.
235 i9x5_display_target_layout(struct i915_texture
*tex
)
237 struct pipe_resource
*pt
= &tex
->b
.b
;
239 if (pt
->last_level
> 0 || util_format_get_blocksize(pt
->format
) != 4)
242 /* fallback to normal textures for small textures */
243 if (pt
->width0
< 240)
246 i915_texture_set_level_info(tex
, 0, 1);
247 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
249 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 64);
250 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
251 tex
->tiling
= I915_TILE_X
;
254 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
255 pt
->width0
, pt
->height0
, util_format_get_blocksize(pt
->format
),
256 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
263 * Helper function for special layouts
266 i9x5_special_layout(struct i915_texture
*tex
)
268 struct pipe_resource
*pt
= &tex
->b
.b
;
270 /* Scanouts needs special care */
271 if (pt
->bind
& PIPE_BIND_SCANOUT
)
272 if (i9x5_scanout_layout(tex
))
275 /* Shared buffers needs to be compatible with X servers
277 * XXX: need a better name than shared for this if it is to be part
278 * of core gallium, and probably move the flag to resource.flags,
279 * rather than bindings.
281 if (pt
->bind
& (PIPE_BIND_SHARED
| PIPE_BIND_DISPLAY_TARGET
))
282 if (i9x5_display_target_layout(tex
))
289 * Cube layout used on i915 and for non-compressed textures on i945.
292 i9x5_texture_layout_cube(struct i915_texture
*tex
)
294 struct pipe_resource
*pt
= &tex
->b
.b
;
295 const unsigned nblocks
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
299 assert(pt
->width0
== pt
->height0
); /* cubemap images are square */
301 /* double pitch for cube layouts */
302 tex
->stride
= align(nblocks
* util_format_get_blocksize(pt
->format
) * 2, 4);
303 tex
->total_nblocksy
= nblocks
* 4;
305 for (level
= 0; level
<= pt
->last_level
; level
++)
306 i915_texture_set_level_info(tex
, level
, 6);
308 for (face
= 0; face
< 6; face
++) {
309 unsigned x
= initial_offsets
[face
][0] * nblocks
;
310 unsigned y
= initial_offsets
[face
][1] * nblocks
;
311 unsigned d
= nblocks
;
313 for (level
= 0; level
<= pt
->last_level
; level
++) {
314 i915_texture_set_image_offset(tex
, level
, face
, x
, y
);
316 x
+= step_offsets
[face
][0] * d
;
317 y
+= step_offsets
[face
][1] * d
;
324 * i915 layout functions
329 i915_texture_layout_2d(struct i915_texture
*tex
)
331 struct pipe_resource
*pt
= &tex
->b
.b
;
333 unsigned width
= pt
->width0
;
334 unsigned height
= pt
->height0
;
335 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->width0
);
336 unsigned align_y
= 2;
338 if (util_format_is_s3tc(pt
->format
))
341 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
342 tex
->total_nblocksy
= 0;
344 for (level
= 0; level
<= pt
->last_level
; level
++) {
345 i915_texture_set_level_info(tex
, level
, 1);
346 i915_texture_set_image_offset(tex
, level
, 0, 0, tex
->total_nblocksy
);
348 tex
->total_nblocksy
+= nblocksy
;
350 width
= u_minify(width
, 1);
351 height
= u_minify(height
, 1);
352 nblocksy
= align_nblocksy(pt
->format
, height
, align_y
);
357 i915_texture_layout_3d(struct i915_texture
*tex
)
359 struct pipe_resource
*pt
= &tex
->b
.b
;
362 unsigned width
= pt
->width0
;
363 unsigned height
= pt
->height0
;
364 unsigned depth
= pt
->depth0
;
365 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->height0
);
366 unsigned stack_nblocksy
= 0;
368 /* Calculate the size of a single slice.
370 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
372 /* XXX: hardware expects/requires 9 levels at minimum.
374 for (level
= 0; level
<= MAX2(8, pt
->last_level
); level
++) {
375 i915_texture_set_level_info(tex
, level
, depth
);
377 stack_nblocksy
+= MAX2(2, nblocksy
);
379 width
= u_minify(width
, 1);
380 height
= u_minify(height
, 1);
381 nblocksy
= util_format_get_nblocksy(pt
->format
, height
);
384 /* Fixup depth image_offsets:
386 for (level
= 0; level
<= pt
->last_level
; level
++) {
388 for (i
= 0; i
< depth
; i
++)
389 i915_texture_set_image_offset(tex
, level
, i
, 0, i
* stack_nblocksy
);
391 depth
= u_minify(depth
, 1);
394 /* Multiply slice size by texture depth for total size. It's
395 * remarkable how wasteful of memory the i915 texture layouts
396 * are. They are largely fixed in the i945.
398 tex
->total_nblocksy
= stack_nblocksy
* pt
->depth0
;
402 i915_texture_layout(struct i915_texture
* tex
)
404 struct pipe_resource
*pt
= &tex
->b
.b
;
406 tex
->tiling
= i915_texture_tiling(pt
);
408 switch (pt
->target
) {
409 case PIPE_TEXTURE_1D
:
410 case PIPE_TEXTURE_2D
:
411 case PIPE_TEXTURE_RECT
:
412 if (!i9x5_special_layout(tex
))
413 i915_texture_layout_2d(tex
);
415 case PIPE_TEXTURE_3D
:
416 i915_texture_layout_3d(tex
);
418 case PIPE_TEXTURE_CUBE
:
419 i9x5_texture_layout_cube(tex
);
431 * i945 layout functions
436 i945_texture_layout_2d(struct i915_texture
*tex
)
438 struct pipe_resource
*pt
= &tex
->b
.b
;
439 int align_x
= 4, align_y
= 2;
443 unsigned width
= pt
->width0
;
444 unsigned height
= pt
->height0
;
445 unsigned nblocksx
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
446 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->height0
);
448 if (util_format_is_s3tc(pt
->format
)) {
453 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
455 /* May need to adjust pitch to accomodate the placement of
456 * the 2nd mipmap level. This occurs when the alignment
457 * constraints of mipmap placement push the right edge of the
458 * 2nd mipmap level out past the width of its parent.
460 if (pt
->last_level
> 0) {
461 unsigned mip1_nblocksx
=
462 align_nblocksx(pt
->format
, u_minify(pt
->width0
, 1), align_x
) +
463 util_format_get_nblocksx(pt
->format
, u_minify(pt
->width0
, 2));
465 if (mip1_nblocksx
> nblocksx
)
466 tex
->stride
= mip1_nblocksx
* util_format_get_blocksize(pt
->format
);
469 /* Pitch must be a whole number of dwords
471 tex
->stride
= align(tex
->stride
, 64);
472 tex
->total_nblocksy
= 0;
474 for (level
= 0; level
<= pt
->last_level
; level
++) {
475 i915_texture_set_level_info(tex
, level
, 1);
476 i915_texture_set_image_offset(tex
, level
, 0, x
, y
);
478 /* Because the images are packed better, the final offset
479 * might not be the maximal one:
481 tex
->total_nblocksy
= MAX2(tex
->total_nblocksy
, y
+ nblocksy
);
483 /* Layout_below: step right after second mipmap level.
491 width
= u_minify(width
, 1);
492 height
= u_minify(height
, 1);
493 nblocksx
= align_nblocksx(pt
->format
, width
, align_x
);
494 nblocksy
= align_nblocksy(pt
->format
, height
, align_y
);
499 i945_texture_layout_3d(struct i915_texture
*tex
)
501 struct pipe_resource
*pt
= &tex
->b
.b
;
502 unsigned width
= pt
->width0
;
503 unsigned height
= pt
->height0
;
504 unsigned depth
= pt
->depth0
;
505 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->width0
);
506 unsigned pack_x_pitch
, pack_x_nr
;
507 unsigned pack_y_pitch
;
510 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
511 tex
->total_nblocksy
= 0;
513 pack_y_pitch
= MAX2(nblocksy
, 2);
514 pack_x_pitch
= tex
->stride
/ util_format_get_blocksize(pt
->format
);
517 for (level
= 0; level
<= pt
->last_level
; level
++) {
522 i915_texture_set_level_info(tex
, level
, depth
);
524 for (q
= 0; q
< depth
;) {
525 for (j
= 0; j
< pack_x_nr
&& q
< depth
; j
++, q
++) {
526 i915_texture_set_image_offset(tex
, level
, q
, x
, y
+ tex
->total_nblocksy
);
534 tex
->total_nblocksy
+= y
;
536 if (pack_x_pitch
> 4) {
539 assert(pack_x_pitch
* pack_x_nr
* util_format_get_blocksize(pt
->format
) <= tex
->stride
);
542 if (pack_y_pitch
> 2) {
546 width
= u_minify(width
, 1);
547 height
= u_minify(height
, 1);
548 depth
= u_minify(depth
, 1);
549 nblocksy
= util_format_get_nblocksy(pt
->format
, height
);
554 i945_texture_layout_cube(struct i915_texture
*tex
)
556 struct pipe_resource
*pt
= &tex
->b
.b
;
557 const unsigned nblocks
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
558 const unsigned dim
= pt
->width0
;
562 assert(pt
->width0
== pt
->height0
); /* cubemap images are square */
563 assert(util_next_power_of_two(pt
->width0
) == pt
->width0
); /* npot only */
564 assert(util_format_is_s3tc(pt
->format
)); /* compressed only */
567 * Depending on the size of the largest images, pitch can be
568 * determined either by the old-style packing of cubemap faces,
569 * or the final row of 4x4, 2x2 and 1x1 faces below this.
574 if (pt
->width0
>= 64)
575 tex
->stride
= nblocks
* 2 * util_format_get_blocksize(pt
->format
);
577 tex
->stride
= 14 * 2 * util_format_get_blocksize(pt
->format
);
580 * Something similary apply for height as well.
583 tex
->total_nblocksy
= nblocks
* 4 + 1;
585 tex
->total_nblocksy
= 1;
587 /* Set all the levels to effectively occupy the whole rectangular region */
588 for (level
= 0; level
<= pt
->last_level
; level
++)
589 i915_texture_set_level_info(tex
, level
, 6);
591 for (face
= 0; face
< 6; face
++) {
592 /* all calculations in pixels */
593 unsigned total_height
= tex
->total_nblocksy
* 4;
594 unsigned x
= initial_offsets
[face
][0] * dim
;
595 unsigned y
= initial_offsets
[face
][1] * dim
;
598 if (dim
== 4 && face
>= 4) {
600 y
= tex
->total_nblocksy
* 4 - 4; /* 4 = 1 block */
601 } else if (dim
< 4 && (face
> 0)) {
603 y
= total_height
- 4;
606 for (level
= 0; level
<= pt
->last_level
; level
++) {
607 i915_texture_set_image_offset(tex
, level
, face
,
608 util_format_get_nblocksx(pt
->format
, x
),
609 util_format_get_nblocksy(pt
->format
, y
));
616 case PIPE_TEX_FACE_POS_X
:
617 case PIPE_TEX_FACE_NEG_X
:
618 x
+= step_offsets
[face
][0] * d
;
619 y
+= step_offsets
[face
][1] * d
;
621 case PIPE_TEX_FACE_POS_Y
:
622 case PIPE_TEX_FACE_NEG_Y
:
626 case PIPE_TEX_FACE_POS_Z
:
627 case PIPE_TEX_FACE_NEG_Z
:
628 y
= total_height
- 4;
634 y
= total_height
- 4;
635 x
= bottom_offsets
[face
];
641 x
+= step_offsets
[face
][0] * d
;
642 y
+= step_offsets
[face
][1] * d
;
650 i945_texture_layout(struct i915_texture
* tex
)
652 struct pipe_resource
*pt
= &tex
->b
.b
;
654 tex
->tiling
= i915_texture_tiling(pt
);
656 switch (pt
->target
) {
657 case PIPE_TEXTURE_1D
:
658 case PIPE_TEXTURE_2D
:
659 case PIPE_TEXTURE_RECT
:
660 if (!i9x5_special_layout(tex
))
661 i945_texture_layout_2d(tex
);
663 case PIPE_TEXTURE_3D
:
664 i945_texture_layout_3d(tex
);
666 case PIPE_TEXTURE_CUBE
:
667 if (!util_format_is_s3tc(pt
->format
))
668 i9x5_texture_layout_cube(tex
);
670 i945_texture_layout_cube(tex
);
683 * Screen texture functions
689 i915_texture_get_handle(struct pipe_screen
* screen
,
690 struct pipe_resource
*texture
,
691 struct winsys_handle
*whandle
)
693 struct i915_screen
*is
= i915_screen(screen
);
694 struct i915_texture
*tex
= i915_texture(texture
);
695 struct i915_winsys
*iws
= is
->iws
;
697 return iws
->buffer_get_handle(iws
, tex
->buffer
, whandle
, tex
->stride
);
702 i915_texture_destroy(struct pipe_screen
*screen
,
703 struct pipe_resource
*pt
)
705 struct i915_texture
*tex
= i915_texture(pt
);
706 struct i915_winsys
*iws
= i915_screen(screen
)->iws
;
709 iws
->buffer_destroy(iws
, tex
->buffer
);
711 for (i
= 0; i
< Elements(tex
->image_offset
); i
++)
712 if (tex
->image_offset
[i
])
713 FREE(tex
->image_offset
[i
]);
718 static struct pipe_transfer
*
719 i915_texture_get_transfer(struct pipe_context
*context
,
720 struct pipe_resource
*resource
,
723 const struct pipe_box
*box
)
725 struct i915_texture
*tex
= i915_texture(resource
);
726 struct pipe_transfer
*transfer
= CALLOC_STRUCT(pipe_transfer
);
727 if (transfer
== NULL
)
730 transfer
->resource
= resource
;
731 transfer
->level
= level
;
732 transfer
->usage
= usage
;
733 transfer
->box
= *box
;
734 transfer
->stride
= tex
->stride
;
735 /* FIXME: layer_stride */
741 i915_texture_transfer_map(struct pipe_context
*pipe
,
742 struct pipe_transfer
*transfer
)
744 struct pipe_resource
*resource
= transfer
->resource
;
745 struct i915_texture
*tex
= i915_texture(resource
);
746 struct i915_winsys
*iws
= i915_screen(pipe
->screen
)->iws
;
747 struct pipe_box
*box
= &transfer
->box
;
748 enum pipe_format format
= resource
->format
;
752 if (resource
->target
!= PIPE_TEXTURE_3D
&&
753 resource
->target
!= PIPE_TEXTURE_CUBE
)
755 offset
= i915_texture_offset(tex
, transfer
->level
, box
->z
);
757 map
= iws
->buffer_map(iws
, tex
->buffer
,
758 (transfer
->usage
& PIPE_TRANSFER_WRITE
) ? TRUE
: FALSE
);
762 return map
+ offset
+
763 box
->y
/ util_format_get_blockheight(format
) * transfer
->stride
+
764 box
->x
/ util_format_get_blockwidth(format
) * util_format_get_blocksize(format
);
768 i915_texture_transfer_unmap(struct pipe_context
*pipe
,
769 struct pipe_transfer
*transfer
)
771 struct i915_texture
*tex
= i915_texture(transfer
->resource
);
772 struct i915_winsys
*iws
= i915_screen(tex
->b
.b
.screen
)->iws
;
773 iws
->buffer_unmap(iws
, tex
->buffer
);
778 struct u_resource_vtbl i915_texture_vtbl
=
780 i915_texture_get_handle
, /* get_handle */
781 i915_texture_destroy
, /* resource_destroy */
782 NULL
, /* is_resource_referenced */
783 i915_texture_get_transfer
, /* get_transfer */
784 u_default_transfer_destroy
, /* transfer_destroy */
785 i915_texture_transfer_map
, /* transfer_map */
786 u_default_transfer_flush_region
, /* transfer_flush_region */
787 i915_texture_transfer_unmap
, /* transfer_unmap */
788 u_default_transfer_inline_write
/* transfer_inline_write */
794 struct pipe_resource
*
795 i915_texture_create(struct pipe_screen
*screen
,
796 const struct pipe_resource
*template)
798 struct i915_screen
*is
= i915_screen(screen
);
799 struct i915_winsys
*iws
= is
->iws
;
800 struct i915_texture
*tex
= CALLOC_STRUCT(i915_texture
);
801 unsigned buf_usage
= 0;
806 tex
->b
.b
= *template;
807 tex
->b
.vtbl
= &i915_texture_vtbl
;
808 pipe_reference_init(&tex
->b
.b
.reference
, 1);
809 tex
->b
.b
.screen
= screen
;
812 if (!i945_texture_layout(tex
))
815 if (!i915_texture_layout(tex
))
819 /* for scanouts and cursors, cursors arn't scanouts */
821 /* XXX: use a custom flag for cursors, don't rely on magically
822 * guessing that this is Xorg asking for a cursor
824 if ((template->bind
& PIPE_BIND_SCANOUT
) && template->width0
!= 64)
825 buf_usage
= I915_NEW_SCANOUT
;
827 buf_usage
= I915_NEW_TEXTURE
;
829 tex
->buffer
= iws
->buffer_create_tiled(iws
, &tex
->stride
, tex
->total_nblocksy
,
830 &tex
->tiling
, buf_usage
);
834 I915_DBG(DBG_TEXTURE
, "%s: %p stride %u, blocks (%u, %u) tiling %s\n", __func__
,
836 tex
->stride
/ util_format_get_blocksize(tex
->b
.b
.format
),
837 tex
->total_nblocksy
, get_tiling_string(tex
->tiling
));
846 struct pipe_resource
*
847 i915_texture_from_handle(struct pipe_screen
* screen
,
848 const struct pipe_resource
*template,
849 struct winsys_handle
*whandle
)
851 struct i915_screen
*is
= i915_screen(screen
);
852 struct i915_texture
*tex
;
853 struct i915_winsys
*iws
= is
->iws
;
854 struct i915_winsys_buffer
*buffer
;
856 enum i915_winsys_buffer_tile tiling
;
860 buffer
= iws
->buffer_from_handle(iws
, whandle
, &tiling
, &stride
);
862 /* Only supports one type */
863 if ((template->target
!= PIPE_TEXTURE_2D
&&
864 template->target
!= PIPE_TEXTURE_RECT
) ||
865 template->last_level
!= 0 ||
866 template->depth0
!= 1) {
870 tex
= CALLOC_STRUCT(i915_texture
);
874 tex
->b
.b
= *template;
875 tex
->b
.vtbl
= &i915_texture_vtbl
;
876 pipe_reference_init(&tex
->b
.b
.reference
, 1);
877 tex
->b
.b
.screen
= screen
;
879 tex
->stride
= stride
;
880 tex
->tiling
= tiling
;
881 tex
->total_nblocksy
= align_nblocksy(tex
->b
.b
.format
, tex
->b
.b
.height0
, 8);
883 i915_texture_set_level_info(tex
, 0, 1);
884 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
886 tex
->buffer
= buffer
;
888 I915_DBG(DBG_TEXTURE
, "%s: %p stride %u, blocks (%u, %u) tiling %s\n", __func__
,
890 tex
->stride
/ util_format_get_blocksize(tex
->b
.b
.format
),
891 tex
->total_nblocksy
, get_tiling_string(tex
->tiling
));