radeon_winsys.h revision 29e55bc5f1b6d7375b6a86e24ca4ae58e399011e
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#include "libdrm/radeon_surface.h" 47 48#define RADEON_MAX_CMDBUF_DWORDS (16 * 1024) 49 50#define RADEON_FLUSH_ASYNC (1 << 0) 51#define RADEON_FLUSH_KEEP_TILING_FLAGS (1 << 1) /* needs DRM 2.12.0 */ 52 53/* Tiling flags. */ 54enum radeon_bo_layout { 55 RADEON_LAYOUT_LINEAR = 0, 56 RADEON_LAYOUT_TILED, 57 RADEON_LAYOUT_SQUARETILED, 58 59 RADEON_LAYOUT_UNKNOWN 60}; 61 62enum radeon_bo_domain { /* bitfield */ 63 RADEON_DOMAIN_GTT = 2, 64 RADEON_DOMAIN_VRAM = 4 65}; 66 67enum radeon_bo_usage { /* bitfield */ 68 RADEON_USAGE_READ = 2, 69 RADEON_USAGE_WRITE = 4, 70 RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE 71}; 72 73struct winsys_handle; 74struct radeon_winsys_cs_handle; 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 boolean r600_virtual_address; 100 uint32_t r600_va_start; 101 uint32_t r600_ib_vm_max_size; 102 boolean r600_has_streamout; 103}; 104 105enum radeon_feature_id { 106 RADEON_FID_R300_HYPERZ_ACCESS, /* ZMask + HiZ */ 107 RADEON_FID_R300_CMASK_ACCESS, 108}; 109 110struct radeon_winsys { 111 /** 112 * Destroy this winsys. 113 * 114 * \param ws The winsys this function is called from. 115 */ 116 void (*destroy)(struct radeon_winsys *ws); 117 118 /** 119 * Query an info structure from winsys. 120 * 121 * \param ws The winsys this function is called from. 122 * \param info Return structure 123 */ 124 void (*query_info)(struct radeon_winsys *ws, 125 struct radeon_info *info); 126 127 /************************************************************************** 128 * Buffer management. Buffer attributes are mostly fixed over its lifetime. 129 * 130 * Remember that gallium gets to choose the interface it needs, and the 131 * window systems must then implement that interface (rather than the 132 * other way around...). 133 *************************************************************************/ 134 135 /** 136 * Create a buffer object. 137 * 138 * \param ws The winsys this function is called from. 139 * \param size The size to allocate. 140 * \param alignment An alignment of the buffer in memory. 141 * \param bind A bitmask of the PIPE_BIND_* flags. 142 * \param domain A bitmask of the RADEON_DOMAIN_* flags. 143 * \return The created buffer object. 144 */ 145 struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws, 146 unsigned size, 147 unsigned alignment, 148 unsigned bind, 149 enum radeon_bo_domain domain); 150 151 struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)( 152 struct pb_buffer *buf); 153 154 /** 155 * Map the entire data store of a buffer object into the client's address 156 * space. 157 * 158 * \param buf A winsys buffer object to map. 159 * \param cs A command stream to flush if the buffer is referenced by it. 160 * \param usage A bitmask of the PIPE_TRANSFER_* flags. 161 * \return The pointer at the beginning of the buffer. 162 */ 163 void *(*buffer_map)(struct pb_buffer *buf, 164 struct radeon_winsys_cs *cs, 165 enum pipe_transfer_usage usage); 166 167 /** 168 * Unmap a buffer object from the client's address space. 169 * 170 * \param buf A winsys buffer object to unmap. 171 */ 172 void (*buffer_unmap)(struct pb_buffer *buf); 173 174 /** 175 * Return TRUE if a buffer object is being used by the GPU. 176 * 177 * \param buf A winsys buffer object. 178 * \param usage Only check whether the buffer is busy for the given usage. 179 */ 180 boolean (*buffer_is_busy)(struct pb_buffer *buf, 181 enum radeon_bo_usage usage); 182 183 /** 184 * Wait for a buffer object until it is not used by a GPU. This is 185 * equivalent to a fence placed after the last command using the buffer, 186 * and synchronizing to the fence. 187 * 188 * \param buf A winsys buffer object to wait for. 189 * \param usage Only wait until the buffer is idle for the given usage, 190 * but may still be busy for some other usage. 191 */ 192 void (*buffer_wait)(struct pb_buffer *buf, enum radeon_bo_usage usage); 193 194 /** 195 * Return tiling flags describing a memory layout of a buffer object. 196 * 197 * \param buf A winsys buffer object to get the flags from. 198 * \param macrotile A pointer to the return value of the microtile flag. 199 * \param microtile A pointer to the return value of the macrotile flag. 200 * 201 * \note microtile and macrotile are not bitmasks! 202 */ 203 void (*buffer_get_tiling)(struct pb_buffer *buf, 204 enum radeon_bo_layout *microtile, 205 enum radeon_bo_layout *macrotile, 206 unsigned *bankw, unsigned *bankh, 207 unsigned *tile_split, 208 unsigned *stencil_tile_split, 209 unsigned *mtilea); 210 211 /** 212 * Set tiling flags describing a memory layout of a buffer object. 213 * 214 * \param buf A winsys buffer object to set the flags for. 215 * \param cs A command stream to flush if the buffer is referenced by it. 216 * \param macrotile A macrotile flag. 217 * \param microtile A microtile flag. 218 * \param stride A stride of the buffer in bytes, for texturing. 219 * 220 * \note microtile and macrotile are not bitmasks! 221 */ 222 void (*buffer_set_tiling)(struct pb_buffer *buf, 223 struct radeon_winsys_cs *cs, 224 enum radeon_bo_layout microtile, 225 enum radeon_bo_layout macrotile, 226 unsigned stride); 227 228 /** 229 * Get a winsys buffer from a winsys handle. The internal structure 230 * of the handle is platform-specific and only a winsys should access it. 231 * 232 * \param ws The winsys this function is called from. 233 * \param whandle A winsys handle pointer as was received from a state 234 * tracker. 235 * \param stride The returned buffer stride in bytes. 236 */ 237 struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws, 238 struct winsys_handle *whandle, 239 unsigned *stride); 240 241 /** 242 * Get a winsys handle from a winsys buffer. The internal structure 243 * of the handle is platform-specific and only a winsys should access it. 244 * 245 * \param buf A winsys buffer object to get the handle from. 246 * \param whandle A winsys handle pointer. 247 * \param stride A stride of the buffer in bytes, for texturing. 248 * \return TRUE on success. 249 */ 250 boolean (*buffer_get_handle)(struct pb_buffer *buf, 251 unsigned stride, 252 struct winsys_handle *whandle); 253 254 /** 255 * Return the virtual address of a buffer. 256 * 257 * \param buf A winsys buffer object 258 * \return virtual address 259 */ 260 uint64_t (*buffer_get_virtual_address)(struct pb_buffer *buf); 261 262 /************************************************************************** 263 * Command submission. 264 * 265 * Each pipe context should create its own command stream and submit 266 * commands independently of other contexts. 267 *************************************************************************/ 268 269 /** 270 * Create a command stream. 271 * 272 * \param ws The winsys this function is called from. 273 */ 274 struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws); 275 276 /** 277 * Destroy a command stream. 278 * 279 * \param cs A command stream to destroy. 280 */ 281 void (*cs_destroy)(struct radeon_winsys_cs *cs); 282 283 /** 284 * Add a new buffer relocation. Every relocation must first be added 285 * before it can be written. 286 * 287 * \param cs A command stream to add buffer for validation against. 288 * \param buf A winsys buffer to validate. 289 * \param usage Whether the buffer is used for read and/or write. 290 * \param domain Bitmask of the RADEON_DOMAIN_* flags. 291 * \return Relocation index. 292 */ 293 unsigned (*cs_add_reloc)(struct radeon_winsys_cs *cs, 294 struct radeon_winsys_cs_handle *buf, 295 enum radeon_bo_usage usage, 296 enum radeon_bo_domain domain); 297 298 /** 299 * Return TRUE if there is enough memory in VRAM and GTT for the relocs 300 * added so far. If the validation fails, all the relocations which have 301 * been added since the last call of cs_validate will be removed and 302 * the CS will be flushed (provided there are still any relocations). 303 * 304 * \param cs A command stream to validate. 305 */ 306 boolean (*cs_validate)(struct radeon_winsys_cs *cs); 307 308 /** 309 * Write a relocated dword to a command buffer. 310 * 311 * \param cs A command stream the relocation is written to. 312 * \param buf A winsys buffer to write the relocation for. 313 */ 314 void (*cs_write_reloc)(struct radeon_winsys_cs *cs, 315 struct radeon_winsys_cs_handle *buf); 316 317 /** 318 * Flush a command stream. 319 * 320 * \param cs A command stream to flush. 321 * \param flags, RADEON_FLUSH_ASYNC or 0. 322 */ 323 void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags); 324 325 /** 326 * Set a flush callback which is called from winsys when flush is 327 * required. 328 * 329 * \param cs A command stream to set the callback for. 330 * \param flush A flush callback function associated with the command stream. 331 * \param user A user pointer that will be passed to the flush callback. 332 */ 333 void (*cs_set_flush_callback)(struct radeon_winsys_cs *cs, 334 void (*flush)(void *ctx, unsigned flags), 335 void *ctx); 336 337 /** 338 * Return TRUE if a buffer is referenced by a command stream. 339 * 340 * \param cs A command stream. 341 * \param buf A winsys buffer. 342 */ 343 boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs, 344 struct radeon_winsys_cs_handle *buf, 345 enum radeon_bo_usage usage); 346 347 /** 348 * Request access to a feature for a command stream. 349 * 350 * \param cs A command stream. 351 * \param fid Feature ID, one of RADEON_FID_* 352 * \param enable Whether to enable or disable the feature. 353 */ 354 boolean (*cs_request_feature)(struct radeon_winsys_cs *cs, 355 enum radeon_feature_id fid, 356 boolean enable); 357 358 /** 359 * Initialize surface 360 * 361 * \param ws The winsys this function is called from. 362 * \param surf Surface structure ptr 363 */ 364 int (*surface_init)(struct radeon_winsys *ws, 365 struct radeon_surface *surf); 366 367 /** 368 * Find best values for a surface 369 * 370 * \param ws The winsys this function is called from. 371 * \param surf Surface structure ptr 372 */ 373 int (*surface_best)(struct radeon_winsys *ws, 374 struct radeon_surface *surf); 375}; 376 377#endif 378