svga_winsys.h revision cdc920a0
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 47struct svga_winsys_screen; 48struct svga_winsys_buffer; 49struct pipe_screen; 50struct pipe_context; 51struct pipe_fence_handle; 52struct pipe_texture; 53struct svga_region; 54 55 56#define SVGA_BUFFER_USAGE_PINNED (PIPE_BUFFER_USAGE_CUSTOM << 0) 57#define SVGA_BUFFER_USAGE_WRAPPED (PIPE_BUFFER_USAGE_CUSTOM << 1) 58 59 60/** Opaque surface handle */ 61struct svga_winsys_surface; 62 63/** Opaque buffer handle */ 64struct svga_winsys_handle; 65 66 67/** 68 * SVGA per-context winsys interface. 69 */ 70struct svga_winsys_context 71{ 72 void 73 (*destroy)(struct svga_winsys_context *swc); 74 75 void * 76 (*reserve)(struct svga_winsys_context *swc, 77 uint32_t nr_bytes, uint32_t nr_relocs ); 78 79 /** 80 * Emit a relocation for a host surface. 81 * 82 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE 83 * 84 * NOTE: Order of this call does matter. It should be the same order 85 * as relocations appear in the command buffer. 86 */ 87 void 88 (*surface_relocation)(struct svga_winsys_context *swc, 89 uint32 *sid, 90 struct svga_winsys_surface *surface, 91 unsigned flags); 92 93 /** 94 * Emit a relocation for a guest memory region. 95 * 96 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE 97 * 98 * NOTE: Order of this call does matter. It should be the same order 99 * as relocations appear in the command buffer. 100 */ 101 void 102 (*region_relocation)(struct svga_winsys_context *swc, 103 struct SVGAGuestPtr *ptr, 104 struct svga_winsys_buffer *buffer, 105 uint32 offset, 106 unsigned flags); 107 108 void 109 (*commit)(struct svga_winsys_context *swc); 110 111 enum pipe_error 112 (*flush)(struct svga_winsys_context *swc, 113 struct pipe_fence_handle **pfence); 114 115 /** 116 * Context ID used to fill in the commands 117 * 118 * Context IDs are arbitrary small non-negative integers, 119 * global to the entire SVGA device. 120 */ 121 uint32 cid; 122}; 123 124 125/** 126 * SVGA per-screen winsys interface. 127 */ 128struct svga_winsys_screen 129{ 130 void 131 (*destroy)(struct svga_winsys_screen *sws); 132 133 boolean 134 (*get_cap)(struct svga_winsys_screen *sws, 135 SVGA3dDevCapIndex index, 136 SVGA3dDevCapResult *result); 137 138 /** 139 * Create a new context. 140 * 141 * Context objects encapsulate all render state, and shader 142 * objects are per-context. 143 * 144 * Surfaces are not per-context. The same surface can be shared 145 * between multiple contexts, and surface operations can occur 146 * without a context. 147 */ 148 struct svga_winsys_context * 149 (*context_create)(struct svga_winsys_screen *sws); 150 151 152 /** 153 * This creates a "surface" object in the SVGA3D device, 154 * and returns the surface ID (sid). Surfaces are generic 155 * containers for host VRAM objects like textures, vertex 156 * buffers, and depth/stencil buffers. 157 * 158 * Surfaces are hierarchial: 159 * 160 * - Surface may have multiple faces (for cube maps) 161 * 162 * - Each face has a list of mipmap levels 163 * 164 * - Each mipmap image may have multiple volume 165 * slices, if the image is three dimensional. 166 * 167 * - Each slice is a 2D array of 'blocks' 168 * 169 * - Each block may be one or more pixels. 170 * (Usually 1, more for DXT or YUV formats.) 171 * 172 * Surfaces are generic host VRAM objects. The SVGA3D device 173 * may optimize surfaces according to the format they were 174 * created with, but this format does not limit the ways in 175 * which the surface may be used. For example, a depth surface 176 * can be used as a texture, or a floating point image may 177 * be used as a vertex buffer. Some surface usages may be 178 * lower performance, due to software emulation, but any 179 * usage should work with any surface. 180 */ 181 struct svga_winsys_surface * 182 (*surface_create)(struct svga_winsys_screen *sws, 183 SVGA3dSurfaceFlags flags, 184 SVGA3dSurfaceFormat format, 185 SVGA3dSize size, 186 uint32 numFaces, 187 uint32 numMipLevels); 188 189 /** 190 * Whether this surface is sitting in a validate list 191 */ 192 boolean 193 (*surface_is_flushed)(struct svga_winsys_screen *sws, 194 struct svga_winsys_surface *surface); 195 196 /** 197 * Reference a SVGA3D surface object. This allows sharing of a 198 * surface between different objects. 199 */ 200 void 201 (*surface_reference)(struct svga_winsys_screen *sws, 202 struct svga_winsys_surface **pdst, 203 struct svga_winsys_surface *src); 204 205 /** 206 * Buffer management. Buffer attributes are mostly fixed over its lifetime. 207 * 208 * Remember that gallium gets to choose the interface it needs, and the 209 * window systems must then implement that interface (rather than the 210 * other way around...). 211 * 212 * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This 213 * usage argument is only an optimization hint, not a guarantee, therefore 214 * proper behavior must be observed in all circumstances. 215 * 216 * alignment indicates the client's alignment requirements, eg for 217 * SSE instructions. 218 */ 219 struct svga_winsys_buffer * 220 (*buffer_create)( struct svga_winsys_screen *sws, 221 unsigned alignment, 222 unsigned usage, 223 unsigned size ); 224 225 /** 226 * Map the entire data store of a buffer object into the client's address. 227 * flags is a bitmask of: 228 * - PIPE_BUFFER_USAGE_CPU_READ/WRITE 229 * - PIPE_BUFFER_USAGE_DONTBLOCK 230 * - PIPE_BUFFER_USAGE_UNSYNCHRONIZED 231 */ 232 void * 233 (*buffer_map)( struct svga_winsys_screen *sws, 234 struct svga_winsys_buffer *buf, 235 unsigned usage ); 236 237 void 238 (*buffer_unmap)( struct svga_winsys_screen *sws, 239 struct svga_winsys_buffer *buf ); 240 241 void 242 (*buffer_destroy)( struct svga_winsys_screen *sws, 243 struct svga_winsys_buffer *buf ); 244 245 246 /** 247 * Reference a fence object. 248 */ 249 void 250 (*fence_reference)( struct svga_winsys_screen *sws, 251 struct pipe_fence_handle **pdst, 252 struct pipe_fence_handle *src ); 253 254 /** 255 * Checks whether the fence has been signalled. 256 * \param flags driver-specific meaning 257 * \return zero on success. 258 */ 259 int (*fence_signalled)( struct svga_winsys_screen *sws, 260 struct pipe_fence_handle *fence, 261 unsigned flag ); 262 263 /** 264 * Wait for the fence to finish. 265 * \param flags driver-specific meaning 266 * \return zero on success. 267 */ 268 int (*fence_finish)( struct svga_winsys_screen *sws, 269 struct pipe_fence_handle *fence, 270 unsigned flag ); 271 272}; 273 274 275struct pipe_screen * 276svga_screen_create(struct svga_winsys_screen *sws); 277 278struct svga_winsys_screen * 279svga_winsys_screen(struct pipe_screen *screen); 280 281struct pipe_buffer * 282svga_screen_buffer_wrap_surface(struct pipe_screen *screen, 283 enum SVGA3dSurfaceFormat format, 284 struct svga_winsys_surface *srf); 285 286struct svga_winsys_surface * 287svga_screen_texture_get_winsys_surface(struct pipe_texture *texture); 288struct svga_winsys_surface * 289svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer); 290 291boolean 292svga_screen_buffer_from_texture(struct pipe_texture *texture, 293 struct pipe_buffer **buffer, 294 unsigned *stride); 295 296struct pipe_texture * 297svga_screen_texture_wrap_surface(struct pipe_screen *screen, 298 struct pipe_texture *base, 299 enum SVGA3dSurfaceFormat format, 300 struct svga_winsys_surface *srf); 301 302#endif /* SVGA_WINSYS_H_ */ 303