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_RESERVED 16
12 void intel_batchbuffer_init(struct intel_context
*intel
);
13 void intel_batchbuffer_reset(struct intel_context
*intel
);
14 void intel_batchbuffer_free(struct intel_context
*intel
);
16 void _intel_batchbuffer_flush(struct intel_context
*intel
,
17 const char *file
, int line
);
19 #define intel_batchbuffer_flush(intel) \
20 _intel_batchbuffer_flush(intel, __FILE__, __LINE__)
24 /* Unlike bmBufferData, this currently requires the buffer be mapped.
25 * Consider it a convenience function wrapping multple
26 * intel_buffer_dword() calls.
28 void intel_batchbuffer_data(struct intel_context
*intel
,
29 const void *data
, GLuint bytes
, bool is_blit
);
31 GLboolean
intel_batchbuffer_emit_reloc(struct intel_context
*intel
,
33 uint32_t read_domains
,
34 uint32_t write_domain
,
36 GLboolean
intel_batchbuffer_emit_reloc_fenced(struct intel_context
*intel
,
38 uint32_t read_domains
,
39 uint32_t write_domain
,
41 void intel_batchbuffer_emit_mi_flush(struct intel_context
*intel
);
42 void intel_emit_post_sync_nonzero_flush(struct intel_context
*intel
);
44 static INLINE
uint32_t float_as_int(float f
)
55 /* Inline functions - might actually be better off with these
56 * non-inlined. Certainly better off switching all command packets to
57 * be passed as structs rather than dwords, but that's a little bit of
60 static INLINE
unsigned
61 intel_batchbuffer_space(struct intel_context
*intel
)
63 return (intel
->batch
.state_batch_offset
- intel
->batch
.reserved_space
)
64 - intel
->batch
.used
*4;
69 intel_batchbuffer_emit_dword(struct intel_context
*intel
, GLuint dword
)
72 assert(intel_batchbuffer_space(intel
) >= 4);
74 intel
->batch
.map
[intel
->batch
.used
++] = dword
;
78 intel_batchbuffer_emit_float(struct intel_context
*intel
, float f
)
80 intel_batchbuffer_emit_dword(intel
, float_as_int(f
));
84 intel_batchbuffer_require_space(struct intel_context
*intel
,
85 GLuint sz
, int is_blit
)
88 if (intel
->gen
>= 6 &&
89 intel
->batch
.is_blit
!= is_blit
&& intel
->batch
.used
) {
90 intel_batchbuffer_flush(intel
);
93 intel
->batch
.is_blit
= is_blit
;
96 assert(sz
< sizeof(intel
->batch
.map
) - BATCH_RESERVED
);
98 if (intel_batchbuffer_space(intel
) < sz
)
99 intel_batchbuffer_flush(intel
);
103 intel_batchbuffer_begin(struct intel_context
*intel
, int n
, bool is_blit
)
105 intel_batchbuffer_require_space(intel
, n
* 4, is_blit
);
107 intel
->batch
.emit
= intel
->batch
.used
;
109 intel
->batch
.total
= n
;
114 intel_batchbuffer_advance(struct intel_context
*intel
)
117 struct intel_batchbuffer
*batch
= &intel
->batch
;
118 unsigned int _n
= batch
->used
- batch
->emit
;
119 assert(batch
->total
!= 0);
120 if (_n
!= batch
->total
) {
121 fprintf(stderr
, "ADVANCE_BATCH: %d of %d dwords emitted\n",
129 void intel_batchbuffer_cached_advance(struct intel_context
*intel
);
131 /* Here are the crusty old macros, to be removed:
135 #define BEGIN_BATCH(n) intel_batchbuffer_begin(intel, n, false)
136 #define BEGIN_BATCH_BLT(n) intel_batchbuffer_begin(intel, n, true)
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);