b5c7a783a726b5fe8e75659ce8ebda8250b219f8
[mesa.git] / src / mesa / drivers / dri / intel / intel_batchbuffer.h
1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
3
4 #include "mtypes.h"
5
6 #include "dri_bufmgr.h"
7
8 struct intel_context;
9
10 #define BATCH_SZ 16384
11 #define BATCH_RESERVED 16
12
13 #define INTEL_BATCH_NO_CLIPRECTS 0x1
14 #define INTEL_BATCH_CLIPRECTS 0x2
15
16 struct intel_batchbuffer
17 {
18 struct intel_context *intel;
19
20 dri_bo *buf;
21 dri_fence *last_fence;
22 GLuint flags;
23
24 GLubyte *map;
25 GLubyte *ptr;
26
27 GLuint size;
28 };
29
30 struct intel_batchbuffer *intel_batchbuffer_alloc(struct intel_context
31 *intel);
32
33 void intel_batchbuffer_free(struct intel_batchbuffer *batch);
34
35
36 void intel_batchbuffer_finish(struct intel_batchbuffer *batch);
37
38 void intel_batchbuffer_flush(struct intel_batchbuffer *batch);
39
40 void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
41
42
43 /* Unlike bmBufferData, this currently requires the buffer be mapped.
44 * Consider it a convenience function wrapping multple
45 * intel_buffer_dword() calls.
46 */
47 void intel_batchbuffer_data(struct intel_batchbuffer *batch,
48 const void *data, GLuint bytes, GLuint flags);
49
50 void intel_batchbuffer_release_space(struct intel_batchbuffer *batch,
51 GLuint bytes);
52
53 GLboolean intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
54 dri_bo *buffer,
55 GLuint flags, GLuint offset);
56
57 /* Inline functions - might actually be better off with these
58 * non-inlined. Certainly better off switching all command packets to
59 * be passed as structs rather than dwords, but that's a little bit of
60 * work...
61 */
62 static INLINE GLuint
63 intel_batchbuffer_space(struct intel_batchbuffer *batch)
64 {
65 return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
66 }
67
68
69 static INLINE void
70 intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, GLuint dword)
71 {
72 assert(batch->map);
73 assert(intel_batchbuffer_space(batch) >= 4);
74 *(GLuint *) (batch->ptr) = dword;
75 batch->ptr += 4;
76 }
77
78 static INLINE void
79 intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
80 GLuint sz, GLuint flags)
81 {
82 assert(sz < batch->size - 8);
83 if (intel_batchbuffer_space(batch) < sz ||
84 (batch->flags != 0 && flags != 0 && batch->flags != flags))
85 intel_batchbuffer_flush(batch);
86
87 batch->flags |= flags;
88 }
89
90 /* Here are the crusty old macros, to be removed:
91 */
92 #define BATCH_LOCALS
93
94 #define BEGIN_BATCH(n, flags) do { \
95 assert(!intel->prim.flush); \
96 intel_batchbuffer_require_space(intel->batch, (n)*4, flags); \
97 } while (0)
98
99 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel->batch, d)
100
101 #define OUT_RELOC(buf, flags, delta) do { \
102 assert((delta) >= 0); \
103 intel_batchbuffer_emit_reloc(intel->batch, buf, flags, delta); \
104 } while (0)
105
106 #define ADVANCE_BATCH() do { } while(0)
107
108
109 #endif