1 /********************************************************** 2 * Copyright 2008-2009 VMware, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 **********************************************************/ 25 26 /** 27 * @file 28 * VMware SVGA specific winsys interface. 29 * 30 * @author Jose Fonseca <jfonseca@vmware.com> 31 * 32 * Documentation taken from the VMware SVGA DDK. 33 */ 34 35 #ifndef SVGA_WINSYS_H_ 36 #define SVGA_WINSYS_H_ 37 38 39 #include "svga_types.h" 40 #include "svga_reg.h" 41 #include "svga3d_reg.h" 42 43 #include "pipe/p_compiler.h" 44 #include "pipe/p_defines.h" 45 46 47 struct svga_winsys_screen; 48 struct svga_winsys_buffer; 49 struct pipe_screen; 50 struct pipe_context; 51 struct pipe_fence_handle; 52 struct pipe_resource; 53 struct svga_region; 54 struct winsys_handle; 55 56 57 #define SVGA_BUFFER_USAGE_PINNED (1 << 0) 58 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1) 59 60 61 #define SVGA_RELOC_WRITE 0x1 62 #define SVGA_RELOC_READ 0x2 63 64 #define SVGA_FENCE_FLAG_EXEC (1 << 0) 65 #define SVGA_FENCE_FLAG_QUERY (1 << 1) 66 67 /** Opaque surface handle */ 68 struct svga_winsys_surface; 69 70 71 /** 72 * SVGA per-context winsys interface. 73 */ 74 struct svga_winsys_context 75 { 76 void 77 (*destroy)(struct svga_winsys_context *swc); 78 79 void * 80 (*reserve)(struct svga_winsys_context *swc, 81 uint32_t nr_bytes, uint32_t nr_relocs ); 82 83 /** 84 * Emit a relocation for a host surface. 85 * 86 * @param flags bitmask of SVGA_RELOC_* flags 87 * 88 * NOTE: Order of this call does matter. It should be the same order 89 * as relocations appear in the command buffer. 90 */ 91 void 92 (*surface_relocation)(struct svga_winsys_context *swc, 93 uint32 *sid, 94 struct svga_winsys_surface *surface, 95 unsigned flags); 96 97 /** 98 * Emit a relocation for a guest memory region. 99 * 100 * @param flags bitmask of SVGA_RELOC_* flags 101 * 102 * NOTE: Order of this call does matter. It should be the same order 103 * as relocations appear in the command buffer. 104 */ 105 void 106 (*region_relocation)(struct svga_winsys_context *swc, 107 struct SVGAGuestPtr *ptr, 108 struct svga_winsys_buffer *buffer, 109 uint32 offset, 110 unsigned flags); 111 112 void 113 (*commit)(struct svga_winsys_context *swc); 114 115 enum pipe_error 116 (*flush)(struct svga_winsys_context *swc, 117 struct pipe_fence_handle **pfence); 118 119 /** 120 * Context ID used to fill in the commands 121 * 122 * Context IDs are arbitrary small non-negative integers, 123 * global to the entire SVGA device. 124 */ 125 uint32 cid; 126 }; 127 128 129 /** 130 * SVGA per-screen winsys interface. 131 */ 132 struct svga_winsys_screen 133 { 134 void 135 (*destroy)(struct svga_winsys_screen *sws); 136 137 SVGA3dHardwareVersion 138 (*get_hw_version)(struct svga_winsys_screen *sws); 139 140 boolean 141 (*get_cap)(struct svga_winsys_screen *sws, 142 SVGA3dDevCapIndex index, 143 SVGA3dDevCapResult *result); 144 145 /** 146 * Create a new context. 147 * 148 * Context objects encapsulate all render state, and shader 149 * objects are per-context. 150 * 151 * Surfaces are not per-context. The same surface can be shared 152 * between multiple contexts, and surface operations can occur 153 * without a context. 154 */ 155 struct svga_winsys_context * 156 (*context_create)(struct svga_winsys_screen *sws); 157 158 159 /** 160 * This creates a "surface" object in the SVGA3D device, 161 * and returns the surface ID (sid). Surfaces are generic 162 * containers for host VRAM objects like textures, vertex 163 * buffers, and depth/stencil buffers. 164 * 165 * Surfaces are hierarchial: 166 * 167 * - Surface may have multiple faces (for cube maps) 168 * 169 * - Each face has a list of mipmap levels 170 * 171 * - Each mipmap image may have multiple volume 172 * slices, if the image is three dimensional. 173 * 174 * - Each slice is a 2D array of 'blocks' 175 * 176 * - Each block may be one or more pixels. 177 * (Usually 1, more for DXT or YUV formats.) 178 * 179 * Surfaces are generic host VRAM objects. The SVGA3D device 180 * may optimize surfaces according to the format they were 181 * created with, but this format does not limit the ways in 182 * which the surface may be used. For example, a depth surface 183 * can be used as a texture, or a floating point image may 184 * be used as a vertex buffer. Some surface usages may be 185 * lower performance, due to software emulation, but any 186 * usage should work with any surface. 187 */ 188 struct svga_winsys_surface * 189 (*surface_create)(struct svga_winsys_screen *sws, 190 SVGA3dSurfaceFlags flags, 191 SVGA3dSurfaceFormat format, 192 SVGA3dSize size, 193 uint32 numFaces, 194 uint32 numMipLevels); 195 196 /** 197 * Creates a surface from a winsys handle. 198 * Used to implement pipe_screen::resource_from_handle. 199 */ 200 struct svga_winsys_surface * 201 (*surface_from_handle)(struct svga_winsys_screen *sws, 202 struct winsys_handle *whandle, 203 SVGA3dSurfaceFormat *format); 204 205 /** 206 * Get a winsys_handle from a surface. 207 * Used to implement pipe_screen::resource_get_handle. 208 */ 209 boolean 210 (*surface_get_handle)(struct svga_winsys_screen *sws, 211 struct svga_winsys_surface *surface, 212 unsigned stride, 213 struct winsys_handle *whandle); 214 215 /** 216 * Whether this surface is sitting in a validate list 217 */ 218 boolean 219 (*surface_is_flushed)(struct svga_winsys_screen *sws, 220 struct svga_winsys_surface *surface); 221 222 /** 223 * Reference a SVGA3D surface object. This allows sharing of a 224 * surface between different objects. 225 */ 226 void 227 (*surface_reference)(struct svga_winsys_screen *sws, 228 struct svga_winsys_surface **pdst, 229 struct svga_winsys_surface *src); 230 231 /** 232 * Buffer management. Buffer attributes are mostly fixed over its lifetime. 233 * 234 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags. 235 * 236 * alignment indicates the client's alignment requirements, eg for 237 * SSE instructions. 238 */ 239 struct svga_winsys_buffer * 240 (*buffer_create)( struct svga_winsys_screen *sws, 241 unsigned alignment, 242 unsigned usage, 243 unsigned size ); 244 245 /** 246 * Map the entire data store of a buffer object into the client's address. 247 * usage is a bitmask of PIPE_TRANSFER_* 248 */ 249 void * 250 (*buffer_map)( struct svga_winsys_screen *sws, 251 struct svga_winsys_buffer *buf, 252 unsigned usage ); 253 254 void 255 (*buffer_unmap)( struct svga_winsys_screen *sws, 256 struct svga_winsys_buffer *buf ); 257 258 void 259 (*buffer_destroy)( struct svga_winsys_screen *sws, 260 struct svga_winsys_buffer *buf ); 261 262 263 /** 264 * Reference a fence object. 265 */ 266 void 267 (*fence_reference)( struct svga_winsys_screen *sws, 268 struct pipe_fence_handle **pdst, 269 struct pipe_fence_handle *src ); 270 271 /** 272 * Checks whether the fence has been signalled. 273 * \param flags driver-specific meaning 274 * \return zero on success. 275 */ 276 int (*fence_signalled)( struct svga_winsys_screen *sws, 277 struct pipe_fence_handle *fence, 278 unsigned flag ); 279 280 /** 281 * Wait for the fence to finish. 282 * \param flags driver-specific meaning 283 * \return zero on success. 284 */ 285 int (*fence_finish)( struct svga_winsys_screen *sws, 286 struct pipe_fence_handle *fence, 287 unsigned flag ); 288 289 }; 290 291 292 struct svga_winsys_screen * 293 svga_winsys_screen(struct pipe_screen *screen); 294 295 struct svga_winsys_context * 296 svga_winsys_context(struct pipe_context *context); 297 298 struct pipe_resource * 299 svga_screen_buffer_wrap_surface(struct pipe_screen *screen, 300 enum SVGA3dSurfaceFormat format, 301 struct svga_winsys_surface *srf); 302 303 struct svga_winsys_surface * 304 svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer); 305 306 #endif /* SVGA_WINSYS_H_ */ 307