2007-11-23 17:22:54 +00:00
|
|
|
/**************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
|
* All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
|
* of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \file
|
|
|
|
|
* Generic code for buffers.
|
|
|
|
|
*
|
|
|
|
|
* Behind a pipe buffle handle there can be DMA buffers, client (or user)
|
|
|
|
|
* buffers, regular malloced buffers, etc. This file provides an abstract base
|
|
|
|
|
* buffer handle that allows the driver to cope with all those kinds of buffers
|
|
|
|
|
* in a more flexible way.
|
|
|
|
|
*
|
|
|
|
|
* There is no obligation of a winsys driver to use this library. And a pipe
|
|
|
|
|
* driver should be completly agnostic about it.
|
|
|
|
|
*
|
2008-11-24 13:59:06 +09:00
|
|
|
* \author Jose Fonseca <jrfonseca@tungstengraphics.com>
|
2007-11-23 17:22:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef PB_BUFFER_H_
|
|
|
|
|
#define PB_BUFFER_H_
|
|
|
|
|
|
|
|
|
|
|
2008-01-22 00:13:50 +09:00
|
|
|
#include "pipe/p_compiler.h"
|
2008-02-06 14:37:49 +09:00
|
|
|
#include "pipe/p_debug.h"
|
2008-11-24 13:59:06 +09:00
|
|
|
#include "pipe/p_error.h"
|
2008-01-25 20:53:31 +00:00
|
|
|
#include "pipe/p_state.h"
|
2008-01-27 19:20:48 +09:00
|
|
|
#include "pipe/p_inlines.h"
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
|
2008-02-27 18:39:57 +09:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2008-01-25 20:53:31 +00:00
|
|
|
struct pb_vtbl;
|
2008-11-24 13:59:06 +09:00
|
|
|
struct pb_validate;
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
|
2008-01-17 17:06:16 +09:00
|
|
|
/**
|
|
|
|
|
* Buffer description.
|
|
|
|
|
*
|
|
|
|
|
* Used when allocating the buffer.
|
|
|
|
|
*/
|
|
|
|
|
struct pb_desc
|
|
|
|
|
{
|
|
|
|
|
unsigned alignment;
|
|
|
|
|
unsigned usage;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
/**
|
2008-01-25 20:53:31 +00:00
|
|
|
* Base class for all pb_* buffers.
|
2007-11-23 17:22:54 +00:00
|
|
|
*/
|
2008-01-25 20:53:31 +00:00
|
|
|
struct pb_buffer
|
2007-11-23 17:22:54 +00:00
|
|
|
{
|
2008-01-25 20:53:31 +00:00
|
|
|
struct pipe_buffer base;
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
/**
|
|
|
|
|
* Pointer to the virtual function table.
|
|
|
|
|
*
|
|
|
|
|
* Avoid accessing this table directly. Use the inline functions below
|
|
|
|
|
* instead to avoid mistakes.
|
|
|
|
|
*/
|
2008-01-25 20:53:31 +00:00
|
|
|
const struct pb_vtbl *vtbl;
|
2007-11-23 17:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
2008-01-27 19:20:48 +09:00
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
/**
|
|
|
|
|
* Virtual function table for the buffer storage operations.
|
|
|
|
|
*
|
|
|
|
|
* Note that creation is not done through this table.
|
|
|
|
|
*/
|
2008-01-25 20:53:31 +00:00
|
|
|
struct pb_vtbl
|
2007-11-23 17:22:54 +00:00
|
|
|
{
|
2008-01-25 20:53:31 +00:00
|
|
|
void (*destroy)( struct pb_buffer *buf );
|
2007-11-23 17:22:54 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map the entire data store of a buffer object into the client's address.
|
|
|
|
|
* flags is bitmask of PIPE_BUFFER_FLAG_READ/WRITE.
|
|
|
|
|
*/
|
2008-01-25 20:53:31 +00:00
|
|
|
void *(*map)( struct pb_buffer *buf,
|
2007-11-23 17:22:54 +00:00
|
|
|
unsigned flags );
|
|
|
|
|
|
2008-01-25 20:53:31 +00:00
|
|
|
void (*unmap)( struct pb_buffer *buf );
|
2007-11-23 17:22:54 +00:00
|
|
|
|
2008-11-24 13:59:06 +09:00
|
|
|
enum pipe_error (*validate)( struct pb_buffer *buf,
|
|
|
|
|
struct pb_validate *vl,
|
|
|
|
|
unsigned flags );
|
|
|
|
|
|
|
|
|
|
void (*fence)( struct pb_buffer *buf,
|
|
|
|
|
struct pipe_fence_handle *fence );
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
/**
|
|
|
|
|
* Get the base buffer and the offset.
|
|
|
|
|
*
|
|
|
|
|
* A buffer can be subdivided in smaller buffers. This method should return
|
|
|
|
|
* the underlaying buffer, and the relative offset.
|
|
|
|
|
*
|
|
|
|
|
* Buffers without an underlaying base buffer should return themselves, with
|
|
|
|
|
* a zero offset.
|
|
|
|
|
*
|
|
|
|
|
* Note that this will increase the reference count of the base buffer.
|
|
|
|
|
*/
|
2008-01-25 20:53:31 +00:00
|
|
|
void (*get_base_buffer)( struct pb_buffer *buf,
|
|
|
|
|
struct pb_buffer **base_buf,
|
2007-11-23 17:22:54 +00:00
|
|
|
unsigned *offset );
|
2008-11-24 13:59:06 +09:00
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-01-27 19:20:48 +09:00
|
|
|
static INLINE struct pipe_buffer *
|
|
|
|
|
pb_pipe_buffer( struct pb_buffer *pbuf )
|
|
|
|
|
{
|
|
|
|
|
assert(pbuf);
|
|
|
|
|
return &pbuf->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static INLINE struct pb_buffer *
|
|
|
|
|
pb_buffer( struct pipe_buffer *buf )
|
|
|
|
|
{
|
|
|
|
|
assert(buf);
|
|
|
|
|
/* Could add a magic cookie check on debug builds.
|
|
|
|
|
*/
|
|
|
|
|
return (struct pb_buffer *)buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-25 20:53:31 +00:00
|
|
|
/* Accessor functions for pb->vtbl:
|
|
|
|
|
*/
|
2008-01-20 19:36:23 +01:00
|
|
|
static INLINE void *
|
2008-01-25 20:53:31 +00:00
|
|
|
pb_map(struct pb_buffer *buf,
|
|
|
|
|
unsigned flags)
|
2007-11-23 17:22:54 +00:00
|
|
|
{
|
|
|
|
|
assert(buf);
|
2008-05-22 21:54:41 +09:00
|
|
|
if(!buf)
|
|
|
|
|
return NULL;
|
2009-01-28 15:53:21 +00:00
|
|
|
assert(buf->base.refcount > 0);
|
2007-11-23 17:22:54 +00:00
|
|
|
return buf->vtbl->map(buf, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-20 19:36:23 +01:00
|
|
|
static INLINE void
|
2008-01-25 20:53:31 +00:00
|
|
|
pb_unmap(struct pb_buffer *buf)
|
2007-11-23 17:22:54 +00:00
|
|
|
{
|
|
|
|
|
assert(buf);
|
2008-05-22 21:54:41 +09:00
|
|
|
if(!buf)
|
|
|
|
|
return;
|
2009-01-28 15:53:21 +00:00
|
|
|
assert(buf->base.refcount > 0);
|
2007-11-23 17:22:54 +00:00
|
|
|
buf->vtbl->unmap(buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-20 19:36:23 +01:00
|
|
|
static INLINE void
|
2008-01-25 20:53:31 +00:00
|
|
|
pb_get_base_buffer( struct pb_buffer *buf,
|
|
|
|
|
struct pb_buffer **base_buf,
|
|
|
|
|
unsigned *offset )
|
2007-11-23 17:22:54 +00:00
|
|
|
{
|
2008-05-22 21:54:41 +09:00
|
|
|
assert(buf);
|
|
|
|
|
if(!buf) {
|
|
|
|
|
base_buf = NULL;
|
|
|
|
|
offset = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-28 15:53:21 +00:00
|
|
|
assert(buf->base.refcount > 0);
|
2008-11-24 13:59:06 +09:00
|
|
|
assert(buf->vtbl->get_base_buffer);
|
2007-11-23 17:22:54 +00:00
|
|
|
buf->vtbl->get_base_buffer(buf, base_buf, offset);
|
2009-01-28 15:53:21 +00:00
|
|
|
assert(*base_buf);
|
|
|
|
|
assert(*offset < (*base_buf)->base.size);
|
2007-11-23 17:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-27 19:20:48 +09:00
|
|
|
|
2008-11-24 13:59:06 +09:00
|
|
|
static INLINE enum pipe_error
|
|
|
|
|
pb_validate(struct pb_buffer *buf, struct pb_validate *vl, unsigned flags)
|
|
|
|
|
{
|
|
|
|
|
assert(buf);
|
|
|
|
|
if(!buf)
|
|
|
|
|
return PIPE_ERROR;
|
|
|
|
|
assert(buf->vtbl->validate);
|
|
|
|
|
return buf->vtbl->validate(buf, vl, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static INLINE void
|
|
|
|
|
pb_fence(struct pb_buffer *buf, struct pipe_fence_handle *fence)
|
|
|
|
|
{
|
|
|
|
|
assert(buf);
|
|
|
|
|
if(!buf)
|
|
|
|
|
return;
|
|
|
|
|
assert(buf->vtbl->fence);
|
|
|
|
|
buf->vtbl->fence(buf, fence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-20 19:36:23 +01:00
|
|
|
static INLINE void
|
2008-01-25 20:53:31 +00:00
|
|
|
pb_destroy(struct pb_buffer *buf)
|
|
|
|
|
{
|
|
|
|
|
assert(buf);
|
2008-05-22 21:54:41 +09:00
|
|
|
if(!buf)
|
|
|
|
|
return;
|
2008-10-28 16:11:09 +09:00
|
|
|
assert(buf->base.refcount == 0);
|
2008-01-25 20:53:31 +00:00
|
|
|
buf->vtbl->destroy(buf);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
|
2008-01-27 19:20:48 +09:00
|
|
|
/* XXX: thread safety issues!
|
|
|
|
|
*/
|
|
|
|
|
static INLINE void
|
|
|
|
|
pb_reference(struct pb_buffer **dst,
|
|
|
|
|
struct pb_buffer *src)
|
|
|
|
|
{
|
2008-10-28 16:11:09 +09:00
|
|
|
if (src) {
|
|
|
|
|
assert(src->base.refcount);
|
2008-01-27 19:20:48 +09:00
|
|
|
src->base.refcount++;
|
2008-10-28 16:11:09 +09:00
|
|
|
}
|
2007-11-23 17:22:54 +00:00
|
|
|
|
2008-10-28 16:11:09 +09:00
|
|
|
if (*dst) {
|
|
|
|
|
assert((*dst)->base.refcount);
|
|
|
|
|
if(--(*dst)->base.refcount == 0)
|
|
|
|
|
pb_destroy( *dst );
|
|
|
|
|
}
|
2007-11-23 17:22:54 +00:00
|
|
|
|
2008-01-27 19:20:48 +09:00
|
|
|
*dst = src;
|
|
|
|
|
}
|
2007-11-23 17:22:54 +00:00
|
|
|
|
|
|
|
|
|
2008-04-15 15:41:08 +09:00
|
|
|
/**
|
2008-07-02 12:22:51 +09:00
|
|
|
* Utility function to check whether the provided alignment is consistent with
|
|
|
|
|
* the requested or not.
|
2008-04-15 15:41:08 +09:00
|
|
|
*/
|
2008-07-02 12:22:51 +09:00
|
|
|
static INLINE boolean
|
2008-04-15 15:41:08 +09:00
|
|
|
pb_check_alignment(size_t requested, size_t provided)
|
|
|
|
|
{
|
2009-01-30 14:06:25 +00:00
|
|
|
if(!requested)
|
|
|
|
|
return TRUE;
|
|
|
|
|
if(requested > provided)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if(provided % requested != 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
return TRUE;
|
2008-07-02 12:22:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Utility function to check whether the provided alignment is consistent with
|
|
|
|
|
* the requested or not.
|
|
|
|
|
*/
|
|
|
|
|
static INLINE boolean
|
|
|
|
|
pb_check_usage(unsigned requested, unsigned provided)
|
|
|
|
|
{
|
2008-07-09 11:46:16 -06:00
|
|
|
return (requested & provided) == requested ? TRUE : FALSE;
|
2008-04-15 15:41:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
/**
|
|
|
|
|
* Malloc-based buffer to store data that can't be used by the graphics
|
|
|
|
|
* hardware.
|
|
|
|
|
*/
|
2008-01-25 20:53:31 +00:00
|
|
|
struct pb_buffer *
|
2008-01-17 17:06:16 +09:00
|
|
|
pb_malloc_buffer_create(size_t size,
|
|
|
|
|
const struct pb_desc *desc);
|
2008-01-25 20:53:31 +00:00
|
|
|
|
|
|
|
|
|
2008-02-27 18:39:57 +09:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-11-23 17:22:54 +00:00
|
|
|
#endif /*PB_BUFFER_H_*/
|