i915_batch.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 #ifndef I915_BATCH_H
00029 #define I915_BATCH_H
00030 
00031 #include "i915_winsys.h"
00032 
00033 struct i915_batchbuffer
00034 {
00035    struct pipe_buffer *buffer;
00036    struct i915_winsys *winsys;
00037 
00038    unsigned char *map;
00039    unsigned char *ptr;
00040 
00041    size_t size;
00042    size_t actual_size;
00043 
00044    size_t relocs;
00045    size_t max_relocs;
00046 };
00047 
00048 static INLINE boolean
00049 i915_batchbuffer_check( struct i915_batchbuffer *batch,
00050                         size_t dwords,
00051                         size_t relocs )
00052 {
00054    return dwords * 4 <= batch->size - (batch->ptr - batch->map);
00055 }
00056 
00057 static INLINE size_t
00058 i915_batchbuffer_space( struct i915_batchbuffer *batch )
00059 {
00060    return batch->size - (batch->ptr - batch->map);
00061 }
00062 
00063 static INLINE void
00064 i915_batchbuffer_dword( struct i915_batchbuffer *batch,
00065                         unsigned dword )
00066 {
00067    if (i915_batchbuffer_space(batch) < 4)
00068       return;
00069 
00070    *(unsigned *)batch->ptr = dword;
00071    batch->ptr += 4;
00072 }
00073 
00074 static INLINE void
00075 i915_batchbuffer_write( struct i915_batchbuffer *batch,
00076                         void *data,
00077                         size_t size )
00078 {
00079    if (i915_batchbuffer_space(batch) < size)
00080       return;
00081 
00082    memcpy(data, batch->ptr, size);
00083    batch->ptr += size;
00084 }
00085 
00086 static INLINE void
00087 i915_batchbuffer_reloc( struct i915_batchbuffer *batch,
00088                         struct pipe_buffer *buffer,
00089                         size_t flags,
00090                         size_t offset )
00091 {
00092    batch->winsys->batch_reloc( batch->winsys, buffer, flags, offset );
00093 }
00094 
00095 static INLINE void
00096 i915_batchbuffer_flush( struct i915_batchbuffer *batch,
00097                         struct pipe_fence_handle **fence )
00098 {
00099    batch->winsys->batch_flush( batch->winsys, fence );
00100 }
00101 
00102 #define BEGIN_BATCH( dwords, relocs ) \
00103    (i915_batchbuffer_check( i915->batch, dwords, relocs ))
00104 
00105 #define OUT_BATCH( dword ) \
00106    i915_batchbuffer_dword( i915->batch, dword )
00107 
00108 #define OUT_RELOC( buf, flags, delta ) \
00109    i915_batchbuffer_reloc( i915->batch, buf, flags, delta )
00110 
00111 #define FLUSH_BATCH(fence) do {                         \
00112    i915->winsys->batch_flush( i915->winsys, fence );    \
00113    i915->hardware_dirty = ~0;                           \
00114 } while (0)
00115 
00116 #endif

Generated on Tue Sep 29 06:25:16 2009 for Gallium3D by  doxygen 1.5.4