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