8f31f05e478feff7ab567e4c02d53c8ff0631572
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_context.h"
34 #include "pipe/p_defines.h"
35 #include "pipe/p_inlines.h"
36 #include "pipe/p_util.h"
37 #include "pipe/p_winsys.h"
39 #include "sp_context.h"
41 #include "sp_texture.h"
42 #include "sp_tile_cache.h"
45 /* Simple, maximally packed layout.
48 static unsigned minify( unsigned d
)
55 softpipe_texture_layout(struct softpipe_texture
* spt
)
57 struct pipe_texture
*pt
= &spt
->base
;
59 unsigned width
= pt
->width
[0];
60 unsigned height
= pt
->height
[0];
61 unsigned depth
= pt
->depth
[0];
65 for (level
= 0; level
<= pt
->last_level
; level
++) {
66 pt
->width
[level
] = width
;
67 pt
->height
[level
] = height
;
68 pt
->depth
[level
] = depth
;
70 spt
->level_offset
[level
] = spt
->buffer_size
;
72 spt
->buffer_size
+= ((pt
->compressed
) ? MAX2(1, height
/4) : height
) *
73 ((pt
->target
== PIPE_TEXTURE_CUBE
) ? 6 : depth
) *
76 width
= minify(width
);
77 height
= minify(height
);
78 depth
= minify(depth
);
84 softpipe_texture_create(struct pipe_context
*pipe
,
85 const struct pipe_texture
*templat
)
87 struct softpipe_texture
*spt
= CALLOC_STRUCT(softpipe_texture
);
93 softpipe_texture_layout(spt
);
95 spt
->buffer
= pipe
->winsys
->buffer_create(pipe
->winsys
, 32,
96 PIPE_BUFFER_USAGE_PIXEL
,
108 softpipe_texture_release(struct pipe_context
*pipe
, struct pipe_texture
**pt
)
114 DBG("%s %p refcount will be %d\n",
115 __FUNCTION__, (void *) *pt, (*pt)->refcount - 1);
117 if (--(*pt
)->refcount
<= 0) {
118 struct softpipe_texture
*spt
= softpipe_texture(*pt
);
121 DBG("%s deleting %p\n", __FUNCTION__, (void *) spt);
124 pipe_buffer_reference(pipe
->winsys
, &spt
->buffer
, NULL
);
133 softpipe_texture_update(struct pipe_context
*pipe
,
134 struct pipe_texture
*texture
)
136 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
138 for (unit
= 0; unit
< PIPE_MAX_SAMPLERS
; unit
++) {
139 if (softpipe
->texture
[unit
] == texture
) {
140 sp_flush_tile_cache(softpipe
, softpipe
->tex_cache
[unit
]);
147 * Called via pipe->get_tex_surface()
149 struct pipe_surface
*
150 softpipe_get_tex_surface(struct pipe_context
*pipe
,
151 struct pipe_texture
*pt
,
152 unsigned face
, unsigned level
, unsigned zslice
)
154 struct softpipe_texture
*spt
= softpipe_texture(pt
);
155 struct pipe_surface
*ps
;
157 assert(level
<= pt
->last_level
);
159 ps
= pipe
->winsys
->surface_alloc(pipe
->winsys
);
161 assert(ps
->refcount
);
163 pipe_buffer_reference(pipe
->winsys
, &ps
->buffer
, spt
->buffer
);
164 ps
->format
= pt
->format
;
166 ps
->width
= pt
->width
[level
];
167 ps
->height
= pt
->height
[level
];
168 ps
->pitch
= ps
->width
;
169 ps
->offset
= spt
->level_offset
[level
];
171 if (pt
->target
== PIPE_TEXTURE_CUBE
|| pt
->target
== PIPE_TEXTURE_3D
) {
172 ps
->offset
+= ((pt
->target
== PIPE_TEXTURE_CUBE
) ? face
: zslice
) *
173 (pt
->compressed
? ps
->height
/4 : ps
->height
) *