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
;
29 struct brw_chipset chipset
;
32 * Values exported to speed up the writing the batchbuffer,
33 * instead of having to go trough a accesor function for
50 struct brw_batchbuffer
*brw_batchbuffer_alloc( struct brw_winsys_screen
*sws
,
51 struct brw_chipset chipset
);
53 void brw_batchbuffer_free(struct brw_batchbuffer
*batch
);
55 void _brw_batchbuffer_flush(struct brw_batchbuffer
*batch
,
56 const char *file
, int line
);
60 brw_batchbuffer_reset(struct brw_batchbuffer
*batch
);
63 /* Unlike bmBufferData, this currently requires the buffer be mapped.
64 * Consider it a convenience function wrapping multple
65 * intel_buffer_dword() calls.
67 enum pipe_error
brw_batchbuffer_data(struct brw_batchbuffer
*batch
,
68 const void *data
, GLuint bytes
,
69 enum cliprect_mode cliprect_mode
);
72 enum pipe_error
brw_batchbuffer_emit_reloc(struct brw_batchbuffer
*batch
,
73 struct brw_winsys_buffer
*buffer
,
74 enum brw_buffer_usage usage
,
77 /* Inline functions - might actually be better off with these
78 * non-inlined. Certainly better off switching all command packets to
79 * be passed as structs rather than dwords, but that's a little bit of
83 brw_batchbuffer_space(struct brw_batchbuffer
*batch
)
85 return (batch
->size
- BATCH_RESERVED
) - (batch
->ptr
- batch
->map
);
90 brw_batchbuffer_emit_dword(struct brw_batchbuffer
*batch
, GLuint dword
)
93 assert(brw_batchbuffer_space(batch
) >= 4);
94 *(GLuint
*) (batch
->ptr
) = dword
;
98 static INLINE
enum pipe_error
99 brw_batchbuffer_require_space(struct brw_batchbuffer
*batch
,
102 assert(sz
< batch
->size
- 8);
103 if (brw_batchbuffer_space(batch
) < sz
) {
105 return PIPE_ERROR_OUT_OF_MEMORY
;
108 batch
->emit
.end_ptr
= batch
->ptr
+ sz
;
113 /* Here are the crusty old macros, to be removed:
115 #define BEGIN_BATCH(n, cliprect_mode) do { \
116 brw_batchbuffer_require_space(brw->batch, (n)*4); \
119 #define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d)
121 #define OUT_RELOC(buf, usage, delta) do { \
122 assert((unsigned) (delta) < buf->size); \
123 brw_batchbuffer_emit_reloc(brw->batch, buf, \
128 #define ADVANCE_BATCH() do { \
129 unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \
131 debug_printf("%s: %d too many bytes emitted to batch\n", \
135 brw->batch->emit.end_ptr = NULL; \
138 #define ADVANCE_BATCH()
142 brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer
*batch
)
144 brw_batchbuffer_require_space(batch
, 4);
145 brw_batchbuffer_emit_dword(batch
, MI_FLUSH
);