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