{
unsigned drm_flags = 0;
- if (flags & PIPE_BUFFER_FLAG_WRITE)
+ if (flags & PIPE_BUFFER_USAGE_CPU_WRITE)
drm_flags |= DRM_BO_FLAG_WRITE;
- if (flags & PIPE_BUFFER_FLAG_READ)
+ if (flags & PIPE_BUFFER_USAGE_CPU_READ)
drm_flags |= DRM_BO_FLAG_READ;
return driBOMap( dri_bo(buf), drm_flags, 0 );
}
-/* Grabs the hardware lock!
- */
-static int intel_buffer_data(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
- unsigned size, const void *data,
- unsigned usage )
-{
- driBOData( dri_bo(buf), size, data, 0 );
- return 0;
-}
-
-static int intel_buffer_subdata(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
- unsigned long offset,
- unsigned long size,
- const void *data)
-{
- driBOSubData( dri_bo(buf), offset, size, data );
- return 0;
-}
-
-static int intel_buffer_get_subdata(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
- unsigned long offset,
- unsigned long size,
- void *data)
-{
- driBOGetSubData( dri_bo(buf), offset, size, data );
- return 0;
-}
-
/* Pipe has no concept of pools. We choose the tex/region pool
* for all buffers.
+ * Grabs the hardware lock!
*/
static struct pipe_buffer_handle *
intel_buffer_create(struct pipe_winsys *winsys,
unsigned alignment,
- unsigned flags,
- unsigned hint )
+ unsigned usage,
+ unsigned size )
{
struct _DriBufferObject *buffer;
struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys);
+ unsigned flags = 0;
+
+ if (usage & (PIPE_BUFFER_USAGE_VERTEX /*| IWS_BUFFER_USAGE_LOCAL*/)) {
+ flags |= DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED;
+ } else {
+ flags |= DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT;
+ }
+
+ if (usage & PIPE_BUFFER_USAGE_GPU_READ)
+ flags |= DRM_BO_FLAG_READ;
+
+ if (usage & PIPE_BUFFER_USAGE_GPU_WRITE)
+ flags |= DRM_BO_FLAG_WRITE;
+
+ /* drm complains if we don't set any read/write flags.
+ */
+ if ((flags & (DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE)) == 0)
+ flags |= DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE;
+
+#if 0
+ if (flags & IWS_BUFFER_USAGE_EXE)
+ flags |= DRM_BO_FLAG_EXE;
+
+ if (usage & IWS_BUFFER_USAGE_CACHED)
+ flags |= DRM_BO_FLAG_CACHED;
+#endif
+
driGenBuffers( iws->regionPool,
- "pipe buffer", 1, &buffer, alignment, flags, hint );
+ "pipe buffer", 1, &buffer, alignment, flags, 0 );
+ driBOData( buffer, size, NULL, 0 );
return pipe_bo(buffer);
}
surf->pitch = round_up(width, alignment / surf->cpp);
assert(!surf->buffer);
- surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0);
+ surf->buffer = winsys->buffer_create(winsys, alignment,
+ PIPE_BUFFER_USAGE_PIXEL,
+ surf->pitch * surf->cpp * height);
if(!surf->buffer)
return -1;
- ret = winsys->buffer_data(winsys,
- surf->buffer,
- surf->pitch * surf->cpp * height,
- NULL,
- PIPE_BUFFER_USAGE_PIXEL);
if(ret) {
winsys->buffer_reference(winsys, &surf->buffer, NULL);
return ret;
iws->winsys.buffer_map = intel_buffer_map;
iws->winsys.buffer_unmap = intel_buffer_unmap;
iws->winsys.buffer_reference = intel_buffer_reference;
- iws->winsys.buffer_data = intel_buffer_data;
- iws->winsys.buffer_subdata = intel_buffer_subdata;
- iws->winsys.buffer_get_subdata = intel_buffer_get_subdata;
iws->winsys.flush_frontbuffer = intel_flush_frontbuffer;
iws->winsys.printf = intel_printf;
iws->winsys.get_name = intel_get_name;
void *buf
= pipe->winsys->buffer_map(pipe->winsys,
i915->vertex_buffer[i].buffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_vertex_buffer(draw, i, buf);
}
}
if (indexBuffer) {
void *mapped_indexes
= pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
}
else {
/* FIXME: handle failure */
assert(!i915->vbo);
- i915->vbo = winsys->buffer_create(winsys, 64, 0, 0);
- winsys->buffer_data( winsys, i915->vbo,
- size, NULL,
- I915_BUFFER_USAGE_LIT_VERTEX );
+ i915->vbo = winsys->buffer_create(winsys, 64, I915_BUFFER_USAGE_LIT_VERTEX,
+ size);
i915->dirty |= I915_NEW_VBO;
return winsys->buffer_map(winsys,
i915->vbo,
- PIPE_BUFFER_FLAG_WRITE );
+ PIPE_BUFFER_USAGE_CPU_WRITE);
}
{
void *mapped;
if (buf->size &&
- (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_FLAG_READ))) {
+ (mapped = ws->buffer_map(ws, buf->buffer,
+ PIPE_BUFFER_USAGE_CPU_READ))) {
memcpy(i915->current.constants[shader], mapped, buf->size);
ws->buffer_unmap(ws, buf->buffer);
i915->current.num_user_constants[shader]
sizeof(struct i915_texture) - sizeof(struct pipe_texture));
if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) :
- i915_miptree_layout(pipe, tex)) {
- tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, 0, 0);
-
- if (tex->buffer)
- pipe->winsys->buffer_data(pipe->winsys, tex->buffer,
- tex->pitch * tex->base.cpp *
- tex->total_height, NULL,
- PIPE_BUFFER_USAGE_PIXEL);
- }
+ i915_miptree_layout(pipe, tex))
+ tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64,
+ PIPE_BUFFER_USAGE_PIXEL,
+ tex->pitch * tex->base.cpp *
+ tex->total_height);
if (!tex->buffer) {
FREE(tex);
/* FIXME: buffer size is num_consts + num_immediates */
if (brw->vs.prog_data->num_consts) {
/* map the vertex constant buffer and copy to curbe: */
- ws->buffer_map(ws, cbuffer->buffer, 0);
+ void *data = ws->buffer_map(ws, cbuffer->buffer, 0);
/* FIXME: this is wrong. the cbuffer->size currently
* represents size of consts + immediates. so if we'll
* have both we'll copy over the end of the buffer
* with the subsequent memcpy */
- ws->buffer_get_subdata(ws, cbuffer->buffer,
- 0,
- cbuffer->size,
- &buf[offset]);
+ memcpy(&buf[offset], data, cbuffer->size);
ws->buffer_unmap(ws, cbuffer->buffer);
offset += cbuffer->size;
}
for (i = 0; i < nr_enabled; i++) {
OUT_BATCH( vbp.vb[i].vb0.dword );
- OUT_RELOC( vbp.vb[i].buffer, PIPE_BUFFER_FLAG_READ,
+ OUT_RELOC( vbp.vb[i].buffer, PIPE_BUFFER_USAGE_GPU_READ,
vbp.vb[i].offset);
OUT_BATCH( vbp.vb[i].max_index );
OUT_BATCH( vbp.vb[i].instance_data_step_rate );
BEGIN_BATCH(4, 0);
OUT_BATCH( ib.header.dword );
- OUT_RELOC( index_buffer, PIPE_BUFFER_FLAG_READ, start);
- OUT_RELOC( index_buffer, PIPE_BUFFER_FLAG_READ, start + count);
+ OUT_RELOC( index_buffer, PIPE_BUFFER_USAGE_GPU_READ, start);
+ OUT_RELOC( index_buffer, PIPE_BUFFER_USAGE_GPU_READ, start + count);
OUT_BATCH( 0 );
ADVANCE_BATCH();
}
// (depth_surface->region->tiled << 27) |
(BRW_SURFACE_2D << 29));
OUT_RELOC(depth_surface->buffer,
- PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE, 0);
+ PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE, 0);
OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) |
((depth_surface->pitch - 1) << 6) |
((depth_surface->height - 1) << 19));
BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS);
OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (6 - 2));
OUT_RELOC(brw->pool[BRW_GS_POOL].buffer,
- PIPE_BUFFER_FLAG_READ,
+ PIPE_BUFFER_USAGE_GPU_READ,
1); /* General state base address */
OUT_RELOC(brw->pool[BRW_SS_POOL].buffer,
- PIPE_BUFFER_FLAG_READ,
+ PIPE_BUFFER_USAGE_GPU_READ,
1); /* Surface state base address */
OUT_BATCH(1); /* Indirect object base address */
OUT_BATCH(1); /* General state upper bound */
pool->brw = brw;
pool->buffer = brw->pipe.winsys->buffer_create(brw->pipe.winsys,
- 4096, 0, 0);
-
- brw->pipe.winsys->buffer_data(brw->pipe.winsys,
- pool->buffer,
- size,
- NULL,
- 0 /* DRM_BO_FLAG_MEM_TT */);
+ 4096,
+ 0 /* DRM_BO_FLAG_MEM_TT */,
+ size);
}
static void brw_destroy_pool( struct brw_context *brw,
memset(&tex->base + 1, 0,
sizeof(struct brw_texture) - sizeof(struct pipe_texture));
- if (brw_miptree_layout(pipe, tex)) {
- tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, 0, 0);
-
- if (tex->buffer)
- pipe->winsys->buffer_data(pipe->winsys, tex->buffer,
- tex->pitch * tex->base.cpp *
- tex->total_height, NULL,
- PIPE_BUFFER_USAGE_PIXEL);
- }
+ if (brw_miptree_layout(pipe, tex))
+ tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64,
+ PIPE_BUFFER_USAGE_PIXEL,
+ tex->pitch * tex->base.cpp *
+ tex->total_height);
if (!tex->buffer) {
FREE(tex);
#define PIPE_SURFACE_STATUS_CLEAR 2
-/**
- * Buffer access flags
- */
-#define PIPE_BUFFER_FLAG_READ 0x1
-#define PIPE_BUFFER_FLAG_WRITE 0x2
-#define PIPE_BUFFER_FLAG_MEM_LOCAL 0x4
-#define PIPE_BUFFER_FLAG_CACHED 0x8
-#define PIPE_BUFFER_FLAG_CUSTOM (1<<16)
-
-
-
/**
* Buffer usage flags
*/
-#define PIPE_BUFFER_USAGE_PIXEL (1 << 0)
-#define PIPE_BUFFER_USAGE_VERTEX (1 << 1)
-#define PIPE_BUFFER_USAGE_INDEX (1 << 2)
-#define PIPE_BUFFER_USAGE_CONSTANT (1 << 3)
+#define PIPE_BUFFER_USAGE_CPU_READ (1 << 0)
+#define PIPE_BUFFER_USAGE_CPU_WRITE (1 << 1)
+#define PIPE_BUFFER_USAGE_GPU_READ (1 << 2)
+#define PIPE_BUFFER_USAGE_GPU_WRITE (1 << 3)
+#define PIPE_BUFFER_USAGE_PIXEL (1 << 4)
+#define PIPE_BUFFER_USAGE_VERTEX (1 << 5)
+#define PIPE_BUFFER_USAGE_INDEX (1 << 6)
+#define PIPE_BUFFER_USAGE_CONSTANT (1 << 7)
/** Pipe driver custam usage flags should be greater or equal to this value */
-#define PIPE_BUFFER_USAGE_CUSTOM (1 << 16)
+#define PIPE_BUFFER_USAGE_CUSTOM (1 << 16)
+
/**
* Flush types:
pipe_surface_map(struct pipe_surface *surface)
{
return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer,
- PIPE_BUFFER_FLAG_WRITE |
- PIPE_BUFFER_FLAG_READ )
+ PIPE_BUFFER_USAGE_CPU_WRITE |
+ PIPE_BUFFER_USAGE_CPU_READ )
+ surface->offset;
}
-/**************************************************************************
+ /**************************************************************************
*
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
/**
- * The buffer manager is modeled after the dri_bufmgr interface, which
- * in turn is modeled after the ARB_vertex_buffer_object extension,
- * but this is the subset that gallium cares about. Remember that
- * gallium gets to choose the interface it needs, and the window
- * systems must then implement that interface (rather than the
+ * Buffer management. Buffer attributes are mostly fixed over its lifetime.
+ *
+ * Remember that gallium gets to choose the interface it needs, and the
+ * window systems must then implement that interface (rather than the
* other way around...).
+ *
+ * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
+ * usage argument is only an optimization hint, not a guarantee, therefore
+ * proper behavior must be observed in all circumstances.
*/
struct pipe_buffer_handle *(*buffer_create)( struct pipe_winsys *sws,
unsigned alignment,
- unsigned flags,
- unsigned hint );
+ unsigned usage,
+ unsigned size );
/** Create a buffer that wraps user-space data */
struct pipe_buffer_handle *(*user_buffer_create)(struct pipe_winsys *sws,
*/
void *(*buffer_map)( struct pipe_winsys *sws,
struct pipe_buffer_handle *buf,
- unsigned flags );
+ unsigned usage );
void (*buffer_unmap)( struct pipe_winsys *sws,
struct pipe_buffer_handle *buf );
struct pipe_buffer_handle **ptr,
struct pipe_buffer_handle *buf );
- /**
- * Create the data store of a buffer and optionally initialize it.
- *
- * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
- * usage argument is only an optimization hint, not a guarantee, therefore
- * proper behavior must be observed in all circumstances.
- *
- * Returns zero on success.
- */
- int (*buffer_data)(struct pipe_winsys *sws,
- struct pipe_buffer_handle *buf,
- unsigned size, const void *data,
- unsigned usage);
- /**
- * Modify some or all of the data contained in a buffer's data store.
- *
- * Returns zero on success.
- */
- int (*buffer_subdata)(struct pipe_winsys *sws,
- struct pipe_buffer_handle *buf,
- unsigned long offset,
- unsigned long size,
- const void *data);
-
- /**
- * Query some or all of the data contained in a buffer's data store.
- *
- * Returns zero on success.
- */
- int (*buffer_get_subdata)(struct pipe_winsys *sws,
- struct pipe_buffer_handle *buf,
- unsigned long offset,
- unsigned long size,
- void *data);
-
-
- /** Set ptr = buf, with reference counting */
+ /** Set ptr = fence, with reference counting */
void (*fence_reference)( struct pipe_winsys *sws,
struct pipe_fence_handle **ptr,
struct pipe_fence_handle *fence );
static struct pipe_buffer_handle *
buffer_handle_create(struct pipe_winsys *winsys,
unsigned alignment,
- unsigned flags,
- unsigned hint)
+ unsigned usage,
+ unsigned size)
{
struct pipe_buffer_handle *handle;
handle->refcount = 1;
handle->alignment = alignment;
- handle->flags = flags;
- handle->hint = hint;
+ handle->usage = usage;
+ handle->size = size;
handle->buf = &null_buffer;
struct pipe_buffer_handle *handle;
struct pipe_buffer *buf;
- handle = buffer_handle_create(winsys, 1, 0, 0);
+ handle = buffer_handle_create(winsys, 1, 0, size);
if(!handle)
return NULL;
}
-static int
-buffer_handle_subdata(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *handle,
- unsigned long offset,
- unsigned long size,
- const void *data)
-{
- void *map;
- assert(handle);
- assert(data);
- map = buffer_handle_map(winsys, handle, PIPE_BUFFER_FLAG_WRITE);
- if(map) {
- memcpy((char *)map + offset, data, size);
- buffer_handle_unmap(winsys, handle);
- return 0;
- }
- return -1;
-}
-
-
-static int
-buffer_handle_get_subdata(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *handle,
- unsigned long offset,
- unsigned long size,
- void *data)
-{
- void *map;
- assert(handle);
- assert(data);
- map = buffer_handle_map(winsys, handle, PIPE_BUFFER_FLAG_READ);
- if(map) {
- memcpy(data, (char *)map + offset, size);
- buffer_handle_unmap(winsys, handle);
- return 0;
- }
- return -1;
-}
-
-
void
buffer_handle_init_winsys(struct pipe_winsys *winsys)
{
winsys->buffer_map = buffer_handle_map;
winsys->buffer_unmap = buffer_handle_unmap;
winsys->buffer_reference = buffer_handle_reference;
- winsys->buffer_subdata = buffer_handle_subdata;
- winsys->buffer_get_subdata = buffer_handle_get_subdata;
}
/** Allocation characteristics */
unsigned alignment;
- unsigned flags;
- unsigned hint;
+ unsigned usage;
+ unsigned size;
/**
* The actual buffer.
mm->buffer = buffer;
mm->map = buffer_map(mm->buffer,
- PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE );
+ PIPE_BUFFER_USAGE_CPU_READ |
+ PIPE_BUFFER_USAGE_CPU_WRITE);
if(!mm->map)
goto failure;
goto failure;
pool->map = buffer_map(pool->buffer,
- PIPE_BUFFER_FLAG_READ |
- PIPE_BUFFER_FLAG_WRITE );
+ PIPE_BUFFER_USAGE_CPU_READ |
+ PIPE_BUFFER_USAGE_CPU_WRITE);
if(!pool->map)
goto failure;
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_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
}
draw_set_mapped_constant_buffer(sp->draw,
void *buf
= pipe->winsys->buffer_map(pipe->winsys,
sp->vertex_buffer[i].buffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_vertex_buffer(draw, i, buf);
}
}
if (indexBuffer) {
void *mapped_indexes
= pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
}
else {
softpipe_texture_layout(spt);
- spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0);
-
- if (spt->buffer) {
- pipe->winsys->buffer_data(pipe->winsys, spt->buffer, spt->buffer_size,
- NULL, PIPE_BUFFER_USAGE_PIXEL);
- }
+ spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32,
+ PIPE_BUFFER_USAGE_PIXEL,
+ spt->buffer_size);
if (!spt->buffer) {
FREE(spt);
}
}
-static int
-xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
- unsigned size, const void *data, unsigned usage )
-{
- struct xm_buffer *xm_buf = xm_bo(buf);
- assert(!xm_buf->userBuffer);
- if (xm_buf->size != size) {
- if (xm_buf->data)
- align_free(xm_buf->data);
- /* align to 16-byte multiple for Cell */
- xm_buf->data = align_malloc(size, 16);
- xm_buf->size = size;
- }
- if (data)
- memcpy(xm_buf->data, data, size);
- return 0;
-}
-
-static int
-xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
- unsigned long offset, unsigned long size, const void *data)
-{
- struct xm_buffer *xm_buf = xm_bo(buf);
- GLubyte *b = (GLubyte *) xm_buf->data;
- assert(!xm_buf->userBuffer);
- assert(b);
- memcpy(b + offset, data, size);
- return 0;
-}
-
-static int
-xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
- unsigned long offset, unsigned long size, void *data)
-{
- const struct xm_buffer *xm_buf = xm_bo(buf);
- const GLubyte *b = (GLubyte *) xm_buf->data;
- assert(!xm_buf->userBuffer);
- assert(b);
- memcpy(data, b + offset, size);
- return 0;
-}
-
/**
* Display a surface that's in a tiled configuration. That is, all the
static struct pipe_buffer_handle *
xm_buffer_create(struct pipe_winsys *pws,
unsigned alignment,
- unsigned flags,
- unsigned hints)
+ unsigned usage,
+ unsigned size)
{
struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
buffer->refcount = 1;
+
+ /* align to 16-byte multiple for Cell */
+ buffer->data = align_malloc(size, max(alignment, 16));
+ buffer->size = size;
+
return pipe_bo(buffer);
}
unsigned flags)
{
const unsigned alignment = 64;
- int ret;
surf->width = width;
surf->height = height;
#endif
assert(!surf->buffer);
- surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0);
+ surf->buffer = winsys->buffer_create(winsys, alignment,
+ PIPE_BUFFER_USAGE_PIXEL,
+ surf->pitch * surf->cpp * height);
if(!surf->buffer)
return -1;
-
- ret = winsys->buffer_data(winsys,
- surf->buffer,
- surf->pitch * surf->cpp * height,
- NULL,
- 0);
- if(ret) {
- winsys->buffer_reference(winsys, &surf->buffer, NULL);
- return ret;
- }
return 0;
}
ws->buffer_map = xm_buffer_map;
ws->buffer_unmap = xm_buffer_unmap;
ws->buffer_reference = xm_buffer_reference;
- ws->buffer_data = xm_buffer_data;
- ws->buffer_subdata = xm_buffer_subdata;
- ws->buffer_get_subdata = xm_buffer_get_subdata;
ws->surface_alloc = xm_surface_alloc;
ws->surface_alloc_storage = xm_surface_alloc_storage;
assert(sbo->data);
- if (flags & PIPE_BUFFER_FLAG_WRITE)
+ if (flags & PIPE_BUFFER_USAGE_CPU_WRITE)
sbo->dump_on_unmap = 1;
sbo->map_count++;
}
-static int aub_buffer_data(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
- unsigned size, const void *data,
- unsigned usage )
-{
- struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys);
- struct aub_buffer *sbo = aub_bo(buf);
-
- /* Could reuse buffers that are not referenced in current
- * batchbuffer. Can't do that atm, so always reallocate:
- */
- if (1 || sbo->size < size) {
- assert(iws->used + size < iws->size);
- sbo->data = iws->pool + iws->used;
- sbo->offset = AUB_BUF_START + iws->used;
- iws->used += align(size, 4096);
- }
-
- sbo->size = size;
-
- if (data != NULL) {
- memcpy(sbo->data, data, size);
-
- brw_aub_gtt_data( iws->aubfile,
- sbo->offset,
- sbo->data,
- sbo->size,
- 0,
- 0 );
- }
- return 0;
-}
-
-static int aub_buffer_subdata(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
- unsigned long offset,
- unsigned long size,
- const void *data)
-{
- struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys);
- struct aub_buffer *sbo = aub_bo(buf);
-
- assert(sbo->size > offset + size);
- memcpy(sbo->data + offset, data, size);
-
- brw_aub_gtt_data( iws->aubfile,
- sbo->offset + offset,
- sbo->data + offset,
- size,
- 0,
- 0 );
- return 0;
-}
-
-
void xmesa_buffer_subdata_aub(struct pipe_winsys *winsys,
struct pipe_buffer_handle *buf,
unsigned long offset,
-static int aub_buffer_get_subdata(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
- unsigned long offset,
- unsigned long size,
- void *data)
-{
- struct aub_buffer *sbo = aub_bo(buf);
- assert(sbo->size >= offset + size);
- memcpy(data, sbo->data + offset, size);
- return 0;
-}
-
/* Pipe has no concept of pools. We choose the tex/region pool
* for all buffers.
*/
static struct pipe_buffer_handle *
aub_buffer_create(struct pipe_winsys *winsys,
- unsigned alignment,
- unsigned flags,
- unsigned hint)
+ unsigned alignment,
+ unsigned usage,
+ unsigned size)
{
+ struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys);
struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer);
+
sbo->refcount = 1;
+
+ /* Could reuse buffers that are not referenced in current
+ * batchbuffer. Can't do that atm, so always reallocate:
+ */
+ assert(iws->used + size < iws->size);
+ sbo->data = iws->pool + iws->used;
+ sbo->offset = AUB_BUF_START + iws->used;
+ iws->used += align(size, 4096);
+
+ sbo->size = size;
+
return pipe_bo(sbo);
}
static struct pipe_buffer_handle *
aub_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes)
{
- struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer);
-
- sbo->refcount = 1;
+ struct aub_buffer *sbo;
/* Lets hope this is meant for upload, not as a result!
*/
- aub_buffer_data( winsys,
- pipe_bo(sbo),
- bytes,
- ptr,
- 0 );
+ sbo = aub_bo(aub_buffer_create( winsys, 0, 0, 0 ));
+
+ sbo->data = ptr;
+ sbo->size = bytes;
return pipe_bo(sbo);
}
unsigned flags)
{
const unsigned alignment = 64;
- int ret;
surf->width = width;
surf->height = height;
surf->pitch = round_up(width, alignment / surf->cpp);
assert(!surf->buffer);
- surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0);
+ surf->buffer = winsys->buffer_create(winsys, alignment,
+ PIPE_BUFFER_USAGE_PIXEL,
+ surf->pitch * surf->cpp * height);
if(!surf->buffer)
return -1;
- ret = winsys->buffer_data(winsys,
- surf->buffer,
- surf->pitch * surf->cpp * height,
- NULL,
- 0);
- if(ret) {
- winsys->buffer_reference(winsys, &surf->buffer, NULL);
- return ret;
- }
-
return 0;
}
iws->winsys.buffer_map = aub_buffer_map;
iws->winsys.buffer_unmap = aub_buffer_unmap;
iws->winsys.buffer_reference = aub_buffer_reference;
- iws->winsys.buffer_data = aub_buffer_data;
- iws->winsys.buffer_subdata = aub_buffer_subdata;
- iws->winsys.buffer_get_subdata = aub_buffer_get_subdata;
iws->winsys.flush_frontbuffer = aub_flush_frontbuffer;
iws->winsys.printf = aub_printf;
iws->winsys.get_name = aub_get_name;
_mesa_load_state_parameters(st->ctx, params);
- if (!cbuf->buffer)
- cbuf->buffer = ws->buffer_create(ws, 1, 0, 0);
+ if (cbuf->buffer && cbuf->size != paramBytes)
+ ws->buffer_reference( ws, &cbuf->buffer, NULL );
+
+ if (!cbuf->buffer) {
+ cbuf->buffer = ws->buffer_create(ws, 1, PIPE_BUFFER_USAGE_CONSTANT,
+ paramBytes);
+ }
if (0)
{
}
/* load Mesa constants into the constant buffer */
- ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues,
- PIPE_BUFFER_USAGE_CONSTANT);
+ if (cbuf->buffer) {
+ memcpy(ws->buffer_map(ws, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
+ params->ParameterValues, paramBytes);
+ ws->buffer_unmap(ws, cbuf->buffer);
+ }
cbuf->size = paramBytes;
static struct gl_buffer_object *
st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target)
{
- struct st_context *st = st_context(ctx);
struct st_buffer_object *st_obj = CALLOC_STRUCT(st_buffer_object);
if (!st_obj)
_mesa_initialize_buffer_object(&st_obj->Base, name, target);
- st_obj->buffer = st->pipe->winsys->buffer_create( st->pipe->winsys, 32, 0, 0 );
-
return &st_obj->Base;
}
+/**
+ * Replace data in a subrange of buffer object. If the data range
+ * specified by size + offset extends beyond the end of the buffer or
+ * if data is NULL, no copy is performed.
+ * Called via glBufferSubDataARB().
+ */
+static void
+st_bufferobj_subdata(GLcontext *ctx,
+ GLenum target,
+ GLintptrARB offset,
+ GLsizeiptrARB size,
+ const GLvoid * data, struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+ char *map;
+
+ if (offset >= st_obj->size || size > (st_obj->size - offset))
+ return;
+
+ map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer,
+ PIPE_BUFFER_USAGE_CPU_WRITE);
+ memcpy(map + offset, data, size);
+ pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer);
+}
+
+
+/**
+ * Called via glGetBufferSubDataARB().
+ */
+static void
+st_bufferobj_get_subdata(GLcontext *ctx,
+ GLenum target,
+ GLintptrARB offset,
+ GLsizeiptrARB size,
+ GLvoid * data, struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+ char *map;
+
+ if (offset >= st_obj->size || size > (st_obj->size - offset))
+ return;
+
+ map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer,
+ PIPE_BUFFER_USAGE_CPU_READ);
+ memcpy(data, map + offset, size);
+ pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer);
+}
+
+
/**
* Allocate space for and store data in a buffer object. Any data that was
* previously stored in the buffer object is lost. If data is NULL,
GLenum usage,
struct gl_buffer_object *obj)
{
- struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_context *st = st_context(ctx);
+ struct pipe_context *pipe = st->pipe;
struct st_buffer_object *st_obj = st_buffer_object(obj);
unsigned buffer_usage;
buffer_usage = 0;
}
- pipe->winsys->buffer_data( pipe->winsys, st_obj->buffer,
- size, data,
- buffer_usage );
-}
+ pipe->winsys->buffer_reference( pipe->winsys, &st_obj->buffer, NULL );
+ st_obj->buffer = pipe->winsys->buffer_create( pipe->winsys, 32, buffer_usage,
+ size );
-/**
- * Replace data in a subrange of buffer object. If the data range
- * specified by size + offset extends beyond the end of the buffer or
- * if data is NULL, no copy is performed.
- * Called via glBufferSubDataARB().
- */
-static void
-st_bufferobj_subdata(GLcontext *ctx,
- GLenum target,
- GLintptrARB offset,
- GLsizeiptrARB size,
- const GLvoid * data, struct gl_buffer_object *obj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
-
- pipe->winsys->buffer_subdata(pipe->winsys, st_obj->buffer, offset, size, data);
-}
-
-
-/**
- * Called via glGetBufferSubDataARB().
- */
-static void
-st_bufferobj_get_subdata(GLcontext *ctx,
- GLenum target,
- GLintptrARB offset,
- GLsizeiptrARB size,
- GLvoid * data, struct gl_buffer_object *obj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
+ st_obj->size = size;
- pipe->winsys->buffer_get_subdata(pipe->winsys, st_obj->buffer, offset, size, data);
+ if (data)
+ st_bufferobj_subdata(ctx, target, 0, size, data, obj);
}
switch (access) {
case GL_WRITE_ONLY:
- flags = PIPE_BUFFER_FLAG_WRITE;
+ flags = PIPE_BUFFER_USAGE_CPU_WRITE;
break;
case GL_READ_ONLY:
- flags = PIPE_BUFFER_FLAG_READ;
+ flags = PIPE_BUFFER_USAGE_CPU_READ;
break;
case GL_READ_WRITE:
/* fall-through */
default:
- flags = PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE;
+ flags = PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE;
break;
}
{
struct gl_buffer_object Base;
struct pipe_buffer_handle *buffer;
+ GLsizeiptrARB size;
};
struct st_fragment_program *combined_prog;
} bitmap;
- /**
- * Buffer object which stores the ctx->Current.Attrib[] values.
- * Used for vertex array drawing when we we need an attribute for
- * which there's no enabled array.
- */
- struct pipe_buffer_handle *default_attrib_buffer;
-
struct cso_cache *cache;
};
}
-/**
- * The default attribute buffer is basically a copy of the
- * ctx->Current.Attrib[] array. It's used when the vertex program
- * references an attribute for which we don't have a VBO/array.
- */
-static void
-create_default_attribs_buffer(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- /* XXX don't hardcode magic 32 here */
- st->default_attrib_buffer = pipe->winsys->buffer_create( pipe->winsys, 32, 0, 0 );
-}
-
-
-static void
-destroy_default_attribs_buffer(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- pipe->winsys->buffer_reference(pipe->winsys,
- &st->default_attrib_buffer, NULL);
-}
-
-
/**
* This function gets plugged into the VBO module and is called when
* we have something to render.
}
/* XXX create one-time */
- vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0);
- pipe->winsys->buffer_data(pipe->winsys, vbuf,
- vertex_bytes, verts,
- PIPE_BUFFER_USAGE_VERTEX);
+ vbuf = pipe->winsys->buffer_create(pipe->winsys, 32,
+ PIPE_BUFFER_USAGE_VERTEX, vertex_bytes);
+ assert(vbuf);
+
+ memcpy(pipe->winsys->buffer_map(pipe->winsys, vbuf,
+ PIPE_BUFFER_USAGE_CPU_WRITE),
+ verts, vertex_bytes);
+ pipe->winsys->buffer_unmap(pipe->winsys, vbuf);
/* tell pipe about the vertex buffer */
vbuffer.buffer = vbuf;
/* map the attrib buffer */
map = pipe->winsys->buffer_map(pipe->winsys,
vbuffer[attr].buffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_vertex_buffer(draw, attr, map);
}
map = pipe->winsys->buffer_map(pipe->winsys,
index_buffer_handle,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_element_buffer(draw, indexSize, map);
}
else {
/* map constant buffers */
mapped_constants = winsys->buffer_map(winsys,
st->state.constants[PIPE_SHADER_VERTEX].buffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_constant_buffer(st->draw, mapped_constants);
{
GLcontext *ctx = st->ctx;
- /* actually, not used here, but elsewhere */
- create_default_attribs_buffer(st);
-
vbo_set_draw_func(ctx, st_draw_vbo);
}
void st_destroy_draw( struct st_context *st )
{
- destroy_default_attribs_buffer(st);
}