i915_winsys.h revision 2ff0879a6365e7f7d7e5277274bc965ad57a82b4
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
31struct i915_winsys;
32struct i915_winsys_buffer;
33struct i915_winsys_batchbuffer;
34struct pipe_resource;
35struct pipe_fence_handle;
36struct winsys_handle;
37
38enum 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
49enum 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/* These need to be in sync with the definitions of libdrm-intel! */
57enum i915_winsys_buffer_tile
58{
59   I915_TILE_NONE,
60   I915_TILE_X,
61   I915_TILE_Y
62};
63
64struct i915_winsys_batchbuffer {
65
66   struct i915_winsys *iws;
67
68   /**
69    * Values exported to speed up the writing the batchbuffer,
70    * instead of having to go trough a accesor function for
71    * each dword written.
72    */
73   /*{@*/
74   uint8_t *map;
75   uint8_t *ptr;
76   size_t size;
77
78   size_t relocs;
79   size_t max_relocs;
80   /*@}*/
81};
82
83struct i915_winsys {
84
85   unsigned pci_id; /**< PCI ID for the device */
86
87   /**
88    * Batchbuffer functions.
89    */
90   /*@{*/
91   /**
92    * Create a new batchbuffer.
93    */
94   struct i915_winsys_batchbuffer *
95      (*batchbuffer_create)(struct i915_winsys *iws);
96
97   /**
98    * Emit a relocation to a buffer.
99    * Target position in batchbuffer is the same as ptr.
100    *
101    * @batch
102    * @reloc buffer address to be inserted into target.
103    * @usage how is the hardware going to use the buffer.
104    * @offset add this to the reloc buffers address
105    * @target buffer where to write the address, null for batchbuffer.
106    */
107   int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch,
108                            struct i915_winsys_buffer *reloc,
109                            enum i915_winsys_buffer_usage usage,
110                            unsigned offset, bool fenced);
111
112   /**
113    * Flush a bufferbatch.
114    */
115   void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch,
116                             struct pipe_fence_handle **fence);
117
118   /**
119    * Destroy a batchbuffer.
120    */
121   void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch);
122   /*@}*/
123
124
125   /**
126    * Buffer functions.
127    */
128   /*@{*/
129   /**
130    * Create a buffer.
131    */
132   struct i915_winsys_buffer *
133      (*buffer_create)(struct i915_winsys *iws,
134                       unsigned size,
135                       enum i915_winsys_buffer_type type);
136
137   /**
138    * Create a tiled buffer.
139    *
140    * *stride, height are in bytes. The winsys tries to allocate the buffer with
141    * the tiling mode provide in *tiling. If tiling is no possible, *tiling will
142    * be set to I915_TILE_NONE. The calculated stride (incorporateing hw/kernel
143    * requirements) is always returned in *stride.
144    */
145   struct i915_winsys_buffer *
146      (*buffer_create_tiled)(struct i915_winsys *iws,
147                             unsigned *stride, unsigned height,
148                             enum i915_winsys_buffer_tile *tiling,
149                             enum i915_winsys_buffer_type type);
150
151   /**
152    * Creates a buffer from a handle.
153    * Used to implement pipe_screen::resource_from_handle.
154    * Also provides the stride information needed for the
155    * texture via the stride argument.
156    */
157   struct i915_winsys_buffer *
158      (*buffer_from_handle)(struct i915_winsys *iws,
159                            struct winsys_handle *whandle,
160                            enum i915_winsys_buffer_tile *tiling,
161                            unsigned *stride);
162
163   /**
164    * Used to implement pipe_screen::resource_get_handle.
165    * The winsys might need the stride information.
166    */
167   boolean (*buffer_get_handle)(struct i915_winsys *iws,
168                                struct i915_winsys_buffer *buffer,
169                                struct winsys_handle *whandle,
170                                unsigned stride);
171
172   /**
173    * Map a buffer.
174    */
175   void *(*buffer_map)(struct i915_winsys *iws,
176                       struct i915_winsys_buffer *buffer,
177                       boolean write);
178
179   /**
180    * Unmap a buffer.
181    */
182   void (*buffer_unmap)(struct i915_winsys *iws,
183                        struct i915_winsys_buffer *buffer);
184
185   /**
186    * Write to a buffer.
187    *
188    * Arguments follows pipe_buffer_write.
189    */
190   int (*buffer_write)(struct i915_winsys *iws,
191                       struct i915_winsys_buffer *dst,
192                       size_t offset,
193                       size_t size,
194                       const void *data);
195
196   void (*buffer_destroy)(struct i915_winsys *iws,
197                          struct i915_winsys_buffer *buffer);
198   /*@}*/
199
200
201   /**
202    * Fence functions.
203    */
204   /*@{*/
205   /**
206    * Reference fence and set ptr to fence.
207    */
208   void (*fence_reference)(struct i915_winsys *iws,
209                           struct pipe_fence_handle **ptr,
210                           struct pipe_fence_handle *fence);
211
212   /**
213    * Check if a fence has finished.
214    */
215   int (*fence_signalled)(struct i915_winsys *iws,
216                          struct pipe_fence_handle *fence);
217
218   /**
219    * Wait on a fence to finish.
220    */
221   int (*fence_finish)(struct i915_winsys *iws,
222                       struct pipe_fence_handle *fence);
223   /*@}*/
224
225
226   /**
227    * Destroy the winsys.
228    */
229   void (*destroy)(struct i915_winsys *iws);
230};
231
232#endif
233