Пример #1
0
static void r300_setup_miptree(struct r300_texture* tex)
{
    struct pipe_texture* base = &tex->tex;
    int stride, size, offset;
    int i;

    for (i = 0; i <= base->last_level; i++) {
        if (i > 0) {
            base->width[i] = minify(base->width[i-1]);
            base->height[i] = minify(base->height[i-1]);
            base->depth[i] = minify(base->depth[i-1]);
        }

        base->nblocksx[i] = pf_get_nblocksx(&base->block, base->width[i]);
        base->nblocksy[i] = pf_get_nblocksy(&base->block, base->width[i]);

        /* Radeons enjoy things in multiples of 32. */
        /* XXX this can be 32 when POT */
        stride = (base->nblocksx[i] * base->block.size + 63) & ~63;
        size = stride * base->nblocksy[i] * base->depth[i];

        tex->offset[i] = (tex->size + 63) & ~63;
        tex->size = tex->offset[i] + size;

        if (i == 0) {
            tex->stride = stride;
        }
    }
}
Пример #2
0
static struct pipe_texture *
softpipe_texture_blanket(struct pipe_screen * screen,
                         const struct pipe_texture *base,
                         const unsigned *stride,
                         struct pipe_buffer *buffer)
{
   struct softpipe_texture *spt;
   assert(screen);

   /* Only supports one type */
   if (base->target != PIPE_TEXTURE_2D ||
       base->last_level != 0 ||
       base->depth[0] != 1) {
      return NULL;
   }

   spt = CALLOC_STRUCT(softpipe_texture);
   if (!spt)
      return NULL;

   spt->base = *base;
   spt->base.refcount = 1;
   spt->base.screen = screen;
   spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]);  
   spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]);  
   spt->stride[0] = stride[0];

   pipe_buffer_reference(screen, &spt->buffer, buffer);

   return &spt->base;
}
Пример #3
0
/* Hack it up to use the old winsys->surface_alloc_storage()
 * method for now:
 */
static boolean
softpipe_displaytarget_layout(struct pipe_screen *screen,
                              struct softpipe_texture * spt)
{
   struct pipe_winsys *ws = screen->winsys;
   struct pipe_surface surf;
   unsigned flags = (PIPE_BUFFER_USAGE_CPU_READ |
                     PIPE_BUFFER_USAGE_CPU_WRITE |
                     PIPE_BUFFER_USAGE_GPU_READ |
                     PIPE_BUFFER_USAGE_GPU_WRITE);


   memset(&surf, 0, sizeof(surf));

   ws->surface_alloc_storage( ws, 
                              &surf,
                              spt->base.width[0], 
                              spt->base.height[0],
                              spt->base.format,
                              flags,
                              spt->base.tex_usage);
      
   /* Now extract the goodies: 
    */
   spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]);  
   spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]);  
   spt->stride[0] = surf.stride;
   spt->buffer = surf.buffer;

   return spt->buffer != NULL;
}
Пример #4
0
static struct llvmpipe_displaytarget *
xm_displaytarget_create(struct llvmpipe_winsys *winsys,
                        enum pipe_format format,
                        unsigned width, unsigned height,
                        unsigned alignment,
                        unsigned *stride)
{
   struct xm_displaytarget *xm_dt = CALLOC_STRUCT(xm_displaytarget);
   unsigned nblocksx, nblocksy, size;

   xm_dt = CALLOC_STRUCT(xm_displaytarget);
   if(!xm_dt)
      goto no_xm_dt;

   xm_dt->format = format;
   xm_dt->width = width;
   xm_dt->height = height;

   pf_get_block(format, &xm_dt->block);
   nblocksx = pf_get_nblocksx(&xm_dt->block, width);
   nblocksy = pf_get_nblocksy(&xm_dt->block, height);
   xm_dt->stride = align(nblocksx * xm_dt->block.size, alignment);
   size = xm_dt->stride * nblocksy;

#ifdef USE_XSHM
   if (!debug_get_bool_option("XLIB_NO_SHM", FALSE))
   {
      xm_dt->shminfo.shmid = -1;
      xm_dt->shminfo.shmaddr = (char *) -1;
      xm_dt->shm = TRUE;
         
      xm_dt->data = alloc_shm(xm_dt, size);
      if(!xm_dt->data)
         goto no_data;
   }
#endif

   if(!xm_dt->data) {
      xm_dt->data = align_malloc(size, alignment);
      if(!xm_dt->data)
         goto no_data;
   }

   *stride = xm_dt->stride;
   return (struct llvmpipe_displaytarget *)xm_dt;

no_data:
   FREE(xm_dt);
no_xm_dt:
   return NULL;
}
Пример #5
0
static struct pipe_buffer *
xm_surface_buffer_create(struct pipe_winsys *winsys,
                         unsigned width, unsigned height,
                         enum pipe_format format,
                         unsigned usage,
                         unsigned tex_usage,
                         unsigned *stride)
{
   const unsigned alignment = 64;
   struct pipe_format_block block;
   unsigned nblocksx, nblocksy, size;

   pf_get_block(format, &block);
   nblocksx = pf_get_nblocksx(&block, width);
   nblocksy = pf_get_nblocksy(&block, height);
   *stride = align(nblocksx * block.size, alignment);
   size = *stride * nblocksy;

#ifdef USE_XSHM
   if (!debug_get_bool_option("XLIB_NO_SHM", FALSE))
   {
      struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);

      pipe_reference_init(&buffer->base.reference, 1);
      buffer->base.alignment = alignment;
      buffer->base.usage = usage;
      buffer->base.size = size;
      buffer->userBuffer = FALSE;
      buffer->shminfo.shmid = -1;
      buffer->shminfo.shmaddr = (char *) -1;
      buffer->shm = TRUE;
         
      buffer->data = alloc_shm(buffer, size);
      if (!buffer->data)
         goto out;

      return &buffer->base;
         
   out:
      if (buffer)
         FREE(buffer);
   }
#endif
   

   return winsys->buffer_create(winsys, alignment,
                                usage,
                                size);
}
Пример #6
0
static boolean
softpipe_displaytarget_layout(struct pipe_screen *screen,
                              struct softpipe_texture * spt)
{
   unsigned usage = (PIPE_BUFFER_USAGE_CPU_READ_WRITE |
                     PIPE_BUFFER_USAGE_GPU_READ_WRITE);

   spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]);  
   spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]);  

   spt->buffer = screen->surface_buffer_create( screen, 
                                                spt->base.width[0], 
                                                spt->base.height[0],
                                                spt->base.format,
                                                usage,
                                                &spt->stride[0]);

   return spt->buffer != NULL;
}
Пример #7
0
static struct pipe_buffer *
st_softpipe_surface_buffer_create(struct pipe_winsys *winsys,
                                  unsigned width, unsigned height,
                                  enum pipe_format format,
                                  unsigned usage,
                                  unsigned tex_usage,
                                  unsigned *stride)
{
   const unsigned alignment = 64;
   struct pipe_format_block block;
   unsigned nblocksx, nblocksy;

   pf_get_block(format, &block);
   nblocksx = pf_get_nblocksx(&block, width);
   nblocksy = pf_get_nblocksy(&block, height);
   *stride = round_up(nblocksx * block.size, alignment);

   return winsys->buffer_create(winsys, alignment,
                                usage,
                                *stride * nblocksy);
}
Пример #8
0
/* Conventional allocation path for non-display textures:
 */
static boolean
softpipe_texture_layout(struct pipe_screen *screen,
                        struct softpipe_texture * spt)
{
   struct pipe_winsys *ws = screen->winsys;
   struct pipe_texture *pt = &spt->base;
   unsigned level;
   unsigned width = pt->width[0];
   unsigned height = pt->height[0];
   unsigned depth = pt->depth[0];

   unsigned buffer_size = 0;

   for (level = 0; level <= pt->last_level; level++) {
      pt->width[level] = width;
      pt->height[level] = height;
      pt->depth[level] = depth;
      pt->nblocksx[level] = pf_get_nblocksx(&pt->block, width);  
      pt->nblocksy[level] = pf_get_nblocksy(&pt->block, height);  
      spt->stride[level] = pt->nblocksx[level]*pt->block.size;

      spt->level_offset[level] = buffer_size;

      buffer_size += (pt->nblocksy[level] *
                      ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) *
                      spt->stride[level]);

      width  = minify(width);
      height = minify(height);
      depth = minify(depth);
   }

   spt->buffer = ws->buffer_create(ws, 32,
                                   PIPE_BUFFER_USAGE_PIXEL,
                                   buffer_size);

   return spt->buffer != NULL;
}