2e287c67eeaf097a8986b3a96e356aa6e8c5ee85
[mesa.git] / src / gallium / drivers / radeon / radeon_winsys.h
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 #include "pipebuffer/pb_buffer.h"
30
31 #include "amd/common/amd_family.h"
32
33 #define RADEON_FLUSH_ASYNC (1 << 0)
34 #define RADEON_FLUSH_END_OF_FRAME (1 << 1)
35
36 /* Tiling flags. */
37 enum radeon_bo_layout {
38 RADEON_LAYOUT_LINEAR = 0,
39 RADEON_LAYOUT_TILED,
40 RADEON_LAYOUT_SQUARETILED,
41
42 RADEON_LAYOUT_UNKNOWN
43 };
44
45 enum radeon_bo_domain { /* bitfield */
46 RADEON_DOMAIN_GTT = 2,
47 RADEON_DOMAIN_VRAM = 4,
48 RADEON_DOMAIN_VRAM_GTT = RADEON_DOMAIN_VRAM | RADEON_DOMAIN_GTT
49 };
50
51 enum radeon_bo_flag { /* bitfield */
52 RADEON_FLAG_GTT_WC = (1 << 0),
53 RADEON_FLAG_CPU_ACCESS = (1 << 1),
54 RADEON_FLAG_NO_CPU_ACCESS = (1 << 2),
55 RADEON_FLAG_HANDLE = (1 << 3), /* the buffer must not be suballocated */
56 RADEON_FLAG_SPARSE = (1 << 4),
57 };
58
59 enum 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 /* The winsys ensures that the CS submission will be scheduled after
65 * previously flushed CSs referencing this BO in a conflicting way.
66 */
67 RADEON_USAGE_SYNCHRONIZED = 8
68 };
69
70 #define RADEON_SPARSE_PAGE_SIZE (64 * 1024)
71
72 enum ring_type {
73 RING_GFX = 0,
74 RING_COMPUTE,
75 RING_DMA,
76 RING_UVD,
77 RING_VCE,
78 RING_LAST,
79 };
80
81 enum radeon_value_id {
82 RADEON_REQUESTED_VRAM_MEMORY,
83 RADEON_REQUESTED_GTT_MEMORY,
84 RADEON_MAPPED_VRAM,
85 RADEON_MAPPED_GTT,
86 RADEON_BUFFER_WAIT_TIME_NS,
87 RADEON_NUM_MAPPED_BUFFERS,
88 RADEON_TIMESTAMP,
89 RADEON_NUM_GFX_IBS,
90 RADEON_NUM_SDMA_IBS,
91 RADEON_NUM_BYTES_MOVED,
92 RADEON_NUM_EVICTIONS,
93 RADEON_VRAM_USAGE,
94 RADEON_VRAM_VIS_USAGE,
95 RADEON_GTT_USAGE,
96 RADEON_GPU_TEMPERATURE, /* DRM 2.42.0 */
97 RADEON_CURRENT_SCLK,
98 RADEON_CURRENT_MCLK,
99 RADEON_GPU_RESET_COUNTER, /* DRM 2.43.0 */
100 RADEON_CS_THREAD_TIME,
101 };
102
103 /* Each group of four has the same priority. */
104 enum radeon_bo_priority {
105 RADEON_PRIO_FENCE = 0,
106 RADEON_PRIO_TRACE,
107 RADEON_PRIO_SO_FILLED_SIZE,
108 RADEON_PRIO_QUERY,
109
110 RADEON_PRIO_IB1 = 4, /* main IB submitted to the kernel */
111 RADEON_PRIO_IB2, /* IB executed with INDIRECT_BUFFER */
112 RADEON_PRIO_DRAW_INDIRECT,
113 RADEON_PRIO_INDEX_BUFFER,
114
115 RADEON_PRIO_VCE = 8,
116 RADEON_PRIO_UVD,
117 RADEON_PRIO_SDMA_BUFFER,
118 RADEON_PRIO_SDMA_TEXTURE,
119
120 RADEON_PRIO_CP_DMA = 12,
121
122 RADEON_PRIO_CONST_BUFFER = 16,
123 RADEON_PRIO_DESCRIPTORS,
124 RADEON_PRIO_BORDER_COLORS,
125
126 RADEON_PRIO_SAMPLER_BUFFER = 20,
127 RADEON_PRIO_VERTEX_BUFFER,
128
129 RADEON_PRIO_SHADER_RW_BUFFER = 24,
130 RADEON_PRIO_COMPUTE_GLOBAL,
131
132 RADEON_PRIO_SAMPLER_TEXTURE = 28,
133 RADEON_PRIO_SHADER_RW_IMAGE,
134
135 RADEON_PRIO_SAMPLER_TEXTURE_MSAA = 32,
136
137 RADEON_PRIO_COLOR_BUFFER = 36,
138
139 RADEON_PRIO_DEPTH_BUFFER = 40,
140
141 RADEON_PRIO_COLOR_BUFFER_MSAA = 44,
142
143 RADEON_PRIO_DEPTH_BUFFER_MSAA = 48,
144
145 RADEON_PRIO_CMASK = 52,
146 RADEON_PRIO_DCC,
147 RADEON_PRIO_HTILE,
148 RADEON_PRIO_SHADER_BINARY, /* the hw can't hide instruction cache misses */
149
150 RADEON_PRIO_SHADER_RINGS = 56,
151
152 RADEON_PRIO_SCRATCH_BUFFER = 60,
153 /* 63 is the maximum value */
154 };
155
156 struct winsys_handle;
157 struct radeon_winsys_ctx;
158
159 struct radeon_winsys_cs_chunk {
160 unsigned cdw; /* Number of used dwords. */
161 unsigned max_dw; /* Maximum number of dwords. */
162 uint32_t *buf; /* The base pointer of the chunk. */
163 };
164
165 struct radeon_winsys_cs {
166 struct radeon_winsys_cs_chunk current;
167 struct radeon_winsys_cs_chunk *prev;
168 unsigned num_prev; /* Number of previous chunks. */
169 unsigned max_prev; /* Space in array pointed to by prev. */
170 unsigned prev_dw; /* Total number of dwords in previous chunks. */
171
172 /* Memory usage of the buffer list. These are always 0 for CE and preamble
173 * IBs. */
174 uint64_t used_vram;
175 uint64_t used_gart;
176 };
177
178 struct radeon_info {
179 /* PCI info: domain:bus:dev:func */
180 uint32_t pci_domain;
181 uint32_t pci_bus;
182 uint32_t pci_dev;
183 uint32_t pci_func;
184
185 /* Device info. */
186 uint32_t pci_id;
187 enum radeon_family family;
188 enum chip_class chip_class;
189 uint32_t gart_page_size;
190 uint64_t gart_size;
191 uint64_t vram_size;
192 uint64_t vram_vis_size;
193 uint64_t max_alloc_size;
194 uint32_t min_alloc_size;
195 bool has_dedicated_vram;
196 bool has_virtual_memory;
197 bool gfx_ib_pad_with_type2;
198 bool has_sdma;
199 bool has_uvd;
200 uint32_t uvd_fw_version;
201 uint32_t vce_fw_version;
202 uint32_t me_fw_version;
203 uint32_t pfp_fw_version;
204 uint32_t ce_fw_version;
205 uint32_t vce_harvest_config;
206 uint32_t clock_crystal_freq;
207 uint32_t tcc_cache_line_size;
208
209 /* Kernel info. */
210 uint32_t drm_major; /* version */
211 uint32_t drm_minor;
212 uint32_t drm_patchlevel;
213 bool has_userptr;
214
215 /* Shader cores. */
216 uint32_t r600_max_quad_pipes; /* wave size / 16 */
217 uint32_t max_shader_clock;
218 uint32_t num_good_compute_units;
219 uint32_t max_se; /* shader engines */
220 uint32_t max_sh_per_se; /* shader arrays per shader engine */
221
222 /* Render backends (color + depth blocks). */
223 uint32_t r300_num_gb_pipes;
224 uint32_t r300_num_z_pipes;
225 uint32_t r600_gb_backend_map; /* R600 harvest config */
226 bool r600_gb_backend_map_valid;
227 uint32_t r600_num_banks;
228 uint32_t num_render_backends;
229 uint32_t num_tile_pipes; /* pipe count from PIPE_CONFIG */
230 uint32_t pipe_interleave_bytes;
231 uint32_t enabled_rb_mask; /* GCN harvest config */
232
233 /* Tile modes. */
234 uint32_t si_tile_mode_array[32];
235 uint32_t cik_macrotile_mode_array[16];
236 };
237
238 /* Tiling info for display code, DRI sharing, and other data. */
239 struct radeon_bo_metadata {
240 /* Tiling flags describing the texture layout for display code
241 * and DRI sharing.
242 */
243 union {
244 struct {
245 enum radeon_bo_layout microtile;
246 enum radeon_bo_layout macrotile;
247 unsigned pipe_config;
248 unsigned bankw;
249 unsigned bankh;
250 unsigned tile_split;
251 unsigned mtilea;
252 unsigned num_banks;
253 unsigned stride;
254 bool scanout;
255 } legacy;
256
257 struct {
258 /* surface flags */
259 unsigned swizzle_mode:5;
260 } gfx9;
261 } u;
262
263 /* Additional metadata associated with the buffer, in bytes.
264 * The maximum size is 64 * 4. This is opaque for the winsys & kernel.
265 * Supported by amdgpu only.
266 */
267 uint32_t size_metadata;
268 uint32_t metadata[64];
269 };
270
271 enum radeon_feature_id {
272 RADEON_FID_R300_HYPERZ_ACCESS, /* ZMask + HiZ */
273 RADEON_FID_R300_CMASK_ACCESS,
274 };
275
276 #define RADEON_SURF_MAX_LEVELS 15
277
278 enum radeon_surf_mode {
279 RADEON_SURF_MODE_LINEAR_ALIGNED = 1,
280 RADEON_SURF_MODE_1D = 2,
281 RADEON_SURF_MODE_2D = 3,
282 };
283
284 /* These are defined exactly like GB_TILE_MODEn.MICRO_TILE_MODE_NEW. */
285 enum radeon_micro_mode {
286 RADEON_MICRO_MODE_DISPLAY = 0,
287 RADEON_MICRO_MODE_THIN = 1,
288 RADEON_MICRO_MODE_DEPTH = 2,
289 RADEON_MICRO_MODE_ROTATED = 3,
290 };
291
292 /* the first 16 bits are reserved for libdrm_radeon, don't use them */
293 #define RADEON_SURF_SCANOUT (1 << 16)
294 #define RADEON_SURF_ZBUFFER (1 << 17)
295 #define RADEON_SURF_SBUFFER (1 << 18)
296 #define RADEON_SURF_Z_OR_SBUFFER (RADEON_SURF_ZBUFFER | RADEON_SURF_SBUFFER)
297 /* bits 19 and 20 are reserved for libdrm_radeon, don't use them */
298 #define RADEON_SURF_FMASK (1 << 21)
299 #define RADEON_SURF_DISABLE_DCC (1 << 22)
300 #define RADEON_SURF_TC_COMPATIBLE_HTILE (1 << 23)
301 #define RADEON_SURF_IMPORTED (1 << 24)
302 #define RADEON_SURF_OPTIMIZE_FOR_SPACE (1 << 25)
303
304 struct legacy_surf_level {
305 uint64_t offset;
306 uint64_t slice_size;
307 uint64_t dcc_offset;
308 uint64_t dcc_fast_clear_size;
309 uint16_t nblk_x;
310 uint16_t nblk_y;
311 enum radeon_surf_mode mode;
312 };
313
314 struct legacy_surf_layout {
315 unsigned bankw:4; /* max 8 */
316 unsigned bankh:4; /* max 8 */
317 unsigned mtilea:4; /* max 8 */
318 unsigned tile_split:13; /* max 4K */
319 unsigned stencil_tile_split:13; /* max 4K */
320 unsigned pipe_config:5; /* max 17 */
321 unsigned num_banks:5; /* max 16 */
322 unsigned macro_tile_index:4; /* max 15 */
323
324 /* Whether the depth miptree or stencil miptree as used by the DB are
325 * adjusted from their TC compatible form to ensure depth/stencil
326 * compatibility. If either is true, the corresponding plane cannot be
327 * sampled from.
328 */
329 unsigned depth_adjusted:1;
330 unsigned stencil_adjusted:1;
331
332 struct legacy_surf_level level[RADEON_SURF_MAX_LEVELS];
333 struct legacy_surf_level stencil_level[RADEON_SURF_MAX_LEVELS];
334 uint8_t tiling_index[RADEON_SURF_MAX_LEVELS];
335 uint8_t stencil_tiling_index[RADEON_SURF_MAX_LEVELS];
336 };
337
338 /* Same as addrlib - AddrResourceType. */
339 enum gfx9_resource_type {
340 RADEON_RESOURCE_1D = 0,
341 RADEON_RESOURCE_2D,
342 RADEON_RESOURCE_3D,
343 };
344
345 struct gfx9_surf_flags {
346 uint16_t swizzle_mode; /* tile mode */
347 uint16_t epitch; /* (pitch - 1) or (height - 1) */
348 };
349
350 struct gfx9_surf_meta_flags {
351 unsigned rb_aligned:1; /* optimal for RBs */
352 unsigned pipe_aligned:1; /* optimal for TC */
353 };
354
355 struct gfx9_surf_layout {
356 struct gfx9_surf_flags surf; /* color or depth surface */
357 struct gfx9_surf_flags fmask; /* not added to surf_size */
358 struct gfx9_surf_flags stencil; /* added to surf_size, use stencil_offset */
359
360 struct gfx9_surf_meta_flags dcc; /* metadata of color */
361 struct gfx9_surf_meta_flags htile; /* metadata of depth and stencil */
362 struct gfx9_surf_meta_flags cmask; /* metadata of fmask */
363
364 enum gfx9_resource_type resource_type; /* 1D, 2D or 3D */
365 uint64_t surf_offset; /* 0 unless imported with an offset */
366 /* The size of the 2D plane containing all mipmap levels. */
367 uint64_t surf_slice_size;
368 uint16_t surf_pitch; /* in blocks */
369 uint16_t surf_height;
370 /* Mipmap level offset within the slice in bytes. Only valid for LINEAR. */
371 uint32_t offset[RADEON_SURF_MAX_LEVELS];
372
373 uint16_t dcc_pitch_max; /* (mip chain pitch - 1) */
374
375 uint64_t stencil_offset; /* separate stencil */
376 uint64_t fmask_size;
377 uint64_t cmask_size;
378
379 uint32_t fmask_alignment;
380 uint32_t cmask_alignment;
381 };
382
383 struct radeon_surf {
384 /* Format properties. */
385 unsigned blk_w:4;
386 unsigned blk_h:4;
387 unsigned bpe:5;
388 /* Number of mipmap levels where DCC is enabled starting from level 0.
389 * Non-zero levels may be disabled due to alignment constraints, but not
390 * the first level.
391 */
392 unsigned num_dcc_levels:4;
393 unsigned is_linear:1;
394 /* Displayable, thin, depth, rotated. AKA D,S,Z,R swizzle modes. */
395 unsigned micro_tile_mode:3;
396 uint32_t flags;
397
398 /* These are return values. Some of them can be set by the caller, but
399 * they will be treated as hints (e.g. bankw, bankh) and might be
400 * changed by the calculator.
401 */
402 uint64_t surf_size;
403 uint64_t dcc_size;
404 uint64_t htile_size;
405
406 uint32_t surf_alignment;
407 uint32_t dcc_alignment;
408 uint32_t htile_alignment;
409
410 union {
411 /* R600-VI return values.
412 *
413 * Some of them can be set by the caller if certain parameters are
414 * desirable. The allocator will try to obey them.
415 */
416 struct legacy_surf_layout legacy;
417
418 /* GFX9+ return values. */
419 struct gfx9_surf_layout gfx9;
420 } u;
421 };
422
423 struct radeon_bo_list_item {
424 uint64_t bo_size;
425 uint64_t vm_address;
426 uint64_t priority_usage; /* mask of (1 << RADEON_PRIO_*) */
427 };
428
429 struct radeon_winsys {
430 /**
431 * The screen object this winsys was created for
432 */
433 struct pipe_screen *screen;
434
435 /**
436 * Decrement the winsys reference count.
437 *
438 * \param ws The winsys this function is called for.
439 * \return True if the winsys and screen should be destroyed.
440 */
441 bool (*unref)(struct radeon_winsys *ws);
442
443 /**
444 * Destroy this winsys.
445 *
446 * \param ws The winsys this function is called from.
447 */
448 void (*destroy)(struct radeon_winsys *ws);
449
450 /**
451 * Query an info structure from winsys.
452 *
453 * \param ws The winsys this function is called from.
454 * \param info Return structure
455 */
456 void (*query_info)(struct radeon_winsys *ws,
457 struct radeon_info *info);
458
459 /**************************************************************************
460 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
461 *
462 * Remember that gallium gets to choose the interface it needs, and the
463 * window systems must then implement that interface (rather than the
464 * other way around...).
465 *************************************************************************/
466
467 /**
468 * Create a buffer object.
469 *
470 * \param ws The winsys this function is called from.
471 * \param size The size to allocate.
472 * \param alignment An alignment of the buffer in memory.
473 * \param use_reusable_pool Whether the cache buffer manager should be used.
474 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
475 * \return The created buffer object.
476 */
477 struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
478 uint64_t size,
479 unsigned alignment,
480 enum radeon_bo_domain domain,
481 enum radeon_bo_flag flags);
482
483 /**
484 * Map the entire data store of a buffer object into the client's address
485 * space.
486 *
487 * \param buf A winsys buffer object to map.
488 * \param cs A command stream to flush if the buffer is referenced by it.
489 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
490 * \return The pointer at the beginning of the buffer.
491 */
492 void *(*buffer_map)(struct pb_buffer *buf,
493 struct radeon_winsys_cs *cs,
494 enum pipe_transfer_usage usage);
495
496 /**
497 * Unmap a buffer object from the client's address space.
498 *
499 * \param buf A winsys buffer object to unmap.
500 */
501 void (*buffer_unmap)(struct pb_buffer *buf);
502
503 /**
504 * Wait for the buffer and return true if the buffer is not used
505 * by the device.
506 *
507 * The timeout of 0 will only return the status.
508 * The timeout of PIPE_TIMEOUT_INFINITE will always wait until the buffer
509 * is idle.
510 */
511 bool (*buffer_wait)(struct pb_buffer *buf, uint64_t timeout,
512 enum radeon_bo_usage usage);
513
514 /**
515 * Return buffer metadata.
516 * (tiling info for display code, DRI sharing, and other data)
517 *
518 * \param buf A winsys buffer object to get the flags from.
519 * \param md Metadata
520 */
521 void (*buffer_get_metadata)(struct pb_buffer *buf,
522 struct radeon_bo_metadata *md);
523
524 /**
525 * Set buffer metadata.
526 * (tiling info for display code, DRI sharing, and other data)
527 *
528 * \param buf A winsys buffer object to set the flags for.
529 * \param md Metadata
530 */
531 void (*buffer_set_metadata)(struct pb_buffer *buf,
532 struct radeon_bo_metadata *md);
533
534 /**
535 * Get a winsys buffer from a winsys handle. The internal structure
536 * of the handle is platform-specific and only a winsys should access it.
537 *
538 * \param ws The winsys this function is called from.
539 * \param whandle A winsys handle pointer as was received from a state
540 * tracker.
541 * \param stride The returned buffer stride in bytes.
542 */
543 struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
544 struct winsys_handle *whandle,
545 unsigned *stride, unsigned *offset);
546
547 /**
548 * Get a winsys buffer from a user pointer. The resulting buffer can't
549 * be exported. Both pointer and size must be page aligned.
550 *
551 * \param ws The winsys this function is called from.
552 * \param pointer User pointer to turn into a buffer object.
553 * \param Size Size in bytes for the new buffer.
554 */
555 struct pb_buffer *(*buffer_from_ptr)(struct radeon_winsys *ws,
556 void *pointer, uint64_t size);
557
558 /**
559 * Whether the buffer was created from a user pointer.
560 *
561 * \param buf A winsys buffer object
562 * \return whether \p buf was created via buffer_from_ptr
563 */
564 bool (*buffer_is_user_ptr)(struct pb_buffer *buf);
565
566 /**
567 * Get a winsys handle from a winsys buffer. The internal structure
568 * of the handle is platform-specific and only a winsys should access it.
569 *
570 * \param buf A winsys buffer object to get the handle from.
571 * \param whandle A winsys handle pointer.
572 * \param stride A stride of the buffer in bytes, for texturing.
573 * \return true on success.
574 */
575 bool (*buffer_get_handle)(struct pb_buffer *buf,
576 unsigned stride, unsigned offset,
577 unsigned slice_size,
578 struct winsys_handle *whandle);
579
580 /**
581 * Change the commitment of a (64KB-page aligned) region of the given
582 * sparse buffer.
583 *
584 * \warning There is no automatic synchronization with command submission.
585 *
586 * \note Only implemented by the amdgpu winsys.
587 *
588 * \return false on out of memory or other failure, true on success.
589 */
590 bool (*buffer_commit)(struct pb_buffer *buf,
591 uint64_t offset, uint64_t size,
592 bool commit);
593
594 /**
595 * Return the virtual address of a buffer.
596 *
597 * When virtual memory is not in use, this is the offset relative to the
598 * relocation base (non-zero for sub-allocated buffers).
599 *
600 * \param buf A winsys buffer object
601 * \return virtual address
602 */
603 uint64_t (*buffer_get_virtual_address)(struct pb_buffer *buf);
604
605 /**
606 * Return the offset of this buffer relative to the relocation base.
607 * This is only non-zero for sub-allocated buffers.
608 *
609 * This is only supported in the radeon winsys, since amdgpu uses virtual
610 * addresses in submissions even for the video engines.
611 *
612 * \param buf A winsys buffer object
613 * \return the offset for relocations
614 */
615 unsigned (*buffer_get_reloc_offset)(struct pb_buffer *buf);
616
617 /**
618 * Query the initial placement of the buffer from the kernel driver.
619 */
620 enum radeon_bo_domain (*buffer_get_initial_domain)(struct pb_buffer *buf);
621
622 /**************************************************************************
623 * Command submission.
624 *
625 * Each pipe context should create its own command stream and submit
626 * commands independently of other contexts.
627 *************************************************************************/
628
629 /**
630 * Create a command submission context.
631 * Various command streams can be submitted to the same context.
632 */
633 struct radeon_winsys_ctx *(*ctx_create)(struct radeon_winsys *ws);
634
635 /**
636 * Destroy a context.
637 */
638 void (*ctx_destroy)(struct radeon_winsys_ctx *ctx);
639
640 /**
641 * Query a GPU reset status.
642 */
643 enum pipe_reset_status (*ctx_query_reset_status)(struct radeon_winsys_ctx *ctx);
644
645 /**
646 * Create a command stream.
647 *
648 * \param ctx The submission context
649 * \param ring_type The ring type (GFX, DMA, UVD)
650 * \param flush Flush callback function associated with the command stream.
651 * \param user User pointer that will be passed to the flush callback.
652 */
653 struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys_ctx *ctx,
654 enum ring_type ring_type,
655 void (*flush)(void *ctx, unsigned flags,
656 struct pipe_fence_handle **fence),
657 void *flush_ctx);
658
659 /**
660 * Add a constant engine IB to a graphics CS. This makes the graphics CS
661 * from "cs_create" a group of two IBs that share a buffer list and are
662 * flushed together.
663 *
664 * The returned constant CS is only a stream for writing packets to the new
665 * IB. Calling other winsys functions with it is not allowed, not even
666 * "cs_destroy".
667 *
668 * In order to add buffers and check memory usage, use the graphics CS.
669 * In order to flush it, use the graphics CS, which will flush both IBs.
670 * Destroying the graphics CS will destroy both of them.
671 *
672 * \param cs The graphics CS from "cs_create" that will hold the buffer
673 * list and will be used for flushing.
674 */
675 struct radeon_winsys_cs *(*cs_add_const_ib)(struct radeon_winsys_cs *cs);
676
677 /**
678 * Add a constant engine preamble IB to a graphics CS. This add an extra IB
679 * in similar manner to cs_add_const_ib. This should always be called after
680 * cs_add_const_ib.
681 *
682 * The returned IB is a constant engine IB that only gets flushed if the
683 * context changed.
684 *
685 * \param cs The graphics CS from "cs_create" that will hold the buffer
686 * list and will be used for flushing.
687 */
688 struct radeon_winsys_cs *(*cs_add_const_preamble_ib)(struct radeon_winsys_cs *cs);
689 /**
690 * Destroy a command stream.
691 *
692 * \param cs A command stream to destroy.
693 */
694 void (*cs_destroy)(struct radeon_winsys_cs *cs);
695
696 /**
697 * Add a buffer. Each buffer used by a CS must be added using this function.
698 *
699 * \param cs Command stream
700 * \param buf Buffer
701 * \param usage Whether the buffer is used for read and/or write.
702 * \param domain Bitmask of the RADEON_DOMAIN_* flags.
703 * \param priority A higher number means a greater chance of being
704 * placed in the requested domain. 15 is the maximum.
705 * \return Buffer index.
706 */
707 unsigned (*cs_add_buffer)(struct radeon_winsys_cs *cs,
708 struct pb_buffer *buf,
709 enum radeon_bo_usage usage,
710 enum radeon_bo_domain domain,
711 enum radeon_bo_priority priority);
712
713 /**
714 * Return the index of an already-added buffer.
715 *
716 * Not supported on amdgpu. Drivers with GPUVM should not care about
717 * buffer indices.
718 *
719 * \param cs Command stream
720 * \param buf Buffer
721 * \return The buffer index, or -1 if the buffer has not been added.
722 */
723 int (*cs_lookup_buffer)(struct radeon_winsys_cs *cs,
724 struct pb_buffer *buf);
725
726 /**
727 * Return true if there is enough memory in VRAM and GTT for the buffers
728 * added so far. If the validation fails, all buffers which have
729 * been added since the last call of cs_validate will be removed and
730 * the CS will be flushed (provided there are still any buffers).
731 *
732 * \param cs A command stream to validate.
733 */
734 bool (*cs_validate)(struct radeon_winsys_cs *cs);
735
736 /**
737 * Check whether the given number of dwords is available in the IB.
738 * Optionally chain a new chunk of the IB if necessary and supported.
739 *
740 * \param cs A command stream.
741 * \param dw Number of CS dwords requested by the caller.
742 */
743 bool (*cs_check_space)(struct radeon_winsys_cs *cs, unsigned dw);
744
745 /**
746 * Return the buffer list.
747 *
748 * This is the buffer list as passed to the kernel, i.e. it only contains
749 * the parent buffers of sub-allocated buffers.
750 *
751 * \param cs Command stream
752 * \param list Returned buffer list. Set to NULL to query the count only.
753 * \return The buffer count.
754 */
755 unsigned (*cs_get_buffer_list)(struct radeon_winsys_cs *cs,
756 struct radeon_bo_list_item *list);
757
758 /**
759 * Flush a command stream.
760 *
761 * \param cs A command stream to flush.
762 * \param flags, RADEON_FLUSH_ASYNC or 0.
763 * \param fence Pointer to a fence. If non-NULL, a fence is inserted
764 * after the CS and is returned through this parameter.
765 * \return Negative POSIX error code or 0 for success.
766 * Asynchronous submissions never return an error.
767 */
768 int (*cs_flush)(struct radeon_winsys_cs *cs,
769 unsigned flags,
770 struct pipe_fence_handle **fence);
771
772 /**
773 * Create a fence before the CS is flushed.
774 * The user must flush manually to complete the initializaton of the fence.
775 * The fence must not be used before the flush.
776 */
777 struct pipe_fence_handle *(*cs_get_next_fence)(struct radeon_winsys_cs *cs);
778
779 /**
780 * Return true if a buffer is referenced by a command stream.
781 *
782 * \param cs A command stream.
783 * \param buf A winsys buffer.
784 */
785 bool (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
786 struct pb_buffer *buf,
787 enum radeon_bo_usage usage);
788
789 /**
790 * Request access to a feature for a command stream.
791 *
792 * \param cs A command stream.
793 * \param fid Feature ID, one of RADEON_FID_*
794 * \param enable Whether to enable or disable the feature.
795 */
796 bool (*cs_request_feature)(struct radeon_winsys_cs *cs,
797 enum radeon_feature_id fid,
798 bool enable);
799 /**
800 * Make sure all asynchronous flush of the cs have completed
801 *
802 * \param cs A command stream.
803 */
804 void (*cs_sync_flush)(struct radeon_winsys_cs *cs);
805
806 /**
807 * Wait for the fence and return true if the fence has been signalled.
808 * The timeout of 0 will only return the status.
809 * The timeout of PIPE_TIMEOUT_INFINITE will always wait until the fence
810 * is signalled.
811 */
812 bool (*fence_wait)(struct radeon_winsys *ws,
813 struct pipe_fence_handle *fence,
814 uint64_t timeout);
815
816 /**
817 * Reference counting for fences.
818 */
819 void (*fence_reference)(struct pipe_fence_handle **dst,
820 struct pipe_fence_handle *src);
821
822 /**
823 * Initialize surface
824 *
825 * \param ws The winsys this function is called from.
826 * \param tex Input texture description
827 * \param flags Bitmask of RADEON_SURF_* flags
828 * \param bpe Bytes per pixel, it can be different for Z buffers.
829 * \param mode Preferred tile mode. (linear, 1D, or 2D)
830 * \param surf Output structure
831 */
832 int (*surface_init)(struct radeon_winsys *ws,
833 const struct pipe_resource *tex,
834 unsigned flags, unsigned bpe,
835 enum radeon_surf_mode mode,
836 struct radeon_surf *surf);
837
838 uint64_t (*query_value)(struct radeon_winsys *ws,
839 enum radeon_value_id value);
840
841 bool (*read_registers)(struct radeon_winsys *ws, unsigned reg_offset,
842 unsigned num_registers, uint32_t *out);
843 };
844
845 static inline bool radeon_emitted(struct radeon_winsys_cs *cs, unsigned num_dw)
846 {
847 return cs && (cs->prev_dw + cs->current.cdw > num_dw);
848 }
849
850 static inline void radeon_emit(struct radeon_winsys_cs *cs, uint32_t value)
851 {
852 cs->current.buf[cs->current.cdw++] = value;
853 }
854
855 static inline void radeon_emit_array(struct radeon_winsys_cs *cs,
856 const uint32_t *values, unsigned count)
857 {
858 memcpy(cs->current.buf + cs->current.cdw, values, count * 4);
859 cs->current.cdw += count;
860 }
861
862 #endif