José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 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: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 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. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | /* |
| 28 | * Authors: |
| 29 | * Keith Whitwell <keith@tungstengraphics.com> |
| 30 | * Michel Dänzer <michel@tungstengraphics.com> |
| 31 | */ |
| 32 | |
| 33 | #include "pipe/p_context.h" |
| 34 | #include "pipe/p_defines.h" |
José Fonseca | 2848688 | 2010-02-02 14:42:17 +0000 | [diff] [blame] | 35 | #include "util/u_inlines.h" |
Michal Krol | 6df42d8 | 2009-12-03 10:52:47 +0100 | [diff] [blame] | 36 | |
| 37 | #include "util/u_format.h" |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 38 | #include "util/u_math.h" |
| 39 | #include "util/u_memory.h" |
| 40 | |
| 41 | #include "lp_context.h" |
Brian Paul | 0706dae | 2010-01-20 17:44:12 -0700 | [diff] [blame] | 42 | #include "lp_screen.h" |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 43 | #include "lp_texture.h" |
Brian Paul | 0706dae | 2010-01-20 17:44:12 -0700 | [diff] [blame] | 44 | #include "lp_tile_size.h" |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 45 | #include "lp_winsys.h" |
| 46 | |
| 47 | |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Conventional allocation path for non-display textures: |
| 50 | * Simple, maximally packed layout. |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 51 | */ |
| 52 | static boolean |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 53 | llvmpipe_texture_layout(struct llvmpipe_screen *screen, |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 54 | struct llvmpipe_texture *lpt) |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 55 | { |
| 56 | struct pipe_texture *pt = &lpt->base; |
| 57 | unsigned level; |
Roland Scheidegger | d509f84 | 2009-11-26 22:49:58 +0100 | [diff] [blame] | 58 | unsigned width = pt->width0; |
| 59 | unsigned height = pt->height0; |
| 60 | unsigned depth = pt->depth0; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 61 | unsigned buffer_size = 0; |
| 62 | |
| 63 | for (level = 0; level <= pt->last_level; level++) { |
José Fonseca | 838da1d | 2009-10-18 14:31:58 +0100 | [diff] [blame] | 64 | unsigned nblocksx, nblocksy; |
| 65 | |
José Fonseca | 838da1d | 2009-10-18 14:31:58 +0100 | [diff] [blame] | 66 | /* Allocate storage for whole quads. This is particularly important |
Brian Paul | d8d80a8 | 2010-01-19 11:58:43 -0700 | [diff] [blame] | 67 | * for depth surfaces, which are currently stored in a swizzled format. |
| 68 | */ |
Brian Paul | 0706dae | 2010-01-20 17:44:12 -0700 | [diff] [blame] | 69 | nblocksx = util_format_get_nblocksx(pt->format, align(width, TILE_SIZE)); |
| 70 | nblocksy = util_format_get_nblocksy(pt->format, align(height, TILE_SIZE)); |
José Fonseca | 838da1d | 2009-10-18 14:31:58 +0100 | [diff] [blame] | 71 | |
Michal Krol | b1ed72e | 2009-12-17 23:41:57 +0100 | [diff] [blame] | 72 | lpt->stride[level] = align(nblocksx * util_format_get_blocksize(pt->format), 16); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 73 | |
| 74 | lpt->level_offset[level] = buffer_size; |
| 75 | |
José Fonseca | 838da1d | 2009-10-18 14:31:58 +0100 | [diff] [blame] | 76 | buffer_size += (nblocksy * |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 77 | ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * |
| 78 | lpt->stride[level]); |
| 79 | |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 80 | width = u_minify(width, 1); |
Roland Scheidegger | d509f84 | 2009-11-26 22:49:58 +0100 | [diff] [blame] | 81 | height = u_minify(height, 1); |
| 82 | depth = u_minify(depth, 1); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 83 | } |
| 84 | |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 85 | lpt->data = align_malloc(buffer_size, 16); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 86 | |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 87 | return lpt->data != NULL; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 90 | |
| 91 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 92 | static boolean |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 93 | llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen, |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 94 | struct llvmpipe_texture *lpt) |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 95 | { |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame^] | 96 | struct sw_winsys *winsys = screen->winsys; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 97 | |
Brian Paul | 0706dae | 2010-01-20 17:44:12 -0700 | [diff] [blame] | 98 | /* Round up the surface size to a multiple of the tile size to |
| 99 | * avoid tile clipping. |
| 100 | */ |
| 101 | unsigned width = align(lpt->base.width0, TILE_SIZE); |
| 102 | unsigned height = align(lpt->base.height0, TILE_SIZE); |
| 103 | |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 104 | lpt->dt = winsys->displaytarget_create(winsys, |
| 105 | lpt->base.format, |
Brian Paul | 0706dae | 2010-01-20 17:44:12 -0700 | [diff] [blame] | 106 | width, height, |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 107 | 16, |
| 108 | &lpt->stride[0] ); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 109 | |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 110 | return lpt->dt != NULL; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 114 | static struct pipe_texture * |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 115 | llvmpipe_texture_create(struct pipe_screen *_screen, |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 116 | const struct pipe_texture *templat) |
| 117 | { |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 118 | struct llvmpipe_screen *screen = llvmpipe_screen(_screen); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 119 | struct llvmpipe_texture *lpt = CALLOC_STRUCT(llvmpipe_texture); |
| 120 | if (!lpt) |
| 121 | return NULL; |
| 122 | |
| 123 | lpt->base = *templat; |
| 124 | pipe_reference_init(&lpt->base.reference, 1); |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 125 | lpt->base.screen = &screen->base; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 126 | |
José Fonseca | f04ce62 | 2009-08-29 09:17:51 +0100 | [diff] [blame] | 127 | if (lpt->base.tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | |
| 128 | PIPE_TEXTURE_USAGE_PRIMARY)) { |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 129 | if (!llvmpipe_displaytarget_layout(screen, lpt)) |
| 130 | goto fail; |
| 131 | } |
| 132 | else { |
| 133 | if (!llvmpipe_texture_layout(screen, lpt)) |
| 134 | goto fail; |
| 135 | } |
| 136 | |
| 137 | return &lpt->base; |
| 138 | |
| 139 | fail: |
| 140 | FREE(lpt); |
| 141 | return NULL; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | static struct pipe_texture * |
| 146 | llvmpipe_texture_blanket(struct pipe_screen * screen, |
| 147 | const struct pipe_texture *base, |
| 148 | const unsigned *stride, |
| 149 | struct pipe_buffer *buffer) |
| 150 | { |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 151 | /* FIXME */ |
| 152 | #if 0 |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 153 | struct llvmpipe_texture *lpt; |
| 154 | assert(screen); |
| 155 | |
| 156 | /* Only supports one type */ |
| 157 | if (base->target != PIPE_TEXTURE_2D || |
| 158 | base->last_level != 0 || |
Roland Scheidegger | b748a9f | 2009-11-27 17:40:24 +0100 | [diff] [blame] | 159 | base->depth0 != 1) { |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 160 | return NULL; |
| 161 | } |
| 162 | |
| 163 | lpt = CALLOC_STRUCT(llvmpipe_texture); |
| 164 | if (!lpt) |
| 165 | return NULL; |
| 166 | |
| 167 | lpt->base = *base; |
| 168 | pipe_reference_init(&lpt->base.reference, 1); |
| 169 | lpt->base.screen = screen; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 170 | lpt->stride[0] = stride[0]; |
| 171 | |
| 172 | pipe_buffer_reference(&lpt->buffer, buffer); |
| 173 | |
| 174 | return &lpt->base; |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 175 | #else |
Brian Paul | 0bb5c30 | 2010-01-13 09:32:10 -0700 | [diff] [blame] | 176 | debug_printf("llvmpipe_texture_blanket() not implemented!"); |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 177 | return NULL; |
| 178 | #endif |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
| 182 | static void |
| 183 | llvmpipe_texture_destroy(struct pipe_texture *pt) |
| 184 | { |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 185 | struct llvmpipe_screen *screen = llvmpipe_screen(pt->screen); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 186 | struct llvmpipe_texture *lpt = llvmpipe_texture(pt); |
| 187 | |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 188 | if (lpt->dt) { |
| 189 | /* display target */ |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame^] | 190 | struct sw_winsys *winsys = screen->winsys; |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 191 | winsys->displaytarget_destroy(winsys, lpt->dt); |
| 192 | } |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 193 | else { |
| 194 | /* regular texture */ |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 195 | align_free(lpt->data); |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 196 | } |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 197 | |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 198 | FREE(lpt); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | static struct pipe_surface * |
| 203 | llvmpipe_get_tex_surface(struct pipe_screen *screen, |
| 204 | struct pipe_texture *pt, |
| 205 | unsigned face, unsigned level, unsigned zslice, |
| 206 | unsigned usage) |
| 207 | { |
| 208 | struct llvmpipe_texture *lpt = llvmpipe_texture(pt); |
| 209 | struct pipe_surface *ps; |
| 210 | |
| 211 | assert(level <= pt->last_level); |
| 212 | |
| 213 | ps = CALLOC_STRUCT(pipe_surface); |
| 214 | if (ps) { |
| 215 | pipe_reference_init(&ps->reference, 1); |
| 216 | pipe_texture_reference(&ps->texture, pt); |
| 217 | ps->format = pt->format; |
Roland Scheidegger | d509f84 | 2009-11-26 22:49:58 +0100 | [diff] [blame] | 218 | ps->width = u_minify(pt->width0, level); |
| 219 | ps->height = u_minify(pt->height0, level); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 220 | ps->offset = lpt->level_offset[level]; |
| 221 | ps->usage = usage; |
| 222 | |
| 223 | /* Because we are llvmpipe, anything that the state tracker |
| 224 | * thought was going to be done with the GPU will actually get |
| 225 | * done with the CPU. Let's adjust the flags to take that into |
| 226 | * account. |
| 227 | */ |
| 228 | if (ps->usage & PIPE_BUFFER_USAGE_GPU_WRITE) { |
| 229 | /* GPU_WRITE means "render" and that can involve reads (blending) */ |
| 230 | ps->usage |= PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_CPU_READ; |
| 231 | } |
| 232 | |
| 233 | if (ps->usage & PIPE_BUFFER_USAGE_GPU_READ) |
| 234 | ps->usage |= PIPE_BUFFER_USAGE_CPU_READ; |
| 235 | |
| 236 | if (ps->usage & (PIPE_BUFFER_USAGE_CPU_WRITE | |
| 237 | PIPE_BUFFER_USAGE_GPU_WRITE)) { |
Keith Whitwell | 6b65685 | 2009-10-08 16:33:12 +0100 | [diff] [blame] | 238 | /* Mark the surface as dirty. */ |
Keith Whitwell | 0f55a95 | 2009-07-17 10:44:22 +0100 | [diff] [blame] | 239 | lpt->timestamp++; |
| 240 | llvmpipe_screen(screen)->timestamp++; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | ps->face = face; |
| 244 | ps->level = level; |
| 245 | ps->zslice = zslice; |
| 246 | |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 247 | /* XXX shouldn't that rather be |
| 248 | tex_height = align(ps->height, 2); |
| 249 | to account for alignment done in llvmpipe_texture_layout ? |
| 250 | */ |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 251 | if (pt->target == PIPE_TEXTURE_CUBE) { |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 252 | unsigned tex_height = ps->height; |
Michal Krol | b1ed72e | 2009-12-17 23:41:57 +0100 | [diff] [blame] | 253 | ps->offset += face * util_format_get_nblocksy(pt->format, tex_height) * lpt->stride[level]; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 254 | } |
| 255 | else if (pt->target == PIPE_TEXTURE_3D) { |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 256 | unsigned tex_height = ps->height; |
Michal Krol | b1ed72e | 2009-12-17 23:41:57 +0100 | [diff] [blame] | 257 | ps->offset += zslice * util_format_get_nblocksy(pt->format, tex_height) * lpt->stride[level]; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 258 | } |
| 259 | else { |
| 260 | assert(face == 0); |
| 261 | assert(zslice == 0); |
| 262 | } |
| 263 | } |
| 264 | return ps; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | static void |
| 269 | llvmpipe_tex_surface_destroy(struct pipe_surface *surf) |
| 270 | { |
| 271 | /* Effectively do the texture_update work here - if texture images |
| 272 | * needed post-processing to put them into hardware layout, this is |
| 273 | * where it would happen. For llvmpipe, nothing to do. |
| 274 | */ |
| 275 | assert(surf->texture); |
| 276 | pipe_texture_reference(&surf->texture, NULL); |
| 277 | FREE(surf); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static struct pipe_transfer * |
| 282 | llvmpipe_get_tex_transfer(struct pipe_screen *screen, |
| 283 | struct pipe_texture *texture, |
| 284 | unsigned face, unsigned level, unsigned zslice, |
| 285 | enum pipe_transfer_usage usage, |
| 286 | unsigned x, unsigned y, unsigned w, unsigned h) |
| 287 | { |
| 288 | struct llvmpipe_texture *lptex = llvmpipe_texture(texture); |
| 289 | struct llvmpipe_transfer *lpt; |
| 290 | |
| 291 | assert(texture); |
| 292 | assert(level <= texture->last_level); |
| 293 | |
| 294 | lpt = CALLOC_STRUCT(llvmpipe_transfer); |
| 295 | if (lpt) { |
| 296 | struct pipe_transfer *pt = &lpt->base; |
| 297 | pipe_texture_reference(&pt->texture, texture); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 298 | pt->x = x; |
| 299 | pt->y = y; |
Brian Paul | 0706dae | 2010-01-20 17:44:12 -0700 | [diff] [blame] | 300 | pt->width = align(w, TILE_SIZE); |
| 301 | pt->height = align(h, TILE_SIZE); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 302 | pt->stride = lptex->stride[level]; |
| 303 | pt->usage = usage; |
| 304 | pt->face = face; |
| 305 | pt->level = level; |
| 306 | pt->zslice = zslice; |
| 307 | |
| 308 | lpt->offset = lptex->level_offset[level]; |
| 309 | |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 310 | /* XXX shouldn't that rather be |
| 311 | tex_height = align(u_minify(texture->height0, level), 2) |
| 312 | to account for alignment done in llvmpipe_texture_layout ? |
| 313 | */ |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 314 | if (texture->target == PIPE_TEXTURE_CUBE) { |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 315 | unsigned tex_height = u_minify(texture->height0, level); |
Michal Krol | b1ed72e | 2009-12-17 23:41:57 +0100 | [diff] [blame] | 316 | lpt->offset += face * util_format_get_nblocksy(texture->format, tex_height) * pt->stride; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 317 | } |
| 318 | else if (texture->target == PIPE_TEXTURE_3D) { |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 319 | unsigned tex_height = u_minify(texture->height0, level); |
Michal Krol | b1ed72e | 2009-12-17 23:41:57 +0100 | [diff] [blame] | 320 | lpt->offset += zslice * util_format_get_nblocksy(texture->format, tex_height) * pt->stride; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 321 | } |
| 322 | else { |
| 323 | assert(face == 0); |
| 324 | assert(zslice == 0); |
| 325 | } |
| 326 | return pt; |
| 327 | } |
| 328 | return NULL; |
| 329 | } |
| 330 | |
| 331 | |
| 332 | static void |
| 333 | llvmpipe_tex_transfer_destroy(struct pipe_transfer *transfer) |
| 334 | { |
| 335 | /* Effectively do the texture_update work here - if texture images |
| 336 | * needed post-processing to put them into hardware layout, this is |
| 337 | * where it would happen. For llvmpipe, nothing to do. |
| 338 | */ |
| 339 | assert (transfer->texture); |
| 340 | pipe_texture_reference(&transfer->texture, NULL); |
| 341 | FREE(transfer); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | static void * |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 346 | llvmpipe_transfer_map( struct pipe_screen *_screen, |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 347 | struct pipe_transfer *transfer ) |
| 348 | { |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 349 | struct llvmpipe_screen *screen = llvmpipe_screen(_screen); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 350 | ubyte *map, *xfer_map; |
| 351 | struct llvmpipe_texture *lpt; |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 352 | enum pipe_format format; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 353 | |
| 354 | assert(transfer->texture); |
| 355 | lpt = llvmpipe_texture(transfer->texture); |
Roland Scheidegger | c78748a | 2009-12-02 02:08:26 +0100 | [diff] [blame] | 356 | format = lpt->base.format; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 357 | |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 358 | if (lpt->dt) { |
| 359 | /* display target */ |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame^] | 360 | struct sw_winsys *winsys = screen->winsys; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 361 | |
Michel Dänzer | 47e41b0 | 2009-10-02 18:13:26 +0200 | [diff] [blame] | 362 | map = winsys->displaytarget_map(winsys, lpt->dt, |
| 363 | pipe_transfer_buffer_flags(transfer)); |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 364 | if (map == NULL) |
| 365 | return NULL; |
| 366 | } |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 367 | else { |
| 368 | /* regular texture */ |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 369 | map = lpt->data; |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 370 | } |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 371 | |
| 372 | /* May want to different things here depending on read/write nature |
| 373 | * of the map: |
| 374 | */ |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 375 | if (transfer->texture && (transfer->usage & PIPE_TRANSFER_WRITE)) { |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 376 | /* Do something to notify sharing contexts of a texture change. |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 377 | */ |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 378 | screen->timestamp++; |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | xfer_map = map + llvmpipe_transfer(transfer)->offset + |
Michal Krol | b1ed72e | 2009-12-17 23:41:57 +0100 | [diff] [blame] | 382 | transfer->y / util_format_get_blockheight(format) * transfer->stride + |
| 383 | transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 384 | /*printf("map = %p xfer map = %p\n", map, xfer_map);*/ |
| 385 | return xfer_map; |
| 386 | } |
| 387 | |
| 388 | |
| 389 | static void |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 390 | llvmpipe_transfer_unmap(struct pipe_screen *screen, |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 391 | struct pipe_transfer *transfer) |
| 392 | { |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 393 | struct llvmpipe_screen *lp_screen = llvmpipe_screen(screen); |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 394 | struct llvmpipe_texture *lpt; |
| 395 | |
| 396 | assert(transfer->texture); |
| 397 | lpt = llvmpipe_texture(transfer->texture); |
| 398 | |
Brian Paul | 4414a1a | 2010-01-14 14:19:16 -0700 | [diff] [blame] | 399 | if (lpt->dt) { |
| 400 | /* display target */ |
Keith Whitwell | 94ce4eb | 2010-03-04 16:09:33 +0000 | [diff] [blame^] | 401 | struct sw_winsys *winsys = lp_screen->winsys; |
José Fonseca | e173a9b | 2009-08-29 20:02:25 +0100 | [diff] [blame] | 402 | winsys->displaytarget_unmap(winsys, lpt->dt); |
| 403 | } |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | |
| 407 | void |
José Fonseca | 946f432 | 2009-07-26 23:44:38 +0100 | [diff] [blame] | 408 | llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen) |
| 409 | { |
| 410 | screen->texture_create = llvmpipe_texture_create; |
| 411 | screen->texture_blanket = llvmpipe_texture_blanket; |
| 412 | screen->texture_destroy = llvmpipe_texture_destroy; |
| 413 | |
| 414 | screen->get_tex_surface = llvmpipe_get_tex_surface; |
| 415 | screen->tex_surface_destroy = llvmpipe_tex_surface_destroy; |
| 416 | |
| 417 | screen->get_tex_transfer = llvmpipe_get_tex_transfer; |
| 418 | screen->tex_transfer_destroy = llvmpipe_tex_transfer_destroy; |
| 419 | screen->transfer_map = llvmpipe_transfer_map; |
| 420 | screen->transfer_unmap = llvmpipe_transfer_unmap; |
| 421 | } |