1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/**************************************************************************
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
Copyright © 2002 David Dawes
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
#ifndef _INTEL_BATCHBUFFER_H
#define _INTEL_BATCHBUFFER_H
#define BATCH_RESERVED 16
void intel_batch_init(ScrnInfoPtr scrn);
void intel_batch_teardown(ScrnInfoPtr scrn);
void intel_batch_pipelined_flush(ScrnInfoPtr scrn);
void intel_batch_flush(ScrnInfoPtr scrn, Bool flush);
void intel_batch_wait_last(ScrnInfoPtr scrn);
static inline int intel_batch_space(intel_screen_private *intel)
{
return (intel->batch_bo->size - BATCH_RESERVED) - (intel->batch_used);
}
static inline void
intel_batch_require_space(ScrnInfoPtr scrn, intel_screen_private *intel, GLuint sz)
{
assert(sz < intel->batch_bo->size - 8);
if (intel_batch_space(intel) < sz)
intel_batch_flush(scrn, FALSE);
}
static inline void intel_batch_start_atomic(ScrnInfoPtr scrn, unsigned int sz)
{
intel_screen_private *intel = intel_get_screen_private(scrn);
assert(!intel->in_batch_atomic);
intel_batch_require_space(scrn, intel, sz * 4);
intel->in_batch_atomic = TRUE;
intel->batch_atomic_limit = intel->batch_used + sz * 4;
}
static inline void intel_batch_end_atomic(ScrnInfoPtr scrn)
{
intel_screen_private *intel = intel_get_screen_private(scrn);
assert(intel->in_batch_atomic);
assert(intel->batch_used <= intel->batch_atomic_limit);
intel->in_batch_atomic = FALSE;
}
static inline void intel_batch_emit_dword(intel_screen_private *intel, uint32_t dword)
{
assert(intel->batch_ptr != NULL);
assert(intel_batch_space(intel) >= 4);
*(uint32_t *) (intel->batch_ptr + intel->batch_used) = dword;
intel->batch_used += 4;
}
static inline void
intel_batch_emit_reloc(intel_screen_private *intel,
dri_bo * bo,
uint32_t read_domains,
uint32_t write_domains, uint32_t delta)
{
assert(intel_batch_space(intel) >= 4);
*(uint32_t *) (intel->batch_ptr + intel->batch_used) =
bo->offset + delta;
dri_bo_emit_reloc(intel->batch_bo, read_domains, write_domains, delta,
intel->batch_used, bo);
intel->batch_used += 4;
}
static inline void
intel_batch_mark_pixmap_domains(intel_screen_private *intel,
struct intel_pixmap *priv,
uint32_t read_domains, uint32_t write_domain)
{
assert (read_domains);
assert (write_domain == 0 || write_domain == read_domains);
assert (write_domain == 0 ||
priv->flush_write_domain == 0 ||
priv->flush_write_domain == write_domain);
priv->flush_read_domains |= read_domains;
priv->batch_read_domains |= read_domains;
priv->flush_write_domain |= write_domain;
priv->batch_write_domain |= write_domain;
if (list_is_empty(&priv->batch))
list_add(&priv->batch, &intel->batch_pixmaps);
if (list_is_empty(&priv->flush))
list_add(&priv->flush, &intel->flush_pixmaps);
}
static inline void
intel_batch_emit_reloc_pixmap(intel_screen_private *intel, PixmapPtr pixmap,
uint32_t read_domains, uint32_t write_domain,
uint32_t delta)
{
dri_bo *bo = i830_get_pixmap_bo(pixmap);
uint32_t offset;
assert(intel->batch_ptr != NULL);
assert(intel_batch_space(intel) >= 4);
if (bo) {
struct intel_pixmap *priv = i830_get_pixmap_intel(pixmap);
intel_batch_mark_pixmap_domains(intel, priv, read_domains,
write_domain);
intel_batch_emit_reloc(intel, bo, read_domains,
write_domain, delta);
return;
}
offset = intel_get_pixmap_offset(pixmap);
*(uint32_t *)(intel->batch_ptr + intel->batch_used) = offset + delta;
intel->batch_used += 4;
}
#define OUT_BATCH(dword) intel_batch_emit_dword(intel, dword)
#define OUT_RELOC(bo, read_domains, write_domains, delta) \
intel_batch_emit_reloc (intel, bo, read_domains, write_domains, delta)
#define OUT_RELOC_PIXMAP(pixmap, reads, write, delta) \
intel_batch_emit_reloc_pixmap(intel, pixmap, reads, write, delta)
union intfloat {
float f;
unsigned int ui;
};
#define OUT_BATCH_F(x) do { \
union intfloat tmp; \
tmp.f = (float)(x); \
OUT_BATCH(tmp.ui); \
} while(0)
#define BEGIN_BATCH(n) \
do { \
if (intel->batch_emitting != 0) \
FatalError("%s: BEGIN_BATCH called without closing " \
"ADVANCE_BATCH\n", __FUNCTION__); \
assert(!intel->in_batch_atomic); \
intel_batch_require_space(scrn, intel, (n) * 4); \
intel->batch_emitting = (n) * 4; \
intel->batch_emit_start = intel->batch_used; \
} while (0)
/* special-case variant for when we have preallocated space */
#define ATOMIC_BATCH(n) \
do { \
if (intel->batch_emitting != 0) \
FatalError("%s: ATOMIC_BATCH called without closing " \
"ADVANCE_BATCH\n", __FUNCTION__); \
assert(intel->in_batch_atomic); \
assert(intel->batch_used + (n) * 4 <= intel->batch_atomic_limit); \
intel->batch_emitting = (n) * 4; \
intel->batch_emit_start = intel->batch_used; \
} while (0)
#define ADVANCE_BATCH() do { \
if (intel->batch_emitting == 0) \
FatalError("%s: ADVANCE_BATCH called with no matching " \
"BEGIN_BATCH\n", __FUNCTION__); \
if (intel->batch_used > \
intel->batch_emit_start + intel->batch_emitting) \
FatalError("%s: ADVANCE_BATCH: exceeded allocation %d/%d\n ", \
__FUNCTION__, \
intel->batch_used - intel->batch_emit_start, \
intel->batch_emitting); \
if (intel->batch_used < intel->batch_emit_start + \
intel->batch_emitting) \
FatalError("%s: ADVANCE_BATCH: under-used allocation %d/%d\n ", \
__FUNCTION__, \
intel->batch_used - intel->batch_emit_start, \
intel->batch_emitting); \
if ((intel->batch_emitting > 8) && \
(I810_DEBUG & DEBUG_ALWAYS_SYNC)) { \
/* Note: not actually syncing, just flushing each batch. */ \
intel_batch_flush(scrn, FALSE); \
} \
intel->batch_emitting = 0; \
} while (0)
#endif /* _INTEL_BATCHBUFFER_H */
|