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
;
31 /* Main-memory copy of the batch-buffer, built up incrementally &
32 * then copied as one to the true buffer.
34 * XXX: is this still necessary?
35 * XXX: if so, can this be hidden inside the GEM-specific winsys code?
37 boolean use_malloc_buffer
;
38 uint8_t *malloc_buffer
;
41 * Values exported to speed up the writing the batchbuffer,
42 * instead of having to go trough a accesor function for
59 struct brw_batchbuffer
*brw_batchbuffer_alloc( struct brw_winsys_screen
*sws
,
60 struct brw_chipset chipset
);
62 void brw_batchbuffer_free(struct brw_batchbuffer
*batch
);
64 void _brw_batchbuffer_flush(struct brw_batchbuffer
*batch
,
65 const char *file
, int line
);
69 brw_batchbuffer_reset(struct brw_batchbuffer
*batch
);
72 /* Unlike bmBufferData, this currently requires the buffer be mapped.
73 * Consider it a convenience function wrapping multple
74 * intel_buffer_dword() calls.
76 int brw_batchbuffer_data(struct brw_batchbuffer
*batch
,
77 const void *data
, GLuint bytes
,
78 enum cliprect_mode cliprect_mode
);
81 int brw_batchbuffer_emit_reloc(struct brw_batchbuffer
*batch
,
82 struct brw_winsys_buffer
*buffer
,
83 enum brw_buffer_usage usage
,
86 /* Inline functions - might actually be better off with these
87 * non-inlined. Certainly better off switching all command packets to
88 * be passed as structs rather than dwords, but that's a little bit of
92 brw_batchbuffer_space(struct brw_batchbuffer
*batch
)
94 return (batch
->size
- BATCH_RESERVED
) - (batch
->ptr
- batch
->map
);
99 brw_batchbuffer_emit_dword(struct brw_batchbuffer
*batch
, GLuint dword
)
102 assert(brw_batchbuffer_space(batch
) >= 4);
103 *(GLuint
*) (batch
->ptr
) = dword
;
107 static INLINE
enum pipe_error
108 brw_batchbuffer_require_space(struct brw_batchbuffer
*batch
,
111 assert(sz
< batch
->size
- 8);
112 if (brw_batchbuffer_space(batch
) < sz
) {
114 return PIPE_ERROR_OUT_OF_MEMORY
;
117 batch
->emit
.end_ptr
= batch
->ptr
+ sz
;
122 /* Here are the crusty old macros, to be removed:
124 #define BEGIN_BATCH(n, cliprect_mode) do { \
125 brw_batchbuffer_require_space(brw->batch, (n)*4); \
128 #define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d)
130 #define OUT_RELOC(buf, usage, delta) do { \
131 assert((unsigned) (delta) < buf->size); \
132 brw_batchbuffer_emit_reloc(brw->batch, buf, \
137 #define ADVANCE_BATCH() do { \
138 unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \
140 debug_printf("%s: %d too many bytes emitted to batch\n", \
144 brw->batch->emit.end_ptr = NULL; \
147 #define ADVANCE_BATCH()
151 brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer
*batch
)
153 brw_batchbuffer_require_space(batch
, 4);
154 brw_batchbuffer_emit_dword(batch
, MI_FLUSH
);