Use write posting in the kickoff function too.
[mesa.git] / src / mesa / drivers / dri / intel_winsys / intel_batchbuffer.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef INTEL_BATCHBUFFER_H
29 #define INTEL_BATCHBUFFER_H
30
31 #include "pipe/p_compiler.h"
32 #include "dri_bufmgr.h"
33
34 struct intel_context;
35
36 #define BATCH_SZ 16384
37 #define BATCH_RESERVED 16
38
39 #define MAX_RELOCS 4096
40
41 #define INTEL_BATCH_NO_CLIPRECTS 0x1
42 #define INTEL_BATCH_CLIPRECTS 0x2
43
44 struct buffer_reloc
45 {
46 struct _DriBufferObject *buf;
47 uint offset;
48 uint delta; /* not needed? */
49 };
50
51 struct intel_batchbuffer
52 {
53 struct bufmgr *bm;
54 struct intel_context *intel;
55
56 struct _DriBufferObject *buffer;
57 struct _DriFenceObject *last_fence;
58 uint flags;
59
60 drmBOList list;
61 uint list_count;
62 ubyte *map;
63 ubyte *ptr;
64
65 struct buffer_reloc reloc[MAX_RELOCS];
66 uint nr_relocs;
67 uint size;
68 };
69
70 struct intel_batchbuffer *intel_batchbuffer_alloc(struct intel_context *intel);
71
72 void intel_batchbuffer_free(struct intel_batchbuffer *batch);
73
74
75 struct _DriFenceObject *intel_batchbuffer_flush(struct intel_batchbuffer
76 *batch);
77
78 void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
79
80
81 /* Unlike bmBufferData, this currently requires the buffer be mapped.
82 * Consider it a convenience function wrapping multiple
83 * intel_buffer_dword() calls.
84 */
85 void intel_batchbuffer_data(struct intel_batchbuffer *batch,
86 const void *data, uint bytes, uint flags);
87
88 void intel_batchbuffer_release_space(struct intel_batchbuffer *batch,
89 uint bytes);
90
91 boolean intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
92 struct _DriBufferObject *buffer,
93 uint flags,
94 uint mask, uint offset);
95
96 /* Inline functions - might actually be better off with these
97 * non-inlined. Certainly better off switching all command packets to
98 * be passed as structs rather than dwords, but that's a little bit of
99 * work...
100 */
101 static INLINE uint
102 intel_batchbuffer_space(struct intel_batchbuffer *batch)
103 {
104 return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
105 }
106
107
108 static INLINE void
109 intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, uint dword)
110 {
111 assert(batch->map);
112 assert(intel_batchbuffer_space(batch) >= 4);
113 *(uint *) (batch->ptr) = dword;
114 batch->ptr += 4;
115 }
116
117 static INLINE void
118 intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
119 uint sz, uint flags)
120 {
121 assert(sz < batch->size - 8);
122 if (intel_batchbuffer_space(batch) < sz ||
123 (batch->flags != 0 && flags != 0 && batch->flags != flags))
124 intel_batchbuffer_flush(batch);
125
126 batch->flags |= flags;
127 }
128
129 /* Here are the crusty old macros, to be removed:
130 */
131 #define BATCH_LOCALS
132
133 #define BEGIN_BATCH(n, flags) do { \
134 intel_batchbuffer_require_space(intel->batch, (n)*4, flags); \
135 } while (0)
136
137 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel->batch, d)
138
139 #define OUT_RELOC(buf,flags,mask,delta) do { \
140 assert((delta) >= 0); \
141 intel_batchbuffer_emit_reloc(intel->batch, buf, flags, mask, delta); \
142 } while (0)
143
144 #define ADVANCE_BATCH() do { } while(0)
145
146
147 #endif