00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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