1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef INTEL_BATCHBUFFER_H
29 #define INTEL_BATCHBUFFER_H
31 #include "pipe/p_compiler.h"
32 #include "dri_bufmgr.h"
36 #define BATCH_SZ 16384
37 #define BATCH_RESERVED 16
39 #define MAX_RELOCS 4096
41 #define INTEL_BATCH_NO_CLIPRECTS 0x1
42 #define INTEL_BATCH_CLIPRECTS 0x2
46 struct _DriBufferObject
*buf
;
48 uint delta
; /* not needed? */
51 struct intel_batchbuffer
54 struct intel_context
*intel
;
56 struct _DriBufferObject
*buffer
;
57 struct _DriFenceObject
*last_fence
;
65 struct buffer_reloc reloc
[MAX_RELOCS
];
70 struct intel_batchbuffer
*intel_batchbuffer_alloc(struct intel_context
*intel
);
72 void intel_batchbuffer_free(struct intel_batchbuffer
*batch
);
75 struct _DriFenceObject
*intel_batchbuffer_flush(struct intel_batchbuffer
78 void intel_batchbuffer_reset(struct intel_batchbuffer
*batch
);
81 /* Unlike bmBufferData, this currently requires the buffer be mapped.
82 * Consider it a convenience function wrapping multiple
83 * intel_buffer_dword() calls.
85 void intel_batchbuffer_data(struct intel_batchbuffer
*batch
,
86 const void *data
, uint bytes
, uint flags
);
88 void intel_batchbuffer_release_space(struct intel_batchbuffer
*batch
,
91 boolean
intel_batchbuffer_emit_reloc(struct intel_batchbuffer
*batch
,
92 struct _DriBufferObject
*buffer
,
94 uint mask
, uint offset
);
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
102 intel_batchbuffer_space(struct intel_batchbuffer
*batch
)
104 return (batch
->size
- BATCH_RESERVED
) - (batch
->ptr
- batch
->map
);
109 intel_batchbuffer_emit_dword(struct intel_batchbuffer
*batch
, uint dword
)
112 assert(intel_batchbuffer_space(batch
) >= 4);
113 *(uint
*) (batch
->ptr
) = dword
;
118 intel_batchbuffer_require_space(struct intel_batchbuffer
*batch
,
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
);
126 batch
->flags
|= flags
;
129 /* Here are the crusty old macros, to be removed:
133 #define BEGIN_BATCH(n, flags) do { \
134 intel_batchbuffer_require_space(intel->batch, (n)*4, flags); \
137 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel->batch, d)
139 #define OUT_RELOC(buf,flags,mask,delta) do { \
140 assert((delta) >= 0); \
141 intel_batchbuffer_emit_reloc(intel->batch, buf, flags, mask, delta); \
144 #define ADVANCE_BATCH() do { } while(0)