radeon_winsys.h revision 363ff844753c46ac9c13866627e096b091ea81f8
1/* 2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com> 3 * Copyright 2010 Marek Olšák <maraeo@gmail.com> 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 * on the rights to use, copy, modify, merge, publish, distribute, sub 9 * license, and/or sell copies of the Software, and to permit persons to whom 10 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 24#ifndef RADEON_WINSYS_H 25#define RADEON_WINSYS_H 26 27/* The public winsys interface header for the radeon driver. */ 28 29/* R300 features in DRM. 30 * 31 * 2.6.0: 32 * - Hyper-Z 33 * - GB_Z_PEQ_CONFIG on rv350->r4xx 34 * - R500 FG_ALPHA_VALUE 35 * 36 * 2.8.0: 37 * - R500 US_FORMAT regs 38 * - R500 ARGB2101010 colorbuffer 39 * - CMask and AA regs 40 * - R16F/RG16F 41 */ 42 43#include "pipebuffer/pb_bufmgr.h" 44#include "pipe/p_defines.h" 45#include "pipe/p_state.h" 46 47#define RADEON_MAX_CMDBUF_DWORDS (16 * 1024) 48#define RADEON_FLUSH_ASYNC (1 << 0) 49 50/* Tiling flags. */ 51enum radeon_bo_layout { 52 RADEON_LAYOUT_LINEAR = 0, 53 RADEON_LAYOUT_TILED, 54 RADEON_LAYOUT_SQUARETILED, 55 56 RADEON_LAYOUT_UNKNOWN 57}; 58 59enum radeon_bo_usage { /* bitfield */ 60 RADEON_USAGE_READ = 2, 61 RADEON_USAGE_WRITE = 4, 62 RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE 63}; 64 65struct winsys_handle; 66 67struct radeon_winsys_cs_handle { /* for write_reloc etc. */ 68 struct { 69 struct pb_buffer base; 70 } _private; 71 72 unsigned last_flush; 73 unsigned binding; 74}; 75 76struct radeon_winsys_cs { 77 unsigned cdw; /* Number of used dwords. */ 78 uint32_t *buf; /* The command buffer. */ 79}; 80 81struct radeon_info { 82 uint32_t pci_id; 83 uint32_t gart_size; 84 uint32_t vram_size; 85 86 uint32_t drm_major; /* version */ 87 uint32_t drm_minor; 88 uint32_t drm_patchlevel; 89 90 uint32_t r300_num_gb_pipes; 91 uint32_t r300_num_z_pipes; 92 93 uint32_t r600_num_backends; 94 uint32_t r600_clock_crystal_freq; 95 uint32_t r600_tiling_config; 96 uint32_t r600_num_tile_pipes; 97 uint32_t r600_backend_map; 98 boolean r600_backend_map_valid; 99}; 100 101enum radeon_feature_id { 102 RADEON_FID_R300_HYPERZ_ACCESS, /* ZMask + HiZ */ 103 RADEON_FID_R300_CMASK_ACCESS, 104}; 105 106struct radeon_winsys { 107 /** 108 * Destroy this winsys. 109 * 110 * \param ws The winsys this function is called from. 111 */ 112 void (*destroy)(struct radeon_winsys *ws); 113 114 /** 115 * Query an info structure from winsys. 116 * 117 * \param ws The winsys this function is called from. 118 * \param info Return structure 119 */ 120 void (*query_info)(struct radeon_winsys *ws, 121 struct radeon_info *info); 122 123 /************************************************************************** 124 * Buffer management. Buffer attributes are mostly fixed over its lifetime. 125 * 126 * Remember that gallium gets to choose the interface it needs, and the 127 * window systems must then implement that interface (rather than the 128 * other way around...). 129 *************************************************************************/ 130 131 /** 132 * Create a buffer object. 133 * 134 * \param ws The winsys this function is called from. 135 * \param size The size to allocate. 136 * \param alignment An alignment of the buffer in memory. 137 * \param bind A bitmask of the PIPE_BIND_* flags. 138 * \param usage A bitmask of the PIPE_USAGE_* flags. 139 * \return The created buffer object. 140 */ 141 struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws, 142 unsigned size, 143 unsigned alignment, 144 unsigned bind, unsigned usage); 145 146 struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)( 147 struct pb_buffer *buf); 148 149 /** 150 * Map the entire data store of a buffer object into the client's address 151 * space. 152 * 153 * \param buf A winsys buffer object to map. 154 * \param cs A command stream to flush if the buffer is referenced by it. 155 * \param usage A bitmask of the PIPE_TRANSFER_* flags. 156 * \return The pointer at the beginning of the buffer. 157 */ 158 void *(*buffer_map)(struct pb_buffer *buf, 159 struct radeon_winsys_cs *cs, 160 enum pipe_transfer_usage usage); 161 162 /** 163 * Unmap a buffer object from the client's address space. 164 * 165 * \param buf A winsys buffer object to unmap. 166 */ 167 void (*buffer_unmap)(struct pb_buffer *buf); 168 169 /** 170 * Return TRUE if a buffer object is being used by the GPU. 171 * 172 * \param buf A winsys buffer object. 173 * \param usage Only check whether the buffer is busy for the given usage. 174 */ 175 boolean (*buffer_is_busy)(struct pb_buffer *buf, 176 enum radeon_bo_usage usage); 177 178 /** 179 * Wait for a buffer object until it is not used by a GPU. This is 180 * equivalent to a fence placed after the last command using the buffer, 181 * and synchronizing to the fence. 182 * 183 * \param buf A winsys buffer object to wait for. 184 * \param usage Only wait until the buffer is idle for the given usage, 185 * but may still be busy for some other usage. 186 */ 187 void (*buffer_wait)(struct pb_buffer *buf, enum radeon_bo_usage usage); 188 189 /** 190 * Return tiling flags describing a memory layout of a buffer object. 191 * 192 * \param buf A winsys buffer object to get the flags from. 193 * \param macrotile A pointer to the return value of the microtile flag. 194 * \param microtile A pointer to the return value of the macrotile flag. 195 * 196 * \note microtile and macrotile are not bitmasks! 197 */ 198 void (*buffer_get_tiling)(struct pb_buffer *buf, 199 enum radeon_bo_layout *microtile, 200 enum radeon_bo_layout *macrotile); 201 202 /** 203 * Set tiling flags describing a memory layout of a buffer object. 204 * 205 * \param buf A winsys buffer object to set the flags for. 206 * \param cs A command stream to flush if the buffer is referenced by it. 207 * \param macrotile A macrotile flag. 208 * \param microtile A microtile flag. 209 * \param stride A stride of the buffer in bytes, for texturing. 210 * 211 * \note microtile and macrotile are not bitmasks! 212 */ 213 void (*buffer_set_tiling)(struct pb_buffer *buf, 214 struct radeon_winsys_cs *cs, 215 enum radeon_bo_layout microtile, 216 enum radeon_bo_layout macrotile, 217 unsigned stride); 218 219 /** 220 * Get a winsys buffer from a winsys handle. The internal structure 221 * of the handle is platform-specific and only a winsys should access it. 222 * 223 * \param ws The winsys this function is called from. 224 * \param whandle A winsys handle pointer as was received from a state 225 * tracker. 226 * \param stride The returned buffer stride in bytes. 227 */ 228 struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws, 229 struct winsys_handle *whandle, 230 unsigned *stride); 231 232 /** 233 * Get a winsys handle from a winsys buffer. The internal structure 234 * of the handle is platform-specific and only a winsys should access it. 235 * 236 * \param buf A winsys buffer object to get the handle from. 237 * \param whandle A winsys handle pointer. 238 * \param stride A stride of the buffer in bytes, for texturing. 239 * \return TRUE on success. 240 */ 241 boolean (*buffer_get_handle)(struct pb_buffer *buf, 242 unsigned stride, 243 struct winsys_handle *whandle); 244 245 /************************************************************************** 246 * Command submission. 247 * 248 * Each pipe context should create its own command stream and submit 249 * commands independently of other contexts. 250 *************************************************************************/ 251 252 /** 253 * Create a command stream. 254 * 255 * \param ws The winsys this function is called from. 256 */ 257 struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws); 258 259 /** 260 * Destroy a command stream. 261 * 262 * \param cs A command stream to destroy. 263 */ 264 void (*cs_destroy)(struct radeon_winsys_cs *cs); 265 266 /** 267 * Add a new buffer relocation. Every relocation must first be added 268 * before it can be written. 269 * 270 * \param cs A command stream to add buffer for validation against. 271 * \param buf A winsys buffer to validate. 272 * \param usage Whether the buffer is used for read and/or write. 273 * \return Relocation index. 274 */ 275 unsigned (*cs_add_reloc)(struct radeon_winsys_cs *cs, 276 struct radeon_winsys_cs_handle *buf, 277 enum radeon_bo_usage usage); 278 279 /** 280 * Return TRUE if there is enough memory in VRAM and GTT for the relocs 281 * added so far. If the validation fails, all the relocations which have 282 * been added since the last call of cs_validate will be removed and 283 * the CS will be flushed (provided there are still any relocations). 284 * 285 * \param cs A command stream to validate. 286 */ 287 boolean (*cs_validate)(struct radeon_winsys_cs *cs); 288 289 /** 290 * Write a relocated dword to a command buffer. 291 * 292 * \param cs A command stream the relocation is written to. 293 * \param buf A winsys buffer to write the relocation for. 294 */ 295 void (*cs_write_reloc)(struct radeon_winsys_cs *cs, 296 struct radeon_winsys_cs_handle *buf); 297 298 /** 299 * Flush a command stream. 300 * 301 * \param cs A command stream to flush. 302 * \param flags, RADEON_FLUSH_ASYNC or 0. 303 */ 304 void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags); 305 306 /** 307 * Set a flush callback which is called from winsys when flush is 308 * required. 309 * 310 * \param cs A command stream to set the callback for. 311 * \param flush A flush callback function associated with the command stream. 312 * \param user A user pointer that will be passed to the flush callback. 313 */ 314 void (*cs_set_flush_callback)(struct radeon_winsys_cs *cs, 315 void (*flush)(void *ctx, unsigned flags), 316 void *ctx); 317 318 /** 319 * Return TRUE if a buffer is referenced by a command stream. 320 * 321 * \param cs A command stream. 322 * \param buf A winsys buffer. 323 */ 324 boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs, 325 struct radeon_winsys_cs_handle *buf); 326 327 /** 328 * Request access to a feature for a command stream. 329 * 330 * \param cs A command stream. 331 * \param fid Feature ID, one of RADEON_FID_* 332 * \param enable Whether to enable or disable the feature. 333 */ 334 boolean (*cs_request_feature)(struct radeon_winsys_cs *cs, 335 enum radeon_feature_id fid, 336 boolean enable); 337}; 338 339#endif 340