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