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_backend_map
;
215 uint32_t r600_va_start
;
216 uint32_t r600_ib_vm_max_size
;
217 uint32_t r600_max_pipes
;
218 boolean r600_backend_map_valid
;
219 boolean r600_virtual_address
;
220 boolean r600_has_dma
;
222 boolean si_tile_mode_array_valid
;
223 uint32_t si_tile_mode_array
[32];
225 boolean cik_macrotile_mode_array_valid
;
226 uint32_t cik_macrotile_mode_array
[16];
229 enum radeon_feature_id
{
230 RADEON_FID_R300_HYPERZ_ACCESS
, /* ZMask + HiZ */
231 RADEON_FID_R300_CMASK_ACCESS
,
234 struct radeon_winsys
{
238 struct pipe_reference reference
;
241 * The screen object this winsys was created for
243 struct pipe_screen
*screen
;
246 * Destroy this winsys.
248 * \param ws The winsys this function is called from.
250 void (*destroy
)(struct radeon_winsys
*ws
);
253 * Query an info structure from winsys.
255 * \param ws The winsys this function is called from.
256 * \param info Return structure
258 void (*query_info
)(struct radeon_winsys
*ws
,
259 struct radeon_info
*info
);
261 /**************************************************************************
262 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
264 * Remember that gallium gets to choose the interface it needs, and the
265 * window systems must then implement that interface (rather than the
266 * other way around...).
267 *************************************************************************/
270 * Create a buffer object.
272 * \param ws The winsys this function is called from.
273 * \param size The size to allocate.
274 * \param alignment An alignment of the buffer in memory.
275 * \param use_reusable_pool Whether the cache buffer manager should be used.
276 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
277 * \return The created buffer object.
279 struct pb_buffer
*(*buffer_create
)(struct radeon_winsys
*ws
,
282 boolean use_reusable_pool
,
283 enum radeon_bo_domain domain
);
285 struct radeon_winsys_cs_handle
*(*buffer_get_cs_handle
)(
286 struct pb_buffer
*buf
);
289 * Map the entire data store of a buffer object into the client's address
292 * \param buf A winsys buffer object to map.
293 * \param cs A command stream to flush if the buffer is referenced by it.
294 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
295 * \return The pointer at the beginning of the buffer.
297 void *(*buffer_map
)(struct radeon_winsys_cs_handle
*buf
,
298 struct radeon_winsys_cs
*cs
,
299 enum pipe_transfer_usage usage
);
302 * Unmap a buffer object from the client's address space.
304 * \param buf A winsys buffer object to unmap.
306 void (*buffer_unmap
)(struct radeon_winsys_cs_handle
*buf
);
309 * Return TRUE if a buffer object is being used by the GPU.
311 * \param buf A winsys buffer object.
312 * \param usage Only check whether the buffer is busy for the given usage.
314 boolean (*buffer_is_busy
)(struct pb_buffer
*buf
,
315 enum radeon_bo_usage usage
);
318 * Wait for a buffer object until it is not used by a GPU. This is
319 * equivalent to a fence placed after the last command using the buffer,
320 * and synchronizing to the fence.
322 * \param buf A winsys buffer object to wait for.
323 * \param usage Only wait until the buffer is idle for the given usage,
324 * but may still be busy for some other usage.
326 void (*buffer_wait
)(struct pb_buffer
*buf
, enum radeon_bo_usage usage
);
329 * Return tiling flags describing a memory layout of a buffer object.
331 * \param buf A winsys buffer object to get the flags from.
332 * \param macrotile A pointer to the return value of the microtile flag.
333 * \param microtile A pointer to the return value of the macrotile flag.
335 * \note microtile and macrotile are not bitmasks!
337 void (*buffer_get_tiling
)(struct pb_buffer
*buf
,
338 enum radeon_bo_layout
*microtile
,
339 enum radeon_bo_layout
*macrotile
,
340 unsigned *bankw
, unsigned *bankh
,
341 unsigned *tile_split
,
342 unsigned *stencil_tile_split
,
347 * Set tiling flags describing a memory layout of a buffer object.
349 * \param buf A winsys buffer object to set the flags for.
350 * \param cs A command stream to flush if the buffer is referenced by it.
351 * \param macrotile A macrotile flag.
352 * \param microtile A microtile flag.
353 * \param stride A stride of the buffer in bytes, for texturing.
355 * \note microtile and macrotile are not bitmasks!
357 void (*buffer_set_tiling
)(struct pb_buffer
*buf
,
358 struct radeon_winsys_cs
*rcs
,
359 enum radeon_bo_layout microtile
,
360 enum radeon_bo_layout macrotile
,
361 unsigned bankw
, unsigned bankh
,
363 unsigned stencil_tile_split
,
369 * Get a winsys buffer from a winsys handle. The internal structure
370 * of the handle is platform-specific and only a winsys should access it.
372 * \param ws The winsys this function is called from.
373 * \param whandle A winsys handle pointer as was received from a state
375 * \param stride The returned buffer stride in bytes.
377 struct pb_buffer
*(*buffer_from_handle
)(struct radeon_winsys
*ws
,
378 struct winsys_handle
*whandle
,
382 * Get a winsys handle from a winsys buffer. The internal structure
383 * of the handle is platform-specific and only a winsys should access it.
385 * \param buf A winsys buffer object to get the handle from.
386 * \param whandle A winsys handle pointer.
387 * \param stride A stride of the buffer in bytes, for texturing.
388 * \return TRUE on success.
390 boolean (*buffer_get_handle
)(struct pb_buffer
*buf
,
392 struct winsys_handle
*whandle
);
395 * Return the virtual address of a buffer.
397 * \param buf A winsys buffer object
398 * \return virtual address
400 uint64_t (*buffer_get_virtual_address
)(struct radeon_winsys_cs_handle
*buf
);
403 * Query the initial placement of the buffer from the kernel driver.
405 enum radeon_bo_domain (*buffer_get_initial_domain
)(struct radeon_winsys_cs_handle
*buf
);
407 /**************************************************************************
408 * Command submission.
410 * Each pipe context should create its own command stream and submit
411 * commands independently of other contexts.
412 *************************************************************************/
415 * Create a command stream.
417 * \param ws The winsys this function is called from.
418 * \param ring_type The ring type (GFX, DMA, UVD)
419 * \param trace_buf Trace buffer when tracing is enabled
421 struct radeon_winsys_cs
*(*cs_create
)(struct radeon_winsys
*ws
,
422 enum ring_type ring_type
,
423 struct radeon_winsys_cs_handle
*trace_buf
);
426 * Destroy a command stream.
428 * \param cs A command stream to destroy.
430 void (*cs_destroy
)(struct radeon_winsys_cs
*cs
);
433 * Add a new buffer relocation. Every relocation must first be added
434 * before it can be written.
436 * \param cs A command stream to add buffer for validation against.
437 * \param buf A winsys buffer to validate.
438 * \param usage Whether the buffer is used for read and/or write.
439 * \param domain Bitmask of the RADEON_DOMAIN_* flags.
440 * \param priority A higher number means a greater chance of being
441 * placed in the requested domain. 15 is the maximum.
442 * \return Relocation index.
444 unsigned (*cs_add_reloc
)(struct radeon_winsys_cs
*cs
,
445 struct radeon_winsys_cs_handle
*buf
,
446 enum radeon_bo_usage usage
,
447 enum radeon_bo_domain domain
,
448 enum radeon_bo_priority priority
);
451 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
452 * added so far. If the validation fails, all the relocations which have
453 * been added since the last call of cs_validate will be removed and
454 * the CS will be flushed (provided there are still any relocations).
456 * \param cs A command stream to validate.
458 boolean (*cs_validate
)(struct radeon_winsys_cs
*cs
);
461 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
464 * \param cs A command stream to validate.
465 * \param vram VRAM memory size pending to be use
466 * \param gtt GTT memory size pending to be use
468 boolean (*cs_memory_below_limit
)(struct radeon_winsys_cs
*cs
, uint64_t vram
, uint64_t gtt
);
471 * Write a relocated dword to a command buffer.
473 * \param cs A command stream the relocation is written to.
474 * \param buf A winsys buffer to write the relocation for.
476 void (*cs_write_reloc
)(struct radeon_winsys_cs
*cs
,
477 struct radeon_winsys_cs_handle
*buf
);
480 * Flush a command stream.
482 * \param cs A command stream to flush.
483 * \param flags, RADEON_FLUSH_ASYNC or 0.
484 * \param cs_trace_id A unique identifiant for the cs
486 void (*cs_flush
)(struct radeon_winsys_cs
*cs
, unsigned flags
, uint32_t cs_trace_id
);
489 * Set a flush callback which is called from winsys when flush is
492 * \param cs A command stream to set the callback for.
493 * \param flush A flush callback function associated with the command stream.
494 * \param user A user pointer that will be passed to the flush callback.
496 void (*cs_set_flush_callback
)(struct radeon_winsys_cs
*cs
,
497 void (*flush
)(void *ctx
, unsigned flags
),
501 * Return TRUE if a buffer is referenced by a command stream.
503 * \param cs A command stream.
504 * \param buf A winsys buffer.
506 boolean (*cs_is_buffer_referenced
)(struct radeon_winsys_cs
*cs
,
507 struct radeon_winsys_cs_handle
*buf
,
508 enum radeon_bo_usage usage
);
511 * Request access to a feature for a command stream.
513 * \param cs A command stream.
514 * \param fid Feature ID, one of RADEON_FID_*
515 * \param enable Whether to enable or disable the feature.
517 boolean (*cs_request_feature
)(struct radeon_winsys_cs
*cs
,
518 enum radeon_feature_id fid
,
521 * Make sure all asynchronous flush of the cs have completed
523 * \param cs A command stream.
525 void (*cs_sync_flush
)(struct radeon_winsys_cs
*cs
);
528 * Return a fence associated with the CS. The fence will be signalled
529 * once the CS is flushed and all commands in the CS are completed
532 struct pipe_fence_handle
*(*cs_create_fence
)(struct radeon_winsys_cs
*cs
);
535 * Wait for the fence and return true if the fence has been signalled.
536 * The timeout of 0 will only return the status.
537 * The timeout of PIPE_TIMEOUT_INFINITE will always wait until the fence
540 bool (*fence_wait
)(struct radeon_winsys
*ws
,
541 struct pipe_fence_handle
*fence
,
545 * Reference counting for fences.
547 void (*fence_reference
)(struct pipe_fence_handle
**dst
,
548 struct pipe_fence_handle
*src
);
553 * \param ws The winsys this function is called from.
554 * \param surf Surface structure ptr
556 int (*surface_init
)(struct radeon_winsys
*ws
,
557 struct radeon_surface
*surf
);
560 * Find best values for a surface
562 * \param ws The winsys this function is called from.
563 * \param surf Surface structure ptr
565 int (*surface_best
)(struct radeon_winsys
*ws
,
566 struct radeon_surface
*surf
);
568 uint64_t (*query_value
)(struct radeon_winsys
*ws
,
569 enum radeon_value_id value
);
573 * Decrement the winsys reference count.
575 * \param ws The winsys this function is called for.
577 static INLINE boolean
radeon_winsys_unref(struct radeon_winsys
*ws
)
579 return pipe_reference(&ws
->reference
, NULL
);
582 static INLINE
void radeon_emit(struct radeon_winsys_cs
*cs
, uint32_t value
)
584 cs
->buf
[cs
->cdw
++] = value
;
587 static INLINE
void radeon_emit_array(struct radeon_winsys_cs
*cs
,
588 const uint32_t *values
, unsigned count
)
590 memcpy(cs
->buf
+cs
->cdw
, values
, count
* 4);