i915g: prepare winsys/batchbuffer for execbuf2
[mesa.git] / src / gallium / drivers / i915 / i915_winsys.h
1 /**************************************************************************
2 *
3 * Copyright © 2009 Jakob Bornecrantz
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 **************************************************************************/
25
26 #ifndef I915_WINSYS_H
27 #define I915_WINSYS_H
28
29 #include "pipe/p_compiler.h"
30
31 struct i915_winsys;
32 struct i915_winsys_buffer;
33 struct i915_winsys_batchbuffer;
34 struct pipe_resource;
35 struct pipe_fence_handle;
36 struct winsys_handle;
37
38 enum i915_winsys_buffer_usage
39 {
40 /* use on textures */
41 I915_USAGE_RENDER = 0x01,
42 I915_USAGE_SAMPLER = 0x02,
43 I915_USAGE_2D_TARGET = 0x04,
44 I915_USAGE_2D_SOURCE = 0x08,
45 /* use on vertex */
46 I915_USAGE_VERTEX = 0x10
47 };
48
49 enum i915_winsys_buffer_type
50 {
51 I915_NEW_TEXTURE,
52 I915_NEW_SCANOUT, /**< a texture used for scanning out from */
53 I915_NEW_VERTEX
54 };
55
56 enum i915_winsys_buffer_tile
57 {
58 I915_TILE_NONE,
59 I915_TILE_X,
60 I915_TILE_Y
61 };
62
63 struct i915_winsys_batchbuffer {
64
65 struct i915_winsys *iws;
66
67 /**
68 * Values exported to speed up the writing the batchbuffer,
69 * instead of having to go trough a accesor function for
70 * each dword written.
71 */
72 /*{@*/
73 uint8_t *map;
74 uint8_t *ptr;
75 size_t size;
76
77 size_t relocs;
78 size_t max_relocs;
79 /*@}*/
80 };
81
82 struct i915_winsys {
83
84 unsigned pci_id; /**< PCI ID for the device */
85
86 /**
87 * Batchbuffer functions.
88 */
89 /*@{*/
90 /**
91 * Create a new batchbuffer.
92 */
93 struct i915_winsys_batchbuffer *
94 (*batchbuffer_create)(struct i915_winsys *iws);
95
96 /**
97 * Emit a relocation to a buffer.
98 * Target position in batchbuffer is the same as ptr.
99 *
100 * @batch
101 * @reloc buffer address to be inserted into target.
102 * @usage how is the hardware going to use the buffer.
103 * @offset add this to the reloc buffers address
104 * @target buffer where to write the address, null for batchbuffer.
105 */
106 int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch,
107 struct i915_winsys_buffer *reloc,
108 enum i915_winsys_buffer_usage usage,
109 unsigned offset, bool fenced);
110
111 /**
112 * Flush a bufferbatch.
113 */
114 void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch,
115 struct pipe_fence_handle **fence);
116
117 /**
118 * Destroy a batchbuffer.
119 */
120 void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch);
121 /*@}*/
122
123
124 /**
125 * Buffer functions.
126 */
127 /*@{*/
128 /**
129 * Create a buffer.
130 */
131 struct i915_winsys_buffer *
132 (*buffer_create)(struct i915_winsys *iws,
133 unsigned size,
134 enum i915_winsys_buffer_type type);
135
136 /**
137 * Create a tiled buffer.
138 *
139 * *stride, height are in bytes. The winsys tries to allocate the buffer with
140 * the tiling mode provide in *tiling. If tiling is no possible, *tiling will
141 * be set to I915_TILE_NONE. The calculated stride (incorporateing hw/kernel
142 * requirements) is always returned in *stride.
143 */
144 struct i915_winsys_buffer *
145 (*buffer_create_tiled)(struct i915_winsys *iws,
146 unsigned *stride, unsigned height,
147 enum i915_winsys_buffer_tile *tiling,
148 enum i915_winsys_buffer_type type);
149
150 /**
151 * Creates a buffer from a handle.
152 * Used to implement pipe_screen::resource_from_handle.
153 * Also provides the stride information needed for the
154 * texture via the stride argument.
155 */
156 struct i915_winsys_buffer *
157 (*buffer_from_handle)(struct i915_winsys *iws,
158 struct winsys_handle *whandle,
159 unsigned *stride);
160
161 /**
162 * Used to implement pipe_screen::resource_get_handle.
163 * The winsys might need the stride information.
164 */
165 boolean (*buffer_get_handle)(struct i915_winsys *iws,
166 struct i915_winsys_buffer *buffer,
167 struct winsys_handle *whandle,
168 unsigned stride);
169
170 /**
171 * Map a buffer.
172 */
173 void *(*buffer_map)(struct i915_winsys *iws,
174 struct i915_winsys_buffer *buffer,
175 boolean write);
176
177 /**
178 * Unmap a buffer.
179 */
180 void (*buffer_unmap)(struct i915_winsys *iws,
181 struct i915_winsys_buffer *buffer);
182
183 /**
184 * Write to a buffer.
185 *
186 * Arguments follows pipe_buffer_write.
187 */
188 int (*buffer_write)(struct i915_winsys *iws,
189 struct i915_winsys_buffer *dst,
190 size_t offset,
191 size_t size,
192 const void *data);
193
194 void (*buffer_destroy)(struct i915_winsys *iws,
195 struct i915_winsys_buffer *buffer);
196 /*@}*/
197
198
199 /**
200 * Fence functions.
201 */
202 /*@{*/
203 /**
204 * Reference fence and set ptr to fence.
205 */
206 void (*fence_reference)(struct i915_winsys *iws,
207 struct pipe_fence_handle **ptr,
208 struct pipe_fence_handle *fence);
209
210 /**
211 * Check if a fence has finished.
212 */
213 int (*fence_signalled)(struct i915_winsys *iws,
214 struct pipe_fence_handle *fence);
215
216 /**
217 * Wait on a fence to finish.
218 */
219 int (*fence_finish)(struct i915_winsys *iws,
220 struct pipe_fence_handle *fence);
221 /*@}*/
222
223
224 /**
225 * Destroy the winsys.
226 */
227 void (*destroy)(struct i915_winsys *iws);
228 };
229
230 #endif