sp_texture.c File Reference

Include dependency graph for sp_texture.c:

Go to the source code of this file.

Functions

static unsigned minify (unsigned d)
static boolean softpipe_texture_layout (struct pipe_screen *screen, struct softpipe_texture *spt)
static boolean softpipe_displaytarget_layout (struct pipe_screen *screen, struct softpipe_texture *spt)
static struct pipe_texturesoftpipe_texture_create (struct pipe_screen *screen, const struct pipe_texture *templat)
static struct pipe_texturesoftpipe_texture_blanket (struct pipe_screen *screen, const struct pipe_texture *base, const unsigned *stride, struct pipe_buffer *buffer)
static void softpipe_texture_release (struct pipe_screen *screen, struct pipe_texture **pt)
static struct pipe_surfacesoftpipe_get_tex_surface (struct pipe_screen *screen, struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice, unsigned usage)
static void softpipe_tex_surface_release (struct pipe_screen *screen, struct pipe_surface **s)
static void * softpipe_surface_map (struct pipe_screen *screen, struct pipe_surface *surface, unsigned flags)
static void softpipe_surface_unmap (struct pipe_screen *screen, struct pipe_surface *surface)
void softpipe_init_texture_funcs (struct softpipe_context *sp)
void softpipe_init_screen_texture_funcs (struct pipe_screen *screen)


Function Documentation

static unsigned minify ( unsigned  d  )  [static]

Definition at line 50 of file sp_texture.c.

References MAX2.

00051 {
00052    return MAX2(1, d>>1);
00053 }

static boolean softpipe_displaytarget_layout ( struct pipe_screen screen,
struct softpipe_texture spt 
) [static]

Definition at line 101 of file sp_texture.c.

References softpipe_texture::base, pipe_texture::block, softpipe_texture::buffer, pipe_surface::buffer, FALSE, pipe_texture::format, pipe_texture::height, pipe_texture::nblocksx, pipe_texture::nblocksy, pf_get_nblocksx(), pf_get_nblocksy(), PIPE_BUFFER_USAGE_CPU_READ, PIPE_BUFFER_USAGE_CPU_WRITE, PIPE_BUFFER_USAGE_GPU_READ, PIPE_BUFFER_USAGE_GPU_WRITE, pipe_surface::stride, softpipe_texture::stride, pipe_winsys::surface_alloc_storage, pipe_texture::tex_usage, pipe_texture::width, and pipe_screen::winsys.

00103 {
00104    struct pipe_winsys *ws = screen->winsys;
00105    struct pipe_surface surf;
00106    unsigned flags = (PIPE_BUFFER_USAGE_CPU_READ |
00107                      PIPE_BUFFER_USAGE_CPU_WRITE |
00108                      PIPE_BUFFER_USAGE_GPU_READ |
00109                      PIPE_BUFFER_USAGE_GPU_WRITE);
00110    int ret;
00111 
00112 
00113    memset(&surf, 0, sizeof(surf));
00114 
00115    ret =ws->surface_alloc_storage( ws, 
00116                                    &surf,
00117                                    spt->base.width[0], 
00118                                    spt->base.height[0],
00119                                    spt->base.format,
00120                                    flags,
00121                                    spt->base.tex_usage);
00122    if(ret != 0)
00123       return FALSE;
00124 
00125    if (!surf.buffer) {
00126       /* allocation failed */
00127       return FALSE;
00128    }
00129 
00130    /* Now extract the goodies: 
00131     */
00132    spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]);  
00133    spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]);  
00134    spt->stride[0] = surf.stride;
00135 
00136    /* Transfer the reference:
00137     */
00138    spt->buffer = surf.buffer;
00139    surf.buffer = NULL;
00140 
00141    return spt->buffer != NULL;
00142 }

static struct pipe_surface* softpipe_get_tex_surface ( struct pipe_screen screen,
struct pipe_texture pt,
unsigned  face,
unsigned  level,
unsigned  zslice,
unsigned  usage 
) [static, read]

Definition at line 229 of file sp_texture.c.

References assert, pipe_texture::block, pipe_surface::block, softpipe_texture::buffer, pipe_surface::buffer, CALLOC_STRUCT, pipe_surface::face, pipe_texture::format, pipe_surface::format, pipe_texture::height, pipe_surface::height, pipe_surface::level, softpipe_texture::level_offset, softpipe_texture::modified, pipe_texture::nblocksx, pipe_surface::nblocksx, pipe_texture::nblocksy, pipe_surface::nblocksy, pipe_surface::offset, pipe_buffer_reference(), PIPE_BUFFER_USAGE_CPU_READ, PIPE_BUFFER_USAGE_CPU_WRITE, PIPE_BUFFER_USAGE_GPU_READ, PIPE_BUFFER_USAGE_GPU_WRITE, PIPE_TEXTURE_3D, PIPE_TEXTURE_CUBE, pipe_texture_reference(), pipe_surface::refcount, softpipe_texture(), softpipe_texture::stride, pipe_surface::stride, pipe_texture::target, pipe_surface::texture, TRUE, pipe_surface::usage, pipe_texture::width, pipe_surface::width, pipe_screen::winsys, and pipe_surface::zslice.

00233 {
00234    struct pipe_winsys *ws = screen->winsys;
00235    struct softpipe_texture *spt = softpipe_texture(pt);
00236    struct pipe_surface *ps;
00237 
00238    assert(level <= pt->last_level);
00239 
00240    ps = CALLOC_STRUCT(pipe_surface);
00241    ps->refcount = 1;
00242    if (ps) {
00243       assert(ps->refcount);
00244       pipe_texture_reference(&ps->texture, pt);
00245       pipe_buffer_reference(screen, &ps->buffer, spt->buffer);
00246       ps->format = pt->format;
00247       ps->block = pt->block;
00248       ps->width = pt->width[level];
00249       ps->height = pt->height[level];
00250       ps->nblocksx = pt->nblocksx[level];
00251       ps->nblocksy = pt->nblocksy[level];
00252       ps->stride = spt->stride[level];
00253       ps->offset = spt->level_offset[level];
00254       ps->usage = usage;
00255       
00256       /* Because we are softpipe, anything that the state tracker
00257        * thought was going to be done with the GPU will actually get
00258        * done with the CPU.  Let's adjust the flags to take that into
00259        * account.
00260        */
00261       if (ps->usage & PIPE_BUFFER_USAGE_GPU_WRITE) {
00262          /* GPU_WRITE means "render" and that can involve reads (blending) */
00263          ps->usage |= PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_CPU_READ;
00264       }
00265 
00266       if (ps->usage & PIPE_BUFFER_USAGE_GPU_READ)
00267          ps->usage |= PIPE_BUFFER_USAGE_CPU_READ;
00268 
00269       if (ps->usage & (PIPE_BUFFER_USAGE_CPU_WRITE |
00270                        PIPE_BUFFER_USAGE_GPU_WRITE)) {
00271          /* Mark the surface as dirty.  The tile cache will look for this. */
00272          spt->modified = TRUE;
00273       }
00274 
00275       ps->face = face;
00276       ps->level = level;
00277       ps->zslice = zslice;
00278 
00279       if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) {
00280          ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) *
00281             ps->nblocksy *
00282             ps->stride;
00283       }
00284       else {
00285          assert(face == 0);
00286          assert(zslice == 0);
00287       }
00288    }
00289    return ps;
00290 }

void softpipe_init_screen_texture_funcs ( struct pipe_screen screen  ) 

Definition at line 359 of file sp_texture.c.

References pipe_screen::get_tex_surface, softpipe_get_tex_surface(), softpipe_surface_map(), softpipe_surface_unmap(), softpipe_tex_surface_release(), softpipe_texture_blanket(), softpipe_texture_create(), softpipe_texture_release(), pipe_screen::surface_map, pipe_screen::surface_unmap, pipe_screen::tex_surface_release, pipe_screen::texture_blanket, pipe_screen::texture_create, and pipe_screen::texture_release.

void softpipe_init_texture_funcs ( struct softpipe_context sp  ) 

Definition at line 353 of file sp_texture.c.

00354 {
00355 }

static void* softpipe_surface_map ( struct pipe_screen screen,
struct pipe_surface surface,
unsigned  flags 
) [static]

Definition at line 313 of file sp_texture.c.

References assert, pipe_surface::buffer, pipe_surface::offset, pipe_buffer_map(), PIPE_BUFFER_USAGE_CPU_WRITE, softpipe_screen(), pipe_surface::texture, softpipe_screen::timestamp, and pipe_surface::usage.

00316 {
00317    ubyte *map;
00318 
00319    if (flags & ~surface->usage) {
00320       assert(0);
00321       return NULL;
00322    }
00323 
00324    map = pipe_buffer_map( screen, surface->buffer, flags );
00325    if (map == NULL)
00326       return NULL;
00327 
00328    /* May want to different things here depending on read/write nature
00329     * of the map:
00330     */
00331    if (surface->texture &&
00332        (flags & PIPE_BUFFER_USAGE_CPU_WRITE)) 
00333    {
00334       /* Do something to notify sharing contexts of a texture change.
00335        * In softpipe, that would mean flushing the texture cache.
00336        */
00337       softpipe_screen(screen)->timestamp++;
00338    }
00339    
00340    return map + surface->offset;
00341 }

static void softpipe_surface_unmap ( struct pipe_screen screen,
struct pipe_surface surface 
) [static]

Definition at line 345 of file sp_texture.c.

References pipe_surface::buffer, and pipe_buffer_unmap().

00347 {
00348    pipe_buffer_unmap( screen, surface->buffer );
00349 }

static void softpipe_tex_surface_release ( struct pipe_screen screen,
struct pipe_surface **  s 
) [static]

Definition at line 294 of file sp_texture.c.

References assert, pipe_surface::buffer, FREE, pipe_buffer_reference(), pipe_texture_reference(), pipe_surface::refcount, and pipe_surface::texture.

00296 {
00297    struct pipe_surface *surf = *s;
00298    /* Effectively do the texture_update work here - if texture images
00299     * needed post-processing to put them into hardware layout, this is
00300     * where it would happen.  For softpipe, nothing to do.
00301     */
00302    assert ((*s)->texture);
00303    if (--surf->refcount == 0) {
00304       pipe_texture_reference(&surf->texture, NULL); 
00305       pipe_buffer_reference(screen, &surf->buffer, NULL);
00306       FREE(surf);
00307    }
00308    *s = NULL;
00309 }

static struct pipe_texture* softpipe_texture_blanket ( struct pipe_screen screen,
const struct pipe_texture base,
const unsigned *  stride,
struct pipe_buffer buffer 
) [static, read]

Definition at line 179 of file sp_texture.c.

References assert, softpipe_texture::base, pipe_texture::block, softpipe_texture::buffer, CALLOC_STRUCT, pipe_texture::depth, pipe_texture::height, pipe_texture::last_level, pipe_texture::nblocksx, pipe_texture::nblocksy, pf_get_nblocksx(), pf_get_nblocksy(), pipe_buffer_reference(), PIPE_TEXTURE_2D, pipe_texture::refcount, pipe_texture::screen, softpipe_texture::stride, pipe_texture::target, and pipe_texture::width.

00183 {
00184    struct softpipe_texture *spt;
00185    assert(screen);
00186 
00187    /* Only supports one type */
00188    if (base->target != PIPE_TEXTURE_2D ||
00189        base->last_level != 0 ||
00190        base->depth[0] != 1) {
00191       return NULL;
00192    }
00193 
00194    spt = CALLOC_STRUCT(softpipe_texture);
00195    if (!spt)
00196       return NULL;
00197 
00198    spt->base = *base;
00199    spt->base.refcount = 1;
00200    spt->base.screen = screen;
00201    spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]);  
00202    spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]);  
00203    spt->stride[0] = stride[0];
00204 
00205    pipe_buffer_reference(screen, &spt->buffer, buffer);
00206 
00207    return &spt->base;
00208 }

static struct pipe_texture* softpipe_texture_create ( struct pipe_screen screen,
const struct pipe_texture templat 
) [static, read]

Definition at line 149 of file sp_texture.c.

References assert, softpipe_texture::base, CALLOC_STRUCT, FREE, PIPE_TEXTURE_USAGE_DISPLAY_TARGET, pipe_texture::refcount, pipe_texture::screen, softpipe_displaytarget_layout(), softpipe_texture_layout(), and pipe_texture::tex_usage.

00151 {
00152    struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture);
00153    if (!spt)
00154       return NULL;
00155 
00156    spt->base = *templat;
00157    spt->base.refcount = 1;
00158    spt->base.screen = screen;
00159 
00160    if (spt->base.tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) {
00161       if (!softpipe_displaytarget_layout(screen, spt))
00162          goto fail;
00163    }
00164    else {
00165       if (!softpipe_texture_layout(screen, spt))
00166          goto fail;
00167    }
00168     
00169    assert(spt->base.refcount == 1);
00170    return &spt->base;
00171 
00172  fail:
00173    FREE(spt);
00174    return NULL;
00175 }

static boolean softpipe_texture_layout ( struct pipe_screen screen,
struct softpipe_texture spt 
) [static]

Definition at line 59 of file sp_texture.c.

References softpipe_texture::base, pipe_texture::block, softpipe_texture::buffer, pipe_winsys::buffer_create, pipe_texture::depth, pipe_texture::height, pipe_texture::last_level, softpipe_texture::level_offset, minify(), pipe_texture::nblocksx, pipe_texture::nblocksy, pf_get_nblocksx(), pf_get_nblocksy(), PIPE_BUFFER_USAGE_PIXEL, PIPE_TEXTURE_CUBE, pipe_format_block::size, softpipe_texture::stride, pipe_texture::target, pipe_texture::width, and pipe_screen::winsys.

00061 {
00062    struct pipe_winsys *ws = screen->winsys;
00063    struct pipe_texture *pt = &spt->base;
00064    unsigned level;
00065    unsigned width = pt->width[0];
00066    unsigned height = pt->height[0];
00067    unsigned depth = pt->depth[0];
00068 
00069    unsigned buffer_size = 0;
00070 
00071    for (level = 0; level <= pt->last_level; level++) {
00072       pt->width[level] = width;
00073       pt->height[level] = height;
00074       pt->depth[level] = depth;
00075       pt->nblocksx[level] = pf_get_nblocksx(&pt->block, width);  
00076       pt->nblocksy[level] = pf_get_nblocksy(&pt->block, height);  
00077       spt->stride[level] = pt->nblocksx[level]*pt->block.size;
00078 
00079       spt->level_offset[level] = buffer_size;
00080 
00081       buffer_size += (pt->nblocksy[level] *
00082                       ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) *
00083                       spt->stride[level]);
00084 
00085       width  = minify(width);
00086       height = minify(height);
00087       depth = minify(depth);
00088    }
00089 
00090    spt->buffer = ws->buffer_create(ws, 32,
00091                                    PIPE_BUFFER_USAGE_PIXEL,
00092                                    buffer_size);
00093 
00094    return spt->buffer != NULL;
00095 }

static void softpipe_texture_release ( struct pipe_screen screen,
struct pipe_texture **  pt 
) [static]

Definition at line 212 of file sp_texture.c.

References softpipe_texture::buffer, FREE, pipe_buffer_reference(), and softpipe_texture().

00214 {
00215    if (!*pt)
00216       return;
00217 
00218    if (--(*pt)->refcount <= 0) {
00219       struct softpipe_texture *spt = softpipe_texture(*pt);
00220 
00221       pipe_buffer_reference(screen, &spt->buffer, NULL);
00222       FREE(spt);
00223    }
00224    *pt = NULL;
00225 }


Generated on Tue Sep 29 06:25:42 2009 for Gallium3D by  doxygen 1.5.4