i965g: hook up more pipe_context functions
[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
22
23
24 struct brw_batchbuffer {
25
26 struct brw_winsys_screen *sws;
27 struct brw_winsys_buffer *buf;
28
29 /* Main-memory copy of the batch-buffer, built up incrementally &
30 * then copied as one to the true buffer.
31 *
32 * XXX: is this still necessary?
33 * XXX: if so, can this be hidden inside the GEM-specific winsys code?
34 */
35 uint8_t *buffer;
36
37 /**
38 * Values exported to speed up the writing the batchbuffer,
39 * instead of having to go trough a accesor function for
40 * each dword written.
41 */
42 /*{@*/
43 uint8_t *map;
44 uint8_t *ptr;
45 size_t size;
46 struct {
47 uint8_t *end_ptr;
48 } emit;
49
50
51 size_t relocs;
52 size_t max_relocs;
53 /*@}*/
54 };
55
56 struct brw_batchbuffer *brw_batchbuffer_alloc( struct brw_winsys_screen *sws );
57
58 void brw_batchbuffer_free(struct brw_batchbuffer *batch);
59
60 void _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
61 const char *file, int line);
62
63
64 void brw_batchbuffer_reset(struct brw_batchbuffer *batch);
65
66
67 /* Unlike bmBufferData, this currently requires the buffer be mapped.
68 * Consider it a convenience function wrapping multple
69 * intel_buffer_dword() calls.
70 */
71 int brw_batchbuffer_data(struct brw_batchbuffer *batch,
72 const void *data, GLuint bytes,
73 enum cliprect_mode cliprect_mode);
74
75
76 int brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch,
77 struct brw_winsys_buffer *buffer,
78 enum brw_buffer_usage usage,
79 uint32_t offset);
80
81 /* Inline functions - might actually be better off with these
82 * non-inlined. Certainly better off switching all command packets to
83 * be passed as structs rather than dwords, but that's a little bit of
84 * work...
85 */
86 static INLINE GLint
87 brw_batchbuffer_space(struct brw_batchbuffer *batch)
88 {
89 return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
90 }
91
92
93 static INLINE void
94 brw_batchbuffer_emit_dword(struct brw_batchbuffer *batch, GLuint dword)
95 {
96 assert(batch->map);
97 assert(brw_batchbuffer_space(batch) >= 4);
98 *(GLuint *) (batch->ptr) = dword;
99 batch->ptr += 4;
100 }
101
102 static INLINE boolean
103 brw_batchbuffer_require_space(struct brw_batchbuffer *batch,
104 GLuint sz)
105 {
106 assert(sz < batch->size - 8);
107 if (brw_batchbuffer_space(batch) < sz) {
108 assert(0);
109 return FALSE;
110 }
111 #ifdef DEBUG
112 batch->emit.end_ptr = batch->ptr + sz;
113 #endif
114 return TRUE;
115 }
116
117 /* Here are the crusty old macros, to be removed:
118 */
119 #define BEGIN_BATCH(n, cliprect_mode) do { \
120 brw_batchbuffer_require_space(brw->batch, (n)*4); \
121 } while (0)
122
123 #define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d)
124
125 #define OUT_RELOC(buf, usage, delta) do { \
126 assert((unsigned) (delta) < buf->size); \
127 brw_batchbuffer_emit_reloc(brw->batch, buf, \
128 usage, delta); \
129 } while (0)
130
131 #ifdef DEBUG
132 #define ADVANCE_BATCH() do { \
133 unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \
134 if (_n != 0) { \
135 debug_printf("%s: %d too many bytes emitted to batch\n", \
136 __FUNCTION__, _n); \
137 abort(); \
138 } \
139 brw->batch->emit.end_ptr = NULL; \
140 } while(0)
141 #else
142 #define ADVANCE_BATCH()
143 #endif
144
145 static INLINE void
146 brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer *batch)
147 {
148 brw_batchbuffer_require_space(batch, 4);
149 brw_batchbuffer_emit_dword(batch, MI_FLUSH);
150 }
151
152 #endif