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"
47 #define DEBUG_TEXTURES 0
50 * Helper function and arrays
55 * Initial offset for Cube map.
57 static const int initial_offsets
[6][2] = {
58 [PIPE_TEX_FACE_POS_X
] = {0, 0},
59 [PIPE_TEX_FACE_POS_Y
] = {1, 0},
60 [PIPE_TEX_FACE_POS_Z
] = {1, 1},
61 [PIPE_TEX_FACE_NEG_X
] = {0, 2},
62 [PIPE_TEX_FACE_NEG_Y
] = {1, 2},
63 [PIPE_TEX_FACE_NEG_Z
] = {1, 3},
67 * Step offsets for Cube map.
69 static const int step_offsets
[6][2] = {
70 [PIPE_TEX_FACE_POS_X
] = { 0, 2},
71 [PIPE_TEX_FACE_POS_Y
] = {-1, 2},
72 [PIPE_TEX_FACE_POS_Z
] = {-1, 1},
73 [PIPE_TEX_FACE_NEG_X
] = { 0, 2},
74 [PIPE_TEX_FACE_NEG_Y
] = {-1, 2},
75 [PIPE_TEX_FACE_NEG_Z
] = {-1, 1},
79 * For compressed level 2
81 static const int bottom_offsets
[6] = {
82 [PIPE_TEX_FACE_POS_X
] = 16 + 0 * 8,
83 [PIPE_TEX_FACE_POS_Y
] = 16 + 1 * 8,
84 [PIPE_TEX_FACE_POS_Z
] = 16 + 2 * 8,
85 [PIPE_TEX_FACE_NEG_X
] = 16 + 3 * 8,
86 [PIPE_TEX_FACE_NEG_Y
] = 16 + 4 * 8,
87 [PIPE_TEX_FACE_NEG_Z
] = 16 + 5 * 8,
90 static INLINE
unsigned
91 align_nblocksx(enum pipe_format format
, unsigned width
, unsigned align_to
)
93 return align(util_format_get_nblocksx(format
, width
), align_to
);
96 static INLINE
unsigned
97 align_nblocksy(enum pipe_format format
, unsigned width
, unsigned align_to
)
99 return align(util_format_get_nblocksy(format
, width
), align_to
);
102 static INLINE
unsigned
103 get_pot_stride(enum pipe_format format
, unsigned width
)
105 return util_next_power_of_two(util_format_get_stride(format
, width
));
109 * More advanced helper funcs
114 i915_texture_set_level_info(struct i915_texture
*tex
,
115 unsigned level
, unsigned nr_images
)
117 assert(level
< Elements(tex
->nr_images
));
119 assert(!tex
->image_offset
[level
]);
121 tex
->nr_images
[level
] = nr_images
;
122 tex
->image_offset
[level
] = (unsigned *) MALLOC(nr_images
* sizeof(unsigned));
123 tex
->image_offset
[level
][0] = 0;
127 i915_texture_set_image_offset(struct i915_texture
*tex
,
128 unsigned level
, unsigned img
,
129 unsigned x
, unsigned y
)
131 /* for the first image and level make sure offset is zero */
132 assert(!(img
== 0 && level
== 0) || (x
== 0 && y
== 0));
133 assert(img
< tex
->nr_images
[level
]);
135 tex
->image_offset
[level
][img
] = y
* tex
->stride
+ x
* util_format_get_blocksize(tex
->b
.b
.format
);
138 debug_printf("%s: %p level %u, img %u (%u, %u) %p\n", __FUNCTION__
,
139 tex
, level
, img
, x
, y
,
140 (void*)(uintptr_t)tex
->image_offset
[level
][img
]);
146 * Shared layout functions
151 * Special case to deal with scanout textures.
154 i9x5_scanout_layout(struct i915_texture
*tex
)
156 struct pipe_resource
*pt
= &tex
->b
.b
;
158 if (pt
->last_level
> 0 || util_format_get_blocksize(pt
->format
) != 4)
161 i915_texture_set_level_info(tex
, 0, 1);
162 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
164 if (pt
->width0
>= 240) {
165 tex
->stride
= get_pot_stride(pt
->format
, pt
->width0
);
166 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
167 tex
->hw_tiled
= I915_TILE_X
;
168 } else if (pt
->width0
== 64 && pt
->height0
== 64) {
169 tex
->stride
= get_pot_stride(pt
->format
, pt
->width0
);
170 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
176 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
177 pt
->width0
, pt
->height0
, util_format_get_blocksize(pt
->format
),
178 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
185 * Special case to deal with shared textures.
188 i9x5_display_target_layout(struct i915_texture
*tex
)
190 struct pipe_resource
*pt
= &tex
->b
.b
;
192 if (pt
->last_level
> 0 || util_format_get_blocksize(pt
->format
) != 4)
195 /* fallback to normal textures for small textures */
196 if (pt
->width0
< 240)
199 i915_texture_set_level_info(tex
, 0, 1);
200 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
202 tex
->stride
= get_pot_stride(pt
->format
, pt
->width0
);
203 tex
->total_nblocksy
= align_nblocksy(pt
->format
, pt
->height0
, 8);
204 tex
->hw_tiled
= I915_TILE_X
;
207 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
208 pt
->width0
, pt
->height0
, util_format_get_blocksize(pt
->format
),
209 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
216 * Helper function for special layouts
219 i9x5_special_layout(struct i915_texture
*tex
)
221 struct pipe_resource
*pt
= &tex
->b
.b
;
223 /* Scanouts needs special care */
224 if (pt
->bind
& PIPE_BIND_SCANOUT
)
225 if (i9x5_scanout_layout(tex
))
228 /* Shared buffers needs to be compatible with X servers
230 * XXX: need a better name than shared for this if it is to be part
231 * of core gallium, and probably move the flag to resource.flags,
232 * rather than bindings.
234 if (pt
->bind
& (PIPE_BIND_SHARED
| PIPE_BIND_DISPLAY_TARGET
))
235 if (i9x5_display_target_layout(tex
))
242 * Cube layout used on i915 and for non-compressed textures on i945.
245 i9x5_texture_layout_cube(struct i915_texture
*tex
)
247 struct pipe_resource
*pt
= &tex
->b
.b
;
248 const unsigned nblocks
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
252 assert(pt
->width0
== pt
->height0
); /* cubemap images are square */
254 /* double pitch for cube layouts */
255 tex
->stride
= align(nblocks
* util_format_get_blocksize(pt
->format
) * 2, 4);
256 tex
->total_nblocksy
= nblocks
* 4;
258 for (level
= 0; level
<= pt
->last_level
; level
++)
259 i915_texture_set_level_info(tex
, level
, 6);
261 for (face
= 0; face
< 6; face
++) {
262 unsigned x
= initial_offsets
[face
][0] * nblocks
;
263 unsigned y
= initial_offsets
[face
][1] * nblocks
;
264 unsigned d
= nblocks
;
266 for (level
= 0; level
<= pt
->last_level
; level
++) {
267 i915_texture_set_image_offset(tex
, level
, face
, x
, y
);
269 x
+= step_offsets
[face
][0] * d
;
270 y
+= step_offsets
[face
][1] * d
;
277 * i915 layout functions
282 i915_texture_layout_2d(struct i915_texture
*tex
)
284 struct pipe_resource
*pt
= &tex
->b
.b
;
286 unsigned width
= pt
->width0
;
287 unsigned height
= pt
->height0
;
288 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->width0
);
289 unsigned align_y
= 2;
291 if (util_format_is_s3tc(pt
->format
))
294 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
295 tex
->total_nblocksy
= 0;
297 for (level
= 0; level
<= pt
->last_level
; level
++) {
298 i915_texture_set_level_info(tex
, level
, 1);
299 i915_texture_set_image_offset(tex
, level
, 0, 0, tex
->total_nblocksy
);
301 tex
->total_nblocksy
+= nblocksy
;
303 width
= u_minify(width
, 1);
304 height
= u_minify(height
, 1);
305 nblocksy
= align_nblocksy(pt
->format
, height
, align_y
);
310 i915_texture_layout_3d(struct i915_texture
*tex
)
312 struct pipe_resource
*pt
= &tex
->b
.b
;
315 unsigned width
= pt
->width0
;
316 unsigned height
= pt
->height0
;
317 unsigned depth
= pt
->depth0
;
318 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->height0
);
319 unsigned stack_nblocksy
= 0;
321 /* Calculate the size of a single slice.
323 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
325 /* XXX: hardware expects/requires 9 levels at minimum.
327 for (level
= 0; level
<= MAX2(8, pt
->last_level
); level
++) {
328 i915_texture_set_level_info(tex
, level
, depth
);
330 stack_nblocksy
+= MAX2(2, nblocksy
);
332 width
= u_minify(width
, 1);
333 height
= u_minify(height
, 1);
334 nblocksy
= util_format_get_nblocksy(pt
->format
, height
);
337 /* Fixup depth image_offsets:
339 for (level
= 0; level
<= pt
->last_level
; level
++) {
341 for (i
= 0; i
< depth
; i
++)
342 i915_texture_set_image_offset(tex
, level
, i
, 0, i
* stack_nblocksy
);
344 depth
= u_minify(depth
, 1);
347 /* Multiply slice size by texture depth for total size. It's
348 * remarkable how wasteful of memory the i915 texture layouts
349 * are. They are largely fixed in the i945.
351 tex
->total_nblocksy
= stack_nblocksy
* pt
->depth0
;
355 i915_texture_layout(struct i915_texture
* tex
)
357 struct pipe_resource
*pt
= &tex
->b
.b
;
359 switch (pt
->target
) {
360 case PIPE_TEXTURE_1D
:
361 case PIPE_TEXTURE_2D
:
362 if (!i9x5_special_layout(tex
))
363 i915_texture_layout_2d(tex
);
365 case PIPE_TEXTURE_3D
:
366 i915_texture_layout_3d(tex
);
368 case PIPE_TEXTURE_CUBE
:
369 i9x5_texture_layout_cube(tex
);
381 * i945 layout functions
386 i945_texture_layout_2d(struct i915_texture
*tex
)
388 struct pipe_resource
*pt
= &tex
->b
.b
;
389 int align_x
= 4, align_y
= 2;
393 unsigned width
= pt
->width0
;
394 unsigned height
= pt
->height0
;
395 unsigned nblocksx
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
396 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->height0
);
398 if (util_format_is_s3tc(pt
->format
)) {
403 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
405 /* May need to adjust pitch to accomodate the placement of
406 * the 2nd mipmap level. This occurs when the alignment
407 * constraints of mipmap placement push the right edge of the
408 * 2nd mipmap level out past the width of its parent.
410 if (pt
->last_level
> 0) {
411 unsigned mip1_nblocksx
=
412 align_nblocksx(pt
->format
, u_minify(pt
->width0
, 1), align_x
) +
413 util_format_get_nblocksx(pt
->format
, u_minify(pt
->width0
, 2));
415 if (mip1_nblocksx
> nblocksx
)
416 tex
->stride
= mip1_nblocksx
* util_format_get_blocksize(pt
->format
);
419 /* Pitch must be a whole number of dwords
421 tex
->stride
= align(tex
->stride
, 64);
422 tex
->total_nblocksy
= 0;
424 for (level
= 0; level
<= pt
->last_level
; level
++) {
425 i915_texture_set_level_info(tex
, level
, 1);
426 i915_texture_set_image_offset(tex
, level
, 0, x
, y
);
428 /* Because the images are packed better, the final offset
429 * might not be the maximal one:
431 tex
->total_nblocksy
= MAX2(tex
->total_nblocksy
, y
+ nblocksy
);
433 /* Layout_below: step right after second mipmap level.
441 width
= u_minify(width
, 1);
442 height
= u_minify(height
, 1);
443 nblocksx
= align_nblocksx(pt
->format
, width
, align_x
);
444 nblocksy
= align_nblocksy(pt
->format
, height
, align_y
);
449 i945_texture_layout_3d(struct i915_texture
*tex
)
451 struct pipe_resource
*pt
= &tex
->b
.b
;
452 unsigned width
= pt
->width0
;
453 unsigned height
= pt
->height0
;
454 unsigned depth
= pt
->depth0
;
455 unsigned nblocksy
= util_format_get_nblocksy(pt
->format
, pt
->width0
);
456 unsigned pack_x_pitch
, pack_x_nr
;
457 unsigned pack_y_pitch
;
460 tex
->stride
= align(util_format_get_stride(pt
->format
, pt
->width0
), 4);
461 tex
->total_nblocksy
= 0;
463 pack_y_pitch
= MAX2(nblocksy
, 2);
464 pack_x_pitch
= tex
->stride
/ util_format_get_blocksize(pt
->format
);
467 for (level
= 0; level
<= pt
->last_level
; level
++) {
472 i915_texture_set_level_info(tex
, level
, depth
);
474 for (q
= 0; q
< depth
;) {
475 for (j
= 0; j
< pack_x_nr
&& q
< depth
; j
++, q
++) {
476 i915_texture_set_image_offset(tex
, level
, q
, x
, y
+ tex
->total_nblocksy
);
484 tex
->total_nblocksy
+= y
;
486 if (pack_x_pitch
> 4) {
489 assert(pack_x_pitch
* pack_x_nr
* util_format_get_blocksize(pt
->format
) <= tex
->stride
);
492 if (pack_y_pitch
> 2) {
496 width
= u_minify(width
, 1);
497 height
= u_minify(height
, 1);
498 depth
= u_minify(depth
, 1);
499 nblocksy
= util_format_get_nblocksy(pt
->format
, height
);
504 i945_texture_layout_cube(struct i915_texture
*tex
)
506 struct pipe_resource
*pt
= &tex
->b
.b
;
507 const unsigned nblocks
= util_format_get_nblocksx(pt
->format
, pt
->width0
);
508 const unsigned dim
= pt
->width0
;
512 assert(pt
->width0
== pt
->height0
); /* cubemap images are square */
513 assert(util_next_power_of_two(pt
->width0
) == pt
->width0
); /* npot only */
514 assert(util_format_is_s3tc(pt
->format
)); /* compressed only */
517 * Depending on the size of the largest images, pitch can be
518 * determined either by the old-style packing of cubemap faces,
519 * or the final row of 4x4, 2x2 and 1x1 faces below this.
524 if (pt
->width0
>= 64)
525 tex
->stride
= nblocks
* 2 * util_format_get_blocksize(pt
->format
);
527 tex
->stride
= 14 * 2 * util_format_get_blocksize(pt
->format
);
530 * Something similary apply for height as well.
533 tex
->total_nblocksy
= nblocks
* 4 + 1;
535 tex
->total_nblocksy
= 1;
537 /* Set all the levels to effectively occupy the whole rectangular region */
538 for (level
= 0; level
<= pt
->last_level
; level
++)
539 i915_texture_set_level_info(tex
, level
, 6);
541 for (face
= 0; face
< 6; face
++) {
542 /* all calculations in pixels */
543 unsigned total_height
= tex
->total_nblocksy
* 4;
544 unsigned x
= initial_offsets
[face
][0] * dim
;
545 unsigned y
= initial_offsets
[face
][1] * dim
;
548 if (dim
== 4 && face
>= 4) {
550 y
= tex
->total_nblocksy
* 4 - 4; /* 4 = 1 block */
551 } else if (dim
< 4 && (face
> 0)) {
553 y
= total_height
- 4;
556 for (level
= 0; level
<= pt
->last_level
; level
++) {
557 i915_texture_set_image_offset(tex
, level
, face
,
558 util_format_get_nblocksx(pt
->format
, x
),
559 util_format_get_nblocksy(pt
->format
, y
));
566 case PIPE_TEX_FACE_POS_X
:
567 case PIPE_TEX_FACE_NEG_X
:
568 x
+= step_offsets
[face
][0] * d
;
569 y
+= step_offsets
[face
][1] * d
;
571 case PIPE_TEX_FACE_POS_Y
:
572 case PIPE_TEX_FACE_NEG_Y
:
576 case PIPE_TEX_FACE_POS_Z
:
577 case PIPE_TEX_FACE_NEG_Z
:
578 y
= total_height
- 4;
584 y
= total_height
- 4;
585 x
= bottom_offsets
[face
];
591 x
+= step_offsets
[face
][0] * d
;
592 y
+= step_offsets
[face
][1] * d
;
600 i945_texture_layout(struct i915_texture
* tex
)
602 struct pipe_resource
*pt
= &tex
->b
.b
;
604 switch (pt
->target
) {
605 case PIPE_TEXTURE_1D
:
606 case PIPE_TEXTURE_2D
:
607 if (!i9x5_special_layout(tex
))
608 i945_texture_layout_2d(tex
);
610 case PIPE_TEXTURE_3D
:
611 i945_texture_layout_3d(tex
);
613 case PIPE_TEXTURE_CUBE
:
614 if (!util_format_is_s3tc(pt
->format
))
615 i9x5_texture_layout_cube(tex
);
617 i945_texture_layout_cube(tex
);
630 * Screen texture functions
636 i915_texture_get_handle(struct pipe_screen
* screen
,
637 struct pipe_resource
*texture
,
638 struct winsys_handle
*whandle
)
640 struct i915_screen
*is
= i915_screen(screen
);
641 struct i915_texture
*tex
= i915_texture(texture
);
642 struct i915_winsys
*iws
= is
->iws
;
644 return iws
->buffer_get_handle(iws
, tex
->buffer
, whandle
, tex
->stride
);
649 i915_texture_destroy(struct pipe_screen
*screen
,
650 struct pipe_resource
*pt
)
652 struct i915_texture
*tex
= i915_texture(pt
);
653 struct i915_winsys
*iws
= i915_screen(screen
)->iws
;
656 iws
->buffer_destroy(iws
, tex
->buffer
);
658 for (i
= 0; i
< Elements(tex
->image_offset
); i
++)
659 if (tex
->image_offset
[i
])
660 FREE(tex
->image_offset
[i
]);
665 static struct pipe_transfer
*
666 i915_texture_get_transfer(struct pipe_context
*context
,
667 struct pipe_resource
*resource
,
668 struct pipe_subresource sr
,
670 const struct pipe_box
*box
)
672 struct i915_texture
*tex
= i915_texture(resource
);
673 struct pipe_transfer
*transfer
= CALLOC_STRUCT(pipe_transfer
);
674 if (transfer
== NULL
)
677 transfer
->resource
= resource
;
679 transfer
->usage
= usage
;
680 transfer
->box
= *box
;
681 transfer
->stride
= tex
->stride
;
688 i915_texture_transfer_map(struct pipe_context
*pipe
,
689 struct pipe_transfer
*transfer
)
691 struct pipe_resource
*resource
= transfer
->resource
;
692 struct i915_texture
*tex
= i915_texture(resource
);
693 struct i915_winsys
*iws
= i915_screen(pipe
->screen
)->iws
;
694 struct pipe_subresource sr
= transfer
->sr
;
695 struct pipe_box
*box
= &transfer
->box
;
696 enum pipe_format format
= resource
->format
;
700 if (resource
->target
== PIPE_TEXTURE_CUBE
) {
701 offset
= tex
->image_offset
[sr
.level
][sr
.face
];
702 } else if (resource
->target
== PIPE_TEXTURE_3D
) {
703 offset
= tex
->image_offset
[sr
.level
][box
->z
];
705 offset
= tex
->image_offset
[sr
.level
][0];
706 assert(sr
.face
== 0);
710 map
= iws
->buffer_map(iws
, tex
->buffer
,
711 (transfer
->usage
& PIPE_TRANSFER_WRITE
) ? TRUE
: FALSE
);
715 return map
+ offset
+
716 box
->y
/ util_format_get_blockheight(format
) * transfer
->stride
+
717 box
->x
/ util_format_get_blockwidth(format
) * util_format_get_blocksize(format
);
721 i915_texture_transfer_unmap(struct pipe_context
*pipe
,
722 struct pipe_transfer
*transfer
)
724 struct i915_texture
*tex
= i915_texture(transfer
->resource
);
725 struct i915_winsys
*iws
= i915_screen(tex
->b
.b
.screen
)->iws
;
726 iws
->buffer_unmap(iws
, tex
->buffer
);
731 struct u_resource_vtbl i915_texture_vtbl
=
733 i915_texture_get_handle
, /* get_handle */
734 i915_texture_destroy
, /* resource_destroy */
735 NULL
, /* is_resource_referenced */
736 i915_texture_get_transfer
, /* get_transfer */
737 u_default_transfer_destroy
, /* transfer_destroy */
738 i915_texture_transfer_map
, /* transfer_map */
739 u_default_transfer_flush_region
, /* transfer_flush_region */
740 i915_texture_transfer_unmap
, /* transfer_unmap */
741 u_default_transfer_inline_write
/* transfer_inline_write */
747 struct pipe_resource
*
748 i915_texture_create(struct pipe_screen
*screen
,
749 const struct pipe_resource
*template)
751 struct i915_screen
*is
= i915_screen(screen
);
752 struct i915_winsys
*iws
= is
->iws
;
753 struct i915_texture
*tex
= CALLOC_STRUCT(i915_texture
);
755 unsigned buf_usage
= 0;
760 tex
->b
.b
= *template;
761 tex
->b
.vtbl
= &i915_texture_vtbl
;
762 pipe_reference_init(&tex
->b
.b
.reference
, 1);
763 tex
->b
.b
.screen
= screen
;
766 if (!i945_texture_layout(tex
))
769 if (!i915_texture_layout(tex
))
773 tex_size
= tex
->stride
* tex
->total_nblocksy
;
775 /* for scanouts and cursors, cursors arn't scanouts */
777 /* XXX: use a custom flag for cursors, don't rely on magically
778 * guessing that this is Xorg asking for a cursor
780 if ((template->bind
& PIPE_BIND_SCANOUT
) && template->width0
!= 64)
781 buf_usage
= I915_NEW_SCANOUT
;
783 buf_usage
= I915_NEW_TEXTURE
;
785 tex
->buffer
= iws
->buffer_create(iws
, tex_size
, 64, buf_usage
);
789 /* setup any hw fences */
791 assert(tex
->sw_tiled
== I915_TILE_NONE
);
792 iws
->buffer_set_fence_reg(iws
, tex
->buffer
, tex
->stride
, tex
->hw_tiled
);
797 void *ptr
= ws
->buffer_map(ws
, tex
->buffer
,
798 PIPE_BUFFER_USAGE_CPU_WRITE
);
799 memset(ptr
, 0x80, tex_size
);
800 ws
->buffer_unmap(ws
, tex
->buffer
);
804 debug_printf("%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
);
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->last_level
!= 0 ||
835 template->depth0
!= 1) {
839 tex
= CALLOC_STRUCT(i915_texture
);
843 tex
->b
.b
= *template;
844 tex
->b
.vtbl
= &i915_texture_vtbl
;
845 pipe_reference_init(&tex
->b
.b
.reference
, 1);
846 tex
->b
.b
.screen
= screen
;
848 tex
->stride
= stride
;
850 i915_texture_set_level_info(tex
, 0, 1);
851 i915_texture_set_image_offset(tex
, 0, 0, 0, 0);
853 tex
->buffer
= buffer
;