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"
11 * Number of bytes to reserve for commands necessary to complete a batch.
14 * - MI_BATCHBUFFER_END (4 bytes)
15 * - Optional MI_NOOP for ensuring the batch length is qword aligned (4 bytes)
16 * - Any state emitted by vtbl->finish_batch():
17 * - Gen4-5 record ending occlusion query values (4 * 4 = 16 bytes)
19 #define BATCH_RESERVED 24
21 struct intel_batchbuffer
;
23 void intel_batchbuffer_init(struct intel_context
*intel
);
24 void intel_batchbuffer_free(struct intel_context
*intel
);
26 int _intel_batchbuffer_flush(struct intel_context
*intel
,
27 const char *file
, int line
);
29 #define intel_batchbuffer_flush(intel) \
30 _intel_batchbuffer_flush(intel, __FILE__, __LINE__)
34 /* Unlike bmBufferData, this currently requires the buffer be mapped.
35 * Consider it a convenience function wrapping multple
36 * intel_buffer_dword() calls.
38 void intel_batchbuffer_data(struct intel_context
*intel
,
39 const void *data
, GLuint bytes
);
41 bool intel_batchbuffer_emit_reloc(struct intel_context
*intel
,
43 uint32_t read_domains
,
44 uint32_t write_domain
,
46 bool intel_batchbuffer_emit_reloc_fenced(struct intel_context
*intel
,
48 uint32_t read_domains
,
49 uint32_t write_domain
,
51 void intel_batchbuffer_emit_mi_flush(struct intel_context
*intel
);
53 static inline uint32_t float_as_int(float f
)
64 /* Inline functions - might actually be better off with these
65 * non-inlined. Certainly better off switching all command packets to
66 * be passed as structs rather than dwords, but that's a little bit of
69 static inline unsigned
70 intel_batchbuffer_space(struct intel_context
*intel
)
72 return (intel
->batch
.bo
->size
- intel
->batch
.reserved_space
)
73 - intel
->batch
.used
*4;
78 intel_batchbuffer_emit_dword(struct intel_context
*intel
, GLuint dword
)
81 assert(intel_batchbuffer_space(intel
) >= 4);
83 intel
->batch
.map
[intel
->batch
.used
++] = dword
;
87 intel_batchbuffer_emit_float(struct intel_context
*intel
, float f
)
89 intel_batchbuffer_emit_dword(intel
, float_as_int(f
));
93 intel_batchbuffer_require_space(struct intel_context
*intel
,
97 assert(sz
< intel
->maxBatchSize
- BATCH_RESERVED
);
99 if (intel_batchbuffer_space(intel
) < sz
)
100 intel_batchbuffer_flush(intel
);
104 intel_batchbuffer_begin(struct intel_context
*intel
, int n
)
106 intel_batchbuffer_require_space(intel
, n
* 4);
108 intel
->batch
.emit
= intel
->batch
.used
;
110 intel
->batch
.total
= n
;
115 intel_batchbuffer_advance(struct intel_context
*intel
)
118 struct intel_batchbuffer
*batch
= &intel
->batch
;
119 unsigned int _n
= batch
->used
- batch
->emit
;
120 assert(batch
->total
!= 0);
121 if (_n
!= batch
->total
) {
122 fprintf(stderr
, "ADVANCE_BATCH: %d of %d dwords emitted\n",
132 /* Here are the crusty old macros, to be removed:
136 #define BEGIN_BATCH(n) intel_batchbuffer_begin(intel, n)
137 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel, d)
138 #define OUT_BATCH_F(f) intel_batchbuffer_emit_float(intel,f)
139 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
140 intel_batchbuffer_emit_reloc(intel, buf, \
141 read_domains, write_domain, delta); \
143 #define OUT_RELOC_FENCED(buf, read_domains, write_domain, delta) do { \
144 intel_batchbuffer_emit_reloc_fenced(intel, buf, \
145 read_domains, write_domain, delta); \
148 #define ADVANCE_BATCH() intel_batchbuffer_advance(intel);
149 #define CACHED_BATCH() intel_batchbuffer_cached_advance(intel);