1 #ifndef BRW_BATCHBUFFER_H
2 #define BRW_BATCHBUFFER_H
5 #include "brw_winsys.h"
7 #include "util/u_debug.h"
10 #define BATCH_RESERVED 16
24 struct brw_batchbuffer
{
26 struct brw_winsys_screen
*sws
;
27 struct brw_winsys_buffer
*buf
;
29 /* Main-memory copy of the batch-buffer, built up incrementally &
30 * then copied as one to the true buffer.
32 * XXX: is this still necessary?
33 * XXX: if so, can this be hidden inside the GEM-specific winsys code?
38 * Values exported to speed up the writing the batchbuffer,
39 * instead of having to go trough a accesor function for
56 struct brw_batchbuffer
*brw_batchbuffer_alloc( struct brw_winsys_screen
*sws
);
58 void brw_batchbuffer_free(struct brw_batchbuffer
*batch
);
60 void _brw_batchbuffer_flush(struct brw_batchbuffer
*batch
,
61 const char *file
, int line
);
64 void brw_batchbuffer_reset(struct brw_batchbuffer
*batch
);
67 /* Unlike bmBufferData, this currently requires the buffer be mapped.
68 * Consider it a convenience function wrapping multple
69 * intel_buffer_dword() calls.
71 int brw_batchbuffer_data(struct brw_batchbuffer
*batch
,
72 const void *data
, GLuint bytes
,
73 enum cliprect_mode cliprect_mode
);
76 int brw_batchbuffer_emit_reloc(struct brw_batchbuffer
*batch
,
77 struct brw_winsys_buffer
*buffer
,
78 enum brw_buffer_usage usage
,
81 /* Inline functions - might actually be better off with these
82 * non-inlined. Certainly better off switching all command packets to
83 * be passed as structs rather than dwords, but that's a little bit of
87 brw_batchbuffer_space(struct brw_batchbuffer
*batch
)
89 return (batch
->size
- BATCH_RESERVED
) - (batch
->ptr
- batch
->map
);
94 brw_batchbuffer_emit_dword(struct brw_batchbuffer
*batch
, GLuint dword
)
97 assert(brw_batchbuffer_space(batch
) >= 4);
98 *(GLuint
*) (batch
->ptr
) = dword
;
102 static INLINE boolean
103 brw_batchbuffer_require_space(struct brw_batchbuffer
*batch
,
106 assert(sz
< batch
->size
- 8);
107 if (brw_batchbuffer_space(batch
) < sz
) {
112 batch
->emit
.end_ptr
= batch
->ptr
+ sz
;
117 /* Here are the crusty old macros, to be removed:
119 #define BEGIN_BATCH(n, cliprect_mode) do { \
120 brw_batchbuffer_require_space(brw->batch, (n)*4); \
123 #define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d)
125 #define OUT_RELOC(buf, usage, delta) do { \
126 assert((unsigned) (delta) < buf->size); \
127 brw_batchbuffer_emit_reloc(brw->batch, buf, \
132 #define ADVANCE_BATCH() do { \
133 unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \
135 debug_printf("%s: %d too many bytes emitted to batch\n", \
139 brw->batch->emit.end_ptr = NULL; \
142 #define ADVANCE_BATCH()
146 brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer
*batch
)
148 brw_batchbuffer_require_space(batch
, 4);
149 brw_batchbuffer_emit_dword(batch
, MI_FLUSH
);