Revert "Merge branch 'drm-gem'"
[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 enum cliprect_mode {
14 /**
15 * Batchbuffer contents may be looped over per cliprect, but do not
16 * require it.
17 */
18 IGNORE_CLIPRECTS,
19 /**
20 * Batchbuffer contents require looping over per cliprect at batch submit
21 * time.
22 */
23 LOOP_CLIPRECTS,
24 /**
25 * Batchbuffer contents contain drawing that should not be executed multiple
26 * times.
27 */
28 NO_LOOP_CLIPRECTS,
29 /**
30 * Batchbuffer contents contain drawing that already handles cliprects, such
31 * as 2D drawing to front/back/depth that doesn't respect DRAWING_RECTANGLE.
32 * Equivalent behavior to NO_LOOP_CLIPRECTS, but may not persist in batch
33 * outside of LOCK/UNLOCK.
34 */
35 REFERENCES_CLIPRECTS
36 };
37
38 struct intel_batchbuffer
39 {
40 struct intel_context *intel;
41
42 dri_bo *buf;
43 dri_fence *last_fence;
44
45 GLubyte *map;
46 GLubyte *ptr;
47
48 enum cliprect_mode cliprect_mode;
49
50 GLuint size;
51
52 GLuint dirty_state;
53 };
54
55 struct intel_batchbuffer *intel_batchbuffer_alloc(struct intel_context
56 *intel);
57
58 void intel_batchbuffer_free(struct intel_batchbuffer *batch);
59
60
61 void intel_batchbuffer_finish(struct intel_batchbuffer *batch);
62
63 void _intel_batchbuffer_flush(struct intel_batchbuffer *batch,
64 const char *file, int line);
65
66 #define intel_batchbuffer_flush(batch) \
67 _intel_batchbuffer_flush(batch, __FILE__, __LINE__)
68
69 void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
70
71
72 /* Unlike bmBufferData, this currently requires the buffer be mapped.
73 * Consider it a convenience function wrapping multple
74 * intel_buffer_dword() calls.
75 */
76 void intel_batchbuffer_data(struct intel_batchbuffer *batch,
77 const void *data, GLuint bytes,
78 enum cliprect_mode cliprect_mode);
79
80 void intel_batchbuffer_release_space(struct intel_batchbuffer *batch,
81 GLuint bytes);
82
83 GLboolean intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
84 dri_bo *buffer,
85 GLuint flags, GLuint offset);
86
87 /* Inline functions - might actually be better off with these
88 * non-inlined. Certainly better off switching all command packets to
89 * be passed as structs rather than dwords, but that's a little bit of
90 * work...
91 */
92 static INLINE GLuint
93 intel_batchbuffer_space(struct intel_batchbuffer *batch)
94 {
95 return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
96 }
97
98
99 static INLINE void
100 intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, GLuint dword)
101 {
102 assert(batch->map);
103 assert(intel_batchbuffer_space(batch) >= 4);
104 *(GLuint *) (batch->ptr) = dword;
105 batch->ptr += 4;
106 }
107
108 static INLINE void
109 intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
110 GLuint sz,
111 enum cliprect_mode cliprect_mode)
112 {
113 assert(sz < batch->size - 8);
114 if (intel_batchbuffer_space(batch) < sz)
115 intel_batchbuffer_flush(batch);
116
117 if (cliprect_mode != IGNORE_CLIPRECTS) {
118 if (batch->cliprect_mode == IGNORE_CLIPRECTS) {
119 batch->cliprect_mode = cliprect_mode;
120 } else {
121 if (batch->cliprect_mode != cliprect_mode) {
122 intel_batchbuffer_flush(batch);
123 batch->cliprect_mode = cliprect_mode;
124 }
125 }
126 }
127 }
128
129 /* Here are the crusty old macros, to be removed:
130 */
131 #define BATCH_LOCALS
132
133 #define BEGIN_BATCH(n, cliprect_mode) do { \
134 intel_batchbuffer_require_space(intel->batch, (n)*4, cliprect_mode); \
135 } while (0)
136
137 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel->batch, d)
138
139 #define OUT_RELOC(buf, cliprect_mode, delta) do { \
140 assert((delta) >= 0); \
141 intel_batchbuffer_emit_reloc(intel->batch, buf, cliprect_mode, delta); \
142 } while (0)
143
144 #define ADVANCE_BATCH() do { } while(0)
145
146
147 #endif