2 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
3 * Copyright © 2015 Advanced Micro Devices, Inc.
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>
32 #include "amdgpu_cs.h"
34 #include "os/os_time.h"
35 #include "state_tracker/drm_driver.h"
36 #include <amdgpu_drm.h>
40 static inline struct amdgpu_winsys_bo
*amdgpu_winsys_bo(struct pb_buffer
*bo
)
42 return (struct amdgpu_winsys_bo
*)bo
;
45 static bool amdgpu_bo_wait(struct pb_buffer
*_buf
, uint64_t timeout
,
46 enum radeon_bo_usage usage
)
48 struct amdgpu_winsys_bo
*bo
= amdgpu_winsys_bo(_buf
);
49 struct amdgpu_winsys
*ws
= bo
->ws
;
53 /* We can't use user fences for shared buffers, because user fences
54 * are local to this process only. If we want to wait for all buffer
55 * uses in all processes, we have to use amdgpu_bo_wait_for_idle.
57 bool buffer_busy
= true;
60 r
= amdgpu_bo_wait_for_idle(bo
->bo
, timeout
, &buffer_busy
);
62 fprintf(stderr
, "%s: amdgpu_bo_wait_for_idle failed %i\n", __func__
,
68 /* Timeout == 0 is quite simple. */
69 pipe_mutex_lock(ws
->bo_fence_lock
);
70 for (i
= 0; i
< RING_LAST
; i
++)
72 if (amdgpu_fence_wait(bo
->fence
[i
], 0, false)) {
73 /* Release the idle fence to avoid checking it again later. */
74 amdgpu_fence_reference(&bo
->fence
[i
], NULL
);
76 pipe_mutex_unlock(ws
->bo_fence_lock
);
80 pipe_mutex_unlock(ws
->bo_fence_lock
);
84 struct pipe_fence_handle
*fence
[RING_LAST
] = {};
85 bool fence_idle
[RING_LAST
] = {};
86 bool buffer_idle
= true;
87 int64_t abs_timeout
= os_time_get_absolute_timeout(timeout
);
89 /* Take references to all fences, so that we can wait for them
90 * without the lock. */
91 pipe_mutex_lock(ws
->bo_fence_lock
);
92 for (i
= 0; i
< RING_LAST
; i
++)
93 amdgpu_fence_reference(&fence
[i
], bo
->fence
[i
]);
94 pipe_mutex_unlock(ws
->bo_fence_lock
);
96 /* Now wait for the fences. */
97 for (i
= 0; i
< RING_LAST
; i
++) {
99 if (amdgpu_fence_wait(fence
[i
], abs_timeout
, true))
100 fence_idle
[i
] = true;
106 /* Release idle fences to avoid checking them again later. */
107 pipe_mutex_lock(ws
->bo_fence_lock
);
108 for (i
= 0; i
< RING_LAST
; i
++) {
109 if (fence
[i
] == bo
->fence
[i
] && fence_idle
[i
])
110 amdgpu_fence_reference(&bo
->fence
[i
], NULL
);
112 amdgpu_fence_reference(&fence
[i
], NULL
);
114 pipe_mutex_unlock(ws
->bo_fence_lock
);
120 static enum radeon_bo_domain
amdgpu_bo_get_initial_domain(
121 struct pb_buffer
*buf
)
123 return ((struct amdgpu_winsys_bo
*)buf
)->initial_domain
;
126 void amdgpu_bo_destroy(struct pb_buffer
*_buf
)
128 struct amdgpu_winsys_bo
*bo
= amdgpu_winsys_bo(_buf
);
131 amdgpu_bo_va_op(bo
->bo
, 0, bo
->base
.size
, bo
->va
, 0, AMDGPU_VA_OP_UNMAP
);
132 amdgpu_va_range_free(bo
->va_handle
);
133 amdgpu_bo_free(bo
->bo
);
135 for (i
= 0; i
< RING_LAST
; i
++)
136 amdgpu_fence_reference(&bo
->fence
[i
], NULL
);
138 if (bo
->initial_domain
& RADEON_DOMAIN_VRAM
)
139 bo
->ws
->allocated_vram
-= align(bo
->base
.size
, bo
->ws
->gart_page_size
);
140 else if (bo
->initial_domain
& RADEON_DOMAIN_GTT
)
141 bo
->ws
->allocated_gtt
-= align(bo
->base
.size
, bo
->ws
->gart_page_size
);
145 static void amdgpu_bo_destroy_or_cache(struct pb_buffer
*_buf
)
147 struct amdgpu_winsys_bo
*bo
= amdgpu_winsys_bo(_buf
);
149 if (bo
->use_reusable_pool
)
150 pb_cache_add_buffer(&bo
->cache_entry
);
152 amdgpu_bo_destroy(_buf
);
155 static void *amdgpu_bo_map(struct pb_buffer
*buf
,
156 struct radeon_winsys_cs
*rcs
,
157 enum pipe_transfer_usage usage
)
159 struct amdgpu_winsys_bo
*bo
= (struct amdgpu_winsys_bo
*)buf
;
160 struct amdgpu_cs
*cs
= (struct amdgpu_cs
*)rcs
;
164 /* If it's not unsynchronized bo_map, flush CS if needed and then wait. */
165 if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)) {
166 /* DONTBLOCK doesn't make sense with UNSYNCHRONIZED. */
167 if (usage
& PIPE_TRANSFER_DONTBLOCK
) {
168 if (!(usage
& PIPE_TRANSFER_WRITE
)) {
171 * Since we are mapping for read, we don't need to wait
172 * if the GPU is using the buffer for read too
173 * (neither one is changing it).
175 * Only check whether the buffer is being used for write. */
176 if (cs
&& amdgpu_bo_is_referenced_by_cs_with_usage(cs
, bo
,
177 RADEON_USAGE_WRITE
)) {
178 cs
->flush_cs(cs
->flush_data
, RADEON_FLUSH_ASYNC
, NULL
);
182 if (!amdgpu_bo_wait((struct pb_buffer
*)bo
, 0,
183 RADEON_USAGE_WRITE
)) {
187 if (cs
&& amdgpu_bo_is_referenced_by_cs(cs
, bo
)) {
188 cs
->flush_cs(cs
->flush_data
, RADEON_FLUSH_ASYNC
, NULL
);
192 if (!amdgpu_bo_wait((struct pb_buffer
*)bo
, 0,
193 RADEON_USAGE_READWRITE
)) {
198 uint64_t time
= os_time_get_nano();
200 if (!(usage
& PIPE_TRANSFER_WRITE
)) {
203 * Since we are mapping for read, we don't need to wait
204 * if the GPU is using the buffer for read too
205 * (neither one is changing it).
207 * Only check whether the buffer is being used for write. */
208 if (cs
&& amdgpu_bo_is_referenced_by_cs_with_usage(cs
, bo
,
209 RADEON_USAGE_WRITE
)) {
210 cs
->flush_cs(cs
->flush_data
, 0, NULL
);
212 amdgpu_bo_wait((struct pb_buffer
*)bo
, PIPE_TIMEOUT_INFINITE
,
215 /* Mapping for write. */
216 if (cs
&& amdgpu_bo_is_referenced_by_cs(cs
, bo
))
217 cs
->flush_cs(cs
->flush_data
, 0, NULL
);
219 amdgpu_bo_wait((struct pb_buffer
*)bo
, PIPE_TIMEOUT_INFINITE
,
220 RADEON_USAGE_READWRITE
);
223 bo
->ws
->buffer_wait_time
+= os_time_get_nano() - time
;
227 /* If the buffer is created from user memory, return the user pointer. */
231 r
= amdgpu_bo_cpu_map(bo
->bo
, &cpu
);
233 /* Clear the cache and try again. */
234 pb_cache_release_all_buffers(&bo
->ws
->bo_cache
);
235 r
= amdgpu_bo_cpu_map(bo
->bo
, &cpu
);
237 return r
? NULL
: cpu
;
240 static void amdgpu_bo_unmap(struct pb_buffer
*buf
)
242 struct amdgpu_winsys_bo
*bo
= (struct amdgpu_winsys_bo
*)buf
;
244 amdgpu_bo_cpu_unmap(bo
->bo
);
247 static const struct pb_vtbl amdgpu_winsys_bo_vtbl
= {
248 amdgpu_bo_destroy_or_cache
249 /* other functions are never called */
252 static struct amdgpu_winsys_bo
*amdgpu_create_bo(struct amdgpu_winsys
*ws
,
256 enum radeon_bo_domain initial_domain
,
259 struct amdgpu_bo_alloc_request request
= {0};
260 amdgpu_bo_handle buf_handle
;
262 struct amdgpu_winsys_bo
*bo
;
263 amdgpu_va_handle va_handle
;
266 assert(initial_domain
& RADEON_DOMAIN_VRAM_GTT
);
267 bo
= CALLOC_STRUCT(amdgpu_winsys_bo
);
272 pb_cache_init_entry(&ws
->bo_cache
, &bo
->cache_entry
, &bo
->base
);
273 request
.alloc_size
= size
;
274 request
.phys_alignment
= alignment
;
276 if (initial_domain
& RADEON_DOMAIN_VRAM
) {
277 request
.preferred_heap
|= AMDGPU_GEM_DOMAIN_VRAM
;
278 if (flags
& RADEON_FLAG_CPU_ACCESS
)
279 request
.flags
|= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED
;
281 if (initial_domain
& RADEON_DOMAIN_GTT
) {
282 request
.preferred_heap
|= AMDGPU_GEM_DOMAIN_GTT
;
283 if (flags
& RADEON_FLAG_GTT_WC
)
284 request
.flags
|= AMDGPU_GEM_CREATE_CPU_GTT_USWC
;
287 r
= amdgpu_bo_alloc(ws
->dev
, &request
, &buf_handle
);
289 fprintf(stderr
, "amdgpu: Failed to allocate a buffer:\n");
290 fprintf(stderr
, "amdgpu: size : %d bytes\n", size
);
291 fprintf(stderr
, "amdgpu: alignment : %d bytes\n", alignment
);
292 fprintf(stderr
, "amdgpu: domains : %d\n", initial_domain
);
296 r
= amdgpu_va_range_alloc(ws
->dev
, amdgpu_gpu_va_range_general
,
297 size
, alignment
, 0, &va
, &va_handle
, 0);
301 r
= amdgpu_bo_va_op(buf_handle
, 0, size
, va
, 0, AMDGPU_VA_OP_MAP
);
305 pipe_reference_init(&bo
->base
.reference
, 1);
306 bo
->base
.alignment
= alignment
;
307 bo
->base
.usage
= usage
;
308 bo
->base
.size
= size
;
309 bo
->base
.vtbl
= &amdgpu_winsys_bo_vtbl
;
313 bo
->va_handle
= va_handle
;
314 bo
->initial_domain
= initial_domain
;
315 bo
->unique_id
= __sync_fetch_and_add(&ws
->next_bo_unique_id
, 1);
317 if (initial_domain
& RADEON_DOMAIN_VRAM
)
318 ws
->allocated_vram
+= align(size
, ws
->gart_page_size
);
319 else if (initial_domain
& RADEON_DOMAIN_GTT
)
320 ws
->allocated_gtt
+= align(size
, ws
->gart_page_size
);
325 amdgpu_va_range_free(va_handle
);
328 amdgpu_bo_free(buf_handle
);
335 bool amdgpu_bo_can_reclaim(struct pb_buffer
*_buf
)
337 struct amdgpu_winsys_bo
*bo
= amdgpu_winsys_bo(_buf
);
339 if (amdgpu_bo_is_referenced_by_any_cs(bo
)) {
343 return amdgpu_bo_wait(_buf
, 0, RADEON_USAGE_READWRITE
);
346 static unsigned eg_tile_split(unsigned tile_split
)
348 switch (tile_split
) {
349 case 0: tile_split
= 64; break;
350 case 1: tile_split
= 128; break;
351 case 2: tile_split
= 256; break;
352 case 3: tile_split
= 512; break;
354 case 4: tile_split
= 1024; break;
355 case 5: tile_split
= 2048; break;
356 case 6: tile_split
= 4096; break;
361 static unsigned eg_tile_split_rev(unsigned eg_tile_split
)
363 switch (eg_tile_split
) {
375 static void amdgpu_bo_get_tiling(struct pb_buffer
*_buf
,
376 enum radeon_bo_layout
*microtiled
,
377 enum radeon_bo_layout
*macrotiled
,
378 unsigned *bankw
, unsigned *bankh
,
379 unsigned *tile_split
,
380 unsigned *stencil_tile_split
,
384 struct amdgpu_winsys_bo
*bo
= amdgpu_winsys_bo(_buf
);
385 struct amdgpu_bo_info info
= {0};
386 uint32_t tiling_flags
;
389 r
= amdgpu_bo_query_info(bo
->bo
, &info
);
393 tiling_flags
= info
.metadata
.tiling_info
;
395 *microtiled
= RADEON_LAYOUT_LINEAR
;
396 *macrotiled
= RADEON_LAYOUT_LINEAR
;
398 if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
) == 4) /* 2D_TILED_THIN1 */
399 *macrotiled
= RADEON_LAYOUT_TILED
;
400 else if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
) == 2) /* 1D_TILED_THIN1 */
401 *microtiled
= RADEON_LAYOUT_TILED
;
403 if (bankw
&& tile_split
&& mtilea
&& tile_split
) {
404 *bankw
= 1 << AMDGPU_TILING_GET(tiling_flags
, BANK_WIDTH
);
405 *bankh
= 1 << AMDGPU_TILING_GET(tiling_flags
, BANK_HEIGHT
);
406 *tile_split
= eg_tile_split(AMDGPU_TILING_GET(tiling_flags
, TILE_SPLIT
));
407 *mtilea
= 1 << AMDGPU_TILING_GET(tiling_flags
, MACRO_TILE_ASPECT
);
410 *scanout
= AMDGPU_TILING_GET(tiling_flags
, MICRO_TILE_MODE
) == 0; /* DISPLAY */
413 static void amdgpu_bo_set_tiling(struct pb_buffer
*_buf
,
414 struct radeon_winsys_cs
*rcs
,
415 enum radeon_bo_layout microtiled
,
416 enum radeon_bo_layout macrotiled
,
417 unsigned pipe_config
,
418 unsigned bankw
, unsigned bankh
,
420 unsigned stencil_tile_split
,
421 unsigned mtilea
, unsigned num_banks
,
425 struct amdgpu_winsys_bo
*bo
= amdgpu_winsys_bo(_buf
);
426 struct amdgpu_bo_metadata metadata
= {0};
427 uint32_t tiling_flags
= 0;
429 if (macrotiled
== RADEON_LAYOUT_TILED
)
430 tiling_flags
|= AMDGPU_TILING_SET(ARRAY_MODE
, 4); /* 2D_TILED_THIN1 */
431 else if (microtiled
== RADEON_LAYOUT_TILED
)
432 tiling_flags
|= AMDGPU_TILING_SET(ARRAY_MODE
, 2); /* 1D_TILED_THIN1 */
434 tiling_flags
|= AMDGPU_TILING_SET(ARRAY_MODE
, 1); /* LINEAR_ALIGNED */
436 tiling_flags
|= AMDGPU_TILING_SET(PIPE_CONFIG
, pipe_config
);
437 tiling_flags
|= AMDGPU_TILING_SET(BANK_WIDTH
, util_logbase2(bankw
));
438 tiling_flags
|= AMDGPU_TILING_SET(BANK_HEIGHT
, util_logbase2(bankh
));
440 tiling_flags
|= AMDGPU_TILING_SET(TILE_SPLIT
, eg_tile_split_rev(tile_split
));
441 tiling_flags
|= AMDGPU_TILING_SET(MACRO_TILE_ASPECT
, util_logbase2(mtilea
));
442 tiling_flags
|= AMDGPU_TILING_SET(NUM_BANKS
, util_logbase2(num_banks
)-1);
445 tiling_flags
|= AMDGPU_TILING_SET(MICRO_TILE_MODE
, 0); /* DISPLAY_MICRO_TILING */
447 tiling_flags
|= AMDGPU_TILING_SET(MICRO_TILE_MODE
, 1); /* THIN_MICRO_TILING */
449 metadata
.tiling_info
= tiling_flags
;
451 amdgpu_bo_set_metadata(bo
->bo
, &metadata
);
454 static struct pb_buffer
*
455 amdgpu_bo_create(struct radeon_winsys
*rws
,
458 boolean use_reusable_pool
,
459 enum radeon_bo_domain domain
,
460 enum radeon_bo_flag flags
)
462 struct amdgpu_winsys
*ws
= amdgpu_winsys(rws
);
463 struct amdgpu_winsys_bo
*bo
;
466 /* Don't use VRAM if the GPU doesn't have much. This is only the initial
467 * domain. The kernel is free to move the buffer if it wants to.
469 * 64MB means no VRAM by todays standards.
471 if (domain
& RADEON_DOMAIN_VRAM
&& ws
->info
.vram_size
<= 64*1024*1024) {
472 domain
= RADEON_DOMAIN_GTT
;
473 flags
= RADEON_FLAG_GTT_WC
;
476 /* Align size to page size. This is the minimum alignment for normal
477 * BOs. Aligning this here helps the cached bufmgr. Especially small BOs,
478 * like constant/uniform buffers, can benefit from better and more reuse.
480 size
= align(size
, ws
->gart_page_size
);
482 /* Only set one usage bit each for domains and flags, or the cache manager
483 * might consider different sets of domains / flags compatible
485 if (domain
== RADEON_DOMAIN_VRAM_GTT
)
489 assert(flags
< sizeof(usage
) * 8 - 3);
490 usage
|= 1 << (flags
+ 3);
492 /* Get a buffer from the cache. */
493 if (use_reusable_pool
) {
494 bo
= (struct amdgpu_winsys_bo
*)
495 pb_cache_reclaim_buffer(&ws
->bo_cache
, size
, alignment
,
501 /* Create a new one. */
502 bo
= amdgpu_create_bo(ws
, size
, alignment
, usage
, domain
, flags
);
504 /* Clear the cache and try again. */
505 pb_cache_release_all_buffers(&ws
->bo_cache
);
506 bo
= amdgpu_create_bo(ws
, size
, alignment
, usage
, domain
, flags
);
511 bo
->use_reusable_pool
= use_reusable_pool
;
515 static struct pb_buffer
*amdgpu_bo_from_handle(struct radeon_winsys
*rws
,
516 struct winsys_handle
*whandle
,
519 struct amdgpu_winsys
*ws
= amdgpu_winsys(rws
);
520 struct amdgpu_winsys_bo
*bo
;
521 enum amdgpu_bo_handle_type type
;
522 struct amdgpu_bo_import_result result
= {0};
524 amdgpu_va_handle va_handle
;
525 struct amdgpu_bo_info info
= {0};
526 enum radeon_bo_domain initial
= 0;
529 /* Initialize the structure. */
530 bo
= CALLOC_STRUCT(amdgpu_winsys_bo
);
535 switch (whandle
->type
) {
536 case DRM_API_HANDLE_TYPE_SHARED
:
537 type
= amdgpu_bo_handle_type_gem_flink_name
;
539 case DRM_API_HANDLE_TYPE_FD
:
540 type
= amdgpu_bo_handle_type_dma_buf_fd
;
546 r
= amdgpu_bo_import(ws
->dev
, type
, whandle
->handle
, &result
);
550 /* Get initial domains. */
551 r
= amdgpu_bo_query_info(result
.buf_handle
, &info
);
555 r
= amdgpu_va_range_alloc(ws
->dev
, amdgpu_gpu_va_range_general
,
556 result
.alloc_size
, 1 << 20, 0, &va
, &va_handle
, 0);
560 r
= amdgpu_bo_va_op(result
.buf_handle
, 0, result
.alloc_size
, va
, 0, AMDGPU_VA_OP_MAP
);
564 if (info
.preferred_heap
& AMDGPU_GEM_DOMAIN_VRAM
)
565 initial
|= RADEON_DOMAIN_VRAM
;
566 if (info
.preferred_heap
& AMDGPU_GEM_DOMAIN_GTT
)
567 initial
|= RADEON_DOMAIN_GTT
;
570 pipe_reference_init(&bo
->base
.reference
, 1);
571 bo
->base
.alignment
= info
.phys_alignment
;
572 bo
->base
.usage
= PB_USAGE_GPU_WRITE
| PB_USAGE_GPU_READ
;
573 bo
->bo
= result
.buf_handle
;
574 bo
->base
.size
= result
.alloc_size
;
575 bo
->base
.vtbl
= &amdgpu_winsys_bo_vtbl
;
578 bo
->va_handle
= va_handle
;
579 bo
->initial_domain
= initial
;
580 bo
->unique_id
= __sync_fetch_and_add(&ws
->next_bo_unique_id
, 1);
581 bo
->is_shared
= true;
584 *stride
= whandle
->stride
;
586 if (bo
->initial_domain
& RADEON_DOMAIN_VRAM
)
587 ws
->allocated_vram
+= align(bo
->base
.size
, ws
->gart_page_size
);
588 else if (bo
->initial_domain
& RADEON_DOMAIN_GTT
)
589 ws
->allocated_gtt
+= align(bo
->base
.size
, ws
->gart_page_size
);
594 amdgpu_va_range_free(va_handle
);
597 amdgpu_bo_free(result
.buf_handle
);
604 static boolean
amdgpu_bo_get_handle(struct pb_buffer
*buffer
,
606 struct winsys_handle
*whandle
)
608 struct amdgpu_winsys_bo
*bo
= amdgpu_winsys_bo(buffer
);
609 enum amdgpu_bo_handle_type type
;
612 bo
->use_reusable_pool
= false;
614 switch (whandle
->type
) {
615 case DRM_API_HANDLE_TYPE_SHARED
:
616 type
= amdgpu_bo_handle_type_gem_flink_name
;
618 case DRM_API_HANDLE_TYPE_FD
:
619 type
= amdgpu_bo_handle_type_dma_buf_fd
;
621 case DRM_API_HANDLE_TYPE_KMS
:
622 type
= amdgpu_bo_handle_type_kms
;
628 r
= amdgpu_bo_export(bo
->bo
, type
, &whandle
->handle
);
632 whandle
->stride
= stride
;
633 bo
->is_shared
= true;
637 static struct pb_buffer
*amdgpu_bo_from_ptr(struct radeon_winsys
*rws
,
638 void *pointer
, unsigned size
)
640 struct amdgpu_winsys
*ws
= amdgpu_winsys(rws
);
641 amdgpu_bo_handle buf_handle
;
642 struct amdgpu_winsys_bo
*bo
;
644 amdgpu_va_handle va_handle
;
646 bo
= CALLOC_STRUCT(amdgpu_winsys_bo
);
650 if (amdgpu_create_bo_from_user_mem(ws
->dev
, pointer
, size
, &buf_handle
))
653 if (amdgpu_va_range_alloc(ws
->dev
, amdgpu_gpu_va_range_general
,
654 size
, 1 << 12, 0, &va
, &va_handle
, 0))
657 if (amdgpu_bo_va_op(buf_handle
, 0, size
, va
, 0, AMDGPU_VA_OP_MAP
))
661 pipe_reference_init(&bo
->base
.reference
, 1);
663 bo
->base
.alignment
= 0;
664 bo
->base
.usage
= PB_USAGE_GPU_WRITE
| PB_USAGE_GPU_READ
;
665 bo
->base
.size
= size
;
666 bo
->base
.vtbl
= &amdgpu_winsys_bo_vtbl
;
668 bo
->user_ptr
= pointer
;
670 bo
->va_handle
= va_handle
;
671 bo
->initial_domain
= RADEON_DOMAIN_GTT
;
672 bo
->unique_id
= __sync_fetch_and_add(&ws
->next_bo_unique_id
, 1);
674 ws
->allocated_gtt
+= align(bo
->base
.size
, ws
->gart_page_size
);
676 return (struct pb_buffer
*)bo
;
679 amdgpu_va_range_free(va_handle
);
682 amdgpu_bo_free(buf_handle
);
689 static uint64_t amdgpu_bo_get_va(struct pb_buffer
*buf
)
691 return ((struct amdgpu_winsys_bo
*)buf
)->va
;
694 void amdgpu_bo_init_functions(struct amdgpu_winsys
*ws
)
696 ws
->base
.buffer_set_tiling
= amdgpu_bo_set_tiling
;
697 ws
->base
.buffer_get_tiling
= amdgpu_bo_get_tiling
;
698 ws
->base
.buffer_map
= amdgpu_bo_map
;
699 ws
->base
.buffer_unmap
= amdgpu_bo_unmap
;
700 ws
->base
.buffer_wait
= amdgpu_bo_wait
;
701 ws
->base
.buffer_create
= amdgpu_bo_create
;
702 ws
->base
.buffer_from_handle
= amdgpu_bo_from_handle
;
703 ws
->base
.buffer_from_ptr
= amdgpu_bo_from_ptr
;
704 ws
->base
.buffer_get_handle
= amdgpu_bo_get_handle
;
705 ws
->base
.buffer_get_virtual_address
= amdgpu_bo_get_va
;
706 ws
->base
.buffer_get_initial_domain
= amdgpu_bo_get_initial_domain
;