gallium: tex surface checkpoint

This commit is contained in:
Keith Whitwell
2008-05-01 11:07:21 +01:00
parent 7584bcf3f7
commit c9ed86a964
37 changed files with 466 additions and 268 deletions

View File

@@ -415,8 +415,11 @@ aaline_create_texture(struct aaline_stage *aaline)
assert(aaline->texture->width[level] == aaline->texture->height[level]);
surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0);
data = pipe_surface_map(surface);
/* This texture is new, no need to flush.
*/
surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0,
PIPE_BUFFER_USAGE_CPU_WRITE);
data = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE);
if (data == NULL)
return FALSE;
@@ -440,9 +443,8 @@ aaline_create_texture(struct aaline_stage *aaline)
}
/* unmap */
pipe_surface_unmap(surface);
pipe_surface_reference(&surface, NULL);
pipe->texture_update(pipe, aaline->texture, 0, (1 << level));
screen->surface_unmap(screen, surface);
screen->tex_surface_release(screen, &surface);
}
return TRUE;
}

View File

@@ -376,8 +376,14 @@ pstip_update_texture(struct pstip_stage *pstip)
uint i, j;
ubyte *data;
surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0);
data = pipe_surface_map(surface);
/* XXX: want to avoid flushing just because we use stipple:
*/
pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL );
surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0,
PIPE_BUFFER_USAGE_CPU_WRITE);
data = screen->surface_map(screen, surface,
PIPE_BUFFER_USAGE_CPU_WRITE);
/*
* Load alpha texture.
@@ -399,9 +405,8 @@ pstip_update_texture(struct pstip_stage *pstip)
}
/* unmap */
pipe_surface_unmap(surface);
pipe_surface_reference(&surface, NULL);
pipe->texture_update(pipe, pstip->texture, 0, 0x1);
screen->surface_unmap(screen, surface);
screen->tex_surface_release(screen, &surface);
}

View File

@@ -50,6 +50,7 @@ pipe_get_tile_raw(struct pipe_context *pipe,
uint x, uint y, uint w, uint h,
void *p, int dst_stride)
{
struct pipe_screen *screen = pipe->screen;
const uint cpp = ps->cpp;
const ubyte *pSrc;
const uint src_stride = ps->pitch * cpp;
@@ -63,7 +64,11 @@ pipe_get_tile_raw(struct pipe_context *pipe,
if (pipe_clip_tile(x, y, &w, &h, ps))
return;
pSrc = (const ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp;
pSrc = (const ubyte *) screen->surface_map(screen, ps,
PIPE_BUFFER_USAGE_CPU_READ);
assert(pSrc); /* XXX: proper error handling! */
pSrc += (y * ps->pitch + x) * cpp;
pDest = (ubyte *) p;
for (i = 0; i < h; i++) {
@@ -72,7 +77,7 @@ pipe_get_tile_raw(struct pipe_context *pipe,
pSrc += src_stride;
}
pipe_surface_unmap(ps);
screen->surface_unmap(screen, ps);
}
@@ -86,6 +91,7 @@ pipe_put_tile_raw(struct pipe_context *pipe,
uint x, uint y, uint w, uint h,
const void *p, int src_stride)
{
struct pipe_screen *screen = pipe->screen;
const uint cpp = ps->cpp;
const ubyte *pSrc;
const uint dst_stride = ps->pitch * cpp;
@@ -100,7 +106,11 @@ pipe_put_tile_raw(struct pipe_context *pipe,
return;
pSrc = (const ubyte *) p;
pDest = (ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp;
pDest = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
assert(pDest); /* XXX: proper error handling */
pDest += (y * ps->pitch + x) * cpp;
for (i = 0; i < h; i++) {
memcpy(pDest, pSrc, w * cpp);
@@ -108,7 +118,7 @@ pipe_put_tile_raw(struct pipe_context *pipe,
pSrc += src_stride;
}
pipe_surface_unmap(ps);
screen->surface_unmap(screen, ps);
}
@@ -834,18 +844,26 @@ pipe_get_tile_z(struct pipe_context *pipe,
uint x, uint y, uint w, uint h,
uint *z)
{
struct pipe_screen *screen = pipe->screen;
const uint dstStride = w;
void *map;
uint *pDest = z;
uint i, j;
if (pipe_clip_tile(x, y, &w, &h, ps))
return;
map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ);
if (!map) {
assert(0);
return;
}
switch (ps->format) {
case PIPE_FORMAT_Z32_UNORM:
{
const uint *pSrc
= (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
= (const uint *)map + (y * ps->pitch + x);
for (i = 0; i < h; i++) {
memcpy(pDest, pSrc, 4 * w);
pDest += dstStride;
@@ -857,7 +875,7 @@ pipe_get_tile_z(struct pipe_context *pipe,
case PIPE_FORMAT_X8Z24_UNORM:
{
const uint *pSrc
= (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
= (const uint *)map + (y * ps->pitch + x);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
/* convert 24-bit Z to 32-bit Z */
@@ -871,7 +889,7 @@ pipe_get_tile_z(struct pipe_context *pipe,
case PIPE_FORMAT_Z16_UNORM:
{
const ushort *pSrc
= (const ushort *) pipe_surface_map(ps) + (y * ps->pitch + x);
= (const ushort *)map + (y * ps->pitch + x);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
/* convert 16-bit Z to 32-bit Z */
@@ -886,7 +904,7 @@ pipe_get_tile_z(struct pipe_context *pipe,
assert(0);
}
pipe_surface_unmap(ps);
screen->surface_unmap(screen, ps);
}
@@ -896,17 +914,25 @@ pipe_put_tile_z(struct pipe_context *pipe,
uint x, uint y, uint w, uint h,
const uint *zSrc)
{
struct pipe_screen *screen = pipe->screen;
const uint srcStride = w;
const uint *pSrc = zSrc;
void *map;
uint i, j;
if (pipe_clip_tile(x, y, &w, &h, ps))
return;
map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
if (!map) {
assert(0);
return;
}
switch (ps->format) {
case PIPE_FORMAT_Z32_UNORM:
{
uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
uint *pDest = (uint *) map + (y * ps->pitch + x);
for (i = 0; i < h; i++) {
memcpy(pDest, pSrc, 4 * w);
pDest += ps->pitch;
@@ -917,7 +943,7 @@ pipe_put_tile_z(struct pipe_context *pipe,
case PIPE_FORMAT_S8Z24_UNORM:
case PIPE_FORMAT_X8Z24_UNORM:
{
uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
uint *pDest = (uint *) map + (y * ps->pitch + x);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
/* convert 32-bit Z to 24-bit Z (0 stencil) */
@@ -930,7 +956,7 @@ pipe_put_tile_z(struct pipe_context *pipe,
break;
case PIPE_FORMAT_Z16_UNORM:
{
ushort *pDest = (ushort *) pipe_surface_map(ps) + (y * ps->pitch + x);
ushort *pDest = (ushort *) map + (y * ps->pitch + x);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
/* convert 32-bit Z to 16-bit Z */
@@ -945,7 +971,7 @@ pipe_put_tile_z(struct pipe_context *pipe,
assert(0);
}
pipe_surface_unmap(ps);
screen->surface_unmap(screen, ps);
}

View File

@@ -287,7 +287,8 @@ util_blit_pixels(struct blit_state *ctx,
if (!tex)
return;
texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0);
texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0,
PIPE_BUFFER_USAGE_GPU_WRITE);
/* load temp texture */
pipe->surface_copy(pipe, FALSE,

View File

@@ -586,8 +586,11 @@ make_1d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_surface *srcSurf, *dstSurf;
void *srcMap, *dstMap;
srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice);
dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice);
srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice,
PIPE_BUFFER_USAGE_CPU_READ);
dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
PIPE_BUFFER_USAGE_CPU_WRITE);
srcMap = ((ubyte *) winsys->buffer_map(winsys, srcSurf->buffer,
PIPE_BUFFER_USAGE_CPU_READ)
@@ -626,8 +629,10 @@ make_2d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_surface *srcSurf, *dstSurf;
ubyte *srcMap, *dstMap;
srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice);
dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice);
srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice,
PIPE_BUFFER_USAGE_CPU_READ);
dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
PIPE_BUFFER_USAGE_CPU_WRITE);
srcMap = ((ubyte *) winsys->buffer_map(winsys, srcSurf->buffer,
PIPE_BUFFER_USAGE_CPU_READ)
@@ -888,10 +893,14 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
struct pipe_surface *surf =
screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
PIPE_BUFFER_USAGE_GPU_WRITE);
/*
* Setup framebuffer / dest surface
*/
fb.cbufs[0] = screen->get_tex_surface(screen, pt, face, dstLevel, zslice);
fb.cbufs[0] = surf;
fb.width = pt->width[dstLevel];
fb.height = pt->height[dstLevel];
cso_set_framebuffer(ctx->cso, &fb);
@@ -922,7 +931,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
/* need to signal that the texture has changed _after_ rendering to it */
pipe->texture_update(pipe, pt, face, (1 << dstLevel));
pipe_surface_reference( &surf, NULL );
}
/* restore state we changed */

View File

@@ -147,8 +147,8 @@ struct pipe_context *failover_create( struct pipe_context *hw,
failover->pipe.texture_create = hw->texture_create;
failover->pipe.texture_release = hw->texture_release;
failover->pipe.get_tex_surface = hw->get_tex_surface;
#endif
failover->pipe.texture_update = hw->texture_update;
#endif
failover->pipe.flush = hw->flush;

View File

@@ -200,6 +200,35 @@ i915_destroy_screen( struct pipe_screen *screen )
}
static void *
i915_surface_map( struct pipe_screen *screen,
struct pipe_surface *surface,
unsigned flags )
{
char *map = screen->winsys->buffer_map( screen->winsys, surface->buffer, flags );
if (map == NULL)
return NULL;
if (surface->texture &&
(flags & PIPE_BUFFER_USAGE_CPU_WRITE))
{
/* Do something to notify contexts of a texture change.
*/
/* i915_screen(screen)->timestamp++; */
}
return map + surface->offset;
}
static void
i915_surface_unmap(struct pipe_screen *screen,
struct pipe_surface *surface)
{
screen->winsys->buffer_unmap( screen->winsys, surface->buffer );
}
/**
* Create a new i915_screen object
*/
@@ -243,6 +272,8 @@ i915_create_screen(struct pipe_winsys *winsys, uint pci_id)
i915screen->screen.get_param = i915_get_param;
i915screen->screen.get_paramf = i915_get_paramf;
i915screen->screen.is_format_supported = i915_is_format_supported;
i915screen->screen.surface_map = i915_surface_map;
i915screen->screen.surface_unmap = i915_surface_unmap;
i915_init_screen_texture_functions(&i915screen->screen);

View File

@@ -51,17 +51,25 @@ i915_surface_copy(struct pipe_context *pipe,
assert( dst->cpp == src->cpp );
if (0) {
pipe_copy_rect(pipe_surface_map(dst),
void *dst_map = pipe->screen->surface_map( pipe->screen,
dst,
PIPE_BUFFER_USAGE_CPU_WRITE );
const void *src_map = pipe->screen->surface_map( pipe->screen,
src,
PIPE_BUFFER_USAGE_CPU_READ );
pipe_copy_rect(dst_map,
dst->cpp,
dst->pitch,
dstx, dsty,
width, height,
pipe_surface_map(src),
src_map,
do_flip ? -(int) src->pitch : src->pitch,
srcx, do_flip ? 1 - srcy - height : srcy);
pipe_surface_unmap(src);
pipe_surface_unmap(dst);
pipe->screen->surface_unmap(pipe->screen, src);
pipe->screen->surface_unmap(pipe->screen, dst);
}
else {
i915_copy_blit( i915_context(pipe),
@@ -92,7 +100,10 @@ i915_surface_fill(struct pipe_context *pipe,
{
if (0) {
unsigned i, j;
void *dst_map = pipe_surface_map(dst);
void *dst_map = pipe->screen->surface_map( pipe->screen,
dst,
PIPE_BUFFER_USAGE_CPU_WRITE );
switch (dst->cpp) {
case 1: {
@@ -126,7 +137,7 @@ i915_surface_fill(struct pipe_context *pipe,
break;
}
pipe_surface_unmap( dst );
pipe->screen->surface_unmap(pipe->screen, dst);
}
else {
i915_fill_blit( i915_context(pipe),

View File

@@ -541,13 +541,6 @@ i915_texture_release_screen(struct pipe_screen *screen,
}
static void
i915_texture_update(struct pipe_context *pipe, struct pipe_texture *texture,
uint face, uint levelsMask)
{
/* no-op? */
}
/*
* XXX note: same as code in sp_surface.c
@@ -555,7 +548,8 @@ i915_texture_update(struct pipe_context *pipe, struct pipe_texture *texture,
static struct pipe_surface *
i915_get_tex_surface_screen(struct pipe_screen *screen,
struct pipe_texture *pt,
unsigned face, unsigned level, unsigned zslice)
unsigned face, unsigned level, unsigned zslice,
unsigned flags)
{
struct i915_texture *tex = (struct i915_texture *)pt;
struct pipe_winsys *ws = screen->winsys;
@@ -586,6 +580,7 @@ i915_get_tex_surface_screen(struct pipe_screen *screen,
ps->height = pt->height[level];
ps->pitch = tex->pitch;
ps->offset = offset;
ps->usage = flags;
}
return ps;
}
@@ -594,7 +589,7 @@ i915_get_tex_surface_screen(struct pipe_screen *screen,
void
i915_init_texture_functions(struct i915_context *i915)
{
i915->pipe.texture_update = i915_texture_update;
// i915->pipe.texture_update = i915_texture_update;
}

View File

@@ -35,27 +35,6 @@
#include "util/p_tile.h"
/* Upload data to a rectangular sub-region. Lots of choices how to do this:
*
* - memcpy by span to current destination
* - upload data as new buffer and blit
*
* Currently always memcpy.
*/
static void
brw_surface_data(struct pipe_context *pipe,
struct pipe_surface *dst,
unsigned dstx, unsigned dsty,
const void *src, unsigned src_pitch,
unsigned srcx, unsigned srcy, unsigned width, unsigned height)
{
pipe_copy_rect(pipe_surface_map(dst) + dst->offset,
dst->cpp, dst->pitch,
dstx, dsty, width, height, src, src_pitch, srcx, srcy);
pipe_surface_unmap(dst);
}
/* Assumes all values are within bounds -- no checking at this level -
* do it higher up if required.
@@ -72,17 +51,25 @@ brw_surface_copy(struct pipe_context *pipe,
assert(dst->cpp == src->cpp);
if (0) {
pipe_copy_rect(pipe_surface_map(dst) + dst->offset,
void *dst_map = pipe->screen->surface_map( pipe->screen,
dst,
PIPE_BUFFER_USAGE_CPU_WRITE );
const void *src_map = pipe->screen->surface_map( pipe->screen,
src,
PIPE_BUFFER_USAGE_CPU_READ );
pipe_copy_rect(dst_map,
dst->cpp,
dst->pitch,
dstx, dsty,
width, height,
pipe_surface_map(src) + src->offset,
do_flip ? -src->pitch : src->pitch,
src_map,
do_flip ? -(int) src->pitch : src->pitch,
srcx, do_flip ? 1 - srcy - height : srcy);
pipe_surface_unmap(src);
pipe_surface_unmap(dst);
pipe->screen->surface_unmap(pipe->screen, src);
pipe->screen->surface_unmap(pipe->screen, dst);
}
else {
brw_copy_blit(brw_context(pipe),
@@ -113,7 +100,10 @@ brw_surface_fill(struct pipe_context *pipe,
{
if (0) {
unsigned i, j;
void *dst_map = pipe_surface_map(dst);
void *dst_map = pipe->screen->surface_map( pipe->screen,
dst,
PIPE_BUFFER_USAGE_CPU_WRITE );
switch (dst->cpp) {
case 1: {
@@ -147,7 +137,7 @@ brw_surface_fill(struct pipe_context *pipe,
break;
}
pipe_surface_unmap( dst );
pipe->screen->surface_unmap(pipe->screen, dst);
}
else {
brw_fill_blit(brw_context(pipe),
@@ -164,7 +154,6 @@ brw_surface_fill(struct pipe_context *pipe,
void
brw_init_surface_functions(struct brw_context *brw)
{
(void) brw_surface_data; /* silence warning */
brw->pipe.surface_copy = brw_surface_copy;
brw->pipe.surface_fill = brw_surface_fill;
}

View File

@@ -407,7 +407,7 @@ brw_get_tex_surface_screen(struct pipe_screen *screen,
void
brw_init_texture_functions(struct brw_context *brw)
{
brw->pipe.texture_update = brw_texture_update;
// brw->pipe.texture_update = brw_texture_update;
}

View File

@@ -192,11 +192,11 @@ softpipe_create( struct pipe_screen *screen,
* Must be before quad stage setup!
*/
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
softpipe->cbuf_cache[i] = sp_create_tile_cache();
softpipe->zsbuf_cache = sp_create_tile_cache();
softpipe->cbuf_cache[i] = sp_create_tile_cache( screen );
softpipe->zsbuf_cache = sp_create_tile_cache( screen );
for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
softpipe->tex_cache[i] = sp_create_tile_cache();
softpipe->tex_cache[i] = sp_create_tile_cache( screen );
/* setup quad rendering stages */

View File

@@ -50,7 +50,7 @@ softpipe_map_constant_buffers(struct softpipe_context *sp)
for (i = 0; i < 2; i++) {
if (sp->constants[i].size)
sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
PIPE_BUFFER_USAGE_CPU_READ);
PIPE_BUFFER_USAGE_GPU_READ);
}
draw_set_mapped_constant_buffer(sp->draw,
@@ -133,14 +133,14 @@ softpipe_draw_elements(struct pipe_context *pipe,
void *buf
= pipe->winsys->buffer_map(pipe->winsys,
sp->vertex_buffer[i].buffer,
PIPE_BUFFER_USAGE_CPU_READ);
PIPE_BUFFER_USAGE_GPU_READ);
draw_set_mapped_vertex_buffer(draw, i, buf);
}
/* Map index buffer, if present */
if (indexBuffer) {
void *mapped_indexes
= pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
PIPE_BUFFER_USAGE_CPU_READ);
PIPE_BUFFER_USAGE_GPU_READ);
draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
}
else {

View File

@@ -50,25 +50,28 @@ softpipe_flush( struct pipe_context *pipe,
draw_flush(softpipe->draw);
/* - flush the quad pipeline
* - flush the texture cache
* - flush the render cache
*/
if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
for (i = 0; i < softpipe->num_textures; i++) {
sp_flush_tile_cache(softpipe, softpipe->tex_cache[i]);
}
}
for (i = 0; i < softpipe->framebuffer.num_cbufs; i++)
if (softpipe->cbuf_cache[i])
sp_flush_tile_cache(softpipe, softpipe->cbuf_cache[i]);
if (flags & PIPE_FLUSH_RENDER_CACHE) {
for (i = 0; i < softpipe->framebuffer.num_cbufs; i++)
if (softpipe->cbuf_cache[i])
sp_flush_tile_cache(softpipe, softpipe->cbuf_cache[i]);
if (softpipe->zsbuf_cache)
sp_flush_tile_cache(softpipe, softpipe->zsbuf_cache);
if (softpipe->zsbuf_cache)
sp_flush_tile_cache(softpipe, softpipe->zsbuf_cache);
/* Need this call for hardware buffers before swapbuffers.
*
* there should probably be another/different flush-type function
* that's called before swapbuffers because we don't always want
* to unmap surfaces when flushing.
*/
softpipe_unmap_surfaces(softpipe);
/* Need this call for hardware buffers before swapbuffers.
*
* there should probably be another/different flush-type function
* that's called before swapbuffers because we don't always want
* to unmap surfaces when flushing.
*/
softpipe_unmap_surfaces(softpipe);
}
if (fence)
*fence = NULL;

View File

@@ -33,6 +33,7 @@
#include "sp_texture.h"
#include "sp_winsys.h"
#include "sp_screen.h"
static const char *
@@ -137,6 +138,7 @@ softpipe_destroy_screen( struct pipe_screen *screen )
}
/**
* Create a new pipe_screen object
* Note: we're not presently subclassing pipe_screen (no softpipe_screen).
@@ -144,22 +146,22 @@ softpipe_destroy_screen( struct pipe_screen *screen )
struct pipe_screen *
softpipe_create_screen(struct pipe_winsys *winsys)
{
struct pipe_screen *screen = CALLOC_STRUCT(pipe_screen);
struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
if (!screen)
return NULL;
screen->winsys = winsys;
screen->base.winsys = winsys;
screen->destroy = softpipe_destroy_screen;
screen->base.destroy = softpipe_destroy_screen;
screen->get_name = softpipe_get_name;
screen->get_vendor = softpipe_get_vendor;
screen->get_param = softpipe_get_param;
screen->get_paramf = softpipe_get_paramf;
screen->is_format_supported = softpipe_is_format_supported;
screen->base.get_name = softpipe_get_name;
screen->base.get_vendor = softpipe_get_vendor;
screen->base.get_param = softpipe_get_param;
screen->base.get_paramf = softpipe_get_paramf;
screen->base.is_format_supported = softpipe_is_format_supported;
softpipe_init_screen_texture_funcs(screen);
softpipe_init_screen_texture_funcs(&screen->base);
return screen;
return &screen->base;
}

View File

@@ -47,18 +47,27 @@ sp_surface_copy(struct pipe_context *pipe,
unsigned srcx, unsigned srcy, unsigned width, unsigned height)
{
assert( dst->cpp == src->cpp );
void *dst_map = pipe->screen->surface_map( pipe->screen,
dst,
PIPE_BUFFER_USAGE_GPU_WRITE );
pipe_copy_rect(pipe_surface_map(dst),
const void *src_map = pipe->screen->surface_map( pipe->screen,
src,
PIPE_BUFFER_USAGE_GPU_READ );
assert(src_map && dst_map);
pipe_copy_rect(dst_map,
dst->cpp,
dst->pitch,
dstx, dsty,
width, height,
pipe_surface_map(src),
src_map,
do_flip ? -(int) src->pitch : src->pitch,
srcx, do_flip ? 1 - srcy - height : srcy);
pipe_surface_unmap(src);
pipe_surface_unmap(dst);
pipe->screen->surface_unmap(pipe->screen, src);
pipe->screen->surface_unmap(pipe->screen, dst);
}
@@ -83,7 +92,9 @@ sp_surface_fill(struct pipe_context *pipe,
unsigned width, unsigned height, unsigned value)
{
unsigned i, j;
void *dst_map = pipe_surface_map(dst);
void *dst_map = pipe->screen->surface_map( pipe->screen,
dst,
PIPE_BUFFER_USAGE_GPU_WRITE );
assert(dst->pitch > 0);
assert(width <= dst->pitch);
@@ -147,7 +158,7 @@ sp_surface_fill(struct pipe_context *pipe,
break;
}
pipe_surface_unmap( dst );
pipe->screen->surface_unmap(pipe->screen, dst);
}

View File

@@ -40,6 +40,7 @@
#include "sp_state.h"
#include "sp_texture.h"
#include "sp_tile_cache.h"
#include "sp_screen.h"
/* Simple, maximally packed layout.
@@ -116,19 +117,10 @@ softpipe_texture_release(struct pipe_screen *screen,
if (!*pt)
return;
/*
DBG("%s %p refcount will be %d\n",
__FUNCTION__, (void *) *pt, (*pt)->refcount - 1);
*/
if (--(*pt)->refcount <= 0) {
struct softpipe_texture *spt = softpipe_texture(*pt);
/*
DBG("%s deleting %p\n", __FUNCTION__, (void *) spt);
*/
pipe_buffer_reference(screen->winsys, &spt->buffer, NULL);
FREE(spt);
}
*pt = NULL;
@@ -138,7 +130,8 @@ softpipe_texture_release(struct pipe_screen *screen,
static struct pipe_surface *
softpipe_get_tex_surface(struct pipe_screen *screen,
struct pipe_texture *pt,
unsigned face, unsigned level, unsigned zslice)
unsigned face, unsigned level, unsigned zslice,
unsigned usage)
{
struct pipe_winsys *ws = screen->winsys;
struct softpipe_texture *spt = softpipe_texture(pt);
@@ -157,6 +150,7 @@ softpipe_get_tex_surface(struct pipe_screen *screen,
ps->height = pt->height[level];
ps->pitch = ps->width;
ps->offset = spt->level_offset[level];
ps->usage = usage;
if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) {
ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) *
@@ -167,30 +161,74 @@ softpipe_get_tex_surface(struct pipe_screen *screen,
assert(face == 0);
assert(zslice == 0);
}
if (usage & (PIPE_BUFFER_USAGE_CPU_WRITE |
PIPE_BUFFER_USAGE_GPU_WRITE)) {
/* XXX if writing to the texture, invalidate the texcache entries!!! */
assert(0);
}
}
return ps;
}
static void
softpipe_texture_update(struct pipe_context *pipe,
struct pipe_texture *texture,
uint face, uint levelsMask)
softpipe_tex_surface_release(struct pipe_screen *screen,
struct pipe_surface **s)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
uint unit;
for (unit = 0; unit < softpipe->num_textures; unit++) {
if (softpipe->texture[unit] == texture) {
sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]);
}
/* Effectively do the texture_update work here - if texture images
* needed post-processing to put them into hardware layout, this is
* where it would happen. For softpipe, nothing to do.
*/
assert ((*s)->texture);
screen->winsys->surface_release(screen->winsys, s);
}
static void *
softpipe_surface_map( struct pipe_screen *screen,
struct pipe_surface *surface,
unsigned flags )
{
ubyte *map;
if (flags & ~surface->usage) {
assert(0);
return NULL;
}
map = screen->winsys->buffer_map( screen->winsys, surface->buffer, flags );
if (map == NULL)
return NULL;
/* May want to different things here depending on read/write nature
* of the map:
*/
if (surface->texture &&
(flags & PIPE_BUFFER_USAGE_GPU_WRITE))
{
/* Do something to notify sharing contexts of a texture change.
* In softpipe, that would mean flushing the texture cache.
*/
softpipe_screen(screen)->timestamp++;
}
return map + surface->offset;
}
static void
softpipe_surface_unmap(struct pipe_screen *screen,
struct pipe_surface *surface)
{
screen->winsys->buffer_unmap( screen->winsys, surface->buffer );
}
void
softpipe_init_texture_funcs( struct softpipe_context *softpipe )
softpipe_init_texture_funcs(struct softpipe_context *sp)
{
softpipe->pipe.texture_update = softpipe_texture_update;
}
@@ -199,5 +237,10 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
{
screen->texture_create = softpipe_texture_create;
screen->texture_release = softpipe_texture_release;
screen->get_tex_surface = softpipe_get_tex_surface;
screen->tex_surface_release = softpipe_tex_surface_release;
screen->surface_map = softpipe_surface_map;
screen->surface_unmap = softpipe_surface_unmap;
}

View File

@@ -61,7 +61,6 @@ softpipe_texture(struct pipe_texture *pt)
extern void
softpipe_init_texture_funcs( struct softpipe_context *softpipe );
extern void
softpipe_init_screen_texture_funcs(struct pipe_screen *screen);

View File

@@ -49,6 +49,7 @@
struct softpipe_tile_cache
{
struct pipe_screen *screen;
struct pipe_surface *surface; /**< the surface we're caching */
void *surface_map;
struct pipe_texture *texture; /**< if caching a texture */
@@ -109,13 +110,14 @@ clear_clear_flag(uint *bitvec, int x, int y)
struct softpipe_tile_cache *
sp_create_tile_cache(void)
sp_create_tile_cache( struct pipe_screen *screen )
{
struct softpipe_tile_cache *tc;
uint pos;
tc = CALLOC_STRUCT( softpipe_tile_cache );
if (tc) {
tc->screen = screen;
for (pos = 0; pos < NUM_ENTRIES; pos++) {
tc->entries[pos].x =
tc->entries[pos].y = -1;
@@ -154,16 +156,17 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
assert(!tc->texture);
if (tc->surface_map) {
/*assert(tc->surface != ps);*/
pipe_surface_unmap(tc->surface);
tc->screen->surface_unmap(tc->screen, tc->surface);
tc->surface_map = NULL;
}
pipe_surface_reference(&tc->surface, ps);
if (ps) {
if (tc->surface_map)
tc->surface_map = pipe_surface_map(ps);
if (tc->surface) {
if (tc->surface_map) /* XXX: this is always NULL!? */
tc->surface_map = tc->screen->surface_map(tc->screen, tc->surface,
PIPE_BUFFER_USAGE_GPU_READ |
PIPE_BUFFER_USAGE_GPU_WRITE);
tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM ||
ps->format == PIPE_FORMAT_Z16_UNORM ||
@@ -187,10 +190,13 @@ void
sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc)
{
if (tc->surface && !tc->surface_map)
tc->surface_map = pipe_surface_map(tc->surface);
tc->surface_map = tc->screen->surface_map(tc->screen, tc->surface,
PIPE_BUFFER_USAGE_GPU_WRITE |
PIPE_BUFFER_USAGE_GPU_READ);
if (tc->tex_surf && !tc->tex_surf_map)
tc->tex_surf_map = pipe_surface_map(tc->tex_surf);
tc->tex_surf_map = tc->screen->surface_map(tc->screen, tc->tex_surf,
PIPE_BUFFER_USAGE_GPU_READ);
}
@@ -198,12 +204,12 @@ void
sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc)
{
if (tc->surface_map) {
pipe_surface_unmap(tc->surface);
tc->screen->surface_unmap(tc->screen, tc->surface);
tc->surface_map = NULL;
}
if (tc->tex_surf_map) {
pipe_surface_unmap(tc->tex_surf);
tc->screen->surface_unmap(tc->screen, tc->tex_surf);
tc->tex_surf_map = NULL;
}
}
@@ -224,7 +230,7 @@ sp_tile_cache_set_texture(struct pipe_context *pipe,
pipe_texture_reference(&tc->texture, texture);
if (tc->tex_surf_map) {
pipe_surface_unmap(tc->tex_surf);
tc->screen->surface_unmap(tc->screen, tc->tex_surf);
tc->tex_surf_map = NULL;
}
pipe_surface_reference(&tc->tex_surf, NULL);
@@ -514,10 +520,12 @@ sp_get_cached_tile_tex(struct pipe_context *pipe,
/* get new surface (view into texture) */
if (tc->tex_surf_map)
pipe_surface_unmap(tc->tex_surf);
tc->screen->surface_unmap(tc->screen, tc->tex_surf);
tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z);
tc->tex_surf_map = pipe_surface_map(tc->tex_surf);
tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z,
PIPE_BUFFER_USAGE_GPU_READ);
tc->tex_surf_map = screen->surface_map(screen, tc->tex_surf,
PIPE_BUFFER_USAGE_GPU_READ);
tc->tex_face = face;
tc->tex_level = level;

View File

@@ -61,7 +61,7 @@ struct softpipe_cached_tile
extern struct softpipe_tile_cache *
sp_create_tile_cache(void);
sp_create_tile_cache( struct pipe_screen *screen );
extern void
sp_destroy_tile_cache(struct softpipe_tile_cache *tc);

View File

@@ -198,12 +198,6 @@ struct pipe_context {
/*@}*/
/** Called when texture data is changed */
void (*texture_update)(struct pipe_context *pipe,
struct pipe_texture *texture,
uint face, uint dirtyLevelsMask);
/** Flush rendering (flags = bitmask of PIPE_FLUSH_x tokens) */
void (*flush)( struct pipe_context *pipe,
unsigned flags,

View File

@@ -39,20 +39,6 @@ extern "C" {
#endif
static INLINE void *
pipe_surface_map(struct pipe_surface *surface)
{
return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer,
PIPE_BUFFER_USAGE_CPU_WRITE |
PIPE_BUFFER_USAGE_CPU_READ )
+ surface->offset;
}
static INLINE void
pipe_surface_unmap(struct pipe_surface *surface)
{
surface->winsys->buffer_unmap( surface->winsys, surface->buffer );
}
/**
* Set 'ptr' to point to 'surf' and update reference counting.
@@ -66,9 +52,20 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
if (surf)
surf->refcount++;
if (*ptr /* && --(*ptr)->refcount == 0 */) {
struct pipe_winsys *winsys = (*ptr)->winsys;
winsys->surface_release(winsys, ptr);
if (*ptr) {
/* 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);
}

View File

@@ -96,7 +96,22 @@ struct pipe_screen {
struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
struct pipe_texture *texture,
unsigned face, unsigned level,
unsigned zslice);
unsigned zslice,
unsigned usage );
/* Surfaces allocated by the above must be released here:
*/
void (*tex_surface_release)( struct pipe_screen *,
struct pipe_surface ** );
void *(*surface_map)( struct pipe_screen *,
struct pipe_surface *surface,
unsigned flags );
void (*surface_unmap)( struct pipe_screen *,
struct pipe_surface *surface );
};

View File

@@ -273,7 +273,11 @@ struct pipe_surface
unsigned pitch; /**< in pixels */
unsigned offset; /**< offset from start of buffer, in bytes */
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 */
};

View File

@@ -204,7 +204,10 @@ mem_dup(const void *src, uint size)
#define MIN2( A, B ) ( (A)<(B) ? (A) : (B) )
#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) )
#ifndef Elements
#define Elements(x) (sizeof(x)/sizeof((x)[0]))
#endif
#define Offset(TYPE, MEMBER) ((unsigned)&(((TYPE *)NULL)->MEMBER))
/**

View File

@@ -508,6 +508,7 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys,
surf->format = format;
surf->cpp = pf_get_size(format);
surf->pitch = round_up(width, alignment / surf->cpp);
surf->usage = flags;
#ifdef GALLIUM_CELL /* XXX a bit of a hack */
height = round_up(height, TILE_SIZE);
@@ -562,6 +563,7 @@ static void
xm_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)

View File

@@ -148,8 +148,10 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt)
uint *dest;
uint i, j;
surface = screen->get_tex_surface(screen, pt, 0, 0, 0);
dest = (uint *) pipe_surface_map(surface);
surface = screen->get_tex_surface(screen, pt, 0, 0, 0,
PIPE_BUFFER_USAGE_CPU_WRITE);
dest = (uint *) screen->surface_map(screen, surface,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* Pack four 1D maps into a 2D texture:
* R map is placed horizontally, indexed by S, in channel 0
@@ -168,9 +170,8 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt)
}
}
pipe_surface_unmap(surface);
screen->surface_unmap(screen, surface);
pipe_surface_reference(&surface, NULL);
pipe->texture_update(pipe, pt, 0, 0x1);
}

View File

@@ -106,13 +106,15 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{
struct st_renderbuffer *acc_strb = st_renderbuffer(rb);
struct pipe_surface *acc_ps = acc_strb->surface;
struct pipe_screen *screen = ctx->st->pipe->screen;
const GLint xpos = ctx->DrawBuffer->_Xmin;
const GLint ypos = ctx->DrawBuffer->_Ymin;
const GLint width = ctx->DrawBuffer->_Xmax - xpos;
const GLint height = ctx->DrawBuffer->_Ymax - ypos;
GLvoid *map;
map = pipe_surface_map(acc_ps);
map = screen->surface_map(screen, acc_ps,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* note acc_strb->format might not equal acc_ps->format */
switch (acc_strb->format) {
@@ -140,7 +142,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
_mesa_problem(ctx, "unexpected format in st_clear_accum_buffer()");
}
pipe_surface_unmap(acc_ps);
screen->surface_unmap(screen, acc_ps);
}
@@ -150,10 +152,12 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias,
GLint xpos, GLint ypos, GLint width, GLint height,
struct st_renderbuffer *acc_strb)
{
struct pipe_screen *screen = ctx->st->pipe->screen;
struct pipe_surface *acc_ps = acc_strb->surface;
GLvoid *map;
map = pipe_surface_map(acc_ps);
map = screen->surface_map(screen, acc_ps,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* note acc_strb->format might not equal acc_ps->format */
switch (acc_strb->format) {
@@ -174,7 +178,7 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias,
_mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()");
}
pipe_surface_unmap(acc_ps);
screen->surface_unmap(screen, acc_ps);
}

View File

@@ -327,10 +327,11 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
return NULL;
}
surface = screen->get_tex_surface(screen, pt, 0, 0, 0);
surface = screen->get_tex_surface(screen, pt, 0, 0, 0,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* map texture surface */
dest = pipe_surface_map(surface);
dest = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE);
/* Put image into texture surface */
memset(dest, 0xff, height * surface->pitch);
@@ -340,9 +341,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
_mesa_unmap_bitmap_pbo(ctx, unpack);
/* Release surface */
pipe_surface_unmap(surface);
screen->surface_unmap(screen, surface);
pipe_surface_reference(&surface, NULL);
pipe->texture_update(pipe, pt, 0, 0x1);
return pt;
}
@@ -544,8 +544,10 @@ reset_cache(struct st_context *st)
/* Map the texture surface.
* Subsequent glBitmap calls will write into the texture image.
*/
cache->surf = screen->get_tex_surface(screen, cache->texture, 0, 0, 0);
cache->buffer = pipe_surface_map(cache->surf);
cache->surf = screen->get_tex_surface(screen, cache->texture, 0, 0, 0,
PIPE_BUFFER_USAGE_CPU_WRITE);
cache->buffer = screen->surface_map(screen, cache->surf,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* init image to all 0xff */
memset(cache->buffer, 0xff, BITMAP_CACHE_WIDTH * BITMAP_CACHE_HEIGHT);
@@ -562,6 +564,7 @@ st_flush_bitmap_cache(struct st_context *st)
if (st->ctx->DrawBuffer) {
struct bitmap_cache *cache = st->bitmap.cache;
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
assert(cache->xmin <= cache->xmax);
/*
@@ -574,12 +577,18 @@ st_flush_bitmap_cache(struct st_context *st)
/* The texture surface has been mapped until now.
* So unmap and release the texture surface before drawing.
*/
#if 0
pipe_surface_unmap(cache->surf);
pipe_surface_reference(&cache->surf, NULL);
#else
screen->surface_unmap(screen, cache->surf);
screen->tex_surface_release(screen, &cache->surf);
#endif
#if 0
/* XXX is this needed? */
pipe->texture_update(pipe, cache->texture, 0, 0x1);
#endif
draw_bitmap_quad(st->ctx,
cache->xpos,
cache->ypos,

View File

@@ -362,10 +362,12 @@ make_texture(struct st_context *st,
/* we'll do pixel transfer in a fragment shader */
ctx->_ImageTransferState = 0x0;
surface = screen->get_tex_surface(screen, pt, 0, 0, 0);
surface = screen->get_tex_surface(screen, pt, 0, 0, 0,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* map texture surface */
dest = pipe_surface_map(surface);
dest = screen->surface_map(screen, surface,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* Put image into texture surface.
* Note that the image is actually going to be upside down in
@@ -384,9 +386,8 @@ make_texture(struct st_context *st,
unpack);
/* unmap */
pipe_surface_unmap(surface);
screen->surface_unmap(screen, surface);
pipe_surface_reference(&surface, NULL);
pipe->texture_update(pipe, pt, 0, 0x1);
assert(success);
@@ -731,6 +732,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
{
struct st_context *st = ctx->st;
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_surface *ps = st->state.framebuffer.zsbuf;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
GLint skipPixels;
@@ -739,7 +741,8 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
/* map the stencil buffer */
stmap = pipe_surface_map(ps);
stmap = screen->surface_map(screen, ps,
PIPE_BUFFER_USAGE_CPU_WRITE);
/* if width > MAX_WIDTH, have to process image in chunks */
skipPixels = 0;
@@ -796,7 +799,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
}
/* unmap the stencil buffer */
pipe_surface_unmap(ps);
screen->surface_unmap(screen, ps);
}
@@ -869,6 +872,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
GLint dstx, GLint dsty)
{
struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer);
struct pipe_screen *screen = ctx->st->pipe->screen;
struct pipe_surface *psDraw = rbDraw->surface;
ubyte *drawMap;
ubyte *buffer;
@@ -885,7 +889,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
&ctx->DefaultPacking, buffer);
/* map the stencil buffer */
drawMap = pipe_surface_map(psDraw);
drawMap = screen->surface_map(screen, psDraw, PIPE_BUFFER_USAGE_CPU_WRITE);
/* draw */
/* XXX PixelZoom not handled yet */
@@ -925,7 +929,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
free(buffer);
/* unmap the stencil buffer */
pipe_surface_unmap(psDraw);
screen->surface_unmap(screen, psDraw);
}
@@ -994,13 +998,14 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
if (!pt)
return;
psTex = screen->get_tex_surface(screen, pt, 0, 0, 0);
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
srcy = ctx->DrawBuffer->Height - srcy - height;
}
if (srcFormat == texFormat) {
psTex = screen->get_tex_surface(screen, pt, 0, 0, 0,
PIPE_BUFFER_USAGE_GPU_WRITE );
/* copy source framebuffer surface into mipmap/texture */
pipe->surface_copy(pipe,
FALSE,
@@ -1009,21 +1014,26 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
psRead,
srcx, srcy, width, height);
}
else if (type == GL_COLOR) {
/* alternate path using get/put_tile() */
GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf);
pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf);
free(buf);
}
else {
/* GL_DEPTH */
GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
pipe_get_tile_z(pipe, psRead, srcx, srcy, width, height, buf);
pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf);
free(buf);
psTex = screen->get_tex_surface(screen, pt, 0, 0, 0,
PIPE_BUFFER_USAGE_CPU_WRITE );
if (type == GL_COLOR) {
/* alternate path using get/put_tile() */
GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf);
pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf);
free(buf);
}
else {
/* GL_DEPTH */
GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
pipe_get_tile_z(pipe, psRead, srcx, srcy, width, height, buf);
pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf);
free(buf);
}
}
/* draw textured quad */

View File

@@ -91,9 +91,14 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
struct pipe_context *pipe = ctx->st->pipe;
struct st_renderbuffer *strb = st_renderbuffer(rb);
enum pipe_format pipeFormat;
GLbitfield flags = 0x0; /* XXX needed? */
unsigned flags = (PIPE_BUFFER_USAGE_CPU_WRITE |
PIPE_BUFFER_USAGE_CPU_READ |
PIPE_BUFFER_USAGE_GPU_WRITE |
PIPE_BUFFER_USAGE_GPU_READ);
int ret;
pipe_surface_reference( &strb->surface, NULL );
if (!strb->surface) {
/* first time surface creation */
strb->surface = pipe->winsys->surface_alloc(pipe->winsys);
@@ -103,11 +108,16 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
if (!strb->surface)
return GL_FALSE;
}
#if 0
else if (strb->surface->buffer) {
/* release/discard the old surface buffer */
pipe_reference_buffer(pipe, &strb->surface->buffer, NULL);
}
#else
else {
assert(0);
}
#endif
/* Determine surface format here */
if (strb->format != PIPE_FORMAT_NONE) {
assert(strb->format != 0);
@@ -368,7 +378,11 @@ st_render_texture(GLcontext *ctx,
strb->surface = screen->get_tex_surface(screen, pt,
att->CubeMapFace,
att->TextureLevel,
att->Zoffset);
att->Zoffset,
PIPE_BUFFER_USAGE_CPU_READ |
PIPE_BUFFER_USAGE_CPU_WRITE |
PIPE_BUFFER_USAGE_GPU_READ |
PIPE_BUFFER_USAGE_GPU_WRITE);
assert(strb->surface);
assert(screen->is_format_supported(screen, strb->surface->format, PIPE_TEXTURE));
assert(screen->is_format_supported(screen, strb->surface->format, PIPE_SURFACE));
@@ -396,22 +410,19 @@ static void
st_finish_render_texture(GLcontext *ctx,
struct gl_renderbuffer_attachment *att)
{
struct pipe_screen *screen = ctx->st->pipe->screen;
struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer);
assert(strb);
ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
ctx->st->pipe->texture_update(ctx->st->pipe,
st_get_texobj_texture(att->Texture),
att->CubeMapFace, 1 << att->TextureLevel);
screen->tex_surface_release( screen, &strb->surface );
/*
printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface);
*/
pipe_surface_reference(&strb->surface, NULL);
_mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
/* restore previous framebuffer state */

View File

@@ -61,13 +61,14 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
GLvoid *pixels)
{
struct gl_framebuffer *fb = ctx->ReadBuffer;
struct pipe_screen *screen = ctx->st->pipe->screen;
struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
struct pipe_surface *ps = strb->surface;
ubyte *stmap;
GLint j;
/* map the stencil buffer */
stmap = pipe_surface_map(ps);
stmap = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ);
/* width should never be > MAX_WIDTH since we did clipping earlier */
ASSERT(width <= MAX_WIDTH);
@@ -124,7 +125,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
/* unmap the stencil buffer */
pipe_surface_unmap(ps);
screen->surface_unmap(screen, ps);
}

View File

@@ -478,7 +478,6 @@ st_TexImage(GLcontext * ctx,
struct gl_texture_image *texImage,
GLsizei imageSize, int compressed)
{
struct pipe_context *pipe = ctx->st->pipe;
struct st_texture_object *stObj = st_texture_object(texObj);
struct st_texture_image *stImage = st_texture_image(texImage);
GLint postConvWidth, postConvHeight;
@@ -635,7 +634,8 @@ st_TexImage(GLcontext * ctx,
return;
if (stImage->pt) {
texImage->Data = st_texture_image_map(ctx->st, stImage, 0);
texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
PIPE_BUFFER_USAGE_CPU_WRITE);
dstRowStride = stImage->surface->pitch * stImage->surface->cpp;
}
else {
@@ -684,8 +684,9 @@ st_TexImage(GLcontext * ctx,
}
if (stImage->pt && i < depth) {
st_texture_image_unmap(stImage);
texImage->Data = st_texture_image_map(ctx->st, stImage, i);
st_texture_image_unmap(ctx->st, stImage);
texImage->Data = st_texture_image_map(ctx->st, stImage, i,
PIPE_BUFFER_USAGE_CPU_WRITE);
src += srcImageStride;
}
}
@@ -694,13 +695,10 @@ st_TexImage(GLcontext * ctx,
_mesa_unmap_teximage_pbo(ctx, unpack);
if (stImage->pt) {
st_texture_image_unmap(stImage);
st_texture_image_unmap(ctx->st, stImage);
texImage->Data = NULL;
}
if (stObj->pt)
pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level));
if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
ctx->Driver.GenerateMipmap(ctx, target, texObj);
}
@@ -793,7 +791,8 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
/* Image is stored in hardware format in a buffer managed by the
* kernel. Need to explicitly map and unmap it.
*/
texImage->Data = st_texture_image_map(ctx->st, stImage, 0);
texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
PIPE_BUFFER_USAGE_CPU_READ);
texImage->RowStride = stImage->surface->pitch;
}
else {
@@ -823,8 +822,9 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
}
if (stImage->pt && i < depth) {
st_texture_image_unmap(stImage);
texImage->Data = st_texture_image_map(ctx->st, stImage, i);
st_texture_image_unmap(ctx->st, stImage);
texImage->Data = st_texture_image_map(ctx->st, stImage, i,
PIPE_BUFFER_USAGE_CPU_READ);
dest += dstImageStride;
}
}
@@ -833,7 +833,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
/* Unmap */
if (stImage->pt) {
st_texture_image_unmap(stImage);
st_texture_image_unmap(ctx->st, stImage);
texImage->Data = NULL;
}
}
@@ -874,8 +874,6 @@ st_TexSubimage(GLcontext * ctx,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
struct pipe_context *pipe = ctx->st->pipe;
struct st_texture_object *stObj = st_texture_object(texObj);
struct st_texture_image *stImage = st_texture_image(texImage);
GLuint dstRowStride;
GLuint srcImageStride = _mesa_image_image_stride(packing, width, height,
@@ -897,7 +895,8 @@ st_TexSubimage(GLcontext * ctx,
* from uploading the buffer under us.
*/
if (stImage->pt) {
texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset);
texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset,
PIPE_BUFFER_USAGE_CPU_WRITE);
dstRowStride = stImage->surface->pitch * stImage->surface->cpp;
}
@@ -922,8 +921,9 @@ st_TexSubimage(GLcontext * ctx,
if (stImage->pt && i < depth) {
/* map next slice of 3D texture */
st_texture_image_unmap(stImage);
texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i);
st_texture_image_unmap(ctx->st, stImage);
texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i,
PIPE_BUFFER_USAGE_CPU_WRITE);
src += srcImageStride;
}
}
@@ -935,11 +935,9 @@ st_TexSubimage(GLcontext * ctx,
_mesa_unmap_teximage_pbo(ctx, packing);
if (stImage->pt) {
st_texture_image_unmap(stImage);
st_texture_image_unmap(ctx->st, stImage);
texImage->Data = NULL;
}
pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level));
}
@@ -1058,7 +1056,8 @@ fallback_copy_texsubimage(GLcontext *ctx,
src_surf = strb->surface;
dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ);
dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ,
PIPE_BUFFER_USAGE_CPU_WRITE);
assert(width <= MAX_WIDTH);
@@ -1119,7 +1118,6 @@ do_copy_texsubimage(GLcontext *ctx,
struct gl_texture_image *texImage =
_mesa_select_tex_image(ctx, texObj, target, level);
struct st_texture_image *stImage = st_texture_image(texImage);
struct st_texture_object *stObj = st_texture_object(texObj);
GLenum baseFormat = texImage->InternalFormat;
struct gl_framebuffer *fb = ctx->ReadBuffer;
struct st_renderbuffer *strb;
@@ -1157,7 +1155,8 @@ do_copy_texsubimage(GLcontext *ctx,
dest_format = stImage->pt->format;
dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face,
stImage->level, destZ);
stImage->level, destZ,
PIPE_BUFFER_USAGE_CPU_WRITE);
if (ctx->_ImageTransferState == 0x0 &&
strb->surface->buffer &&
@@ -1223,8 +1222,6 @@ do_copy_texsubimage(GLcontext *ctx,
pipe_surface_reference(&dest_surface, NULL);
pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level));
if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
ctx->Driver.GenerateMipmap(ctx, target, texObj);
}
@@ -1529,7 +1526,6 @@ st_finalize_texture(GLcontext *ctx,
if (stImage && stObj->pt != stImage->pt) {
copy_image_data_to_texture(ctx->st, stObj, level, stImage);
*needFlush = GL_TRUE;
pipe->texture_update(pipe, stObj->pt, face, (1 << level));
}
}
}

View File

@@ -123,8 +123,10 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
const ubyte *srcData;
ubyte *dstData;
srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice);
dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice);
srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice,
PIPE_BUFFER_USAGE_CPU_READ);
dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
PIPE_BUFFER_USAGE_CPU_WRITE);
srcData = (ubyte *) pipe_buffer_map(pipe, srcSurf->buffer,
PIPE_BUFFER_USAGE_CPU_READ)

View File

@@ -184,25 +184,30 @@ st_texture_image_offset(const struct pipe_texture * pt,
*/
GLubyte *
st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
GLuint zoffset)
GLuint zoffset,
GLuint flags )
{
struct pipe_screen *screen = st->pipe->screen;
struct pipe_texture *pt = stImage->pt;
DBG("%s \n", __FUNCTION__);
stImage->surface = screen->get_tex_surface(screen, pt, stImage->face,
stImage->level, zoffset);
stImage->level, zoffset,
flags);
return pipe_surface_map(stImage->surface);
return screen->surface_map(screen, stImage->surface, flags);
}
void
st_texture_image_unmap(struct st_texture_image *stImage)
st_texture_image_unmap(struct st_context *st,
struct st_texture_image *stImage)
{
struct pipe_screen *screen = st->pipe->screen;
DBG("%s\n", __FUNCTION__);
pipe_surface_unmap(stImage->surface);
screen->surface_unmap(screen, stImage->surface);
pipe_surface_reference(&stImage->surface, NULL);
}
@@ -224,12 +229,15 @@ st_surface_data(struct pipe_context *pipe,
const void *src, unsigned src_pitch,
unsigned srcx, unsigned srcy, unsigned width, unsigned height)
{
pipe_copy_rect(pipe_surface_map(dst),
struct pipe_screen *screen = pipe->screen;
void *map = screen->surface_map(screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE);
pipe_copy_rect(map,
dst->cpp,
dst->pitch,
dstx, dsty, width, height, src, src_pitch, srcx, srcy);
pipe_surface_unmap(dst);
screen->surface_unmap(screen, dst);
}
@@ -256,7 +264,8 @@ st_texture_image_data(struct pipe_context *pipe,
if(dst->compressed)
height /= 4;
dst_surface = screen->get_tex_surface(screen, dst, face, level, i);
dst_surface = screen->get_tex_surface(screen, dst, face, level, i,
PIPE_BUFFER_USAGE_CPU_WRITE);
st_surface_data(pipe, dst_surface,
0, 0, /* dstx, dsty */
@@ -265,7 +274,7 @@ st_texture_image_data(struct pipe_context *pipe,
0, 0, /* source x, y */
dst->width[level], height); /* width, height */
pipe_surface_reference(&dst_surface, NULL);
screen->tex_surface_release(screen, &dst_surface);
srcUB += src_image_pitch * dst->cpp;
}
@@ -304,8 +313,11 @@ st_texture_image_copy(struct pipe_context *pipe,
assert(src->width[srcLevel] == width);
assert(src->height[srcLevel] == height);
dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i);
src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i);
dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i,
PIPE_BUFFER_USAGE_GPU_WRITE);
src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i,
PIPE_BUFFER_USAGE_GPU_READ);
pipe->surface_copy(pipe,
FALSE,

View File

@@ -121,10 +121,12 @@ st_texture_match_image(const struct pipe_texture *pt,
extern GLubyte *
st_texture_image_map(struct st_context *st,
struct st_texture_image *stImage,
GLuint zoffset);
GLuint zoffset,
GLuint flags);
extern void
st_texture_image_unmap(struct st_texture_image *stImage);
st_texture_image_unmap(struct st_context *st,
struct st_texture_image *stImage);
/* Return pointers to each 2d slice within an image. Indexed by depth