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 "pipe/p_inlines.h"
37 #include "pipe/internal/p_winsys_screen.h"
38 #include "util/u_math.h"
39 #include "util/u_memory.h"
41 #include "i915_context.h"
42 #include "i915_texture.h"
43 #include "i915_debug.h"
44 #include "i915_screen.h"
45 #include "intel_winsys.h"
49 * Helper function and arrays
54 * Initial offset for Cube map.
56 static const int initial_offsets
[6][2] = {
66 * Step offsets for Cube map.
68 static const int step_offsets
[6][2] = {
78 power_of_two(unsigned x
)
87 round_up(unsigned n
, unsigned multiple
)
89 return (n
+ multiple
- 1) & ~(multiple
- 1);
94 * More advanced helper funcs
99 i915_miptree_set_level_info(struct i915_texture
*tex
,
102 unsigned w
, unsigned h
, unsigned d
)
104 struct pipe_texture
*pt
= &tex
->base
;
106 assert(level
< PIPE_MAX_TEXTURE_LEVELS
);
108 pt
->nblocksx
[level
] = pf_get_nblocksx(&pt
->block
, w
);
109 pt
->nblocksy
[level
] = pf_get_nblocksy(&pt
->block
, h
);
111 tex
->nr_images
[level
] = nr_images
;
114 DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
115 level, w, h, d, x, y, tex->level_offset[level]);
118 /* Not sure when this would happen, but anyway:
120 if (tex
->image_offset
[level
]) {
121 FREE(tex
->image_offset
[level
]);
122 tex
->image_offset
[level
] = NULL
;
126 assert(!tex
->image_offset
[level
]);
128 tex
->image_offset
[level
] = (unsigned *) MALLOC(nr_images
* sizeof(unsigned));
129 tex
->image_offset
[level
][0] = 0;
133 i915_miptree_set_image_offset(struct i915_texture
*tex
,
134 unsigned level
, unsigned img
, unsigned x
, unsigned y
)
136 if (img
== 0 && level
== 0)
137 assert(x
== 0 && y
== 0);
139 assert(img
< tex
->nr_images
[level
]);
141 tex
->image_offset
[level
][img
] = y
* tex
->stride
+ x
* tex
->base
.block
.size
;
144 printf("%s level %d img %d pos %d,%d image_offset %x\n",
145 __FUNCTION__, level, img, x, y, tex->image_offset[level][img]);
151 * i915 layout functions, some used by i945
156 * Special case to deal with scanout textures.
159 i915_scanout_layout(struct i915_texture
*tex
)
161 struct pipe_texture
*pt
= &tex
->base
;
163 if (pt
->last_level
> 0 || pt
->block
.size
!= 4)
166 i915_miptree_set_level_info(tex
, 0, 1,
170 i915_miptree_set_image_offset(tex
, 0, 0, 0, 0);
172 if (tex
->base
.width0
>= 240) {
173 tex
->stride
= power_of_two(tex
->base
.nblocksx
[0] * pt
->block
.size
);
174 tex
->total_nblocksy
= round_up(tex
->base
.nblocksy
[0], 8);
175 tex
->hw_tiled
= INTEL_TILE_X
;
176 } else if (tex
->base
.width0
== 64 && tex
->base
.height0
== 64) {
177 tex
->stride
= power_of_two(tex
->base
.nblocksx
[0] * pt
->block
.size
);
178 tex
->total_nblocksy
= round_up(tex
->base
.nblocksy
[0], 8);
183 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
184 tex
->base
.width0
, tex
->base
.height0
, pt
->block
.size
,
185 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
191 * Special case to deal with shared textures.
194 i915_display_target_layout(struct i915_texture
*tex
)
196 struct pipe_texture
*pt
= &tex
->base
;
198 if (pt
->last_level
> 0 || pt
->block
.size
!= 4)
201 /* fallback to normal textures for small textures */
202 if (tex
->base
.width0
< 240)
205 i915_miptree_set_level_info(tex
, 0, 1,
209 i915_miptree_set_image_offset(tex
, 0, 0, 0, 0);
211 tex
->stride
= power_of_two(tex
->base
.nblocksx
[0] * pt
->block
.size
);
212 tex
->total_nblocksy
= round_up(tex
->base
.nblocksy
[0], 8);
213 tex
->hw_tiled
= INTEL_TILE_X
;
215 debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__
,
216 tex
->base
.width0
, tex
->base
.height0
, pt
->block
.size
,
217 tex
->stride
, tex
->total_nblocksy
, tex
->stride
* tex
->total_nblocksy
);
223 i915_miptree_layout_2d(struct i915_texture
*tex
)
225 struct pipe_texture
*pt
= &tex
->base
;
227 unsigned width
= pt
->width0
;
228 unsigned height
= pt
->height0
;
229 unsigned nblocksx
= pt
->nblocksx
[0];
230 unsigned nblocksy
= pt
->nblocksy
[0];
232 /* used for scanouts that need special layouts */
233 if (tex
->base
.tex_usage
& PIPE_TEXTURE_USAGE_PRIMARY
)
234 if (i915_scanout_layout(tex
))
237 /* for shared buffers we use some very like scanout */
238 if (tex
->base
.tex_usage
& PIPE_TEXTURE_USAGE_DISPLAY_TARGET
)
239 if (i915_display_target_layout(tex
))
242 tex
->stride
= round_up(pt
->nblocksx
[0] * pt
->block
.size
, 4);
243 tex
->total_nblocksy
= 0;
245 for (level
= 0; level
<= pt
->last_level
; level
++) {
246 i915_miptree_set_level_info(tex
, level
, 1, width
, height
, 1);
247 i915_miptree_set_image_offset(tex
, level
, 0, 0, tex
->total_nblocksy
);
249 nblocksy
= round_up(MAX2(2, nblocksy
), 2);
251 tex
->total_nblocksy
+= nblocksy
;
253 width
= u_minify(width
, 1);
254 height
= u_minify(height
, 1);
255 nblocksx
= pf_get_nblocksx(&pt
->block
, width
);
256 nblocksy
= pf_get_nblocksy(&pt
->block
, height
);
261 i915_miptree_layout_3d(struct i915_texture
*tex
)
263 struct pipe_texture
*pt
= &tex
->base
;
266 unsigned width
= pt
->width0
;
267 unsigned height
= pt
->height0
;
268 unsigned depth
= pt
->depth0
;
269 unsigned nblocksx
= pt
->nblocksx
[0];
270 unsigned nblocksy
= pt
->nblocksy
[0];
271 unsigned stack_nblocksy
= 0;
273 /* Calculate the size of a single slice.
275 tex
->stride
= round_up(pt
->nblocksx
[0] * pt
->block
.size
, 4);
277 /* XXX: hardware expects/requires 9 levels at minimum.
279 for (level
= 0; level
<= MAX2(8, pt
->last_level
); level
++) {
280 i915_miptree_set_level_info(tex
, level
, depth
, width
, height
, depth
);
282 stack_nblocksy
+= MAX2(2, nblocksy
);
284 width
= u_minify(width
, 1);
285 height
= u_minify(height
, 1);
286 nblocksx
= pf_get_nblocksx(&pt
->block
, width
);
287 nblocksy
= pf_get_nblocksy(&pt
->block
, height
);
290 /* Fixup depth image_offsets:
292 for (level
= 0; level
<= pt
->last_level
; level
++) {
294 for (i
= 0; i
< depth
; i
++)
295 i915_miptree_set_image_offset(tex
, level
, i
, 0, i
* stack_nblocksy
);
297 depth
= u_minify(depth
, 1);
300 /* Multiply slice size by texture depth for total size. It's
301 * remarkable how wasteful of memory the i915 texture layouts
302 * are. They are largely fixed in the i945.
304 tex
->total_nblocksy
= stack_nblocksy
* pt
->depth0
;
308 i915_miptree_layout_cube(struct i915_texture
*tex
)
310 struct pipe_texture
*pt
= &tex
->base
;
311 unsigned width
= pt
->width0
, height
= pt
->height0
;
312 const unsigned nblocks
= pt
->nblocksx
[0];
316 assert(width
== height
); /* cubemap images are square */
318 /* double pitch for cube layouts */
319 tex
->stride
= round_up(nblocks
* pt
->block
.size
* 2, 4);
320 tex
->total_nblocksy
= nblocks
* 4;
322 for (level
= 0; level
<= pt
->last_level
; level
++) {
323 i915_miptree_set_level_info(tex
, level
, 6, width
, height
, 1);
328 for (face
= 0; face
< 6; face
++) {
329 unsigned x
= initial_offsets
[face
][0] * nblocks
;
330 unsigned y
= initial_offsets
[face
][1] * nblocks
;
331 unsigned d
= nblocks
;
333 for (level
= 0; level
<= pt
->last_level
; level
++) {
334 i915_miptree_set_image_offset(tex
, level
, face
, x
, y
);
336 x
+= step_offsets
[face
][0] * d
;
337 y
+= step_offsets
[face
][1] * d
;
343 i915_miptree_layout(struct i915_texture
* tex
)
345 struct pipe_texture
*pt
= &tex
->base
;
347 switch (pt
->target
) {
348 case PIPE_TEXTURE_1D
:
349 case PIPE_TEXTURE_2D
:
350 i915_miptree_layout_2d(tex
);
352 case PIPE_TEXTURE_3D
:
353 i915_miptree_layout_3d(tex
);
355 case PIPE_TEXTURE_CUBE
:
356 i915_miptree_layout_cube(tex
);
368 * i945 layout functions
373 i945_miptree_layout_2d(struct i915_texture
*tex
)
375 struct pipe_texture
*pt
= &tex
->base
;
376 const int align_x
= 2, align_y
= 4;
380 unsigned width
= pt
->width0
;
381 unsigned height
= pt
->height0
;
382 unsigned nblocksx
= pt
->nblocksx
[0];
383 unsigned nblocksy
= pt
->nblocksy
[0];
385 /* used for scanouts that need special layouts */
386 if (tex
->base
.tex_usage
& PIPE_TEXTURE_USAGE_PRIMARY
)
387 if (i915_scanout_layout(tex
))
390 /* for shared buffers we use some very like scanout */
391 if (tex
->base
.tex_usage
& PIPE_TEXTURE_USAGE_DISPLAY_TARGET
)
392 if (i915_display_target_layout(tex
))
395 tex
->stride
= round_up(pt
->nblocksx
[0] * pt
->block
.size
, 4);
397 /* May need to adjust pitch to accomodate the placement of
398 * the 2nd mipmap level. This occurs when the alignment
399 * constraints of mipmap placement push the right edge of the
400 * 2nd mipmap level out past the width of its parent.
402 if (pt
->last_level
> 0) {
403 unsigned mip1_nblocksx
404 = align(pf_get_nblocksx(&pt
->block
, u_minify(width
, 1)), align_x
)
405 + pf_get_nblocksx(&pt
->block
, u_minify(width
, 2));
407 if (mip1_nblocksx
> nblocksx
)
408 tex
->stride
= mip1_nblocksx
* pt
->block
.size
;
411 /* Pitch must be a whole number of dwords
413 tex
->stride
= align(tex
->stride
, 64);
414 tex
->total_nblocksy
= 0;
416 for (level
= 0; level
<= pt
->last_level
; level
++) {
417 i915_miptree_set_level_info(tex
, level
, 1, width
, height
, 1);
418 i915_miptree_set_image_offset(tex
, level
, 0, x
, y
);
420 nblocksy
= align(nblocksy
, align_y
);
422 /* Because the images are packed better, the final offset
423 * might not be the maximal one:
425 tex
->total_nblocksy
= MAX2(tex
->total_nblocksy
, y
+ nblocksy
);
427 /* Layout_below: step right after second mipmap level.
430 x
+= align(nblocksx
, align_x
);
436 width
= u_minify(width
, 1);
437 height
= u_minify(height
, 1);
438 nblocksx
= pf_get_nblocksx(&pt
->block
, width
);
439 nblocksy
= pf_get_nblocksy(&pt
->block
, height
);
444 i945_miptree_layout_3d(struct i915_texture
*tex
)
446 struct pipe_texture
*pt
= &tex
->base
;
447 unsigned width
= pt
->width0
;
448 unsigned height
= pt
->height0
;
449 unsigned depth
= pt
->depth0
;
450 unsigned nblocksx
= pt
->nblocksx
[0];
451 unsigned nblocksy
= pt
->nblocksy
[0];
452 unsigned pack_x_pitch
, pack_x_nr
;
453 unsigned pack_y_pitch
;
456 tex
->stride
= round_up(pt
->nblocksx
[0] * pt
->block
.size
, 4);
457 tex
->total_nblocksy
= 0;
459 pack_y_pitch
= MAX2(pt
->nblocksy
[0], 2);
460 pack_x_pitch
= tex
->stride
/ pt
->block
.size
;
463 for (level
= 0; level
<= pt
->last_level
; level
++) {
468 i915_miptree_set_level_info(tex
, level
, depth
, width
, height
, depth
);
470 for (q
= 0; q
< depth
;) {
471 for (j
= 0; j
< pack_x_nr
&& q
< depth
; j
++, q
++) {
472 i915_miptree_set_image_offset(tex
, level
, q
, x
, y
+ tex
->total_nblocksy
);
480 tex
->total_nblocksy
+= y
;
482 if (pack_x_pitch
> 4) {
485 assert(pack_x_pitch
* pack_x_nr
* pt
->block
.size
<= tex
->stride
);
488 if (pack_y_pitch
> 2) {
492 width
= u_minify(width
, 1);
493 height
= u_minify(height
, 1);
494 depth
= u_minify(depth
, 1);
495 nblocksx
= pf_get_nblocksx(&pt
->block
, width
);
496 nblocksy
= pf_get_nblocksy(&pt
->block
, height
);
501 i945_miptree_layout_cube(struct i915_texture
*tex
)
503 struct pipe_texture
*pt
= &tex
->base
;
506 const unsigned nblocks
= pt
->nblocksx
[0];
508 unsigned width
= pt
->width0
;
509 unsigned height
= pt
->height0
;
512 printf("%s %i, %i\n", __FUNCTION__, pt->width0, pt->height0);
515 assert(width
== height
); /* cubemap images are square */
518 * XXX Should only be used for compressed formats. But lets
519 * keep this code active just in case.
521 * Depending on the size of the largest images, pitch can be
522 * determined either by the old-style packing of cubemap faces,
523 * or the final row of 4x4, 2x2 and 1x1 faces below this.
526 tex
->stride
= round_up(nblocks
* pt
->block
.size
* 2, 4);
528 tex
->stride
= 14 * 8 * pt
->block
.size
;
530 tex
->total_nblocksy
= nblocks
* 4;
532 /* Set all the levels to effectively occupy the whole rectangular region.
534 for (level
= 0; level
<= pt
->last_level
; level
++) {
535 i915_miptree_set_level_info(tex
, level
, 6, width
, height
, 1);
540 for (face
= 0; face
< 6; face
++) {
541 unsigned x
= initial_offsets
[face
][0] * nblocks
;
542 unsigned y
= initial_offsets
[face
][1] * nblocks
;
543 unsigned d
= nblocks
;
545 #if 0 /* Fix and enable this code for compressed formats */
546 if (nblocks
== 4 && face
>= 4) {
547 y
= tex
->total_height
- 4;
550 else if (nblocks
< 4 && (face
> 0)) {
551 y
= tex
->total_height
- 4;
556 for (level
= 0; level
<= pt
->last_level
; level
++) {
557 i915_miptree_set_image_offset(tex
, level
, face
, x
, y
);
561 #if 0 /* Fix and enable this code for compressed formats */
565 case PIPE_TEX_FACE_POS_X
:
566 case PIPE_TEX_FACE_NEG_X
:
567 x
+= step_offsets
[face
][0] * d
;
568 y
+= step_offsets
[face
][1] * d
;
570 case PIPE_TEX_FACE_POS_Y
:
571 case PIPE_TEX_FACE_NEG_Y
:
575 case PIPE_TEX_FACE_POS_Z
:
576 case PIPE_TEX_FACE_NEG_Z
:
577 y
= tex
->total_height
- 4;
582 y
= tex
->total_height
- 4;
591 x
+= step_offsets
[face
][0] * d
;
592 y
+= step_offsets
[face
][1] * d
;
602 i945_miptree_layout(struct i915_texture
* tex
)
604 struct pipe_texture
*pt
= &tex
->base
;
606 switch (pt
->target
) {
607 case PIPE_TEXTURE_1D
:
608 case PIPE_TEXTURE_2D
:
609 i945_miptree_layout_2d(tex
);
611 case PIPE_TEXTURE_3D
:
612 i945_miptree_layout_3d(tex
);
614 case PIPE_TEXTURE_CUBE
:
615 i945_miptree_layout_cube(tex
);
627 * Screen texture functions
631 static struct pipe_texture
*
632 i915_texture_create(struct pipe_screen
*screen
,
633 const struct pipe_texture
*templat
)
635 struct i915_screen
*is
= i915_screen(screen
);
636 struct intel_winsys
*iws
= is
->iws
;
637 struct i915_texture
*tex
= CALLOC_STRUCT(i915_texture
);
639 unsigned buf_usage
= 0;
644 tex
->base
= *templat
;
645 pipe_reference_init(&tex
->base
.reference
, 1);
646 tex
->base
.screen
= screen
;
648 tex
->base
.nblocksx
[0] = pf_get_nblocksx(&tex
->base
.block
, tex
->base
.width0
);
649 tex
->base
.nblocksy
[0] = pf_get_nblocksy(&tex
->base
.block
, tex
->base
.height0
);
652 if (!i945_miptree_layout(tex
))
655 if (!i915_miptree_layout(tex
))
659 tex_size
= tex
->stride
* tex
->total_nblocksy
;
663 /* for scanouts and cursors, cursors arn't scanouts */
664 if (templat
->tex_usage
& PIPE_TEXTURE_USAGE_PRIMARY
&& templat
->width0
!= 64)
665 buf_usage
= INTEL_NEW_SCANOUT
;
667 buf_usage
= INTEL_NEW_TEXTURE
;
669 tex
->buffer
= iws
->buffer_create(iws
, tex_size
, 64, buf_usage
);
673 /* setup any hw fences */
675 assert(tex
->sw_tiled
== INTEL_TILE_NONE
);
676 iws
->buffer_set_fence_reg(iws
, tex
->buffer
, tex
->stride
, tex
->hw_tiled
);
681 void *ptr
= ws
->buffer_map(ws
, tex
->buffer
,
682 PIPE_BUFFER_USAGE_CPU_WRITE
);
683 memset(ptr
, 0x80, tex_size
);
684 ws
->buffer_unmap(ws
, tex
->buffer
);
694 static struct pipe_texture
*
695 i915_texture_blanket(struct pipe_screen
* screen
,
696 const struct pipe_texture
*base
,
697 const unsigned *stride
,
698 struct pipe_buffer
*buffer
)
701 struct i915_texture
*tex
;
704 /* Only supports one type */
705 if (base
->target
!= PIPE_TEXTURE_2D
||
706 base
->last_level
!= 0 ||
711 tex
= CALLOC_STRUCT(i915_texture
);
716 pipe_reference_init(&tex
->base
.reference
, 1);
717 tex
->base
.screen
= screen
;
719 tex
->stride
= stride
[0];
721 i915_miptree_set_level_info(tex
, 0, 1, base
->width0
, base
->height0
, 1);
722 i915_miptree_set_image_offset(tex
, 0, 0, 0, 0);
724 pipe_buffer_reference(&tex
->buffer
, buffer
);
733 i915_texture_destroy(struct pipe_texture
*pt
)
735 struct i915_texture
*tex
= (struct i915_texture
*)pt
;
736 struct intel_winsys
*iws
= i915_screen(pt
->screen
)->iws
;
740 DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
743 iws
->buffer_destroy(iws
, tex
->buffer
);
745 for (i
= 0; i
< PIPE_MAX_TEXTURE_LEVELS
; i
++)
746 if (tex
->image_offset
[i
])
747 FREE(tex
->image_offset
[i
]);
754 * Screen surface functions
758 static struct pipe_surface
*
759 i915_get_tex_surface(struct pipe_screen
*screen
,
760 struct pipe_texture
*pt
,
761 unsigned face
, unsigned level
, unsigned zslice
,
764 struct i915_texture
*tex
= (struct i915_texture
*)pt
;
765 struct pipe_surface
*ps
;
766 unsigned offset
; /* in bytes */
768 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
769 offset
= tex
->image_offset
[level
][face
];
771 else if (pt
->target
== PIPE_TEXTURE_3D
) {
772 offset
= tex
->image_offset
[level
][zslice
];
775 offset
= tex
->image_offset
[level
][0];
780 ps
= CALLOC_STRUCT(pipe_surface
);
782 pipe_reference_init(&ps
->reference
, 1);
783 pipe_texture_reference(&ps
->texture
, pt
);
784 ps
->format
= pt
->format
;
785 ps
->width
= u_minify(pt
->width0
, level
);
786 ps
->height
= u_minify(pt
->height0
, level
);
794 i915_tex_surface_destroy(struct pipe_surface
*surf
)
796 pipe_texture_reference(&surf
->texture
, NULL
);
802 * Screen transfer functions
806 static struct pipe_transfer
*
807 i915_get_tex_transfer(struct pipe_screen
*screen
,
808 struct pipe_texture
*texture
,
809 unsigned face
, unsigned level
, unsigned zslice
,
810 enum pipe_transfer_usage usage
, unsigned x
, unsigned y
,
811 unsigned w
, unsigned h
)
813 struct i915_texture
*tex
= (struct i915_texture
*)texture
;
814 struct i915_transfer
*trans
;
815 unsigned offset
; /* in bytes */
817 if (texture
->target
== PIPE_TEXTURE_CUBE
) {
818 offset
= tex
->image_offset
[level
][face
];
820 else if (texture
->target
== PIPE_TEXTURE_3D
) {
821 offset
= tex
->image_offset
[level
][zslice
];
824 offset
= tex
->image_offset
[level
][0];
829 trans
= CALLOC_STRUCT(i915_transfer
);
831 pipe_texture_reference(&trans
->base
.texture
, texture
);
832 trans
->base
.format
= trans
->base
.format
;
835 trans
->base
.width
= w
;
836 trans
->base
.height
= h
;
837 trans
->base
.block
= texture
->block
;
838 trans
->base
.nblocksx
= texture
->nblocksx
[level
];
839 trans
->base
.nblocksy
= texture
->nblocksy
[level
];
840 trans
->base
.stride
= tex
->stride
;
841 trans
->offset
= offset
;
842 trans
->base
.usage
= usage
;
848 i915_transfer_map(struct pipe_screen
*screen
,
849 struct pipe_transfer
*transfer
)
851 struct i915_texture
*tex
= (struct i915_texture
*)transfer
->texture
;
852 struct intel_winsys
*iws
= i915_screen(tex
->base
.screen
)->iws
;
854 boolean write
= FALSE
;
856 if (transfer
->usage
& PIPE_TRANSFER_WRITE
)
859 map
= iws
->buffer_map(iws
, tex
->buffer
, write
);
863 return map
+ i915_transfer(transfer
)->offset
+
864 transfer
->y
/ transfer
->block
.height
* transfer
->stride
+
865 transfer
->x
/ transfer
->block
.width
* transfer
->block
.size
;
869 i915_transfer_unmap(struct pipe_screen
*screen
,
870 struct pipe_transfer
*transfer
)
872 struct i915_texture
*tex
= (struct i915_texture
*)transfer
->texture
;
873 struct intel_winsys
*iws
= i915_screen(tex
->base
.screen
)->iws
;
874 iws
->buffer_unmap(iws
, tex
->buffer
);
878 i915_tex_transfer_destroy(struct pipe_transfer
*trans
)
880 pipe_texture_reference(&trans
->texture
, NULL
);
886 * Other texture functions
891 i915_init_screen_texture_functions(struct i915_screen
*is
)
893 is
->base
.texture_create
= i915_texture_create
;
894 is
->base
.texture_blanket
= i915_texture_blanket
;
895 is
->base
.texture_destroy
= i915_texture_destroy
;
896 is
->base
.get_tex_surface
= i915_get_tex_surface
;
897 is
->base
.tex_surface_destroy
= i915_tex_surface_destroy
;
898 is
->base
.get_tex_transfer
= i915_get_tex_transfer
;
899 is
->base
.transfer_map
= i915_transfer_map
;
900 is
->base
.transfer_unmap
= i915_transfer_unmap
;
901 is
->base
.tex_transfer_destroy
= i915_tex_transfer_destroy
;
904 struct pipe_texture
*
905 i915_texture_blanket_intel(struct pipe_screen
*screen
,
906 struct pipe_texture
*base
,
908 struct intel_buffer
*buffer
)
910 struct i915_texture
*tex
;
913 /* Only supports one type */
914 if (base
->target
!= PIPE_TEXTURE_2D
||
915 base
->last_level
!= 0 ||
920 tex
= CALLOC_STRUCT(i915_texture
);
925 pipe_reference_init(&tex
->base
.reference
, 1);
926 tex
->base
.screen
= screen
;
928 tex
->stride
= stride
;
930 i915_miptree_set_level_info(tex
, 0, 1, base
->width0
, base
->height0
, 1);
931 i915_miptree_set_image_offset(tex
, 0, 0, 0, 0);
933 tex
->buffer
= buffer
;
939 i915_get_texture_buffer_intel(struct pipe_texture
*texture
,
940 struct intel_buffer
**buffer
,
943 struct i915_texture
*tex
= (struct i915_texture
*)texture
;
948 *stride
= tex
->stride
;
949 *buffer
= tex
->buffer
;