i965: Delete render ring prelude.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_batchbuffer.h
1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
3
4 #include "main/mtypes.h"
5
6 #include "brw_context.h"
7 #include "intel_bufmgr.h"
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /**
14 * Number of bytes to reserve for commands necessary to complete a batch.
15 *
16 * This includes:
17 * - MI_BATCHBUFFER_END (4 bytes)
18 * - Optional MI_NOOP for ensuring the batch length is qword aligned (4 bytes)
19 * - Any state emitted by vtbl->finish_batch():
20 * - Gen4-5 record ending occlusion query values (4 * 4 = 16 bytes)
21 * - Disabling OA counters on Gen6+ (3 DWords = 12 bytes)
22 * - Ending MI_REPORT_PERF_COUNT on Gen5+, plus associated PIPE_CONTROLs:
23 * - Two sets of PIPE_CONTROLs, which become 4 PIPE_CONTROLs each on SNB,
24 * which are 5 DWords each ==> 2 * 4 * 5 * 4 = 160 bytes
25 * - 3 DWords for MI_REPORT_PERF_COUNT itself on Gen6+. ==> 12 bytes.
26 * On Ironlake, it's 6 DWords, but we have some slack due to the lack of
27 * Sandybridge PIPE_CONTROL madness.
28 * - CC_STATE workaround on HSW (17 * 4 = 68 bytes)
29 * - 10 dwords for initial mi_flush
30 * - 2 dwords for CC state setup
31 * - 5 dwords for the required pipe control at the end
32 * - Restoring L3 configuration: (24 dwords = 96 bytes)
33 * - 2*6 dwords for two PIPE_CONTROL flushes.
34 * - 7 dwords for L3 configuration set-up.
35 * - 5 dwords for L3 atomic set-up (on HSW).
36 */
37 #define BATCH_RESERVED 308
38
39 struct intel_batchbuffer;
40
41 void intel_batchbuffer_init(struct intel_batchbuffer *batch, dri_bufmgr *bufmgr,
42 bool has_llc);
43 void intel_batchbuffer_free(struct intel_batchbuffer *batch);
44 void intel_batchbuffer_save_state(struct brw_context *brw);
45 void intel_batchbuffer_reset_to_saved(struct brw_context *brw);
46 void intel_batchbuffer_require_space(struct brw_context *brw, GLuint sz,
47 enum brw_gpu_ring ring);
48 int _intel_batchbuffer_flush_fence(struct brw_context *brw,
49 int in_fence_fd, int *out_fence_fd,
50 const char *file, int line);
51
52 #define intel_batchbuffer_flush(brw) \
53 _intel_batchbuffer_flush_fence((brw), -1, NULL, __FILE__, __LINE__)
54
55 #define intel_batchbuffer_flush_fence(brw, in_fence_fd, out_fence_fd) \
56 _intel_batchbuffer_flush_fence((brw), (in_fence_fd), (out_fence_fd), \
57 __FILE__, __LINE__)
58
59 /* Unlike bmBufferData, this currently requires the buffer be mapped.
60 * Consider it a convenience function wrapping multple
61 * intel_buffer_dword() calls.
62 */
63 void intel_batchbuffer_data(struct brw_context *brw,
64 const void *data, GLuint bytes,
65 enum brw_gpu_ring ring);
66
67 uint32_t intel_batchbuffer_reloc(struct intel_batchbuffer *batch,
68 drm_intel_bo *buffer,
69 uint32_t offset,
70 uint32_t read_domains,
71 uint32_t write_domain,
72 uint32_t delta);
73 uint64_t intel_batchbuffer_reloc64(struct intel_batchbuffer *batch,
74 drm_intel_bo *buffer,
75 uint32_t offset,
76 uint32_t read_domains,
77 uint32_t write_domain,
78 uint32_t delta);
79
80 #define USED_BATCH(batch) ((uintptr_t)((batch).map_next - (batch).map))
81
82 static inline uint32_t float_as_int(float f)
83 {
84 union {
85 float f;
86 uint32_t d;
87 } fi;
88
89 fi.f = f;
90 return fi.d;
91 }
92
93 /* Inline functions - might actually be better off with these
94 * non-inlined. Certainly better off switching all command packets to
95 * be passed as structs rather than dwords, but that's a little bit of
96 * work...
97 */
98 static inline unsigned
99 intel_batchbuffer_space(struct intel_batchbuffer *batch)
100 {
101 return (batch->state_batch_offset - batch->reserved_space)
102 - USED_BATCH(*batch) * 4;
103 }
104
105
106 static inline void
107 intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, GLuint dword)
108 {
109 #ifdef DEBUG
110 assert(intel_batchbuffer_space(batch) >= 4);
111 #endif
112 *batch->map_next++ = dword;
113 assert(batch->ring != UNKNOWN_RING);
114 }
115
116 static inline void
117 intel_batchbuffer_emit_float(struct intel_batchbuffer *batch, float f)
118 {
119 intel_batchbuffer_emit_dword(batch, float_as_int(f));
120 }
121
122 static inline void
123 intel_batchbuffer_begin(struct brw_context *brw, int n, enum brw_gpu_ring ring)
124 {
125 intel_batchbuffer_require_space(brw, n * 4, ring);
126
127 #ifdef DEBUG
128 brw->batch.emit = USED_BATCH(brw->batch);
129 brw->batch.total = n;
130 #endif
131 }
132
133 static inline void
134 intel_batchbuffer_advance(struct brw_context *brw)
135 {
136 #ifdef DEBUG
137 struct intel_batchbuffer *batch = &brw->batch;
138 unsigned int _n = USED_BATCH(*batch) - batch->emit;
139 assert(batch->total != 0);
140 if (_n != batch->total) {
141 fprintf(stderr, "ADVANCE_BATCH: %d of %d dwords emitted\n",
142 _n, batch->total);
143 abort();
144 }
145 batch->total = 0;
146 #else
147 (void) brw;
148 #endif
149 }
150
151 #define BEGIN_BATCH(n) do { \
152 intel_batchbuffer_begin(brw, (n), RENDER_RING); \
153 uint32_t *__map = brw->batch.map_next; \
154 brw->batch.map_next += (n)
155
156 #define BEGIN_BATCH_BLT(n) do { \
157 intel_batchbuffer_begin(brw, (n), BLT_RING); \
158 uint32_t *__map = brw->batch.map_next; \
159 brw->batch.map_next += (n)
160
161 #define OUT_BATCH(d) *__map++ = (d)
162 #define OUT_BATCH_F(f) OUT_BATCH(float_as_int((f)))
163
164 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
165 uint32_t __offset = (__map - brw->batch.map) * 4; \
166 OUT_BATCH(intel_batchbuffer_reloc(&brw->batch, (buf), __offset, \
167 (read_domains), \
168 (write_domain), \
169 (delta))); \
170 } while (0)
171
172 /* Handle 48-bit address relocations for Gen8+ */
173 #define OUT_RELOC64(buf, read_domains, write_domain, delta) do { \
174 uint32_t __offset = (__map - brw->batch.map) * 4; \
175 uint64_t reloc64 = intel_batchbuffer_reloc64(&brw->batch, (buf), __offset, \
176 (read_domains), \
177 (write_domain), \
178 (delta)); \
179 OUT_BATCH(reloc64); \
180 OUT_BATCH(reloc64 >> 32); \
181 } while (0)
182
183 #define ADVANCE_BATCH() \
184 assert(__map == brw->batch.map_next); \
185 intel_batchbuffer_advance(brw); \
186 } while (0)
187
188 #ifdef __cplusplus
189 }
190 #endif
191
192 #endif