2 * Copyright © 2008 Jérôme Glisse
3 * Copyright © 2010 Marek Olšák <maraeo@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
18 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
29 * Marek Olšák <maraeo@gmail.com>
31 * Based on work from libdrm_radeon by:
32 * Aapo Tahkola <aet@rasterburn.org>
33 * Nicolai Haehnle <prefect_@gmx.net>
34 * Jérôme Glisse <glisse@freedesktop.org>
38 This file replaces libdrm's radeon_cs_gem with our own implemention.
39 It's optimized specifically for Radeon DRM.
40 Reloc writes and space checking are faster and simpler than their
41 counterparts in libdrm (the time complexity of all the functions
42 is O(1) in nearly all scenarios, thanks to hashing).
46 cs_add_reloc(cs, buf, read_domain, write_domain) adds a new relocation and
47 also adds the size of 'buf' to the used_gart and used_vram winsys variables
48 based on the domains, which are simply or'd for the accounting purposes.
49 The adding is skipped if the reloc is already present in the list, but it
50 accounts any newly-referenced domains.
52 cs_validate is then called, which just checks:
53 used_vram/gart < vram/gart_size * 0.8
54 The 0.8 number allows for some memory fragmentation. If the validation
55 fails, the pipe driver flushes CS and tries do the validation again,
56 i.e. it validates only that one operation. If it fails again, it drops
57 the operation on the floor and prints some nasty message to stderr.
58 (done in the pipe driver)
60 cs_write_reloc(cs, buf) just writes a reloc that has been added using
61 cs_add_reloc. The read_domain and write_domain parameters have been removed,
62 because we already specify them in cs_add_reloc.
65 #include "radeon_drm_cs.h"
67 #include "util/u_memory.h"
68 #include "os/os_time.h"
76 * this are copy from radeon_drm, once an updated libdrm is released
77 * we should bump configure.ac requirement for it and remove the following
80 #ifndef RADEON_CHUNK_ID_FLAGS
81 #define RADEON_CHUNK_ID_FLAGS 0x03
83 /* The first dword of RADEON_CHUNK_ID_FLAGS is a uint32 of these flags: */
84 #define RADEON_CS_KEEP_TILING_FLAGS 0x01
87 #ifndef RADEON_CS_USE_VM
88 #define RADEON_CS_USE_VM 0x02
89 /* The second dword of RADEON_CHUNK_ID_FLAGS is a uint32 that sets the ring type */
90 #define RADEON_CS_RING_GFX 0
91 #define RADEON_CS_RING_COMPUTE 1
94 #ifndef RADEON_CS_RING_DMA
95 #define RADEON_CS_RING_DMA 2
98 #ifndef RADEON_CS_RING_UVD
99 #define RADEON_CS_RING_UVD 3
102 #ifndef RADEON_CS_RING_VCE
103 #define RADEON_CS_RING_VCE 4
106 #ifndef RADEON_CS_END_OF_FRAME
107 #define RADEON_CS_END_OF_FRAME 0x04
111 #define RELOC_DWORDS (sizeof(struct drm_radeon_cs_reloc) / sizeof(uint32_t))
113 static boolean
radeon_init_cs_context(struct radeon_cs_context
*csc
,
114 struct radeon_drm_winsys
*ws
)
118 csc
->relocs_bo
= (struct radeon_bo
**)
119 CALLOC(1, csc
->nrelocs
* sizeof(struct radeon_bo
*));
120 if (!csc
->relocs_bo
) {
124 csc
->relocs
= (struct drm_radeon_cs_reloc
*)
125 CALLOC(1, csc
->nrelocs
* sizeof(struct drm_radeon_cs_reloc
));
127 FREE(csc
->relocs_bo
);
131 csc
->chunks
[0].chunk_id
= RADEON_CHUNK_ID_IB
;
132 csc
->chunks
[0].length_dw
= 0;
133 csc
->chunks
[0].chunk_data
= (uint64_t)(uintptr_t)csc
->buf
;
134 csc
->chunks
[1].chunk_id
= RADEON_CHUNK_ID_RELOCS
;
135 csc
->chunks
[1].length_dw
= 0;
136 csc
->chunks
[1].chunk_data
= (uint64_t)(uintptr_t)csc
->relocs
;
137 csc
->chunks
[2].chunk_id
= RADEON_CHUNK_ID_FLAGS
;
138 csc
->chunks
[2].length_dw
= 2;
139 csc
->chunks
[2].chunk_data
= (uint64_t)(uintptr_t)&csc
->flags
;
141 csc
->chunk_array
[0] = (uint64_t)(uintptr_t)&csc
->chunks
[0];
142 csc
->chunk_array
[1] = (uint64_t)(uintptr_t)&csc
->chunks
[1];
143 csc
->chunk_array
[2] = (uint64_t)(uintptr_t)&csc
->chunks
[2];
145 csc
->cs
.chunks
= (uint64_t)(uintptr_t)csc
->chunk_array
;
149 static void radeon_cs_context_cleanup(struct radeon_cs_context
*csc
)
153 for (i
= 0; i
< csc
->crelocs
; i
++) {
154 p_atomic_dec(&csc
->relocs_bo
[i
]->num_cs_references
);
155 radeon_bo_reference(&csc
->relocs_bo
[i
], NULL
);
159 csc
->validated_crelocs
= 0;
160 csc
->chunks
[0].length_dw
= 0;
161 csc
->chunks
[1].length_dw
= 0;
164 memset(csc
->is_handle_added
, 0, sizeof(csc
->is_handle_added
));
167 static void radeon_destroy_cs_context(struct radeon_cs_context
*csc
)
169 radeon_cs_context_cleanup(csc
);
170 FREE(csc
->relocs_bo
);
175 static struct radeon_winsys_cs
*radeon_drm_cs_create(struct radeon_winsys
*rws
,
176 enum ring_type ring_type
,
177 struct radeon_winsys_cs_handle
*trace_buf
)
179 struct radeon_drm_winsys
*ws
= radeon_drm_winsys(rws
);
180 struct radeon_drm_cs
*cs
;
182 cs
= CALLOC_STRUCT(radeon_drm_cs
);
186 pipe_semaphore_init(&cs
->flush_completed
, 1);
189 cs
->trace_buf
= (struct radeon_bo
*)trace_buf
;
191 if (!radeon_init_cs_context(&cs
->csc1
, cs
->ws
)) {
195 if (!radeon_init_cs_context(&cs
->csc2
, cs
->ws
)) {
196 radeon_destroy_cs_context(&cs
->csc1
);
201 /* Set the first command buffer as current. */
204 cs
->base
.buf
= cs
->csc
->buf
;
205 cs
->base
.ring_type
= ring_type
;
207 p_atomic_inc(&ws
->num_cs
);
211 #define OUT_CS(cs, value) (cs)->buf[(cs)->cdw++] = (value)
213 static INLINE
void update_reloc_domains(struct drm_radeon_cs_reloc
*reloc
,
214 enum radeon_bo_domain rd
,
215 enum radeon_bo_domain wd
,
216 enum radeon_bo_domain
*added_domains
)
218 *added_domains
= (rd
| wd
) & ~(reloc
->read_domains
| reloc
->write_domain
);
220 reloc
->read_domains
|= rd
;
221 reloc
->write_domain
|= wd
;
224 int radeon_get_reloc(struct radeon_cs_context
*csc
, struct radeon_bo
*bo
)
226 struct drm_radeon_cs_reloc
*reloc
;
228 unsigned hash
= bo
->handle
& (sizeof(csc
->is_handle_added
)-1);
230 if (csc
->is_handle_added
[hash
]) {
231 i
= csc
->reloc_indices_hashlist
[hash
];
232 reloc
= &csc
->relocs
[i
];
233 if (reloc
->handle
== bo
->handle
) {
237 /* Hash collision, look for the BO in the list of relocs linearly. */
238 for (i
= csc
->crelocs
; i
!= 0;) {
240 reloc
= &csc
->relocs
[i
];
241 if (reloc
->handle
== bo
->handle
) {
242 /* Put this reloc in the hash list.
243 * This will prevent additional hash collisions if there are
244 * several consecutive get_reloc calls for the same buffer.
246 * Example: Assuming buffers A,B,C collide in the hash list,
247 * the following sequence of relocs:
248 * AAAAAAAAAAABBBBBBBBBBBBBBCCCCCCCC
249 * will collide here: ^ and here: ^,
250 * meaning that we should get very few collisions in the end. */
251 csc
->reloc_indices_hashlist
[hash
] = i
;
252 /*printf("write_reloc collision, hash: %i, handle: %i\n", hash, bo->handle);*/
261 static unsigned radeon_add_reloc(struct radeon_drm_cs
*cs
,
262 struct radeon_bo
*bo
,
263 enum radeon_bo_usage usage
,
264 enum radeon_bo_domain domains
,
265 enum radeon_bo_domain
*added_domains
)
267 struct radeon_cs_context
*csc
= cs
->csc
;
268 struct drm_radeon_cs_reloc
*reloc
;
269 unsigned hash
= bo
->handle
& (sizeof(csc
->is_handle_added
)-1);
270 enum radeon_bo_domain rd
= usage
& RADEON_USAGE_READ
? domains
: 0;
271 enum radeon_bo_domain wd
= usage
& RADEON_USAGE_WRITE
? domains
: 0;
272 bool update_hash
= TRUE
;
276 if (csc
->is_handle_added
[hash
]) {
277 i
= csc
->reloc_indices_hashlist
[hash
];
278 reloc
= &csc
->relocs
[i
];
279 if (reloc
->handle
!= bo
->handle
) {
280 /* Hash collision, look for the BO in the list of relocs linearly. */
281 for (i
= csc
->crelocs
- 1; i
>= 0; i
--) {
282 reloc
= &csc
->relocs
[i
];
283 if (reloc
->handle
== bo
->handle
) {
284 /*printf("write_reloc collision, hash: %i, handle: %i\n", hash, bo->handle);*/
291 /* On DMA ring we need to emit as many relocation as there is use of the bo
292 * thus each time this function is call we should grow add again the bo to
293 * the relocation buffer
295 * Do not update the hash table if it's dma ring, so that first hash always point
296 * to first bo relocation which will the one used by the kernel. Following relocation
297 * will be ignore by the kernel memory placement (but still use by the kernel to
298 * update the cmd stream with proper buffer offset).
301 update_reloc_domains(reloc
, rd
, wd
, added_domains
);
302 if (cs
->base
.ring_type
!= RING_DMA
) {
303 csc
->reloc_indices_hashlist
[hash
] = i
;
309 /* New relocation, check if the backing array is large enough. */
310 if (csc
->crelocs
>= csc
->nrelocs
) {
314 size
= csc
->nrelocs
* sizeof(struct radeon_bo
*);
315 csc
->relocs_bo
= realloc(csc
->relocs_bo
, size
);
317 size
= csc
->nrelocs
* sizeof(struct drm_radeon_cs_reloc
);
318 csc
->relocs
= realloc(csc
->relocs
, size
);
320 csc
->chunks
[1].chunk_data
= (uint64_t)(uintptr_t)csc
->relocs
;
323 /* Initialize the new relocation. */
324 csc
->relocs_bo
[csc
->crelocs
] = NULL
;
325 radeon_bo_reference(&csc
->relocs_bo
[csc
->crelocs
], bo
);
326 p_atomic_inc(&bo
->num_cs_references
);
327 reloc
= &csc
->relocs
[csc
->crelocs
];
328 reloc
->handle
= bo
->handle
;
329 reloc
->read_domains
= rd
;
330 reloc
->write_domain
= wd
;
333 csc
->is_handle_added
[hash
] = TRUE
;
335 csc
->reloc_indices_hashlist
[hash
] = csc
->crelocs
;
338 csc
->chunks
[1].length_dw
+= RELOC_DWORDS
;
340 *added_domains
= rd
| wd
;
341 return csc
->crelocs
++;
344 static unsigned radeon_drm_cs_add_reloc(struct radeon_winsys_cs
*rcs
,
345 struct radeon_winsys_cs_handle
*buf
,
346 enum radeon_bo_usage usage
,
347 enum radeon_bo_domain domains
)
349 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
350 struct radeon_bo
*bo
= (struct radeon_bo
*)buf
;
351 enum radeon_bo_domain added_domains
;
352 unsigned index
= radeon_add_reloc(cs
, bo
, usage
, domains
, &added_domains
);
354 if (added_domains
& RADEON_DOMAIN_GTT
)
355 cs
->csc
->used_gart
+= bo
->base
.size
;
356 if (added_domains
& RADEON_DOMAIN_VRAM
)
357 cs
->csc
->used_vram
+= bo
->base
.size
;
362 static boolean
radeon_drm_cs_validate(struct radeon_winsys_cs
*rcs
)
364 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
366 cs
->csc
->used_gart
< cs
->ws
->info
.gart_size
* 0.8 &&
367 cs
->csc
->used_vram
< cs
->ws
->info
.vram_size
* 0.8;
370 cs
->csc
->validated_crelocs
= cs
->csc
->crelocs
;
372 /* Remove lately-added relocations. The validation failed with them
373 * and the CS is about to be flushed because of that. Keep only
374 * the already-validated relocations. */
377 for (i
= cs
->csc
->validated_crelocs
; i
< cs
->csc
->crelocs
; i
++) {
378 p_atomic_dec(&cs
->csc
->relocs_bo
[i
]->num_cs_references
);
379 radeon_bo_reference(&cs
->csc
->relocs_bo
[i
], NULL
);
381 cs
->csc
->crelocs
= cs
->csc
->validated_crelocs
;
383 /* Flush if there are any relocs. Clean up otherwise. */
384 if (cs
->csc
->crelocs
) {
385 cs
->flush_cs(cs
->flush_data
, RADEON_FLUSH_ASYNC
);
387 radeon_cs_context_cleanup(cs
->csc
);
389 assert(cs
->base
.cdw
== 0);
390 if (cs
->base
.cdw
!= 0) {
391 fprintf(stderr
, "radeon: Unexpected error in %s.\n", __func__
);
398 static boolean
radeon_drm_cs_memory_below_limit(struct radeon_winsys_cs
*rcs
, uint64_t vram
, uint64_t gtt
)
400 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
402 (cs
->csc
->used_gart
+ gtt
) < cs
->ws
->info
.gart_size
* 0.7 &&
403 (cs
->csc
->used_vram
+ vram
) < cs
->ws
->info
.vram_size
* 0.7;
408 static void radeon_drm_cs_write_reloc(struct radeon_winsys_cs
*rcs
,
409 struct radeon_winsys_cs_handle
*buf
)
411 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
412 struct radeon_bo
*bo
= (struct radeon_bo
*)buf
;
413 unsigned index
= radeon_get_reloc(cs
->csc
, bo
);
416 fprintf(stderr
, "radeon: Cannot get a relocation in %s.\n", __func__
);
420 OUT_CS(&cs
->base
, 0xc0001000);
421 OUT_CS(&cs
->base
, index
* RELOC_DWORDS
);
424 void radeon_drm_cs_emit_ioctl_oneshot(struct radeon_drm_cs
*cs
, struct radeon_cs_context
*csc
)
428 if (drmCommandWriteRead(csc
->fd
, DRM_RADEON_CS
,
429 &csc
->cs
, sizeof(struct drm_radeon_cs
))) {
430 if (debug_get_bool_option("RADEON_DUMP_CS", FALSE
)) {
433 fprintf(stderr
, "radeon: The kernel rejected CS, dumping...\n");
434 for (i
= 0; i
< csc
->chunks
[0].length_dw
; i
++) {
435 fprintf(stderr
, "0x%08X\n", csc
->buf
[i
]);
438 fprintf(stderr
, "radeon: The kernel rejected CS, "
439 "see dmesg for more information.\n");
444 radeon_dump_cs_on_lockup(cs
, csc
);
447 for (i
= 0; i
< csc
->crelocs
; i
++)
448 p_atomic_dec(&csc
->relocs_bo
[i
]->num_active_ioctls
);
450 radeon_cs_context_cleanup(csc
);
454 * Make sure previous submission of this cs are completed
456 void radeon_drm_cs_sync_flush(struct radeon_winsys_cs
*rcs
)
458 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
460 /* Wait for any pending ioctl to complete. */
461 if (cs
->ws
->thread
) {
462 pipe_semaphore_wait(&cs
->flush_completed
);
463 pipe_semaphore_signal(&cs
->flush_completed
);
467 DEBUG_GET_ONCE_BOOL_OPTION(noop
, "RADEON_NOOP", FALSE
)
469 static void radeon_drm_cs_flush(struct radeon_winsys_cs
*rcs
, unsigned flags
, uint32_t cs_trace_id
)
471 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
472 struct radeon_cs_context
*tmp
;
474 switch (cs
->base
.ring_type
) {
476 /* pad DMA ring to 8 DWs */
477 if (cs
->ws
->info
.chip_class
<= SI
) {
479 OUT_CS(&cs
->base
, 0xf0000000); /* NOP packet */
482 OUT_CS(&cs
->base
, 0x00000000); /* NOP packet */
486 /* pad DMA ring to 8 DWs to meet CP fetch alignment requirements
487 * r6xx, requires at least 4 dw alignment to avoid a hw bug.
489 if (cs
->ws
->info
.chip_class
<= SI
) {
491 OUT_CS(&cs
->base
, 0x80000000); /* type2 nop packet */
494 OUT_CS(&cs
->base
, 0xffff1000); /* type3 nop packet */
498 while (rcs
->cdw
& 15)
499 OUT_CS(&cs
->base
, 0x80000000); /* type2 nop packet */
505 if (rcs
->cdw
> RADEON_MAX_CMDBUF_DWORDS
) {
506 fprintf(stderr
, "radeon: command stream overflowed\n");
509 radeon_drm_cs_sync_flush(rcs
);
511 /* Flip command streams. */
516 cs
->cst
->cs_trace_id
= cs_trace_id
;
518 /* If the CS is not empty or overflowed, emit it in a separate thread. */
519 if (cs
->base
.cdw
&& cs
->base
.cdw
<= RADEON_MAX_CMDBUF_DWORDS
&& !debug_get_option_noop()) {
520 unsigned i
, crelocs
= cs
->cst
->crelocs
;
522 cs
->cst
->chunks
[0].length_dw
= cs
->base
.cdw
;
524 for (i
= 0; i
< crelocs
; i
++) {
525 /* Update the number of active asynchronous CS ioctls for the buffer. */
526 p_atomic_inc(&cs
->cst
->relocs_bo
[i
]->num_active_ioctls
);
529 switch (cs
->base
.ring_type
) {
531 cs
->cst
->flags
[0] = 0;
532 cs
->cst
->flags
[1] = RADEON_CS_RING_DMA
;
533 cs
->cst
->cs
.num_chunks
= 3;
534 if (cs
->ws
->info
.r600_virtual_address
) {
535 cs
->cst
->flags
[0] |= RADEON_CS_USE_VM
;
540 cs
->cst
->flags
[0] = 0;
541 cs
->cst
->flags
[1] = RADEON_CS_RING_UVD
;
542 cs
->cst
->cs
.num_chunks
= 3;
546 cs
->cst
->flags
[0] = 0;
547 cs
->cst
->flags
[1] = RADEON_CS_RING_VCE
;
548 cs
->cst
->cs
.num_chunks
= 3;
553 cs
->cst
->flags
[0] = 0;
554 cs
->cst
->flags
[1] = RADEON_CS_RING_GFX
;
555 cs
->cst
->cs
.num_chunks
= 2;
556 if (flags
& RADEON_FLUSH_KEEP_TILING_FLAGS
) {
557 cs
->cst
->flags
[0] |= RADEON_CS_KEEP_TILING_FLAGS
;
558 cs
->cst
->cs
.num_chunks
= 3;
560 if (cs
->ws
->info
.r600_virtual_address
) {
561 cs
->cst
->flags
[0] |= RADEON_CS_USE_VM
;
562 cs
->cst
->cs
.num_chunks
= 3;
564 if (flags
& RADEON_FLUSH_END_OF_FRAME
) {
565 cs
->cst
->flags
[0] |= RADEON_CS_END_OF_FRAME
;
566 cs
->cst
->cs
.num_chunks
= 3;
568 if (flags
& RADEON_FLUSH_COMPUTE
) {
569 cs
->cst
->flags
[1] = RADEON_CS_RING_COMPUTE
;
570 cs
->cst
->cs
.num_chunks
= 3;
575 if (cs
->ws
->thread
) {
576 pipe_semaphore_wait(&cs
->flush_completed
);
577 radeon_drm_ws_queue_cs(cs
->ws
, cs
);
578 if (!(flags
& RADEON_FLUSH_ASYNC
))
579 radeon_drm_cs_sync_flush(rcs
);
581 radeon_drm_cs_emit_ioctl_oneshot(cs
, cs
->cst
);
584 radeon_cs_context_cleanup(cs
->cst
);
587 /* Prepare a new CS. */
588 cs
->base
.buf
= cs
->csc
->buf
;
592 static void radeon_drm_cs_destroy(struct radeon_winsys_cs
*rcs
)
594 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
596 radeon_drm_cs_sync_flush(rcs
);
597 pipe_semaphore_destroy(&cs
->flush_completed
);
598 radeon_cs_context_cleanup(&cs
->csc1
);
599 radeon_cs_context_cleanup(&cs
->csc2
);
600 p_atomic_dec(&cs
->ws
->num_cs
);
601 radeon_destroy_cs_context(&cs
->csc1
);
602 radeon_destroy_cs_context(&cs
->csc2
);
606 static void radeon_drm_cs_set_flush(struct radeon_winsys_cs
*rcs
,
607 void (*flush
)(void *ctx
, unsigned flags
),
610 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
612 cs
->flush_cs
= flush
;
613 cs
->flush_data
= user
;
616 static boolean
radeon_bo_is_referenced(struct radeon_winsys_cs
*rcs
,
617 struct radeon_winsys_cs_handle
*_buf
,
618 enum radeon_bo_usage usage
)
620 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
621 struct radeon_bo
*bo
= (struct radeon_bo
*)_buf
;
624 if (!bo
->num_cs_references
)
627 index
= radeon_get_reloc(cs
->csc
, bo
);
631 if ((usage
& RADEON_USAGE_WRITE
) && cs
->csc
->relocs
[index
].write_domain
)
633 if ((usage
& RADEON_USAGE_READ
) && cs
->csc
->relocs
[index
].read_domains
)
641 static struct pipe_fence_handle
*
642 radeon_cs_create_fence(struct radeon_winsys_cs
*rcs
)
644 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
645 struct pb_buffer
*fence
;
647 /* Create a fence, which is a dummy BO. */
648 fence
= cs
->ws
->base
.buffer_create(&cs
->ws
->base
, 1, 1, TRUE
,
650 /* Add the fence as a dummy relocation. */
651 cs
->ws
->base
.cs_add_reloc(rcs
, cs
->ws
->base
.buffer_get_cs_handle(fence
),
652 RADEON_USAGE_READWRITE
, RADEON_DOMAIN_GTT
);
653 return (struct pipe_fence_handle
*)fence
;
656 static bool radeon_fence_wait(struct radeon_winsys
*ws
,
657 struct pipe_fence_handle
*fence
,
660 struct pb_buffer
*rfence
= (struct pb_buffer
*)fence
;
663 return !ws
->buffer_is_busy(rfence
, RADEON_USAGE_READWRITE
);
665 if (timeout
!= PIPE_TIMEOUT_INFINITE
) {
666 int64_t start_time
= os_time_get();
668 /* Convert to microseconds. */
671 /* Wait in a loop. */
672 while (ws
->buffer_is_busy(rfence
, RADEON_USAGE_READWRITE
)) {
673 if (os_time_get() - start_time
>= timeout
) {
681 ws
->buffer_wait(rfence
, RADEON_USAGE_READWRITE
);
685 static void radeon_fence_reference(struct pipe_fence_handle
**dst
,
686 struct pipe_fence_handle
*src
)
688 pb_reference((struct pb_buffer
**)dst
, (struct pb_buffer
*)src
);
691 void radeon_drm_cs_init_functions(struct radeon_drm_winsys
*ws
)
693 ws
->base
.cs_create
= radeon_drm_cs_create
;
694 ws
->base
.cs_destroy
= radeon_drm_cs_destroy
;
695 ws
->base
.cs_add_reloc
= radeon_drm_cs_add_reloc
;
696 ws
->base
.cs_validate
= radeon_drm_cs_validate
;
697 ws
->base
.cs_memory_below_limit
= radeon_drm_cs_memory_below_limit
;
698 ws
->base
.cs_write_reloc
= radeon_drm_cs_write_reloc
;
699 ws
->base
.cs_flush
= radeon_drm_cs_flush
;
700 ws
->base
.cs_set_flush_callback
= radeon_drm_cs_set_flush
;
701 ws
->base
.cs_is_buffer_referenced
= radeon_bo_is_referenced
;
702 ws
->base
.cs_sync_flush
= radeon_drm_cs_sync_flush
;
703 ws
->base
.cs_create_fence
= radeon_cs_create_fence
;
704 ws
->base
.fence_wait
= radeon_fence_wait
;
705 ws
->base
.fence_reference
= radeon_fence_reference
;