1 #ifndef BRW_BATCHBUFFER_H
2 #define BRW_BATCHBUFFER_H
4 #include "util/u_debug.h"
7 #include "brw_winsys.h"
10 #define BATCH_SZ 16384
11 #define BATCH_RESERVED 16
25 struct brw_batchbuffer {
27 struct brw_winsys_screen *sws;
28 struct brw_winsys_buffer *buf;
31 * Values exported to speed up the writing the batchbuffer,
32 * instead of having to go trough a accesor function for
49 struct brw_batchbuffer *brw_batchbuffer_alloc( struct brw_winsys_screen *sws );
52 void brw_batchbuffer_free(struct brw_batchbuffer *batch);
54 void _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
55 const char *file, int line);
59 brw_batchbuffer_reset(struct brw_batchbuffer *batch);
62 /* Unlike bmBufferData, this currently requires the buffer be mapped.
63 * Consider it a convenience function wrapping multple
64 * intel_buffer_dword() calls.
66 enum pipe_error brw_batchbuffer_data(struct brw_batchbuffer *batch,
67 const void *data, GLuint bytes,
68 enum cliprect_mode cliprect_mode);
71 enum pipe_error brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch,
72 struct brw_winsys_buffer *buffer,
73 enum brw_buffer_usage usage,
76 /* Inline functions - might actually be better off with these
77 * non-inlined. Certainly better off switching all command packets to
78 * be passed as structs rather than dwords, but that's a little bit of
82 brw_batchbuffer_space(struct brw_batchbuffer *batch)
84 return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
89 brw_batchbuffer_emit_dword(struct brw_batchbuffer *batch, GLuint dword)
92 assert(brw_batchbuffer_space(batch) >= 4);
93 *(GLuint *) (batch->ptr) = dword;
97 static INLINE enum pipe_error
98 brw_batchbuffer_require_space(struct brw_batchbuffer *batch,
101 assert(sz < batch->size - 8);
102 if (brw_batchbuffer_space(batch) < sz) {
104 return PIPE_ERROR_OUT_OF_MEMORY;
107 batch->emit.end_ptr = batch->ptr + sz;
112 /* Here are the crusty old macros, to be removed:
114 #define BEGIN_BATCH(n, cliprect_mode) do { \
115 brw_batchbuffer_require_space(brw->batch, (n)*4); \
118 #define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d)
120 #define OUT_RELOC(buf, usage, delta) do { \
121 assert((unsigned) (delta) < buf->size); \
122 brw_batchbuffer_emit_reloc(brw->batch, buf, \
127 #define ADVANCE_BATCH() do { \
128 unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \
130 debug_printf("%s: %d too many bytes emitted to batch\n", \
134 brw->batch->emit.end_ptr = NULL; \
137 #define ADVANCE_BATCH()
141 brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer *batch)
143 brw_batchbuffer_require_space(batch, 4);
144 brw_batchbuffer_emit_dword(batch, MI_FLUSH);