2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
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:
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
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. */
24 #ifndef RADEON_WINSYS_H
25 #define RADEON_WINSYS_H
27 /* The public winsys interface header for the radeon driver. */
29 /* R300 features in DRM.
33 * - GB_Z_PEQ_CONFIG on rv350->r4xx
34 * - R500 FG_ALPHA_VALUE
37 * - R500 US_FORMAT regs
38 * - R500 ARGB2101010 colorbuffer
43 #include "pipebuffer/pb_buffer.h"
44 #include "radeon_surface.h"
46 #define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
48 #define RADEON_FLUSH_ASYNC (1 << 0)
49 #define RADEON_FLUSH_KEEP_TILING_FLAGS (1 << 1) /* needs DRM 2.12.0 */
50 #define RADEON_FLUSH_COMPUTE (1 << 2)
51 #define RADEON_FLUSH_END_OF_FRAME (1 << 3)
54 enum radeon_bo_layout
{
55 RADEON_LAYOUT_LINEAR
= 0,
57 RADEON_LAYOUT_SQUARETILED
,
62 enum radeon_bo_domain
{ /* bitfield */
63 RADEON_DOMAIN_GTT
= 2,
64 RADEON_DOMAIN_VRAM
= 4,
65 RADEON_DOMAIN_VRAM_GTT
= RADEON_DOMAIN_VRAM
| RADEON_DOMAIN_GTT
68 enum radeon_bo_usage
{ /* bitfield */
69 RADEON_USAGE_READ
= 2,
70 RADEON_USAGE_WRITE
= 4,
71 RADEON_USAGE_READWRITE
= RADEON_USAGE_READ
| RADEON_USAGE_WRITE
76 CHIP_R300
, /* R3xx-based cores. */
84 CHIP_R420
, /* R4xx-based cores. */
93 CHIP_RV515
, /* R5xx-based cores. */
157 enum radeon_value_id
{
158 RADEON_REQUESTED_VRAM_MEMORY
,
159 RADEON_REQUESTED_GTT_MEMORY
,
160 RADEON_BUFFER_WAIT_TIME_NS
,
162 RADEON_NUM_CS_FLUSHES
,
163 RADEON_NUM_BYTES_MOVED
,
168 enum radeon_bo_priority
{
170 RADEON_PRIO_SHADER_DATA
, /* shader code, resource descriptors */
171 RADEON_PRIO_SHADER_BUFFER_RO
, /* read-only */
172 RADEON_PRIO_SHADER_TEXTURE_RO
, /* read-only */
173 RADEON_PRIO_SHADER_RESOURCE_RW
, /* buffers, textures, streamout, GS rings, RATs; read/write */
174 RADEON_PRIO_COLOR_BUFFER
,
175 RADEON_PRIO_DEPTH_BUFFER
,
176 RADEON_PRIO_SHADER_TEXTURE_MSAA
,
177 RADEON_PRIO_COLOR_BUFFER_MSAA
,
178 RADEON_PRIO_DEPTH_BUFFER_MSAA
,
179 RADEON_PRIO_COLOR_META
,
180 RADEON_PRIO_DEPTH_META
,
181 RADEON_PRIO_MAX
/* must be <= 15 */
184 struct winsys_handle
;
185 struct radeon_winsys_cs_handle
;
187 struct radeon_winsys_cs
{
188 unsigned cdw
; /* Number of used dwords. */
189 uint32_t *buf
; /* The command buffer. */
190 enum ring_type ring_type
;
195 enum radeon_family family
;
196 enum chip_class chip_class
;
200 uint32_t drm_major
; /* version */
202 uint32_t drm_patchlevel
;
205 uint32_t vce_fw_version
;
207 uint32_t r300_num_gb_pipes
;
208 uint32_t r300_num_z_pipes
;
210 uint32_t r600_num_backends
;
211 uint32_t r600_clock_crystal_freq
;
212 uint32_t r600_tiling_config
;
213 uint32_t r600_num_tile_pipes
;
214 uint32_t r600_max_pipes
;
215 boolean r600_virtual_address
;
216 boolean r600_has_dma
;
218 uint32_t r600_backend_map
;
219 boolean r600_backend_map_valid
;
221 boolean si_tile_mode_array_valid
;
222 uint32_t si_tile_mode_array
[32];
224 boolean cik_macrotile_mode_array_valid
;
225 uint32_t cik_macrotile_mode_array
[16];
228 enum radeon_feature_id
{
229 RADEON_FID_R300_HYPERZ_ACCESS
, /* ZMask + HiZ */
230 RADEON_FID_R300_CMASK_ACCESS
,
233 struct radeon_winsys
{
235 * The screen object this winsys was created for
237 struct pipe_screen
*screen
;
240 * Decrement the winsys reference count.
242 * \param ws The winsys this function is called for.
243 * \return True if the winsys and screen should be destroyed.
245 bool (*unref
)(struct radeon_winsys
*ws
);
248 * Destroy this winsys.
250 * \param ws The winsys this function is called from.
252 void (*destroy
)(struct radeon_winsys
*ws
);
255 * Query an info structure from winsys.
257 * \param ws The winsys this function is called from.
258 * \param info Return structure
260 void (*query_info
)(struct radeon_winsys
*ws
,
261 struct radeon_info
*info
);
263 /**************************************************************************
264 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
266 * Remember that gallium gets to choose the interface it needs, and the
267 * window systems must then implement that interface (rather than the
268 * other way around...).
269 *************************************************************************/
272 * Create a buffer object.
274 * \param ws The winsys this function is called from.
275 * \param size The size to allocate.
276 * \param alignment An alignment of the buffer in memory.
277 * \param use_reusable_pool Whether the cache buffer manager should be used.
278 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
279 * \return The created buffer object.
281 struct pb_buffer
*(*buffer_create
)(struct radeon_winsys
*ws
,
284 boolean use_reusable_pool
,
285 enum radeon_bo_domain domain
);
287 struct radeon_winsys_cs_handle
*(*buffer_get_cs_handle
)(
288 struct pb_buffer
*buf
);
291 * Map the entire data store of a buffer object into the client's address
294 * \param buf A winsys buffer object to map.
295 * \param cs A command stream to flush if the buffer is referenced by it.
296 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
297 * \return The pointer at the beginning of the buffer.
299 void *(*buffer_map
)(struct radeon_winsys_cs_handle
*buf
,
300 struct radeon_winsys_cs
*cs
,
301 enum pipe_transfer_usage usage
);
304 * Unmap a buffer object from the client's address space.
306 * \param buf A winsys buffer object to unmap.
308 void (*buffer_unmap
)(struct radeon_winsys_cs_handle
*buf
);
311 * Return TRUE if a buffer object is being used by the GPU.
313 * \param buf A winsys buffer object.
314 * \param usage Only check whether the buffer is busy for the given usage.
316 boolean (*buffer_is_busy
)(struct pb_buffer
*buf
,
317 enum radeon_bo_usage usage
);
320 * Wait for a buffer object until it is not used by a GPU. This is
321 * equivalent to a fence placed after the last command using the buffer,
322 * and synchronizing to the fence.
324 * \param buf A winsys buffer object to wait for.
325 * \param usage Only wait until the buffer is idle for the given usage,
326 * but may still be busy for some other usage.
328 void (*buffer_wait
)(struct pb_buffer
*buf
, enum radeon_bo_usage usage
);
331 * Return tiling flags describing a memory layout of a buffer object.
333 * \param buf A winsys buffer object to get the flags from.
334 * \param macrotile A pointer to the return value of the microtile flag.
335 * \param microtile A pointer to the return value of the macrotile flag.
337 * \note microtile and macrotile are not bitmasks!
339 void (*buffer_get_tiling
)(struct pb_buffer
*buf
,
340 enum radeon_bo_layout
*microtile
,
341 enum radeon_bo_layout
*macrotile
,
342 unsigned *bankw
, unsigned *bankh
,
343 unsigned *tile_split
,
344 unsigned *stencil_tile_split
,
349 * Set tiling flags describing a memory layout of a buffer object.
351 * \param buf A winsys buffer object to set the flags for.
352 * \param cs A command stream to flush if the buffer is referenced by it.
353 * \param macrotile A macrotile flag.
354 * \param microtile A microtile flag.
355 * \param stride A stride of the buffer in bytes, for texturing.
357 * \note microtile and macrotile are not bitmasks!
359 void (*buffer_set_tiling
)(struct pb_buffer
*buf
,
360 struct radeon_winsys_cs
*rcs
,
361 enum radeon_bo_layout microtile
,
362 enum radeon_bo_layout macrotile
,
363 unsigned bankw
, unsigned bankh
,
365 unsigned stencil_tile_split
,
371 * Get a winsys buffer from a winsys handle. The internal structure
372 * of the handle is platform-specific and only a winsys should access it.
374 * \param ws The winsys this function is called from.
375 * \param whandle A winsys handle pointer as was received from a state
377 * \param stride The returned buffer stride in bytes.
379 struct pb_buffer
*(*buffer_from_handle
)(struct radeon_winsys
*ws
,
380 struct winsys_handle
*whandle
,
384 * Get a winsys handle from a winsys buffer. The internal structure
385 * of the handle is platform-specific and only a winsys should access it.
387 * \param buf A winsys buffer object to get the handle from.
388 * \param whandle A winsys handle pointer.
389 * \param stride A stride of the buffer in bytes, for texturing.
390 * \return TRUE on success.
392 boolean (*buffer_get_handle
)(struct pb_buffer
*buf
,
394 struct winsys_handle
*whandle
);
397 * Return the virtual address of a buffer.
399 * \param buf A winsys buffer object
400 * \return virtual address
402 uint64_t (*buffer_get_virtual_address
)(struct radeon_winsys_cs_handle
*buf
);
405 * Query the initial placement of the buffer from the kernel driver.
407 enum radeon_bo_domain (*buffer_get_initial_domain
)(struct radeon_winsys_cs_handle
*buf
);
409 /**************************************************************************
410 * Command submission.
412 * Each pipe context should create its own command stream and submit
413 * commands independently of other contexts.
414 *************************************************************************/
417 * Create a command stream.
419 * \param ws The winsys this function is called from.
420 * \param ring_type The ring type (GFX, DMA, UVD)
421 * \param flush Flush callback function associated with the command stream.
422 * \param user User pointer that will be passed to the flush callback.
423 * \param trace_buf Trace buffer when tracing is enabled
425 struct radeon_winsys_cs
*(*cs_create
)(struct radeon_winsys
*ws
,
426 enum ring_type ring_type
,
427 void (*flush
)(void *ctx
, unsigned flags
),
429 struct radeon_winsys_cs_handle
*trace_buf
);
432 * Destroy a command stream.
434 * \param cs A command stream to destroy.
436 void (*cs_destroy
)(struct radeon_winsys_cs
*cs
);
439 * Add a new buffer relocation. Every relocation must first be added
440 * before it can be written.
442 * \param cs A command stream to add buffer for validation against.
443 * \param buf A winsys buffer to validate.
444 * \param usage Whether the buffer is used for read and/or write.
445 * \param domain Bitmask of the RADEON_DOMAIN_* flags.
446 * \param priority A higher number means a greater chance of being
447 * placed in the requested domain. 15 is the maximum.
448 * \return Relocation index.
450 unsigned (*cs_add_reloc
)(struct radeon_winsys_cs
*cs
,
451 struct radeon_winsys_cs_handle
*buf
,
452 enum radeon_bo_usage usage
,
453 enum radeon_bo_domain domain
,
454 enum radeon_bo_priority priority
);
457 * Return the index of an already-added buffer.
459 * \param cs Command stream
461 * \return The buffer index, or -1 if the buffer has not been added.
463 int (*cs_get_reloc
)(struct radeon_winsys_cs
*cs
,
464 struct radeon_winsys_cs_handle
*buf
);
467 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
468 * added so far. If the validation fails, all the relocations which have
469 * been added since the last call of cs_validate will be removed and
470 * the CS will be flushed (provided there are still any relocations).
472 * \param cs A command stream to validate.
474 boolean (*cs_validate
)(struct radeon_winsys_cs
*cs
);
477 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
480 * \param cs A command stream to validate.
481 * \param vram VRAM memory size pending to be use
482 * \param gtt GTT memory size pending to be use
484 boolean (*cs_memory_below_limit
)(struct radeon_winsys_cs
*cs
, uint64_t vram
, uint64_t gtt
);
487 * Flush a command stream.
489 * \param cs A command stream to flush.
490 * \param flags, RADEON_FLUSH_ASYNC or 0.
491 * \param cs_trace_id A unique identifiant for the cs
493 void (*cs_flush
)(struct radeon_winsys_cs
*cs
, unsigned flags
, uint32_t cs_trace_id
);
496 * Return TRUE if a buffer is referenced by a command stream.
498 * \param cs A command stream.
499 * \param buf A winsys buffer.
501 boolean (*cs_is_buffer_referenced
)(struct radeon_winsys_cs
*cs
,
502 struct radeon_winsys_cs_handle
*buf
,
503 enum radeon_bo_usage usage
);
506 * Request access to a feature for a command stream.
508 * \param cs A command stream.
509 * \param fid Feature ID, one of RADEON_FID_*
510 * \param enable Whether to enable or disable the feature.
512 boolean (*cs_request_feature
)(struct radeon_winsys_cs
*cs
,
513 enum radeon_feature_id fid
,
516 * Make sure all asynchronous flush of the cs have completed
518 * \param cs A command stream.
520 void (*cs_sync_flush
)(struct radeon_winsys_cs
*cs
);
523 * Return a fence associated with the CS. The fence will be signalled
524 * once the CS is flushed and all commands in the CS are completed
527 struct pipe_fence_handle
*(*cs_create_fence
)(struct radeon_winsys_cs
*cs
);
530 * Wait for the fence and return true if the fence has been signalled.
531 * The timeout of 0 will only return the status.
532 * The timeout of PIPE_TIMEOUT_INFINITE will always wait until the fence
535 bool (*fence_wait
)(struct radeon_winsys
*ws
,
536 struct pipe_fence_handle
*fence
,
540 * Reference counting for fences.
542 void (*fence_reference
)(struct pipe_fence_handle
**dst
,
543 struct pipe_fence_handle
*src
);
548 * \param ws The winsys this function is called from.
549 * \param surf Surface structure ptr
551 int (*surface_init
)(struct radeon_winsys
*ws
,
552 struct radeon_surface
*surf
);
555 * Find best values for a surface
557 * \param ws The winsys this function is called from.
558 * \param surf Surface structure ptr
560 int (*surface_best
)(struct radeon_winsys
*ws
,
561 struct radeon_surface
*surf
);
563 uint64_t (*query_value
)(struct radeon_winsys
*ws
,
564 enum radeon_value_id value
);
568 static INLINE
void radeon_emit(struct radeon_winsys_cs
*cs
, uint32_t value
)
570 cs
->buf
[cs
->cdw
++] = value
;
573 static INLINE
void radeon_emit_array(struct radeon_winsys_cs
*cs
,
574 const uint32_t *values
, unsigned count
)
576 memcpy(cs
->buf
+cs
->cdw
, values
, count
* 4);