i965g: more work on compiling
[mesa.git] / src / gallium / drivers / i965 / brw_batchbuffer.h
1 #ifndef BRW_BATCHBUFFER_H
2 #define BRW_BATCHBUFFER_H
3
4 #include "brw_types.h"
5 #include "brw_winsys.h"
6 #include "brw_reg.h"
7 #include "util/u_debug.h"
8
9 #define BATCH_SZ 16384
10 #define BATCH_RESERVED 16
11
12 /* All ignored:
13 */
14 enum cliprect_mode {
15 IGNORE_CLIPRECTS,
16 LOOP_CLIPRECTS,
17 NO_LOOP_CLIPRECTS,
18 REFERENCES_CLIPRECTS
19 };
20
21 void brw_batchbuffer_free(struct brw_batchbuffer *batch);
22
23 void _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
24 const char *file, int line);
25
26 #define brw_batchbuffer_flush(batch) \
27 _brw_batchbuffer_flush(batch, __FILE__, __LINE__)
28
29 void brw_batchbuffer_reset(struct brw_batchbuffer *batch);
30
31
32 /* Unlike bmBufferData, this currently requires the buffer be mapped.
33 * Consider it a convenience function wrapping multple
34 * intel_buffer_dword() calls.
35 */
36 void brw_batchbuffer_data(struct brw_batchbuffer *batch,
37 const void *data, GLuint bytes,
38 enum cliprect_mode cliprect_mode);
39
40 void brw_batchbuffer_release_space(struct brw_batchbuffer *batch,
41 GLuint bytes);
42
43 GLboolean brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch,
44 struct brw_winsys_buffer *buffer,
45 uint32_t read_domains,
46 uint32_t write_domain,
47 uint32_t offset);
48
49 /* Inline functions - might actually be better off with these
50 * non-inlined. Certainly better off switching all command packets to
51 * be passed as structs rather than dwords, but that's a little bit of
52 * work...
53 */
54 static INLINE GLint
55 brw_batchbuffer_space(struct brw_batchbuffer *batch)
56 {
57 return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
58 }
59
60
61 static INLINE void
62 brw_batchbuffer_emit_dword(struct brw_batchbuffer *batch, GLuint dword)
63 {
64 assert(batch->map);
65 assert(brw_batchbuffer_space(batch) >= 4);
66 *(GLuint *) (batch->ptr) = dword;
67 batch->ptr += 4;
68 }
69
70 static INLINE boolean
71 brw_batchbuffer_require_space(struct brw_batchbuffer *batch,
72 GLuint sz)
73 {
74 assert(sz < batch->size - 8);
75 if (brw_batchbuffer_space(batch) < sz) {
76 assert(0);
77 return FALSE;
78 }
79 #ifdef DEBUG
80 batch->emit.end_ptr = batch->ptr + sz;
81 #endif
82 return TRUE;
83 }
84
85 /* Here are the crusty old macros, to be removed:
86 */
87 #define BEGIN_BATCH(n, cliprect_mode) do { \
88 brw_batchbuffer_require_space(brw->batch, (n)*4); \
89 } while (0)
90
91 #define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d)
92
93 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
94 assert((unsigned) (delta) < buf->size); \
95 brw_batchbuffer_emit_reloc(brw->batch, buf, \
96 read_domains, write_domain, delta); \
97 } while (0)
98
99 #ifdef DEBUG
100 #define ADVANCE_BATCH() do { \
101 unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \
102 if (_n != 0) { \
103 debug_printf("%s: %d too many bytes emitted to batch\n", __FUNCTION__, _n); \
104 abort(); \
105 } \
106 brw->batch->emit.end_ptr = NULL; \
107 } while(0)
108 #else
109 #define ADVANCE_BATCH()
110 #endif
111
112 static INLINE void
113 brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer *batch)
114 {
115 brw_batchbuffer_require_space(batch, 4);
116 brw_batchbuffer_emit_dword(batch, MI_FLUSH);
117 }
118
119 #endif