pb_bufmgr.h revision 92fcbf6e7bc622dcace226bb70ff6d5cdbdbaecb
14499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino/**************************************************************************
24499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
34499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
44499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * All Rights Reserved.
54499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
64499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Permission is hereby granted, free of charge, to any person obtaining a
74499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * copy of this software and associated documentation files (the
84499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * "Software"), to deal in the Software without restriction, including
94499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * without limitation the rights to use, copy, modify, merge, publish,
104499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * distribute, sub license, and/or sell copies of the Software, and to
114499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * permit persons to whom the Software is furnished to do so, subject to
124499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * the following conditions:
134499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
144499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * The above copyright notice and this permission notice (including the
154499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * next paragraph) shall be included in all copies or substantial portions
164499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * of the Software.
174499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
184499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
214499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
224499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
264499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino **************************************************************************/
274499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
284499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino/**
294499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * \file
304499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Buffer management.
314499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
324499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * A buffer manager does only one basic thing: it creates buffers. Actually,
334499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * "buffer factory" would probably a more accurate description.
344499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
354499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * You can chain buffer managers so that you can have a finer grained memory
364499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * management and pooling.
374499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
384499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * For example, for a simple batch buffer manager you would chain:
394499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * - the native buffer manager, which provides DMA memory from the graphics
404499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * memory space;
414499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * - the pool buffer manager, which keep around a pool of equally sized buffers
424499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * to avoid latency associated with the native buffer manager;
434499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * - the fenced buffer manager, which will delay buffer destruction until the
444499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * the moment the card finishing processing it.
454499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
464499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * \author Jos� Fonseca <jrfonseca@tungstengraphics.com>
474499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino */
484499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
494499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino#ifndef PB_BUFMGR_H_
504499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino#define PB_BUFMGR_H_
514499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
524499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
534499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino#include <stddef.h>
544499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
554499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
564499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinostruct pb_desc;
574499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinostruct pipe_buffer;
584499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinostruct pipe_winsys;
594499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
604499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
614499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino/**
624499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Abstract base class for all buffer managers.
634499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino */
644499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinostruct pb_manager
65becfc2312367ee47993495745ec96d7be1a3b3baDave Lerner{
664499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino   /* XXX: we will likely need more allocation flags */
674499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino   struct pb_buffer *
684499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino   (*create_buffer)( struct pb_manager *mgr,
694499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino	             size_t size,
704499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino	             const struct pb_desc *desc);
714499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
724499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino   void
734499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino   (*destroy)( struct pb_manager *mgr );
744499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino};
754499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
764499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
774499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino/**
784499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Static buffer pool manager.
794499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
804499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Manages the allocation of equally sized buffers. It does so by allocating
814499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * a single big buffer and divide it equally sized buffers.
824499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
834499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * It is meant to manage the allocation of batch buffer pools.
844499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino */
854499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinostruct pb_manager *
864499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinopool_bufmgr_create(struct pb_manager *provider,
874499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino                   size_t n, size_t size,
884499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino                   const struct pb_desc *desc);
894499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
904499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
914499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino/**
924499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Wraper around the old memory manager.
934499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
944499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * It managers buffers of different sizes. It does so by allocating a buffer
954499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * with the size of the heap, and then using the old mm memory manager to manage
964499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * that heap.
974499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino */
984499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinostruct pb_manager *
994499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinomm_bufmgr_create(struct pb_manager *provider,
1004499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino                 size_t size, size_t align2);
1014499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
1024499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino/**
1034499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Same as mm_bufmgr_create.
1044499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino *
1054499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino * Buffer will be release when the manager is destroyed.
1064499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino */
1074499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinostruct pb_manager *
1084499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulinomm_bufmgr_create_from_buffer(struct pb_buffer *buffer,
1094499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino                             size_t size, size_t align2);
1104499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
1114499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino
1129ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino/**
1139ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino * Fenced buffer manager.
1149ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino *
1159ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino * This manager is just meant for convenience. It wraps the buffers returned
1169ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino * by another manager in fenced buffers, so that
1179ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino *
1189ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino * NOTE: the buffer manager that provides the buffers will be destroyed
1199ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino * at the same time.
1209ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino */
1219ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulinostruct pb_manager *
1229ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulinofenced_bufmgr_create(struct pb_manager *provider,
1239ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino                     struct pipe_winsys *winsys);
1249ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino
1259ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino
1269ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino#endif /*PB_BUFMGR_H_*/
1279ea6af8ed5ee7b07f8de6d774bc6df2b7320f0e8Jose Flavio Aguilar Paulino