Commit 58973833 authored by Jose Fonseca's avatar Jose Fonseca

gallium: Remove the standalone surfaces.

This commit is mostly just a cosmetic change that cleans-up the interfaces,
replacing pipe_winsys::surface_* calls by

   /**
    * Allocate storage for a display target surface.
    *
    * Often surfaces which are meant to be blitted to the front screen (i.e.,
    * display targets) must be allocated with special characteristics, memory
    * pools, or obtained directly from the windowing system.
    *
    * This callback is invoked by the pipe_screenwhen creating a texture marked
    * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag  to get the underlying
    * buffer storage.
    */
   struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws,
                                        unsigned width, unsigned height,
                                        enum pipe_format format,
                                        unsigned usage,
                                        unsigned *stride);

Most drivers were updated but not all were tested. Use the softpipe pipe
driver and the xlib winsys changes as a reference when fixing other drivers.
parent ecc563b1
......@@ -205,34 +205,18 @@ timed_flush_frontbuffer( struct pipe_winsys *winsys,
static struct pipe_surface *
timed_surface_alloc(struct pipe_winsys *winsys)
{
struct pipe_winsys *backend = timed_winsys(winsys)->backend;
uint64_t start = time_start();
struct pipe_surface *surf = backend->surface_alloc( backend );
time_finish(winsys, start, 6, __FUNCTION__);
return surf;
}
static int
timed_surface_alloc_storage(struct pipe_winsys *winsys,
struct pipe_surface *surf,
static struct pipe_buffer *
timed_surface_buffer_create(struct pipe_winsys *winsys,
unsigned width, unsigned height,
enum pipe_format format,
unsigned flags,
unsigned tex_usage)
unsigned usage,
unsigned *stride)
{
struct pipe_winsys *backend = timed_winsys(winsys)->backend;
uint64_t start = time_start();
int ret = backend->surface_alloc_storage( backend, surf, width, height,
format, flags, tex_usage );
struct pipe_buffer *ret = backend->surface_buffer_create( backend, width, height,
format, usage, stride );
time_finish(winsys, start, 7, __FUNCTION__);
......@@ -240,19 +224,6 @@ timed_surface_alloc_storage(struct pipe_winsys *winsys,
}
static void
timed_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
{
struct pipe_winsys *backend = timed_winsys(winsys)->backend;
uint64_t start = time_start();
backend->surface_release( backend, s );
time_finish(winsys, start, 8, __FUNCTION__);
}
static const char *
timed_get_name( struct pipe_winsys *winsys )
{
......@@ -331,9 +302,7 @@ struct pipe_winsys *u_timed_winsys_create( struct pipe_winsys *backend )
ws->base.buffer_create = timed_buffer_create;
ws->base.flush_frontbuffer = timed_flush_frontbuffer;
ws->base.get_name = timed_get_name;
ws->base.surface_alloc = timed_surface_alloc;
ws->base.surface_alloc_storage = timed_surface_alloc_storage;
ws->base.surface_release = timed_surface_release;
ws->base.surface_buffer_create = timed_surface_buffer_create;
ws->base.fence_reference = timed_fence_reference;
ws->base.fence_signalled = timed_fence_signalled;
ws->base.fence_finish = timed_fence_finish;
......
......@@ -683,7 +683,6 @@ i915_get_tex_surface(struct pipe_screen *screen,
ps = CALLOC_STRUCT(pipe_surface);
if (ps) {
ps->refcount = 1;
ps->winsys = ws;
pipe_texture_reference(&ps->texture, pt);
pipe_buffer_reference(screen, &ps->buffer, tex->buffer);
ps->format = pt->format;
......
......@@ -365,10 +365,10 @@ brw_get_tex_surface_screen(struct pipe_screen *screen,
assert(zslice == 0);
}
ps = ws->surface_alloc(ws);
ps = CALLOC_STRUCT(pipe_surface);
if (ps) {
assert(ps->format);
assert(ps->refcount);
ps->refcount = 1;
pipe_texture_reference(&ps->texture, pt);
winsys_buffer_reference(ws, &ps->buffer, tex->buffer);
ps->format = pt->format;
ps->width = pt->width[level];
......@@ -378,6 +378,7 @@ brw_get_tex_surface_screen(struct pipe_screen *screen,
ps->nblocksy = pt->nblocksy[level];
ps->stride = tex->stride;
ps->offset = offset;
ps->status = PIPE_SURFACE_STATUS_DEFINED;
}
return ps;
}
......
......@@ -96,13 +96,12 @@ nv04_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
struct nv04_miptree *nv04mt = (struct nv04_miptree *)pt;
struct pipe_surface *ps;
ps = ws->surface_alloc(ws);
ps = CALLOC_STRUCT(pipe_surface);
if (!ps)
return NULL;
pipe_texture_reference(&ps->texture, pt);
pipe_buffer_reference(pscreen, &ps->buffer, nv04mt->buffer);
ps->format = pt->format;
ps->width = pt->width[level];
ps->height = pt->height[level];
ps->block = pt->block;
ps->width = pt->width[level];
ps->height = pt->height[level];
......@@ -110,7 +109,6 @@ nv04_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
ps->nblocksy = pt->nblocksy[level];
ps->stride = nv04mt->level[level].pitch;
ps->refcount = 1;
ps->winsys = pscreen->winsys;
if (pt->target == PIPE_TEXTURE_CUBE) {
ps->offset = nv04mt->level[level].image_offset[face];
......
......@@ -110,9 +110,10 @@ nv10_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
struct nv10_miptree *nv10mt = (struct nv10_miptree *)pt;
struct pipe_surface *ps;
ps = ws->surface_alloc(ws);
ps = CALLOC_STRUCT(pipe_surface);
if (!ps)
return NULL;
pipe_texture_reference(&ps->texture, pt);
pipe_buffer_reference(screen, &ps->buffer, nv10mt->buffer);
ps->format = pt->format;
ps->width = pt->width[level];
......@@ -122,7 +123,6 @@ nv10_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
ps->nblocksy = pt->nblocksy[level];
ps->stride = nv10mt->level[level].pitch;
ps->refcount = 1;
ps->winsys = screen->winsys;
if (pt->target == PIPE_TEXTURE_CUBE) {
ps->offset = nv10mt->level[level].image_offset[face];
......
......@@ -117,7 +117,6 @@ nv20_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
ps->usage = flags;
ps->status = PIPE_SURFACE_STATUS_DEFINED;
ps->refcount = 1;
ps->winsys = screen->winsys;
if (pt->target == PIPE_TEXTURE_CUBE) {
ps->offset = nv20mt->level[level].image_offset[face];
......
......@@ -154,7 +154,6 @@ nv30_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
ps->usage = flags;
ps->status = PIPE_SURFACE_STATUS_DEFINED;
ps->refcount = 1;
ps->winsys = pscreen->winsys;
ps->face = face;
ps->level = level;
ps->zslice = zslice;
......
......@@ -155,7 +155,6 @@ nv40_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
ps->usage = flags;
ps->status = PIPE_SURFACE_STATUS_DEFINED;
ps->refcount = 1;
ps->winsys = pscreen->winsys;
ps->face = face;
ps->level = level;
ps->zslice = zslice;
......
......@@ -217,7 +217,6 @@ nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
{
struct nv50_miptree *mt = nv50_miptree(pt);
struct nv50_miptree_level *lvl = &mt->level[level];
struct nv50_surface *s;
struct pipe_surface *ps;
int img;
......@@ -229,13 +228,11 @@ nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
else
img = 0;
s = CALLOC_STRUCT(nv50_surface);
if (!s)
ps = CALLOC_STRUCT(pipe_surface);
if (!ps)
return NULL;
ps = &s->base;
ps->refcount = 1;
ps->winsys = pscreen->winsys;
pipe_texture_reference(&ps->texture, pt);
pipe_buffer_reference(pscreen, &ps->buffer, mt->buffer);
ps->format = pt->format;
ps->width = pt->width[level];
ps->height = pt->height[level];
......@@ -245,6 +242,10 @@ nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
ps->stride = ps->width * ps->block.size;
ps->usage = flags;
ps->status = PIPE_SURFACE_STATUS_DEFINED;
ps->refcount = 1;
ps->face = face;
ps->level = level;
ps->zslice = zslice;
if (flags & PIPE_BUFFER_USAGE_CPU_READ_WRITE) {
assert(!(flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE));
......
......@@ -94,49 +94,23 @@ softpipe_texture_layout(struct pipe_screen *screen,
return spt->buffer != NULL;
}
/* 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);
int ret;
memset(&surf, 0, sizeof(surf));
ret =ws->surface_alloc_storage( ws,
&surf,
spt->base.width[0],
spt->base.height[0],
spt->base.format,
flags,
spt->base.tex_usage);
if(ret != 0)
return FALSE;
if (!surf.buffer) {
/* allocation failed */
return FALSE;
}
unsigned usage = (PIPE_BUFFER_USAGE_CPU_READ_WRITE |
PIPE_BUFFER_USAGE_GPU_READ_WRITE);
/* 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;
/* Transfer the reference:
*/
spt->buffer = surf.buffer;
surf.buffer = NULL;
spt->buffer = ws->surface_buffer_create( ws,
spt->base.width[0],
spt->base.height[0],
spt->base.format,
usage,
&spt->stride[0]);
return spt->buffer != NULL;
}
......@@ -231,7 +205,6 @@ softpipe_get_tex_surface(struct pipe_screen *screen,
unsigned face, unsigned level, unsigned zslice,
unsigned usage)
{
struct pipe_winsys *ws = screen->winsys;
struct softpipe_texture *spt = softpipe_texture(pt);
struct pipe_surface *ps;
......
......@@ -42,7 +42,7 @@ struct softpipe_texture
struct pipe_texture base;
unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS];
unsigned long stride[PIPE_MAX_TEXTURE_LEVELS];
unsigned stride[PIPE_MAX_TEXTURE_LEVELS];
/* The data is held here:
*/
......
......@@ -87,7 +87,6 @@ trace_surface_create(struct trace_texture *tr_tex,
memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));
tr_surf->base.winsys = tr_tex->base.screen->winsys;
tr_surf->base.texture = NULL;
pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base);
tr_surf->surface = surface;
......
......@@ -98,86 +98,41 @@ trace_winsys_flush_frontbuffer(struct pipe_winsys *_winsys,
}
static struct pipe_surface *
trace_winsys_surface_alloc(struct pipe_winsys *_winsys)
{
struct trace_winsys *tr_ws = trace_winsys(_winsys);
struct pipe_winsys *winsys = tr_ws->winsys;
struct pipe_surface *result;
trace_dump_call_begin("pipe_winsys", "surface_alloc");
trace_dump_arg(ptr, winsys);
result = winsys->surface_alloc(winsys);
trace_dump_ret(ptr, result);
trace_dump_call_end();
assert(!result || !result->texture);
return result;
}
static int
trace_winsys_surface_alloc_storage(struct pipe_winsys *_winsys,
struct pipe_surface *surface,
static struct pipe_buffer *
trace_winsys_surface_buffer_create(struct pipe_winsys *_winsys,
unsigned width, unsigned height,
enum pipe_format format,
unsigned flags,
unsigned tex_usage)
unsigned usage,
unsigned *pstride)
{
struct trace_winsys *tr_ws = trace_winsys(_winsys);
struct pipe_winsys *winsys = tr_ws->winsys;
int result;
unsigned stride;
struct pipe_buffer *result;
assert(surface && !surface->texture);
trace_dump_call_begin("pipe_winsys", "surface_alloc_storage");
trace_dump_call_begin("pipe_winsys", "surface_buffer_create");
trace_dump_arg(ptr, winsys);
trace_dump_arg(ptr, surface);
trace_dump_arg(uint, width);
trace_dump_arg(uint, height);
trace_dump_arg(format, format);
trace_dump_arg(uint, flags);
trace_dump_arg(uint, tex_usage);
trace_dump_arg(uint, usage);
result = winsys->surface_alloc_storage(winsys,
surface,
result = winsys->surface_buffer_create(winsys,
width, height,
format,
flags,
tex_usage);
usage,
pstride);
trace_dump_ret(int, result);
stride = *pstride;
trace_dump_call_end();
trace_dump_arg(uint, stride);
return result;
}
static void
trace_winsys_surface_release(struct pipe_winsys *_winsys,
struct pipe_surface **psurface)
{
struct trace_winsys *tr_ws = trace_winsys(_winsys);
struct pipe_winsys *winsys = tr_ws->winsys;
struct pipe_surface *surface = *psurface;
assert(psurface && *psurface && !(*psurface)->texture);
trace_dump_call_begin("pipe_winsys", "surface_release");
trace_dump_arg(ptr, winsys);
trace_dump_arg(ptr, surface);
winsys->surface_release(winsys, psurface);
trace_dump_ret(ptr, result);
trace_dump_call_end();
return result;
}
......@@ -465,9 +420,7 @@ trace_winsys_create(struct pipe_winsys *winsys)
tr_ws->base.destroy = trace_winsys_destroy;
tr_ws->base.get_name = trace_winsys_get_name;
tr_ws->base.flush_frontbuffer = trace_winsys_flush_frontbuffer;
tr_ws->base.surface_alloc = trace_winsys_surface_alloc;
tr_ws->base.surface_alloc_storage = trace_winsys_surface_alloc_storage;
tr_ws->base.surface_release = trace_winsys_surface_release;
tr_ws->base.surface_buffer_create = trace_winsys_surface_buffer_create;
tr_ws->base.buffer_create = trace_winsys_buffer_create;
tr_ws->base.user_buffer_create = trace_winsys_user_buffer_create;
tr_ws->base.buffer_map = trace_winsys_buffer_map;
......
......@@ -45,30 +45,19 @@ extern "C" {
static INLINE void *
pipe_surface_map( struct pipe_surface *surf, unsigned flags )
{
if (surf->texture) {
struct pipe_screen *screen = surf->texture->screen;
return surf->texture->screen->surface_map( screen, surf, flags );
}
else {
struct pipe_winsys *winsys = surf->winsys;
char *map = (char *)winsys->buffer_map( winsys, surf->buffer, flags );
if (map == NULL)
return NULL;
return (void *)(map + surf->offset);
}
struct pipe_screen *screen;
assert(surf->texture);
screen = surf->texture->screen;
return screen->surface_map( screen, surf, flags );
}
static INLINE void
pipe_surface_unmap( struct pipe_surface *surf )
{
if (surf->texture) {
struct pipe_screen *screen = surf->texture->screen;
surf->texture->screen->surface_unmap( screen, surf );
}
else {
struct pipe_winsys *winsys = surf->winsys;
winsys->buffer_unmap( winsys, surf->buffer );
}
struct pipe_screen *screen;
assert(surf->texture);
screen = surf->texture->screen;
screen->surface_unmap( screen, surf );
}
......@@ -88,20 +77,11 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
}
if (*ptr) {
struct pipe_screen *screen;
assert((*ptr)->refcount);
/* There are currently two sorts of surfaces... This needs to be
* fixed so that all surfaces are views into a texture.
*/
if ((*ptr)->texture) {
struct pipe_screen *screen = (*ptr)->texture->screen;
screen->tex_surface_release( screen, ptr );
}
else {
struct pipe_winsys *winsys = (*ptr)->winsys;
winsys->surface_release(winsys, ptr);
}
assert((*ptr)->texture);
screen = (*ptr)->texture->screen;
screen->tex_surface_release( screen, ptr );
assert(!*ptr);
}
......
......@@ -292,9 +292,7 @@ struct pipe_surface
unsigned refcount;
unsigned usage; /**< PIPE_BUFFER_USAGE_* */
struct pipe_winsys *winsys; /**< winsys which owns/created the surface */
struct pipe_texture *texture; /**< optional texture into which this is a view */
struct pipe_texture *texture; /**< texture into which this is a view */
unsigned face;
unsigned level;
unsigned zslice;
......
......@@ -76,24 +76,6 @@ struct pipe_winsys
void *context_private );
/** allocate a new surface (no context dependency) */
struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws);
/**
* Allocate storage for a pipe_surface.
* \param flags XXX unused, remove someday
* \return 0 if succeeds.
*/
int (*surface_alloc_storage)(struct pipe_winsys *ws,
struct pipe_surface *surf,
unsigned width, unsigned height,
enum pipe_format format,
unsigned flags,
unsigned tex_usage);
void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s);
/**
* Buffer management. Buffer attributes are mostly fixed over its lifetime.
*
......@@ -138,6 +120,24 @@ struct pipe_winsys
void *ptr,
unsigned bytes);
/**
* Allocate storage for a display target surface.
*
* Often surfaces which are meant to be blitted to the front screen (i.e.,
* display targets) must be allocated with special characteristics, memory
* pools, or obtained directly from the windowing system.
*
* This callback is invoked by the pipe_screenwhen creating a texture marked
* with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
* buffer storage.
*/
struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws,
unsigned width, unsigned height,
enum pipe_format format,
unsigned usage,
unsigned *stride);
/**
* Map the entire data store of a buffer object into the client's address.
* flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
......
......@@ -168,63 +168,25 @@ round_up(unsigned n, unsigned multiple)
}
static int
st_softpipe_surface_alloc_storage(struct pipe_winsys *winsys,
struct pipe_surface *surf,
static struct pipe_buffer *
st_softpipe_surface_buffer_create(struct pipe_winsys *winsys,
unsigned width, unsigned height,
enum pipe_format format,
unsigned flags,
unsigned tex_usage)
enum pipe_format format,
unsigned usage,
unsigned *stride)
{
const unsigned alignment = 64;
struct pipe_format_block block;
unsigned nblocksx, nblocksy;
surf->width = width;
surf->height = height;
surf->format = format;
pf_get_block(format, &surf->block);
surf->nblocksx = pf_get_nblocksx(&surf->block, width);
surf->nblocksy = pf_get_nblocksy(&surf->block, height);
surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
surf->usage = flags;
assert(!surf->buffer);
surf->buffer = winsys->buffer_create(winsys, alignment,
PIPE_BUFFER_USAGE_PIXEL,
surf->stride * surf->nblocksy);
if(!surf->buffer)
return -1;
return 0;
}
static struct pipe_surface *
st_softpipe_surface_alloc(struct pipe_winsys *winsys)
{
struct pipe_surface *surface = CALLOC_STRUCT(pipe_surface);
assert(winsys);
surface->refcount = 1;
surface->winsys = winsys;
return surface;
}
pf_get_block(format, &block);
nblocksx = pf_get_nblocksx(&block, width);
nblocksy = pf_get_nblocksy(&block, height);
*stride = round_up(nblocksx * block.size, alignment);
static void
st_softpipe_surface_release(struct pipe_winsys *winsys,
struct pipe_surface **s)
{
struct pipe_surface *surf = *s;
assert(!surf->texture);
surf->refcount--;
if (surf->refcount == 0) {
if (surf->buffer)
winsys_buffer_reference(winsys, &surf->buffer, NULL);
free(surf);
}
*s = NULL;
return winsys->buffer_create(winsys, alignment,
usage,
*stride * nblocksy);
}
......@@ -279,9 +241,7 @@ st_softpipe_screen_create(void)
winsys->buffer_unmap = st_softpipe_buffer_unmap;
winsys->buffer_destroy = st_softpipe_buffer_destroy;
winsys->surface_alloc = st_softpipe_surface_alloc;
winsys->surface_alloc_storage = st_softpipe_surface_alloc_storage;
winsys->surface_release = st_softpipe_surface_release;
winsys->surface_buffer_create = st_softpipe_surface_buffer_create;
winsys->fence_reference = st_softpipe_fence_reference;
winsys->fence_signalled = st_softpipe_fence_signalled;
......
......@@ -157,35 +157,25 @@ err:
}
/*
* Surface functions.
*
* Deprecated!
*/
static struct pipe_surface *
intel_i915_surface_alloc(struct pipe_winsys *winsys)
{
assert((size_t)"intel_i915_surface_alloc is deprecated" & 0);
return NULL;
}
static int
intel_i915_surface_alloc_storage(struct pipe_winsys *winsys,
struct pipe_surface *surf,
static struct pipe_buffer *
intel_i915_surface_buffer_create(struct pipe_winsys *winsys,
unsigned width, unsigned height,
enum pipe_format format,
unsigned flags,
unsigned tex_usage)
{
assert((size_t)"intel_i915_surface_alloc_storage is deprecated" & 0);
return -1;
}
static void
intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
unsigned usage,
unsigned *stride)
{
assert((size_t)"intel_i915_surface_release is deprecated" & 0);
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);
}
......@@ -238,9 +228,7 @@ intel_be_init_device(struct intel_be_device *dev, int fd, unsigned id)
dev->base.buffer_map = intel_be_buffer_map;
dev->base.buffer_unmap = intel_be_buffer_unmap;
dev->base.buffer_destroy = intel_be_buffer_destroy;
dev->base.surface_alloc = intel_i915_surface_alloc;
dev->base.surface_alloc_storage = intel_i915_surface_alloc_storage;
dev->base.surface_release = intel_i915_surface_release;
dev->base.surface_buffer_create = intel_i915_surface_buffer_create;
dev->base.fence_reference = intel_be_fence_reference;
dev->base.fence_signalled = intel_be_fence_signalled;
dev->base.fence_finish = intel_be_fence_finish;
......
......@@ -161,65 +161,25 @@ buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf)
}
/**
* Called via winsys->surface_alloc() to create new surfaces.
*/
static struct pipe_surface *
surface_alloc(struct pipe_winsys *ws)
{
struct pipe_surface *surf = CALLOC_STRUCT(pipe_surface);
if (!surf)
return NULL;