Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/radeon/radeon_winsys.h
4570 views
1
/*
2
* Copyright 2008 Corbin Simpson <[email protected]>
3
* Copyright 2010 Marek Olšák <[email protected]>
4
* Copyright 2018 Advanced Micro Devices, Inc.
5
* All Rights Reserved.
6
*
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the "Software"),
9
* to deal in the Software without restriction, including without limitation
10
* on the rights to use, copy, modify, merge, publish, distribute, sub
11
* license, and/or sell copies of the Software, and to permit persons to whom
12
* the Software is furnished to do so, subject to the following conditions:
13
*
14
* The above copyright notice and this permission notice (including the next
15
* paragraph) shall be included in all copies or substantial portions of the
16
* Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24
* USE OR OTHER DEALINGS IN THE SOFTWARE. */
25
26
#ifndef RADEON_WINSYS_H
27
#define RADEON_WINSYS_H
28
29
/* The public winsys interface header for the radeon driver. */
30
31
/* Skip command submission. Same as RADEON_NOOP=1. */
32
#define RADEON_FLUSH_NOOP (1u << 29)
33
34
/* Toggle the secure submission boolean after the flush */
35
#define RADEON_FLUSH_TOGGLE_SECURE_SUBMISSION (1u << 30)
36
37
/* Whether the next IB can start immediately and not wait for draws and
38
* dispatches from the current IB to finish. */
39
#define RADEON_FLUSH_START_NEXT_GFX_IB_NOW (1u << 31)
40
41
#define RADEON_FLUSH_ASYNC_START_NEXT_GFX_IB_NOW \
42
(PIPE_FLUSH_ASYNC | RADEON_FLUSH_START_NEXT_GFX_IB_NOW)
43
44
#include "amd/common/ac_gpu_info.h"
45
#include "amd/common/ac_surface.h"
46
#include "pipebuffer/pb_buffer.h"
47
48
/* Tiling flags. */
49
enum radeon_bo_layout
50
{
51
RADEON_LAYOUT_LINEAR = 0,
52
RADEON_LAYOUT_TILED,
53
RADEON_LAYOUT_SQUARETILED,
54
55
RADEON_LAYOUT_UNKNOWN
56
};
57
58
enum radeon_bo_domain
59
{ /* bitfield */
60
RADEON_DOMAIN_GTT = 2,
61
RADEON_DOMAIN_VRAM = 4,
62
RADEON_DOMAIN_VRAM_GTT = RADEON_DOMAIN_VRAM | RADEON_DOMAIN_GTT,
63
RADEON_DOMAIN_GDS = 8,
64
RADEON_DOMAIN_OA = 16,
65
};
66
67
enum radeon_bo_flag
68
{ /* bitfield */
69
RADEON_FLAG_GTT_WC = (1 << 0),
70
RADEON_FLAG_NO_CPU_ACCESS = (1 << 1),
71
RADEON_FLAG_NO_SUBALLOC = (1 << 2),
72
RADEON_FLAG_SPARSE = (1 << 3),
73
RADEON_FLAG_NO_INTERPROCESS_SHARING = (1 << 4),
74
RADEON_FLAG_READ_ONLY = (1 << 5),
75
RADEON_FLAG_32BIT = (1 << 6),
76
RADEON_FLAG_ENCRYPTED = (1 << 7),
77
RADEON_FLAG_UNCACHED = (1 << 8), /* only gfx9 and newer */
78
RADEON_FLAG_DRIVER_INTERNAL = (1 << 9),
79
};
80
81
enum radeon_dependency_flag
82
{
83
/* Add the dependency to the parallel compute IB only. */
84
RADEON_DEPENDENCY_PARALLEL_COMPUTE_ONLY = 1 << 0,
85
86
/* Instead of waiting for a job to finish execution, the dependency will
87
* be signaled when the job starts execution.
88
*/
89
RADEON_DEPENDENCY_START_FENCE = 1 << 1,
90
};
91
92
enum radeon_bo_usage
93
{ /* bitfield */
94
RADEON_USAGE_READ = 2,
95
RADEON_USAGE_WRITE = 4,
96
RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE,
97
98
/* The winsys ensures that the CS submission will be scheduled after
99
* previously flushed CSs referencing this BO in a conflicting way.
100
*/
101
RADEON_USAGE_SYNCHRONIZED = 8,
102
103
/* When used, an implicit sync is done to make sure a compute shader
104
* will read the written values from a previous draw.
105
*/
106
RADEON_USAGE_NEEDS_IMPLICIT_SYNC = 16,
107
};
108
109
enum radeon_map_flags
110
{
111
/* Indicates that the caller will unmap the buffer.
112
*
113
* Not unmapping buffers is an important performance optimization for
114
* OpenGL (avoids kernel overhead for frequently mapped buffers).
115
*/
116
RADEON_MAP_TEMPORARY = (PIPE_MAP_DRV_PRV << 0),
117
};
118
119
#define RADEON_SPARSE_PAGE_SIZE (64 * 1024)
120
121
enum radeon_value_id
122
{
123
RADEON_REQUESTED_VRAM_MEMORY,
124
RADEON_REQUESTED_GTT_MEMORY,
125
RADEON_MAPPED_VRAM,
126
RADEON_MAPPED_GTT,
127
RADEON_SLAB_WASTED_VRAM,
128
RADEON_SLAB_WASTED_GTT,
129
RADEON_BUFFER_WAIT_TIME_NS,
130
RADEON_NUM_MAPPED_BUFFERS,
131
RADEON_TIMESTAMP,
132
RADEON_NUM_GFX_IBS,
133
RADEON_NUM_SDMA_IBS,
134
RADEON_GFX_BO_LIST_COUNTER, /* number of BOs submitted in gfx IBs */
135
RADEON_GFX_IB_SIZE_COUNTER,
136
RADEON_NUM_BYTES_MOVED,
137
RADEON_NUM_EVICTIONS,
138
RADEON_NUM_VRAM_CPU_PAGE_FAULTS,
139
RADEON_VRAM_USAGE,
140
RADEON_VRAM_VIS_USAGE,
141
RADEON_GTT_USAGE,
142
RADEON_GPU_TEMPERATURE, /* DRM 2.42.0 */
143
RADEON_CURRENT_SCLK,
144
RADEON_CURRENT_MCLK,
145
RADEON_CS_THREAD_TIME,
146
};
147
148
enum radeon_bo_priority
149
{
150
/* Each group of two has the same priority. */
151
RADEON_PRIO_FENCE = 0,
152
RADEON_PRIO_TRACE,
153
154
RADEON_PRIO_SO_FILLED_SIZE = 2,
155
RADEON_PRIO_QUERY,
156
157
RADEON_PRIO_IB1 = 4, /* main IB submitted to the kernel */
158
RADEON_PRIO_IB2, /* IB executed with INDIRECT_BUFFER */
159
160
RADEON_PRIO_DRAW_INDIRECT = 6,
161
RADEON_PRIO_INDEX_BUFFER,
162
163
RADEON_PRIO_CP_DMA = 8,
164
RADEON_PRIO_BORDER_COLORS,
165
166
RADEON_PRIO_CONST_BUFFER = 10,
167
RADEON_PRIO_DESCRIPTORS,
168
169
RADEON_PRIO_SAMPLER_BUFFER = 12,
170
RADEON_PRIO_VERTEX_BUFFER,
171
172
RADEON_PRIO_SHADER_RW_BUFFER = 14,
173
RADEON_PRIO_COMPUTE_GLOBAL,
174
175
RADEON_PRIO_SAMPLER_TEXTURE = 16,
176
RADEON_PRIO_SHADER_RW_IMAGE,
177
178
RADEON_PRIO_SAMPLER_TEXTURE_MSAA = 18,
179
RADEON_PRIO_COLOR_BUFFER,
180
181
RADEON_PRIO_DEPTH_BUFFER = 20,
182
183
RADEON_PRIO_COLOR_BUFFER_MSAA = 22,
184
185
RADEON_PRIO_DEPTH_BUFFER_MSAA = 24,
186
187
RADEON_PRIO_SEPARATE_META = 26,
188
RADEON_PRIO_SHADER_BINARY, /* the hw can't hide instruction cache misses */
189
190
RADEON_PRIO_SHADER_RINGS = 28,
191
192
RADEON_PRIO_SCRATCH_BUFFER = 30,
193
/* 31 is the maximum value */
194
};
195
196
struct winsys_handle;
197
struct radeon_winsys_ctx;
198
199
struct radeon_cmdbuf_chunk {
200
unsigned cdw; /* Number of used dwords. */
201
unsigned max_dw; /* Maximum number of dwords. */
202
uint32_t *buf; /* The base pointer of the chunk. */
203
};
204
205
struct radeon_cmdbuf {
206
struct radeon_cmdbuf_chunk current;
207
struct radeon_cmdbuf_chunk *prev;
208
uint16_t num_prev; /* Number of previous chunks. */
209
uint16_t max_prev; /* Space in array pointed to by prev. */
210
unsigned prev_dw; /* Total number of dwords in previous chunks. */
211
212
/* Memory usage of the buffer list. These are always 0 for preamble IBs. */
213
uint32_t used_vram_kb;
214
uint32_t used_gart_kb;
215
uint64_t gpu_address;
216
217
/* Private winsys data. */
218
void *priv;
219
};
220
221
/* Tiling info for display code, DRI sharing, and other data. */
222
struct radeon_bo_metadata {
223
/* Tiling flags describing the texture layout for display code
224
* and DRI sharing.
225
*/
226
union {
227
struct {
228
enum radeon_bo_layout microtile;
229
enum radeon_bo_layout macrotile;
230
unsigned pipe_config;
231
unsigned bankw;
232
unsigned bankh;
233
unsigned tile_split;
234
unsigned mtilea;
235
unsigned num_banks;
236
unsigned stride;
237
bool scanout;
238
} legacy;
239
} u;
240
241
enum radeon_surf_mode mode; /* Output from buffer_get_metadata */
242
243
/* Additional metadata associated with the buffer, in bytes.
244
* The maximum size is 64 * 4. This is opaque for the winsys & kernel.
245
* Supported by amdgpu only.
246
*/
247
uint32_t size_metadata;
248
uint32_t metadata[64];
249
};
250
251
enum radeon_feature_id
252
{
253
RADEON_FID_R300_HYPERZ_ACCESS, /* ZMask + HiZ */
254
RADEON_FID_R300_CMASK_ACCESS,
255
};
256
257
struct radeon_bo_list_item {
258
uint64_t bo_size;
259
uint64_t vm_address;
260
uint32_t priority_usage; /* mask of (1 << RADEON_PRIO_*) */
261
};
262
263
struct radeon_winsys {
264
/**
265
* The screen object this winsys was created for
266
*/
267
struct pipe_screen *screen;
268
/**
269
* Has the application created at least one TMZ buffer.
270
*/
271
const bool uses_secure_bos;
272
273
/**
274
* Decrement the winsys reference count.
275
*
276
* \param ws The winsys this function is called for.
277
* \return True if the winsys and screen should be destroyed.
278
*/
279
bool (*unref)(struct radeon_winsys *ws);
280
281
/**
282
* Destroy this winsys.
283
*
284
* \param ws The winsys this function is called from.
285
*/
286
void (*destroy)(struct radeon_winsys *ws);
287
288
/**
289
* Query an info structure from winsys.
290
*
291
* \param ws The winsys this function is called from.
292
* \param info Return structure
293
*/
294
void (*query_info)(struct radeon_winsys *ws, struct radeon_info *info,
295
bool enable_smart_access_memory,
296
bool disable_smart_access_memory);
297
298
/**
299
* A hint for the winsys that it should pin its execution threads to
300
* a group of cores sharing a specific L3 cache if the CPU has multiple
301
* L3 caches. This is needed for good multithreading performance on
302
* AMD Zen CPUs.
303
*/
304
void (*pin_threads_to_L3_cache)(struct radeon_winsys *ws, unsigned cache);
305
306
/**************************************************************************
307
* Buffer management. Buffer attributes are mostly fixed over its lifetime.
308
*
309
* Remember that gallium gets to choose the interface it needs, and the
310
* window systems must then implement that interface (rather than the
311
* other way around...).
312
*************************************************************************/
313
314
/**
315
* Create a buffer object.
316
*
317
* \param ws The winsys this function is called from.
318
* \param size The size to allocate.
319
* \param alignment An alignment of the buffer in memory.
320
* \param use_reusable_pool Whether the cache buffer manager should be used.
321
* \param domain A bitmask of the RADEON_DOMAIN_* flags.
322
* \return The created buffer object.
323
*/
324
struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws, uint64_t size, unsigned alignment,
325
enum radeon_bo_domain domain, enum radeon_bo_flag flags);
326
327
/**
328
* Map the entire data store of a buffer object into the client's address
329
* space.
330
*
331
* Callers are expected to unmap buffers again if and only if the
332
* RADEON_MAP_TEMPORARY flag is set in \p usage.
333
*
334
* \param buf A winsys buffer object to map.
335
* \param cs A command stream to flush if the buffer is referenced by it.
336
* \param usage A bitmask of the PIPE_MAP_* and RADEON_MAP_* flags.
337
* \return The pointer at the beginning of the buffer.
338
*/
339
void *(*buffer_map)(struct radeon_winsys *ws, struct pb_buffer *buf,
340
struct radeon_cmdbuf *cs, enum pipe_map_flags usage);
341
342
/**
343
* Unmap a buffer object from the client's address space.
344
*
345
* \param buf A winsys buffer object to unmap.
346
*/
347
void (*buffer_unmap)(struct radeon_winsys *ws, struct pb_buffer *buf);
348
349
/**
350
* Wait for the buffer and return true if the buffer is not used
351
* by the device.
352
*
353
* The timeout of 0 will only return the status.
354
* The timeout of PIPE_TIMEOUT_INFINITE will always wait until the buffer
355
* is idle.
356
*/
357
bool (*buffer_wait)(struct radeon_winsys *ws, struct pb_buffer *buf,
358
uint64_t timeout, enum radeon_bo_usage usage);
359
360
/**
361
* Return buffer metadata.
362
* (tiling info for display code, DRI sharing, and other data)
363
*
364
* \param buf A winsys buffer object to get the flags from.
365
* \param md Metadata
366
*/
367
void (*buffer_get_metadata)(struct radeon_winsys *ws, struct pb_buffer *buf,
368
struct radeon_bo_metadata *md, struct radeon_surf *surf);
369
370
/**
371
* Set buffer metadata.
372
* (tiling info for display code, DRI sharing, and other data)
373
*
374
* \param buf A winsys buffer object to set the flags for.
375
* \param md Metadata
376
*/
377
void (*buffer_set_metadata)(struct radeon_winsys *ws, struct pb_buffer *buf,
378
struct radeon_bo_metadata *md, struct radeon_surf *surf);
379
380
/**
381
* Get a winsys buffer from a winsys handle. The internal structure
382
* of the handle is platform-specific and only a winsys should access it.
383
*
384
* \param ws The winsys this function is called from.
385
* \param whandle A winsys handle pointer as was received from a state
386
* tracker.
387
*/
388
struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws, struct winsys_handle *whandle,
389
unsigned vm_alignment);
390
391
/**
392
* Get a winsys buffer from a user pointer. The resulting buffer can't
393
* be exported. Both pointer and size must be page aligned.
394
*
395
* \param ws The winsys this function is called from.
396
* \param pointer User pointer to turn into a buffer object.
397
* \param Size Size in bytes for the new buffer.
398
*/
399
struct pb_buffer *(*buffer_from_ptr)(struct radeon_winsys *ws, void *pointer, uint64_t size);
400
401
/**
402
* Whether the buffer was created from a user pointer.
403
*
404
* \param buf A winsys buffer object
405
* \return whether \p buf was created via buffer_from_ptr
406
*/
407
bool (*buffer_is_user_ptr)(struct pb_buffer *buf);
408
409
/** Whether the buffer was suballocated. */
410
bool (*buffer_is_suballocated)(struct pb_buffer *buf);
411
412
/**
413
* Get a winsys handle from a winsys buffer. The internal structure
414
* of the handle is platform-specific and only a winsys should access it.
415
*
416
* \param ws The winsys instance for which the handle is to be valid
417
* \param buf A winsys buffer object to get the handle from.
418
* \param whandle A winsys handle pointer.
419
* \return true on success.
420
*/
421
bool (*buffer_get_handle)(struct radeon_winsys *ws, struct pb_buffer *buf,
422
struct winsys_handle *whandle);
423
424
/**
425
* Change the commitment of a (64KB-page aligned) region of the given
426
* sparse buffer.
427
*
428
* \warning There is no automatic synchronization with command submission.
429
*
430
* \note Only implemented by the amdgpu winsys.
431
*
432
* \return false on out of memory or other failure, true on success.
433
*/
434
bool (*buffer_commit)(struct radeon_winsys *ws, struct pb_buffer *buf,
435
uint64_t offset, uint64_t size, bool commit);
436
437
/**
438
* Return the virtual address of a buffer.
439
*
440
* When virtual memory is not in use, this is the offset relative to the
441
* relocation base (non-zero for sub-allocated buffers).
442
*
443
* \param buf A winsys buffer object
444
* \return virtual address
445
*/
446
uint64_t (*buffer_get_virtual_address)(struct pb_buffer *buf);
447
448
/**
449
* Return the offset of this buffer relative to the relocation base.
450
* This is only non-zero for sub-allocated buffers.
451
*
452
* This is only supported in the radeon winsys, since amdgpu uses virtual
453
* addresses in submissions even for the video engines.
454
*
455
* \param buf A winsys buffer object
456
* \return the offset for relocations
457
*/
458
unsigned (*buffer_get_reloc_offset)(struct pb_buffer *buf);
459
460
/**
461
* Query the initial placement of the buffer from the kernel driver.
462
*/
463
enum radeon_bo_domain (*buffer_get_initial_domain)(struct pb_buffer *buf);
464
465
/**
466
* Query the flags used for creation of this buffer.
467
*
468
* Note that for imported buffer this may be lossy since not all flags
469
* are passed 1:1.
470
*/
471
enum radeon_bo_flag (*buffer_get_flags)(struct pb_buffer *buf);
472
473
/**************************************************************************
474
* Command submission.
475
*
476
* Each pipe context should create its own command stream and submit
477
* commands independently of other contexts.
478
*************************************************************************/
479
480
/**
481
* Create a command submission context.
482
* Various command streams can be submitted to the same context.
483
*/
484
struct radeon_winsys_ctx *(*ctx_create)(struct radeon_winsys *ws);
485
486
/**
487
* Destroy a context.
488
*/
489
void (*ctx_destroy)(struct radeon_winsys_ctx *ctx);
490
491
/**
492
* Query a GPU reset status.
493
*/
494
enum pipe_reset_status (*ctx_query_reset_status)(struct radeon_winsys_ctx *ctx,
495
bool full_reset_only,
496
bool *needs_reset);
497
498
/**
499
* Create a command stream.
500
*
501
* \param cs The returned structure that is initialized by cs_create.
502
* \param ctx The submission context
503
* \param ring_type The ring type (GFX, DMA, UVD)
504
* \param flush Flush callback function associated with the command stream.
505
* \param user User pointer that will be passed to the flush callback.
506
*
507
* \return true on success
508
*/
509
bool (*cs_create)(struct radeon_cmdbuf *cs,
510
struct radeon_winsys_ctx *ctx, enum ring_type ring_type,
511
void (*flush)(void *ctx, unsigned flags,
512
struct pipe_fence_handle **fence),
513
void *flush_ctx, bool stop_exec_on_failure);
514
515
/**
516
* Add a parallel compute IB to a gfx IB. It will share the buffer list
517
* and fence dependencies with the gfx IB. The gfx flush call will submit
518
* both IBs at the same time.
519
*
520
* The compute IB doesn't have an output fence, so the primary IB has
521
* to use a wait packet for synchronization.
522
*
523
* The returned IB is only a stream for writing packets to the new
524
* IB. The only function that can be used on the compute cs is cs_check_space.
525
*
526
* \param compute_cs The returned structure of the command stream.
527
* \param gfx_cs Gfx IB
528
*
529
* \return true on success
530
*/
531
bool (*cs_add_parallel_compute_ib)(struct radeon_cmdbuf *compute_cs,
532
struct radeon_cmdbuf *gfx_cs,
533
bool uses_gds_ordered_append);
534
535
/**
536
* Set up and enable mid command buffer preemption for the command stream.
537
*
538
* \param cs Command stream
539
* \param preamble_ib Non-preemptible preamble IB for the context.
540
* \param preamble_num_dw Number of dwords in the preamble IB.
541
*/
542
bool (*cs_setup_preemption)(struct radeon_cmdbuf *cs, const uint32_t *preamble_ib,
543
unsigned preamble_num_dw);
544
545
/**
546
* Destroy a command stream.
547
*
548
* \param cs A command stream to destroy.
549
*/
550
void (*cs_destroy)(struct radeon_cmdbuf *cs);
551
552
/**
553
* Add a buffer. Each buffer used by a CS must be added using this function.
554
*
555
* \param cs Command stream
556
* \param buf Buffer
557
* \param usage Whether the buffer is used for read and/or write.
558
* \param domain Bitmask of the RADEON_DOMAIN_* flags.
559
* \param priority A higher number means a greater chance of being
560
* placed in the requested domain. 15 is the maximum.
561
* \return Buffer index.
562
*/
563
unsigned (*cs_add_buffer)(struct radeon_cmdbuf *cs, struct pb_buffer *buf,
564
enum radeon_bo_usage usage, enum radeon_bo_domain domain,
565
enum radeon_bo_priority priority);
566
567
/**
568
* Return the index of an already-added buffer.
569
*
570
* Not supported on amdgpu. Drivers with GPUVM should not care about
571
* buffer indices.
572
*
573
* \param cs Command stream
574
* \param buf Buffer
575
* \return The buffer index, or -1 if the buffer has not been added.
576
*/
577
int (*cs_lookup_buffer)(struct radeon_cmdbuf *cs, struct pb_buffer *buf);
578
579
/**
580
* Return true if there is enough memory in VRAM and GTT for the buffers
581
* added so far. If the validation fails, all buffers which have
582
* been added since the last call of cs_validate will be removed and
583
* the CS will be flushed (provided there are still any buffers).
584
*
585
* \param cs A command stream to validate.
586
*/
587
bool (*cs_validate)(struct radeon_cmdbuf *cs);
588
589
/**
590
* Check whether the given number of dwords is available in the IB.
591
* Optionally chain a new chunk of the IB if necessary and supported.
592
*
593
* \param cs A command stream.
594
* \param dw Number of CS dwords requested by the caller.
595
* \param force_chaining Chain the IB into a new buffer now to discard
596
* the CP prefetch cache (to emulate PKT3_REWIND)
597
* \return true if there is enough space
598
*/
599
bool (*cs_check_space)(struct radeon_cmdbuf *cs, unsigned dw, bool force_chaining);
600
601
/**
602
* Return the buffer list.
603
*
604
* This is the buffer list as passed to the kernel, i.e. it only contains
605
* the parent buffers of sub-allocated buffers.
606
*
607
* \param cs Command stream
608
* \param list Returned buffer list. Set to NULL to query the count only.
609
* \return The buffer count.
610
*/
611
unsigned (*cs_get_buffer_list)(struct radeon_cmdbuf *cs, struct radeon_bo_list_item *list);
612
613
/**
614
* Flush a command stream.
615
*
616
* \param cs A command stream to flush.
617
* \param flags, PIPE_FLUSH_* flags.
618
* \param fence Pointer to a fence. If non-NULL, a fence is inserted
619
* after the CS and is returned through this parameter.
620
* \return Negative POSIX error code or 0 for success.
621
* Asynchronous submissions never return an error.
622
*/
623
int (*cs_flush)(struct radeon_cmdbuf *cs, unsigned flags, struct pipe_fence_handle **fence);
624
625
/**
626
* Create a fence before the CS is flushed.
627
* The user must flush manually to complete the initializaton of the fence.
628
*
629
* The fence must not be used for anything except \ref cs_add_fence_dependency
630
* before the flush.
631
*/
632
struct pipe_fence_handle *(*cs_get_next_fence)(struct radeon_cmdbuf *cs);
633
634
/**
635
* Return true if a buffer is referenced by a command stream.
636
*
637
* \param cs A command stream.
638
* \param buf A winsys buffer.
639
*/
640
bool (*cs_is_buffer_referenced)(struct radeon_cmdbuf *cs, struct pb_buffer *buf,
641
enum radeon_bo_usage usage);
642
643
/**
644
* Request access to a feature for a command stream.
645
*
646
* \param cs A command stream.
647
* \param fid Feature ID, one of RADEON_FID_*
648
* \param enable Whether to enable or disable the feature.
649
*/
650
bool (*cs_request_feature)(struct radeon_cmdbuf *cs, enum radeon_feature_id fid, bool enable);
651
/**
652
* Make sure all asynchronous flush of the cs have completed
653
*
654
* \param cs A command stream.
655
*/
656
void (*cs_sync_flush)(struct radeon_cmdbuf *cs);
657
658
/**
659
* Add a fence dependency to the CS, so that the CS will wait for
660
* the fence before execution.
661
*
662
* \param dependency_flags Bitmask of RADEON_DEPENDENCY_*
663
*/
664
void (*cs_add_fence_dependency)(struct radeon_cmdbuf *cs, struct pipe_fence_handle *fence,
665
unsigned dependency_flags);
666
667
/**
668
* Signal a syncobj when the CS finishes execution.
669
*/
670
void (*cs_add_syncobj_signal)(struct radeon_cmdbuf *cs, struct pipe_fence_handle *fence);
671
672
/**
673
* Wait for the fence and return true if the fence has been signalled.
674
* The timeout of 0 will only return the status.
675
* The timeout of PIPE_TIMEOUT_INFINITE will always wait until the fence
676
* is signalled.
677
*/
678
bool (*fence_wait)(struct radeon_winsys *ws, struct pipe_fence_handle *fence, uint64_t timeout);
679
680
/**
681
* Reference counting for fences.
682
*/
683
void (*fence_reference)(struct pipe_fence_handle **dst, struct pipe_fence_handle *src);
684
685
/**
686
* Create a new fence object corresponding to the given syncobj fd.
687
*/
688
struct pipe_fence_handle *(*fence_import_syncobj)(struct radeon_winsys *ws, int fd);
689
690
/**
691
* Create a new fence object corresponding to the given sync_file.
692
*/
693
struct pipe_fence_handle *(*fence_import_sync_file)(struct radeon_winsys *ws, int fd);
694
695
/**
696
* Return a sync_file FD corresponding to the given fence object.
697
*/
698
int (*fence_export_sync_file)(struct radeon_winsys *ws, struct pipe_fence_handle *fence);
699
700
/**
701
* Return a sync file FD that is already signalled.
702
*/
703
int (*export_signalled_sync_file)(struct radeon_winsys *ws);
704
705
/**
706
* Initialize surface
707
*
708
* \param ws The winsys this function is called from.
709
* \param tex Input texture description
710
* \param flags Bitmask of RADEON_SURF_* flags
711
* \param bpe Bytes per pixel, it can be different for Z buffers.
712
* \param mode Preferred tile mode. (linear, 1D, or 2D)
713
* \param surf Output structure
714
*/
715
int (*surface_init)(struct radeon_winsys *ws, const struct pipe_resource *tex, unsigned flags,
716
unsigned bpe, enum radeon_surf_mode mode, struct radeon_surf *surf);
717
718
uint64_t (*query_value)(struct radeon_winsys *ws, enum radeon_value_id value);
719
720
bool (*read_registers)(struct radeon_winsys *ws, unsigned reg_offset, unsigned num_registers,
721
uint32_t *out);
722
723
/**
724
* Secure context
725
*/
726
bool (*cs_is_secure)(struct radeon_cmdbuf *cs);
727
};
728
729
static inline bool radeon_emitted(struct radeon_cmdbuf *cs, unsigned num_dw)
730
{
731
return cs && (cs->prev_dw + cs->current.cdw > num_dw);
732
}
733
734
static inline void radeon_emit(struct radeon_cmdbuf *cs, uint32_t value)
735
{
736
cs->current.buf[cs->current.cdw++] = value;
737
}
738
739
static inline void radeon_emit_array(struct radeon_cmdbuf *cs, const uint32_t *values,
740
unsigned count)
741
{
742
memcpy(cs->current.buf + cs->current.cdw, values, count * 4);
743
cs->current.cdw += count;
744
}
745
746
static inline bool radeon_uses_secure_bos(struct radeon_winsys* ws)
747
{
748
return ws->uses_secure_bos;
749
}
750
751
static inline void
752
radeon_bo_reference(struct radeon_winsys *rws, struct pb_buffer **dst, struct pb_buffer *src)
753
{
754
pb_reference_with_winsys(rws, dst, src);
755
}
756
757
enum radeon_heap
758
{
759
RADEON_HEAP_VRAM_NO_CPU_ACCESS,
760
RADEON_HEAP_VRAM_READ_ONLY,
761
RADEON_HEAP_VRAM_READ_ONLY_32BIT,
762
RADEON_HEAP_VRAM_32BIT,
763
RADEON_HEAP_VRAM,
764
RADEON_HEAP_GTT_WC,
765
RADEON_HEAP_GTT_WC_READ_ONLY,
766
RADEON_HEAP_GTT_WC_READ_ONLY_32BIT,
767
RADEON_HEAP_GTT_WC_32BIT,
768
RADEON_HEAP_GTT,
769
RADEON_HEAP_GTT_UNCACHED_WC,
770
RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY,
771
RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY_32BIT,
772
RADEON_HEAP_GTT_UNCACHED_WC_32BIT,
773
RADEON_HEAP_GTT_UNCACHED,
774
RADEON_MAX_SLAB_HEAPS,
775
RADEON_MAX_CACHED_HEAPS = RADEON_MAX_SLAB_HEAPS,
776
};
777
778
static inline enum radeon_bo_domain radeon_domain_from_heap(enum radeon_heap heap)
779
{
780
switch (heap) {
781
case RADEON_HEAP_VRAM_NO_CPU_ACCESS:
782
case RADEON_HEAP_VRAM_READ_ONLY:
783
case RADEON_HEAP_VRAM_READ_ONLY_32BIT:
784
case RADEON_HEAP_VRAM_32BIT:
785
case RADEON_HEAP_VRAM:
786
return RADEON_DOMAIN_VRAM;
787
case RADEON_HEAP_GTT_WC:
788
case RADEON_HEAP_GTT_WC_READ_ONLY:
789
case RADEON_HEAP_GTT_WC_READ_ONLY_32BIT:
790
case RADEON_HEAP_GTT_WC_32BIT:
791
case RADEON_HEAP_GTT:
792
case RADEON_HEAP_GTT_UNCACHED_WC:
793
case RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY:
794
case RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY_32BIT:
795
case RADEON_HEAP_GTT_UNCACHED_WC_32BIT:
796
case RADEON_HEAP_GTT_UNCACHED:
797
return RADEON_DOMAIN_GTT;
798
default:
799
assert(0);
800
return (enum radeon_bo_domain)0;
801
}
802
}
803
804
static inline unsigned radeon_flags_from_heap(enum radeon_heap heap)
805
{
806
unsigned flags = RADEON_FLAG_NO_INTERPROCESS_SHARING;
807
808
switch (heap) {
809
case RADEON_HEAP_GTT:
810
case RADEON_HEAP_GTT_UNCACHED:
811
break;
812
default:
813
flags |= RADEON_FLAG_GTT_WC;
814
}
815
816
switch (heap) {
817
case RADEON_HEAP_GTT_UNCACHED_WC:
818
case RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY:
819
case RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY_32BIT:
820
case RADEON_HEAP_GTT_UNCACHED_WC_32BIT:
821
case RADEON_HEAP_GTT_UNCACHED:
822
flags |= RADEON_FLAG_UNCACHED;
823
break;
824
default:
825
break;
826
}
827
828
switch (heap) {
829
case RADEON_HEAP_VRAM_READ_ONLY:
830
case RADEON_HEAP_VRAM_READ_ONLY_32BIT:
831
case RADEON_HEAP_GTT_WC_READ_ONLY:
832
case RADEON_HEAP_GTT_WC_READ_ONLY_32BIT:
833
case RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY:
834
case RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY_32BIT:
835
flags |= RADEON_FLAG_READ_ONLY;
836
break;
837
default:
838
break;
839
}
840
841
switch (heap) {
842
case RADEON_HEAP_VRAM_READ_ONLY_32BIT:
843
case RADEON_HEAP_VRAM_32BIT:
844
case RADEON_HEAP_GTT_WC_READ_ONLY_32BIT:
845
case RADEON_HEAP_GTT_WC_32BIT:
846
case RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY_32BIT:
847
case RADEON_HEAP_GTT_UNCACHED_WC_32BIT:
848
flags |= RADEON_FLAG_32BIT;
849
FALLTHROUGH;
850
default:
851
break;
852
}
853
854
switch (heap) {
855
case RADEON_HEAP_VRAM_NO_CPU_ACCESS:
856
flags |= RADEON_FLAG_NO_CPU_ACCESS;
857
break;
858
default:
859
break;
860
}
861
862
return flags;
863
}
864
865
/* Return the heap index for winsys allocators, or -1 on failure. */
866
static inline int radeon_get_heap_index(enum radeon_bo_domain domain, enum radeon_bo_flag flags)
867
{
868
bool uncached;
869
870
/* VRAM implies WC (write combining) */
871
assert(!(domain & RADEON_DOMAIN_VRAM) || flags & RADEON_FLAG_GTT_WC);
872
/* NO_CPU_ACCESS implies VRAM only. */
873
assert(!(flags & RADEON_FLAG_NO_CPU_ACCESS) || domain == RADEON_DOMAIN_VRAM);
874
875
/* Resources with interprocess sharing don't use any winsys allocators. */
876
if (!(flags & RADEON_FLAG_NO_INTERPROCESS_SHARING))
877
return -1;
878
879
/* Unsupported flags: NO_SUBALLOC, SPARSE. */
880
if (flags & ~(RADEON_FLAG_GTT_WC | RADEON_FLAG_NO_CPU_ACCESS | RADEON_FLAG_UNCACHED |
881
RADEON_FLAG_NO_INTERPROCESS_SHARING | RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT |
882
RADEON_FLAG_DRIVER_INTERNAL))
883
return -1;
884
885
switch (domain) {
886
case RADEON_DOMAIN_VRAM:
887
switch (flags & (RADEON_FLAG_NO_CPU_ACCESS | RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT)) {
888
case RADEON_FLAG_NO_CPU_ACCESS | RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT:
889
case RADEON_FLAG_NO_CPU_ACCESS | RADEON_FLAG_READ_ONLY:
890
assert(!"NO_CPU_ACCESS | READ_ONLY doesn't make sense");
891
return -1;
892
case RADEON_FLAG_NO_CPU_ACCESS | RADEON_FLAG_32BIT:
893
assert(!"NO_CPU_ACCESS with 32BIT is disallowed");
894
return -1;
895
case RADEON_FLAG_NO_CPU_ACCESS:
896
return RADEON_HEAP_VRAM_NO_CPU_ACCESS;
897
case RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT:
898
return RADEON_HEAP_VRAM_READ_ONLY_32BIT;
899
case RADEON_FLAG_READ_ONLY:
900
return RADEON_HEAP_VRAM_READ_ONLY;
901
case RADEON_FLAG_32BIT:
902
return RADEON_HEAP_VRAM_32BIT;
903
case 0:
904
return RADEON_HEAP_VRAM;
905
}
906
break;
907
case RADEON_DOMAIN_GTT:
908
uncached = flags & RADEON_FLAG_UNCACHED;
909
910
switch (flags & (RADEON_FLAG_GTT_WC | RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT)) {
911
case RADEON_FLAG_GTT_WC | RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT:
912
return uncached ? RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY_32BIT
913
: RADEON_HEAP_GTT_WC_READ_ONLY_32BIT;
914
case RADEON_FLAG_GTT_WC | RADEON_FLAG_READ_ONLY:
915
return uncached ? RADEON_HEAP_GTT_UNCACHED_WC_READ_ONLY
916
: RADEON_HEAP_GTT_WC_READ_ONLY;
917
case RADEON_FLAG_GTT_WC | RADEON_FLAG_32BIT:
918
return uncached ? RADEON_HEAP_GTT_UNCACHED_WC_32BIT
919
: RADEON_HEAP_GTT_WC_32BIT;
920
case RADEON_FLAG_GTT_WC:
921
return uncached ? RADEON_HEAP_GTT_UNCACHED_WC : RADEON_HEAP_GTT_WC;
922
case RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT:
923
case RADEON_FLAG_READ_ONLY:
924
assert(!"READ_ONLY without WC is disallowed");
925
return -1;
926
case RADEON_FLAG_32BIT:
927
assert(!"32BIT without WC is disallowed");
928
return -1;
929
case 0:
930
return uncached ? RADEON_HEAP_GTT_UNCACHED : RADEON_HEAP_GTT;
931
}
932
break;
933
default:
934
break;
935
}
936
return -1;
937
}
938
939
#endif
940
941