intel: Drop the internal_format field of the mipmap tree.
[mesa.git] / src / mesa / drivers / dri / intel / intel_batchbuffer.h
1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
3
4 #include "main/mtypes.h"
5
6 #include "intel_context.h"
7 #include "intel_bufmgr.h"
8 #include "intel_reg.h"
9
10 #define BATCH_RESERVED 16
11
12 void intel_batchbuffer_reset(struct intel_context *intel);
13 void intel_batchbuffer_free(struct intel_context *intel);
14
15 void _intel_batchbuffer_flush(struct intel_context *intel,
16 const char *file, int line);
17
18 #define intel_batchbuffer_flush(intel) \
19 _intel_batchbuffer_flush(intel, __FILE__, __LINE__)
20
21
22
23 /* Unlike bmBufferData, this currently requires the buffer be mapped.
24 * Consider it a convenience function wrapping multple
25 * intel_buffer_dword() calls.
26 */
27 void intel_batchbuffer_data(struct intel_context *intel,
28 const void *data, GLuint bytes, bool is_blit);
29
30 GLboolean intel_batchbuffer_emit_reloc(struct intel_context *intel,
31 drm_intel_bo *buffer,
32 uint32_t read_domains,
33 uint32_t write_domain,
34 uint32_t offset);
35 GLboolean intel_batchbuffer_emit_reloc_fenced(struct intel_context *intel,
36 drm_intel_bo *buffer,
37 uint32_t read_domains,
38 uint32_t write_domain,
39 uint32_t offset);
40 void intel_batchbuffer_emit_mi_flush(struct intel_context *intel);
41
42 static INLINE uint32_t float_as_int(float f)
43 {
44 union {
45 float f;
46 uint32_t d;
47 } fi;
48
49 fi.f = f;
50 return fi.d;
51 }
52
53 /* Inline functions - might actually be better off with these
54 * non-inlined. Certainly better off switching all command packets to
55 * be passed as structs rather than dwords, but that's a little bit of
56 * work...
57 */
58 static INLINE GLint
59 intel_batchbuffer_space(struct intel_context *intel)
60 {
61 return (intel->batch.state_batch_offset - intel->batch.reserved_space) - intel->batch.used*4;
62 }
63
64
65 static INLINE void
66 intel_batchbuffer_emit_dword(struct intel_context *intel, GLuint dword)
67 {
68 #ifdef DEBUG
69 assert(intel_batchbuffer_space(intel) >= 4);
70 #endif
71 intel->batch.map[intel->batch.used++] = dword;
72 }
73
74 static INLINE void
75 intel_batchbuffer_emit_float(struct intel_context *intel, float f)
76 {
77 intel_batchbuffer_emit_dword(intel, float_as_int(f));
78 }
79
80 static INLINE void
81 intel_batchbuffer_require_space(struct intel_context *intel,
82 GLuint sz, int is_blit)
83 {
84
85 if (intel->gen >= 6 &&
86 intel->batch.is_blit != is_blit && intel->batch.used) {
87 intel_batchbuffer_flush(intel);
88 }
89
90 intel->batch.is_blit = is_blit;
91
92 #ifdef DEBUG
93 assert(sz < sizeof(intel->batch.map) - BATCH_RESERVED);
94 #endif
95 if (intel_batchbuffer_space(intel) < sz)
96 intel_batchbuffer_flush(intel);
97 }
98
99 static INLINE void
100 intel_batchbuffer_begin(struct intel_context *intel, int n, bool is_blit)
101 {
102 intel_batchbuffer_require_space(intel, n * 4, is_blit);
103
104 intel->batch.emit = intel->batch.used;
105 #ifdef DEBUG
106 intel->batch.total = n;
107 #endif
108 }
109
110 static INLINE void
111 intel_batchbuffer_advance(struct intel_context *intel)
112 {
113 #ifdef DEBUG
114 struct intel_batchbuffer *batch = &intel->batch;
115 unsigned int _n = batch->used - batch->emit;
116 assert(batch->total != 0);
117 if (_n != batch->total) {
118 fprintf(stderr, "ADVANCE_BATCH: %d of %d dwords emitted\n",
119 _n, batch->total);
120 abort();
121 }
122 batch->total = 0;
123 #endif
124 }
125
126 void intel_batchbuffer_cached_advance(struct intel_context *intel);
127
128 /* Here are the crusty old macros, to be removed:
129 */
130 #define BATCH_LOCALS
131
132 #define BEGIN_BATCH(n) intel_batchbuffer_begin(intel, n, false)
133 #define BEGIN_BATCH_BLT(n) intel_batchbuffer_begin(intel, n, true)
134 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel, d)
135 #define OUT_BATCH_F(f) intel_batchbuffer_emit_float(intel,f)
136 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
137 intel_batchbuffer_emit_reloc(intel, buf, \
138 read_domains, write_domain, delta); \
139 } while (0)
140 #define OUT_RELOC_FENCED(buf, read_domains, write_domain, delta) do { \
141 intel_batchbuffer_emit_reloc_fenced(intel, buf, \
142 read_domains, write_domain, delta); \
143 } while (0)
144
145 #define ADVANCE_BATCH() intel_batchbuffer_advance(intel);
146 #define CACHED_BATCH() intel_batchbuffer_cached_advance(intel);
147
148 #endif