1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
4 #include "main/mtypes.h"
6 #include "intel_context.h"
7 #include "intel_bufmgr.h"
10 #define BATCH_SZ 16384
11 #define BATCH_RESERVED 16
14 struct intel_batchbuffer
16 struct intel_context
*intel
;
27 /** Tracking of BEGIN_BATCH()/OUT_BATCH()/ADVANCE_BATCH() debugging */
34 GLuint reserved_space
;
37 struct intel_batchbuffer
*intel_batchbuffer_alloc(struct intel_context
40 void intel_batchbuffer_free(struct intel_batchbuffer
*batch
);
43 void _intel_batchbuffer_flush(struct intel_batchbuffer
*batch
,
44 const char *file
, int line
);
46 #define intel_batchbuffer_flush(batch) \
47 _intel_batchbuffer_flush(batch, __FILE__, __LINE__)
49 void intel_batchbuffer_reset(struct intel_batchbuffer
*batch
);
52 /* Unlike bmBufferData, this currently requires the buffer be mapped.
53 * Consider it a convenience function wrapping multple
54 * intel_buffer_dword() calls.
56 void intel_batchbuffer_data(struct intel_batchbuffer
*batch
,
57 const void *data
, GLuint bytes
);
59 void intel_batchbuffer_release_space(struct intel_batchbuffer
*batch
,
62 GLboolean
intel_batchbuffer_emit_reloc(struct intel_batchbuffer
*batch
,
64 uint32_t read_domains
,
65 uint32_t write_domain
,
67 void intel_batchbuffer_emit_mi_flush(struct intel_batchbuffer
*batch
);
69 /* Inline functions - might actually be better off with these
70 * non-inlined. Certainly better off switching all command packets to
71 * be passed as structs rather than dwords, but that's a little bit of
75 intel_batchbuffer_space(struct intel_batchbuffer
*batch
)
77 return (batch
->size
- batch
->reserved_space
) - (batch
->ptr
- batch
->map
);
82 intel_batchbuffer_emit_dword(struct intel_batchbuffer
*batch
, GLuint dword
)
85 assert(intel_batchbuffer_space(batch
) >= 4);
86 *(GLuint
*) (batch
->ptr
) = dword
;
91 intel_batchbuffer_require_space(struct intel_batchbuffer
*batch
,
94 assert(sz
< batch
->size
- 8);
95 if (intel_batchbuffer_space(batch
) < sz
)
96 intel_batchbuffer_flush(batch
);
99 /* Here are the crusty old macros, to be removed:
103 #define BEGIN_BATCH(n) do { \
104 intel_batchbuffer_require_space(intel->batch, (n)*4); \
105 assert(intel->batch->emit.start_ptr == NULL); \
106 intel->batch->emit.total = (n) * 4; \
107 intel->batch->emit.start_ptr = intel->batch->ptr; \
110 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel->batch, d)
112 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
113 assert((unsigned) (delta) < buf->size); \
114 intel_batchbuffer_emit_reloc(intel->batch, buf, \
115 read_domains, write_domain, delta); \
118 #define ADVANCE_BATCH() do { \
119 unsigned int _n = intel->batch->ptr - intel->batch->emit.start_ptr; \
120 assert(intel->batch->emit.start_ptr != NULL); \
121 if (_n != intel->batch->emit.total) { \
122 fprintf(stderr, "ADVANCE_BATCH: %d of %d dwords emitted\n", \
123 _n, intel->batch->emit.total); \
126 intel->batch->emit.start_ptr = NULL; \