Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / i965 / brw_batchbuffer.h
1 #ifndef BRW_BATCHBUFFER_H
2 #define BRW_BATCHBUFFER_H
3
4 #include "util/u_debug.h"
5
6 #include "brw_types.h"
7 #include "brw_winsys.h"
8 #include "brw_reg.h"
9
10 #define BATCH_SZ 16384
11 #define BATCH_RESERVED 16
12
13 /* All ignored:
14 */
15 enum cliprect_mode {
16 IGNORE_CLIPRECTS,
17 LOOP_CLIPRECTS,
18 NO_LOOP_CLIPRECTS,
19 REFERENCES_CLIPRECTS
20 };
21
22
23
24
25 struct brw_batchbuffer {
26
27 struct brw_winsys_screen *sws;
28 struct brw_winsys_buffer *buf;
29 struct brw_chipset chipset;
30
31 /**
32 * Values exported to speed up the writing the batchbuffer,
33 * instead of having to go trough a accesor function for
34 * each dword written.
35 */
36 /*{@*/
37 uint8_t *map;
38 uint8_t *ptr;
39 size_t size;
40 struct {
41 uint8_t *end_ptr;
42 } emit;
43
44
45 size_t relocs;
46 size_t max_relocs;
47 /*@}*/
48 };
49
50 struct brw_batchbuffer *brw_batchbuffer_alloc( struct brw_winsys_screen *sws,
51 struct brw_chipset chipset );
52
53 void brw_batchbuffer_free(struct brw_batchbuffer *batch);
54
55 void _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
56 const char *file, int line);
57
58
59 enum pipe_error
60 brw_batchbuffer_reset(struct brw_batchbuffer *batch);
61
62
63 /* Unlike bmBufferData, this currently requires the buffer be mapped.
64 * Consider it a convenience function wrapping multple
65 * intel_buffer_dword() calls.
66 */
67 enum pipe_error brw_batchbuffer_data(struct brw_batchbuffer *batch,
68 const void *data, GLuint bytes,
69 enum cliprect_mode cliprect_mode);
70
71
72 enum pipe_error brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch,
73 struct brw_winsys_buffer *buffer,
74 enum brw_buffer_usage usage,
75 uint32_t offset);
76
77 /* Inline functions - might actually be better off with these
78 * non-inlined. Certainly better off switching all command packets to
79 * be passed as structs rather than dwords, but that's a little bit of
80 * work...
81 */
82 static INLINE GLint
83 brw_batchbuffer_space(struct brw_batchbuffer *batch)
84 {
85 return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
86 }
87
88
89 static INLINE void
90 brw_batchbuffer_emit_dword(struct brw_batchbuffer *batch, GLuint dword)
91 {
92 assert(batch->map);
93 assert(brw_batchbuffer_space(batch) >= 4);
94 *(GLuint *) (batch->ptr) = dword;
95 batch->ptr += 4;
96 }
97
98 static INLINE enum pipe_error
99 brw_batchbuffer_require_space(struct brw_batchbuffer *batch,
100 GLuint sz)
101 {
102 assert(sz < batch->size - 8);
103 if (brw_batchbuffer_space(batch) < sz) {
104 assert(0);
105 return PIPE_ERROR_OUT_OF_MEMORY;
106 }
107 #ifdef DEBUG
108 batch->emit.end_ptr = batch->ptr + sz;
109 #endif
110 return 0;
111 }
112
113 /* Here are the crusty old macros, to be removed:
114 */
115 #define BEGIN_BATCH(n, cliprect_mode) do { \
116 brw_batchbuffer_require_space(brw->batch, (n)*4); \
117 } while (0)
118
119 #define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d)
120
121 #define OUT_RELOC(buf, usage, delta) do { \
122 assert((unsigned) (delta) < buf->size); \
123 brw_batchbuffer_emit_reloc(brw->batch, buf, \
124 usage, delta); \
125 } while (0)
126
127 #ifdef DEBUG
128 #define ADVANCE_BATCH() do { \
129 unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \
130 if (_n != 0) { \
131 debug_printf("%s: %d too many bytes emitted to batch\n", \
132 __FUNCTION__, _n); \
133 abort(); \
134 } \
135 brw->batch->emit.end_ptr = NULL; \
136 } while(0)
137 #else
138 #define ADVANCE_BATCH()
139 #endif
140
141 static INLINE void
142 brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer *batch)
143 {
144 brw_batchbuffer_require_space(batch, 4);
145 brw_batchbuffer_emit_dword(batch, MI_FLUSH);
146 }
147
148 #endif