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