1
/**************************************************************************
3
* Copyright 2006 VMware, Inc.
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 VMWARE 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 <keithw@vmware.com>
30
* Michel Dänzer <daenzer@vmware.com>
33
#include "pipe/p_context.h"
34
#include "pipe/p_defines.h"
35
#include "pipe/p_state.h"
36
#include "util/format/u_format.h"
37
#include "util/u_inlines.h"
38
#include "util/u_math.h"
39
#include "util/u_memory.h"
40
#include "util/u_rect.h"
42
#include "i915_context.h"
43
#include "i915_debug.h"
44
#include "i915_resource.h"
45
#include "i915_screen.h"
46
#include "i915_winsys.h"
48
#define DEBUG_TEXTURES 0
51
* 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}, [PIPE_TEX_FACE_POS_Y] = {1, 0},
59
[PIPE_TEX_FACE_POS_Z] = {1, 1}, [PIPE_TEX_FACE_NEG_X] = {0, 2},
60
[PIPE_TEX_FACE_NEG_Y] = {1, 2}, [PIPE_TEX_FACE_NEG_Z] = {1, 3},
64
* Step offsets for Cube map.
66
static const int step_offsets[6][2] = {
67
[PIPE_TEX_FACE_POS_X] = {0, 2}, [PIPE_TEX_FACE_POS_Y] = {-1, 2},
68
[PIPE_TEX_FACE_POS_Z] = {-1, 1}, [PIPE_TEX_FACE_NEG_X] = {0, 2},
69
[PIPE_TEX_FACE_NEG_Y] = {-1, 2}, [PIPE_TEX_FACE_NEG_Z] = {-1, 1},
73
* For compressed level 2
75
static const int bottom_offsets[6] = {
76
[PIPE_TEX_FACE_POS_X] = 16 + 0 * 8, [PIPE_TEX_FACE_POS_Y] = 16 + 1 * 8,
77
[PIPE_TEX_FACE_POS_Z] = 16 + 2 * 8, [PIPE_TEX_FACE_NEG_X] = 16 + 3 * 8,
78
[PIPE_TEX_FACE_NEG_Y] = 16 + 4 * 8, [PIPE_TEX_FACE_NEG_Z] = 16 + 5 * 8,
81
static inline unsigned
82
align_nblocksx(enum pipe_format format, unsigned width, unsigned align_to)
84
return align(util_format_get_nblocksx(format, width), align_to);
87
static inline unsigned
88
align_nblocksy(enum pipe_format format, unsigned width, unsigned align_to)
90
return align(util_format_get_nblocksy(format, width), align_to);
93
static inline unsigned
94
get_pot_stride(enum pipe_format format, unsigned width)
96
return util_next_power_of_two(util_format_get_stride(format, width));
99
static inline const char *
100
get_tiling_string(enum i915_winsys_buffer_tile tile)
116
* More advanced helper funcs
120
i915_texture_set_level_info(struct i915_texture *tex, unsigned level,
123
assert(level < ARRAY_SIZE(tex->nr_images));
125
assert(!tex->image_offset[level]);
127
tex->nr_images[level] = nr_images;
128
tex->image_offset[level] = MALLOC(nr_images * sizeof(struct offset_pair));
129
tex->image_offset[level][0].nblocksx = 0;
130
tex->image_offset[level][0].nblocksy = 0;
134
i915_texture_offset(const struct i915_texture *tex, unsigned level,
138
x = tex->image_offset[level][layer].nblocksx *
139
util_format_get_blocksize(tex->b.format);
140
y = tex->image_offset[level][layer].nblocksy;
142
return y * tex->stride + x;
146
i915_texture_set_image_offset(struct i915_texture *tex, unsigned level,
147
unsigned img, unsigned nblocksx,
150
/* for the first image and level make sure offset is zero */
151
assert(!(img == 0 && level == 0) || (nblocksx == 0 && nblocksy == 0));
152
assert(img < tex->nr_images[level]);
154
tex->image_offset[level][img].nblocksx = nblocksx;
155
tex->image_offset[level][img].nblocksy = nblocksy;
158
debug_printf("%s: %p level %u, img %u (%u, %u)\n", __FUNCTION__, tex, level,
163
static enum i915_winsys_buffer_tile
164
i915_texture_tiling(struct i915_screen *is, struct i915_texture *tex)
166
if (!is->debug.tiling)
167
return I915_TILE_NONE;
169
if (tex->b.target == PIPE_TEXTURE_1D)
170
return I915_TILE_NONE;
172
if (util_format_is_compressed(tex->b.format))
175
if (is->debug.use_blitter)
182
* Shared layout functions
186
* Special case to deal with scanout textures.
189
i9x5_scanout_layout(struct i915_texture *tex)
191
struct pipe_resource *pt = &tex->b;
193
if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4)
196
if (pt->width0 >= 240) {
197
tex->stride = align(util_format_get_stride(pt->format, pt->width0), 64);
198
tex->total_nblocksy = align_nblocksy(pt->format, pt->height0, 8);
199
tex->tiling = I915_TILE_X;
200
/* special case for cursors */
201
} else if (pt->width0 == 64 && pt->height0 == 64) {
202
tex->stride = get_pot_stride(pt->format, pt->width0);
203
tex->total_nblocksy = align_nblocksy(pt->format, pt->height0, 8);
208
i915_texture_set_level_info(tex, 0, 1);
209
i915_texture_set_image_offset(tex, 0, 0, 0, 0);
213
debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
214
pt->width0, pt->height0, util_format_get_blocksize(pt->format),
215
tex->stride, tex->total_nblocksy,
216
tex->stride * tex->total_nblocksy);
223
* Special case to deal with shared textures.
226
i9x5_display_target_layout(struct i915_texture *tex)
228
struct pipe_resource *pt = &tex->b;
230
if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4)
233
/* fallback to normal textures for small textures */
234
if (pt->width0 < 240)
237
i915_texture_set_level_info(tex, 0, 1);
238
i915_texture_set_image_offset(tex, 0, 0, 0, 0);
240
tex->stride = align(util_format_get_stride(pt->format, pt->width0), 64);
241
tex->total_nblocksy = align_nblocksy(pt->format, pt->height0, 8);
242
tex->tiling = I915_TILE_X;
245
debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
246
pt->width0, pt->height0, util_format_get_blocksize(pt->format),
247
tex->stride, tex->total_nblocksy,
248
tex->stride * tex->total_nblocksy);
255
* Helper function for special layouts
258
i9x5_special_layout(struct i915_texture *tex)
260
struct pipe_resource *pt = &tex->b;
262
/* Scanouts needs special care */
263
if (pt->bind & PIPE_BIND_SCANOUT)
264
if (i9x5_scanout_layout(tex))
267
/* Shared buffers needs to be compatible with X servers
269
* XXX: need a better name than shared for this if it is to be part
270
* of core gallium, and probably move the flag to resource.flags,
271
* rather than bindings.
273
if (pt->bind & (PIPE_BIND_SHARED | PIPE_BIND_DISPLAY_TARGET))
274
if (i9x5_display_target_layout(tex))
281
* Cube layout used on i915 and for non-compressed textures on i945.
283
* Hardware layout looks like:
325
i9x5_texture_layout_cube(struct i915_texture *tex)
327
struct pipe_resource *pt = &tex->b;
328
unsigned width = util_next_power_of_two(pt->width0);
329
const unsigned nblocks = util_format_get_nblocksx(pt->format, width);
333
assert(pt->width0 == pt->height0); /* cubemap images are square */
335
/* double pitch for cube layouts */
336
tex->stride = align(nblocks * util_format_get_blocksize(pt->format) * 2, 4);
337
tex->total_nblocksy = nblocks * 4;
339
for (level = 0; level <= pt->last_level; level++)
340
i915_texture_set_level_info(tex, level, 6);
342
for (face = 0; face < 6; face++) {
343
unsigned x = initial_offsets[face][0] * nblocks;
344
unsigned y = initial_offsets[face][1] * nblocks;
345
unsigned d = nblocks;
347
for (level = 0; level <= pt->last_level; level++) {
348
i915_texture_set_image_offset(tex, level, face, x, y);
350
x += step_offsets[face][0] * d;
351
y += step_offsets[face][1] * d;
357
* i915 layout functions
361
i915_texture_layout_2d(struct i915_texture *tex)
363
struct pipe_resource *pt = &tex->b;
365
unsigned width = util_next_power_of_two(pt->width0);
366
unsigned height = util_next_power_of_two(pt->height0);
367
unsigned nblocksy = util_format_get_nblocksy(pt->format, width);
368
unsigned align_y = 2;
370
if (util_format_is_compressed(pt->format))
373
tex->stride = align(util_format_get_stride(pt->format, width), 4);
374
tex->total_nblocksy = 0;
376
for (level = 0; level <= pt->last_level; level++) {
377
i915_texture_set_level_info(tex, level, 1);
378
i915_texture_set_image_offset(tex, level, 0, 0, tex->total_nblocksy);
380
tex->total_nblocksy += nblocksy;
382
width = u_minify(width, 1);
383
height = u_minify(height, 1);
384
nblocksy = align_nblocksy(pt->format, height, align_y);
389
i915_texture_layout_3d(struct i915_texture *tex)
391
struct pipe_resource *pt = &tex->b;
394
unsigned width = util_next_power_of_two(pt->width0);
395
unsigned height = util_next_power_of_two(pt->height0);
396
unsigned depth = util_next_power_of_two(pt->depth0);
397
unsigned nblocksy = util_format_get_nblocksy(pt->format, height);
398
unsigned stack_nblocksy = 0;
400
/* Calculate the size of a single slice.
402
tex->stride = align(util_format_get_stride(pt->format, width), 4);
404
/* XXX: hardware expects/requires 9 levels at minimum.
406
for (level = 0; level <= MAX2(8, pt->last_level); level++) {
407
i915_texture_set_level_info(tex, level, depth);
409
stack_nblocksy += MAX2(2, nblocksy);
411
width = u_minify(width, 1);
412
height = u_minify(height, 1);
413
nblocksy = util_format_get_nblocksy(pt->format, height);
416
/* Fixup depth image_offsets:
418
for (level = 0; level <= pt->last_level; level++) {
420
for (i = 0; i < depth; i++)
421
i915_texture_set_image_offset(tex, level, i, 0, i * stack_nblocksy);
423
depth = u_minify(depth, 1);
426
/* Multiply slice size by texture depth for total size. It's
427
* remarkable how wasteful of memory the i915 texture layouts
428
* are. They are largely fixed in the i945.
430
tex->total_nblocksy = stack_nblocksy * util_next_power_of_two(pt->depth0);
434
i915_texture_layout(struct i915_texture *tex)
436
switch (tex->b.target) {
437
case PIPE_TEXTURE_1D:
438
case PIPE_TEXTURE_2D:
439
case PIPE_TEXTURE_RECT:
440
if (!i9x5_special_layout(tex))
441
i915_texture_layout_2d(tex);
443
case PIPE_TEXTURE_3D:
444
i915_texture_layout_3d(tex);
446
case PIPE_TEXTURE_CUBE:
447
i9x5_texture_layout_cube(tex);
458
* i945 layout functions
462
i945_texture_layout_2d(struct i915_texture *tex)
464
struct pipe_resource *pt = &tex->b;
465
int align_x = 4, align_y = 2;
469
unsigned width = util_next_power_of_two(pt->width0);
470
unsigned height = util_next_power_of_two(pt->height0);
471
unsigned nblocksx = util_format_get_nblocksx(pt->format, width);
472
unsigned nblocksy = util_format_get_nblocksy(pt->format, height);
474
if (util_format_is_compressed(pt->format)) {
479
tex->stride = align(util_format_get_stride(pt->format, width), 4);
481
/* May need to adjust pitch to accommodate the placement of
482
* the 2nd mipmap level. This occurs when the alignment
483
* constraints of mipmap placement push the right edge of the
484
* 2nd mipmap level out past the width of its parent.
486
if (pt->last_level > 0) {
487
unsigned mip1_nblocksx =
488
align_nblocksx(pt->format, u_minify(width, 1), align_x) +
489
util_format_get_nblocksx(pt->format, u_minify(width, 2));
491
if (mip1_nblocksx > nblocksx)
492
tex->stride = mip1_nblocksx * util_format_get_blocksize(pt->format);
495
/* Pitch must be a whole number of dwords
497
tex->stride = align(tex->stride, 64);
498
tex->total_nblocksy = 0;
500
for (level = 0; level <= pt->last_level; level++) {
501
i915_texture_set_level_info(tex, level, 1);
502
i915_texture_set_image_offset(tex, level, 0, x, y);
504
/* Because the images are packed better, the final offset
505
* might not be the maximal one:
507
tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy);
509
/* Layout_below: step right after second mipmap level.
517
width = u_minify(width, 1);
518
height = u_minify(height, 1);
519
nblocksx = align_nblocksx(pt->format, width, align_x);
520
nblocksy = align_nblocksy(pt->format, height, align_y);
525
i945_texture_layout_3d(struct i915_texture *tex)
527
struct pipe_resource *pt = &tex->b;
528
unsigned width = util_next_power_of_two(pt->width0);
529
unsigned height = util_next_power_of_two(pt->height0);
530
unsigned depth = util_next_power_of_two(pt->depth0);
531
unsigned nblocksy = util_format_get_nblocksy(pt->format, height);
532
unsigned pack_x_pitch, pack_x_nr;
533
unsigned pack_y_pitch;
536
tex->stride = align(util_format_get_stride(pt->format, width), 4);
537
tex->total_nblocksy = 0;
539
pack_y_pitch = MAX2(nblocksy, 2);
540
pack_x_pitch = tex->stride / util_format_get_blocksize(pt->format);
543
for (level = 0; level <= pt->last_level; level++) {
548
i915_texture_set_level_info(tex, level, depth);
550
for (q = 0; q < depth;) {
551
for (j = 0; j < pack_x_nr && q < depth; j++, q++) {
552
i915_texture_set_image_offset(tex, level, q, x,
553
y + tex->total_nblocksy);
561
tex->total_nblocksy += y;
563
if (pack_x_pitch > 4) {
566
assert(pack_x_pitch * pack_x_nr *
567
util_format_get_blocksize(pt->format) <=
571
if (pack_y_pitch > 2) {
575
width = u_minify(width, 1);
576
height = u_minify(height, 1);
577
depth = u_minify(depth, 1);
578
nblocksy = util_format_get_nblocksy(pt->format, height);
583
* Compressed cube texture map layout for i945 and later.
585
* The hardware layout looks like the 830-915 layout, except for the small
586
* sizes. A zoomed in view of the layout for 945 is:
628
* +---+ +---+---+---+---+---+---+---+---+---+
629
* |4x4| |4x4| |2x2| |2x2| |2x2| |2x2|
630
* | +z| | -z| | +x| | +y| | +z| | -x| ...
631
* | | | | | | | | | | | |
632
* +---+ +---+ +---+ +---+ +---+ +---+
634
* The bottom row continues with the remaining 2x2 then the 1x1 mip contents
635
* in order, with each of them aligned to a 8x8 block boundary. Thus, for
636
* 32x32 cube maps and smaller, the bottom row layout is going to dictate the
637
* pitch of the tree. For a tree with 4x4 images, the pitch is at least
638
* 14 * 8 = 112 texels, for 2x2 it is at least 12 * 8 texels, and for 1x1
639
* it is 6 * 8 texels.
642
i945_texture_layout_cube(struct i915_texture *tex)
644
struct pipe_resource *pt = &tex->b;
645
unsigned width = util_next_power_of_two(pt->width0);
646
const unsigned nblocks = util_format_get_nblocksx(pt->format, width);
647
const unsigned dim = width;
651
assert(pt->width0 == pt->height0); /* cubemap images are square */
652
assert(util_format_is_compressed(pt->format)); /* compressed only */
655
* Depending on the size of the largest images, pitch can be
656
* determined either by the old-style packing of cubemap faces,
657
* or the final row of 4x4, 2x2 and 1x1 faces below this.
663
tex->stride = nblocks * 2 * util_format_get_blocksize(pt->format);
665
tex->stride = 14 * 2 * util_format_get_blocksize(pt->format);
668
* Something similary apply for height as well.
671
tex->total_nblocksy = nblocks * 4 + 1;
673
tex->total_nblocksy = 1;
675
/* Set all the levels to effectively occupy the whole rectangular region */
676
for (level = 0; level <= pt->last_level; level++)
677
i915_texture_set_level_info(tex, level, 6);
679
for (face = 0; face < 6; face++) {
680
/* all calculations in pixels */
681
unsigned total_height = tex->total_nblocksy * 4;
682
unsigned x = initial_offsets[face][0] * dim;
683
unsigned y = initial_offsets[face][1] * dim;
686
if (dim == 4 && face >= 4) {
688
y = tex->total_nblocksy * 4 - 4; /* 4 = 1 block */
689
} else if (dim < 4 && (face > 0)) {
691
y = total_height - 4;
694
for (level = 0; level <= pt->last_level; level++) {
695
i915_texture_set_image_offset(tex, level, face,
696
util_format_get_nblocksx(pt->format, x),
697
util_format_get_nblocksy(pt->format, y));
704
case PIPE_TEX_FACE_POS_X:
705
case PIPE_TEX_FACE_NEG_X:
706
x += step_offsets[face][0] * d;
707
y += step_offsets[face][1] * d;
709
case PIPE_TEX_FACE_POS_Y:
710
case PIPE_TEX_FACE_NEG_Y:
714
case PIPE_TEX_FACE_POS_Z:
715
case PIPE_TEX_FACE_NEG_Z:
716
y = total_height - 4;
722
y = total_height - 4;
723
x = bottom_offsets[face];
729
x += step_offsets[face][0] * d;
730
y += step_offsets[face][1] * d;
738
i945_texture_layout(struct i915_texture *tex)
740
switch (tex->b.target) {
741
case PIPE_TEXTURE_1D:
742
case PIPE_TEXTURE_2D:
743
case PIPE_TEXTURE_RECT:
744
if (!i9x5_special_layout(tex))
745
i945_texture_layout_2d(tex);
747
case PIPE_TEXTURE_3D:
748
i945_texture_layout_3d(tex);
750
case PIPE_TEXTURE_CUBE:
751
if (!util_format_is_compressed(tex->b.format))
752
i9x5_texture_layout_cube(tex);
754
i945_texture_layout_cube(tex);
765
* Screen texture functions
769
i915_resource_get_handle(struct pipe_screen *screen,
770
struct pipe_context *context,
771
struct pipe_resource *texture,
772
struct winsys_handle *whandle, unsigned usage)
774
if (texture->target == PIPE_BUFFER)
777
struct i915_screen *is = i915_screen(screen);
778
struct i915_texture *tex = i915_texture(texture);
779
struct i915_winsys *iws = is->iws;
781
return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride);
785
i915_texture_transfer_map(struct pipe_context *pipe,
786
struct pipe_resource *resource, unsigned level,
787
unsigned usage, const struct pipe_box *box,
788
struct pipe_transfer **ptransfer)
790
struct i915_context *i915 = i915_context(pipe);
791
struct i915_texture *tex = i915_texture(resource);
792
struct i915_transfer *transfer = slab_alloc_st(&i915->texture_transfer_pool);
793
bool use_staging_texture = false;
794
struct i915_winsys *iws = i915_screen(pipe->screen)->iws;
795
enum pipe_format format = resource->format;
802
transfer->b.resource = resource;
803
transfer->b.level = level;
804
transfer->b.usage = usage;
805
transfer->b.box = *box;
806
transfer->b.stride = tex->stride;
807
transfer->staging_texture = NULL;
808
/* XXX: handle depth textures everyhwere*/
809
transfer->b.layer_stride = 0;
811
/* if we use staging transfers, only support textures we can render to,
812
* because we need that for u_blitter */
814
util_blitter_is_copy_supported(i915->blitter, resource, resource) &&
815
(usage & PIPE_MAP_WRITE) &&
817
(PIPE_MAP_READ | PIPE_MAP_DONTBLOCK | PIPE_MAP_UNSYNCHRONIZED)))
818
use_staging_texture = true;
820
use_staging_texture = false;
822
if (use_staging_texture) {
824
* Allocate the untiled staging texture.
825
* If the alloc fails, transfer->staging_texture is NULL and we fallback
828
transfer->staging_texture =
829
i915_texture_create(pipe->screen, resource, true);
832
if (resource->target != PIPE_TEXTURE_3D &&
833
resource->target != PIPE_TEXTURE_CUBE) {
835
assert(box->depth == 1);
838
if (transfer->staging_texture) {
839
tex = i915_texture(transfer->staging_texture);
841
/* TODO this is a sledgehammer */
842
tex = i915_texture(resource);
843
pipe->flush(pipe, NULL, 0);
846
offset = i915_texture_offset(tex, transfer->b.level, box->z);
848
map = iws->buffer_map(iws, tex->buffer,
849
(transfer->b.usage & PIPE_MAP_WRITE) ? true : false);
851
pipe_resource_reference(&transfer->staging_texture, NULL);
856
*ptransfer = &transfer->b;
858
return map + offset +
859
box->y / util_format_get_blockheight(format) * transfer->b.stride +
860
box->x / util_format_get_blockwidth(format) *
861
util_format_get_blocksize(format);
865
i915_texture_transfer_unmap(struct pipe_context *pipe,
866
struct pipe_transfer *transfer)
868
struct i915_context *i915 = i915_context(pipe);
869
struct i915_transfer *itransfer = (struct i915_transfer *)transfer;
870
struct i915_texture *tex = i915_texture(itransfer->b.resource);
871
struct i915_winsys *iws = i915_screen(tex->b.screen)->iws;
873
if (itransfer->staging_texture)
874
tex = i915_texture(itransfer->staging_texture);
876
iws->buffer_unmap(iws, tex->buffer);
878
if ((itransfer->staging_texture) && (transfer->usage & PIPE_MAP_WRITE)) {
879
struct pipe_box sbox;
881
u_box_origin_2d(itransfer->b.box.width, itransfer->b.box.height, &sbox);
882
pipe->resource_copy_region(pipe, itransfer->b.resource,
883
itransfer->b.level, itransfer->b.box.x,
884
itransfer->b.box.y, itransfer->b.box.z,
885
itransfer->staging_texture, 0, &sbox);
886
pipe->flush(pipe, NULL, 0);
887
pipe_resource_reference(&itransfer->staging_texture, NULL);
890
slab_free_st(&i915->texture_transfer_pool, itransfer);
894
i915_texture_subdata(struct pipe_context *pipe, struct pipe_resource *resource,
895
unsigned level, unsigned usage, const struct pipe_box *box,
896
const void *data, unsigned stride, unsigned layer_stride)
898
/* i915's cube and 3D maps are not laid out such that one could use a
899
* layer_stride to get from one layer to the next, so we have to walk the
900
* layers individually.
902
struct pipe_box layer_box = *box;
904
for (layer_box.z = box->z; layer_box.z < box->z + box->depth;
906
u_default_texture_subdata(pipe, resource, level, usage, &layer_box, data,
907
stride, layer_stride);
908
data += layer_stride;
912
struct pipe_resource *
913
i915_texture_create(struct pipe_screen *screen,
914
const struct pipe_resource *template, bool force_untiled)
916
struct i915_screen *is = i915_screen(screen);
917
struct i915_winsys *iws = is->iws;
918
struct i915_texture *tex = CALLOC_STRUCT(i915_texture);
919
unsigned buf_usage = 0;
925
pipe_reference_init(&tex->b.reference, 1);
926
tex->b.screen = screen;
928
if ((force_untiled) || (template->usage == PIPE_USAGE_STREAM))
929
tex->tiling = I915_TILE_NONE;
931
tex->tiling = i915_texture_tiling(is, tex);
934
if (!i945_texture_layout(tex))
937
if (!i915_texture_layout(tex))
941
/* for scanouts and cursors, cursors arn't scanouts */
943
/* XXX: use a custom flag for cursors, don't rely on magically
944
* guessing that this is Xorg asking for a cursor
946
if ((template->bind & PIPE_BIND_SCANOUT) && template->width0 != 64)
947
buf_usage = I915_NEW_SCANOUT;
949
buf_usage = I915_NEW_TEXTURE;
951
tex->buffer = iws->buffer_create_tiled(
952
iws, &tex->stride, tex->total_nblocksy, &tex->tiling, buf_usage);
956
I915_DBG(DBG_TEXTURE, "%s: %p stride %u, blocks (%u, %u) tiling %s\n",
957
__func__, tex, tex->stride,
958
tex->stride / util_format_get_blocksize(tex->b.format),
959
tex->total_nblocksy, get_tiling_string(tex->tiling));
968
struct pipe_resource *
969
i915_texture_from_handle(struct pipe_screen *screen,
970
const struct pipe_resource *template,
971
struct winsys_handle *whandle)
973
struct i915_screen *is = i915_screen(screen);
974
struct i915_texture *tex;
975
struct i915_winsys *iws = is->iws;
976
struct i915_winsys_buffer *buffer;
978
enum i915_winsys_buffer_tile tiling;
982
buffer = iws->buffer_from_handle(iws, whandle, template->height0, &tiling,
985
/* Only supports one type */
986
if ((template->target != PIPE_TEXTURE_2D &&
987
template->target != PIPE_TEXTURE_RECT) ||
988
template->last_level != 0 || template->depth0 != 1) {
992
tex = CALLOC_STRUCT(i915_texture);
997
pipe_reference_init(&tex->b.reference, 1);
998
tex->b.screen = screen;
1000
tex->stride = stride;
1001
tex->tiling = tiling;
1002
tex->total_nblocksy = align_nblocksy(tex->b.format, tex->b.height0, 8);
1004
i915_texture_set_level_info(tex, 0, 1);
1005
i915_texture_set_image_offset(tex, 0, 0, 0, 0);
1007
tex->buffer = buffer;
1009
I915_DBG(DBG_TEXTURE, "%s: %p stride %u, blocks (%u, %u) tiling %s\n",
1010
__func__, tex, tex->stride,
1011
tex->stride / util_format_get_blocksize(tex->b.format),
1012
tex->total_nblocksy, get_tiling_string(tex->tiling));