i915_winsys.h revision 287c94ea4987033f9c99a2f91c5750c9083504ca
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 56enum i915_winsys_buffer_tile 57{ 58 I915_TILE_NONE, 59 I915_TILE_X, 60 I915_TILE_Y 61}; 62 63struct 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 82struct i915_winsys { 83 84 /** 85 * Batchbuffer functions. 86 */ 87 /*@{*/ 88 /** 89 * Create a new batchbuffer. 90 */ 91 struct i915_winsys_batchbuffer * 92 (*batchbuffer_create)(struct i915_winsys *iws); 93 94 /** 95 * Emit a relocation to a buffer. 96 * Target position in batchbuffer is the same as ptr. 97 * 98 * @batch 99 * @reloc buffer address to be inserted into target. 100 * @usage how is the hardware going to use the buffer. 101 * @offset add this to the reloc buffers address 102 * @target buffer where to write the address, null for batchbuffer. 103 */ 104 int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch, 105 struct i915_winsys_buffer *reloc, 106 enum i915_winsys_buffer_usage usage, 107 unsigned offset); 108 109 /** 110 * Flush a bufferbatch. 111 */ 112 void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch, 113 struct pipe_fence_handle **fence); 114 115 /** 116 * Destroy a batchbuffer. 117 */ 118 void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch); 119 /*@}*/ 120 121 122 /** 123 * Buffer functions. 124 */ 125 /*@{*/ 126 /** 127 * Create a buffer. 128 */ 129 struct i915_winsys_buffer * 130 (*buffer_create)(struct i915_winsys *iws, 131 unsigned size, unsigned alignment, 132 enum i915_winsys_buffer_type type); 133 134 /** 135 * Creates a buffer from a handle. 136 * Used to implement pipe_screen::resource_from_handle. 137 * Also provides the stride information needed for the 138 * texture via the stride argument. 139 */ 140 struct i915_winsys_buffer * 141 (*buffer_from_handle)(struct i915_winsys *iws, 142 struct winsys_handle *whandle, 143 unsigned *stride); 144 145 /** 146 * Used to implement pipe_screen::resource_get_handle. 147 * The winsys might need the stride information. 148 */ 149 boolean (*buffer_get_handle)(struct i915_winsys *iws, 150 struct i915_winsys_buffer *buffer, 151 struct winsys_handle *whandle, 152 unsigned stride); 153 154 /** 155 * Fence a buffer with a fence reg. 156 * Not to be confused with pipe_fence_handle. 157 */ 158 int (*buffer_set_fence_reg)(struct i915_winsys *iws, 159 struct i915_winsys_buffer *buffer, 160 unsigned stride, 161 enum i915_winsys_buffer_tile tile); 162 163 /** 164 * Map a buffer. 165 */ 166 void *(*buffer_map)(struct i915_winsys *iws, 167 struct i915_winsys_buffer *buffer, 168 boolean write); 169 170 /** 171 * Unmap a buffer. 172 */ 173 void (*buffer_unmap)(struct i915_winsys *iws, 174 struct i915_winsys_buffer *buffer); 175 176 /** 177 * Write to a buffer. 178 * 179 * Arguments follows pipe_buffer_write. 180 */ 181 int (*buffer_write)(struct i915_winsys *iws, 182 struct i915_winsys_buffer *dst, 183 size_t offset, 184 size_t size, 185 const void *data); 186 187 void (*buffer_destroy)(struct i915_winsys *iws, 188 struct i915_winsys_buffer *buffer); 189 /*@}*/ 190 191 192 /** 193 * Fence functions. 194 */ 195 /*@{*/ 196 /** 197 * Reference fence and set ptr to fence. 198 */ 199 void (*fence_reference)(struct i915_winsys *iws, 200 struct pipe_fence_handle **ptr, 201 struct pipe_fence_handle *fence); 202 203 /** 204 * Check if a fence has finished. 205 */ 206 int (*fence_signalled)(struct i915_winsys *iws, 207 struct pipe_fence_handle *fence); 208 209 /** 210 * Wait on a fence to finish. 211 */ 212 int (*fence_finish)(struct i915_winsys *iws, 213 struct pipe_fence_handle *fence); 214 /*@}*/ 215 216 217 /** 218 * Destroy the winsys. 219 */ 220 void (*destroy)(struct i915_winsys *iws); 221}; 222 223 224/** 225 * Create i915 pipe_screen. 226 */ 227struct pipe_screen *i915_create_screen(struct i915_winsys *iws, unsigned pci_id); 228 229 230#endif 231