2 * Copyright 2013 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "util/u_memory.h"
29 #include "util/u_upload_mgr.h"
33 bool si_rings_is_buffer_referenced(struct r600_common_context
*ctx
,
34 struct pb_buffer
*buf
,
35 enum radeon_bo_usage usage
)
37 if (ctx
->ws
->cs_is_buffer_referenced(ctx
->gfx
.cs
, buf
, usage
)) {
40 if (radeon_emitted(ctx
->dma
.cs
, 0) &&
41 ctx
->ws
->cs_is_buffer_referenced(ctx
->dma
.cs
, buf
, usage
)) {
47 void *si_buffer_map_sync_with_rings(struct r600_common_context
*ctx
,
48 struct r600_resource
*resource
,
51 enum radeon_bo_usage rusage
= RADEON_USAGE_READWRITE
;
54 assert(!(resource
->flags
& RADEON_FLAG_SPARSE
));
56 if (usage
& PIPE_TRANSFER_UNSYNCHRONIZED
) {
57 return ctx
->ws
->buffer_map(resource
->buf
, NULL
, usage
);
60 if (!(usage
& PIPE_TRANSFER_WRITE
)) {
61 /* have to wait for the last write */
62 rusage
= RADEON_USAGE_WRITE
;
65 if (radeon_emitted(ctx
->gfx
.cs
, ctx
->initial_gfx_cs_size
) &&
66 ctx
->ws
->cs_is_buffer_referenced(ctx
->gfx
.cs
,
67 resource
->buf
, rusage
)) {
68 if (usage
& PIPE_TRANSFER_DONTBLOCK
) {
69 ctx
->gfx
.flush(ctx
, RADEON_FLUSH_ASYNC
, NULL
);
72 ctx
->gfx
.flush(ctx
, 0, NULL
);
76 if (radeon_emitted(ctx
->dma
.cs
, 0) &&
77 ctx
->ws
->cs_is_buffer_referenced(ctx
->dma
.cs
,
78 resource
->buf
, rusage
)) {
79 if (usage
& PIPE_TRANSFER_DONTBLOCK
) {
80 ctx
->dma
.flush(ctx
, RADEON_FLUSH_ASYNC
, NULL
);
83 ctx
->dma
.flush(ctx
, 0, NULL
);
88 if (busy
|| !ctx
->ws
->buffer_wait(resource
->buf
, 0, rusage
)) {
89 if (usage
& PIPE_TRANSFER_DONTBLOCK
) {
92 /* We will be wait for the GPU. Wait for any offloaded
93 * CS flush to complete to avoid busy-waiting in the winsys. */
94 ctx
->ws
->cs_sync_flush(ctx
->gfx
.cs
);
96 ctx
->ws
->cs_sync_flush(ctx
->dma
.cs
);
100 /* Setting the CS to NULL will prevent doing checks we have done already. */
101 return ctx
->ws
->buffer_map(resource
->buf
, NULL
, usage
);
104 void si_init_resource_fields(struct r600_common_screen
*rscreen
,
105 struct r600_resource
*res
,
106 uint64_t size
, unsigned alignment
)
108 struct r600_texture
*rtex
= (struct r600_texture
*)res
;
111 res
->bo_alignment
= alignment
;
113 res
->texture_handle_allocated
= false;
114 res
->image_handle_allocated
= false;
116 switch (res
->b
.b
.usage
) {
117 case PIPE_USAGE_STREAM
:
118 res
->flags
= RADEON_FLAG_GTT_WC
;
120 case PIPE_USAGE_STAGING
:
121 /* Transfers are likely to occur more often with these
123 res
->domains
= RADEON_DOMAIN_GTT
;
125 case PIPE_USAGE_DYNAMIC
:
126 /* Older kernels didn't always flush the HDP cache before
129 if (rscreen
->info
.drm_major
== 2 &&
130 rscreen
->info
.drm_minor
< 40) {
131 res
->domains
= RADEON_DOMAIN_GTT
;
132 res
->flags
|= RADEON_FLAG_GTT_WC
;
136 case PIPE_USAGE_DEFAULT
:
137 case PIPE_USAGE_IMMUTABLE
:
139 /* Not listing GTT here improves performance in some
141 res
->domains
= RADEON_DOMAIN_VRAM
;
142 res
->flags
|= RADEON_FLAG_GTT_WC
;
146 if (res
->b
.b
.target
== PIPE_BUFFER
&&
147 res
->b
.b
.flags
& (PIPE_RESOURCE_FLAG_MAP_PERSISTENT
|
148 PIPE_RESOURCE_FLAG_MAP_COHERENT
)) {
149 /* Use GTT for all persistent mappings with older
150 * kernels, because they didn't always flush the HDP
151 * cache before CS execution.
153 * Write-combined CPU mappings are fine, the kernel
154 * ensures all CPU writes finish before the GPU
155 * executes a command stream.
157 if (rscreen
->info
.drm_major
== 2 &&
158 rscreen
->info
.drm_minor
< 40)
159 res
->domains
= RADEON_DOMAIN_GTT
;
162 /* Tiled textures are unmappable. Always put them in VRAM. */
163 if ((res
->b
.b
.target
!= PIPE_BUFFER
&& !rtex
->surface
.is_linear
) ||
164 res
->flags
& R600_RESOURCE_FLAG_UNMAPPABLE
) {
165 res
->domains
= RADEON_DOMAIN_VRAM
;
166 res
->flags
|= RADEON_FLAG_NO_CPU_ACCESS
|
170 /* Displayable and shareable surfaces are not suballocated. */
171 if (res
->b
.b
.bind
& (PIPE_BIND_SHARED
| PIPE_BIND_SCANOUT
))
172 res
->flags
|= RADEON_FLAG_NO_SUBALLOC
; /* shareable */
174 res
->flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
176 /* If VRAM is just stolen system memory, allow both VRAM and
177 * GTT, whichever has free space. If a buffer is evicted from
178 * VRAM to GTT, it will stay there.
180 * DRM 3.6.0 has good BO move throttling, so we can allow VRAM-only
181 * placements even with a low amount of stolen VRAM.
183 if (!rscreen
->info
.has_dedicated_vram
&&
184 (rscreen
->info
.drm_major
< 3 || rscreen
->info
.drm_minor
< 6) &&
185 res
->domains
== RADEON_DOMAIN_VRAM
) {
186 res
->domains
= RADEON_DOMAIN_VRAM_GTT
;
187 res
->flags
&= ~RADEON_FLAG_NO_CPU_ACCESS
; /* disallowed with VRAM_GTT */
190 if (rscreen
->debug_flags
& DBG_NO_WC
)
191 res
->flags
&= ~RADEON_FLAG_GTT_WC
;
193 /* Set expected VRAM and GART usage for the buffer. */
197 if (res
->domains
& RADEON_DOMAIN_VRAM
)
198 res
->vram_usage
= size
;
199 else if (res
->domains
& RADEON_DOMAIN_GTT
)
200 res
->gart_usage
= size
;
203 bool si_alloc_resource(struct r600_common_screen
*rscreen
,
204 struct r600_resource
*res
)
206 struct pb_buffer
*old_buf
, *new_buf
;
208 /* Allocate a new resource. */
209 new_buf
= rscreen
->ws
->buffer_create(rscreen
->ws
, res
->bo_size
,
211 res
->domains
, res
->flags
);
216 /* Replace the pointer such that if res->buf wasn't NULL, it won't be
217 * NULL. This should prevent crashes with multiple contexts using
218 * the same buffer where one of the contexts invalidates it while
219 * the others are using it. */
221 res
->buf
= new_buf
; /* should be atomic */
223 if (rscreen
->info
.has_virtual_memory
)
224 res
->gpu_address
= rscreen
->ws
->buffer_get_virtual_address(res
->buf
);
226 res
->gpu_address
= 0;
228 pb_reference(&old_buf
, NULL
);
230 util_range_set_empty(&res
->valid_buffer_range
);
231 res
->TC_L2_dirty
= false;
233 /* Print debug information. */
234 if (rscreen
->debug_flags
& DBG_VM
&& res
->b
.b
.target
== PIPE_BUFFER
) {
235 fprintf(stderr
, "VM start=0x%"PRIX64
" end=0x%"PRIX64
" | Buffer %"PRIu64
" bytes\n",
236 res
->gpu_address
, res
->gpu_address
+ res
->buf
->size
,
242 static void r600_buffer_destroy(struct pipe_screen
*screen
,
243 struct pipe_resource
*buf
)
245 struct r600_resource
*rbuffer
= r600_resource(buf
);
247 threaded_resource_deinit(buf
);
248 util_range_destroy(&rbuffer
->valid_buffer_range
);
249 pb_reference(&rbuffer
->buf
, NULL
);
254 r600_invalidate_buffer(struct r600_common_context
*rctx
,
255 struct r600_resource
*rbuffer
)
257 /* Shared buffers can't be reallocated. */
258 if (rbuffer
->b
.is_shared
)
261 /* Sparse buffers can't be reallocated. */
262 if (rbuffer
->flags
& RADEON_FLAG_SPARSE
)
265 /* In AMD_pinned_memory, the user pointer association only gets
266 * broken when the buffer is explicitly re-allocated.
268 if (rbuffer
->b
.is_user_ptr
)
271 /* Check if mapping this buffer would cause waiting for the GPU. */
272 if (si_rings_is_buffer_referenced(rctx
, rbuffer
->buf
, RADEON_USAGE_READWRITE
) ||
273 !rctx
->ws
->buffer_wait(rbuffer
->buf
, 0, RADEON_USAGE_READWRITE
)) {
274 rctx
->invalidate_buffer(&rctx
->b
, &rbuffer
->b
.b
);
276 util_range_set_empty(&rbuffer
->valid_buffer_range
);
282 /* Replace the storage of dst with src. */
283 void si_replace_buffer_storage(struct pipe_context
*ctx
,
284 struct pipe_resource
*dst
,
285 struct pipe_resource
*src
)
287 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
288 struct r600_resource
*rdst
= r600_resource(dst
);
289 struct r600_resource
*rsrc
= r600_resource(src
);
290 uint64_t old_gpu_address
= rdst
->gpu_address
;
292 pb_reference(&rdst
->buf
, rsrc
->buf
);
293 rdst
->gpu_address
= rsrc
->gpu_address
;
294 rdst
->b
.b
.bind
= rsrc
->b
.b
.bind
;
295 rdst
->flags
= rsrc
->flags
;
297 assert(rdst
->vram_usage
== rsrc
->vram_usage
);
298 assert(rdst
->gart_usage
== rsrc
->gart_usage
);
299 assert(rdst
->bo_size
== rsrc
->bo_size
);
300 assert(rdst
->bo_alignment
== rsrc
->bo_alignment
);
301 assert(rdst
->domains
== rsrc
->domains
);
303 rctx
->rebind_buffer(ctx
, dst
, old_gpu_address
);
306 void si_invalidate_resource(struct pipe_context
*ctx
,
307 struct pipe_resource
*resource
)
309 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
310 struct r600_resource
*rbuffer
= r600_resource(resource
);
312 /* We currently only do anyting here for buffers */
313 if (resource
->target
== PIPE_BUFFER
)
314 (void)r600_invalidate_buffer(rctx
, rbuffer
);
317 static void *r600_buffer_get_transfer(struct pipe_context
*ctx
,
318 struct pipe_resource
*resource
,
320 const struct pipe_box
*box
,
321 struct pipe_transfer
**ptransfer
,
322 void *data
, struct r600_resource
*staging
,
325 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
326 struct r600_transfer
*transfer
;
328 if (usage
& TC_TRANSFER_MAP_THREADED_UNSYNC
)
329 transfer
= slab_alloc(&rctx
->pool_transfers_unsync
);
331 transfer
= slab_alloc(&rctx
->pool_transfers
);
333 transfer
->b
.b
.resource
= NULL
;
334 pipe_resource_reference(&transfer
->b
.b
.resource
, resource
);
335 transfer
->b
.b
.level
= 0;
336 transfer
->b
.b
.usage
= usage
;
337 transfer
->b
.b
.box
= *box
;
338 transfer
->b
.b
.stride
= 0;
339 transfer
->b
.b
.layer_stride
= 0;
340 transfer
->b
.staging
= NULL
;
341 transfer
->offset
= offset
;
342 transfer
->staging
= staging
;
343 *ptransfer
= &transfer
->b
.b
;
347 static bool r600_can_dma_copy_buffer(struct r600_common_context
*rctx
,
348 unsigned dstx
, unsigned srcx
, unsigned size
)
350 bool dword_aligned
= !(dstx
% 4) && !(srcx
% 4) && !(size
% 4);
352 return rctx
->screen
->has_cp_dma
||
353 (dword_aligned
&& (rctx
->dma
.cs
||
354 rctx
->screen
->has_streamout
));
358 static void *r600_buffer_transfer_map(struct pipe_context
*ctx
,
359 struct pipe_resource
*resource
,
362 const struct pipe_box
*box
,
363 struct pipe_transfer
**ptransfer
)
365 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
366 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)ctx
->screen
;
367 struct r600_resource
*rbuffer
= r600_resource(resource
);
370 assert(box
->x
+ box
->width
<= resource
->width0
);
372 /* From GL_AMD_pinned_memory issues:
374 * 4) Is glMapBuffer on a shared buffer guaranteed to return the
375 * same system address which was specified at creation time?
377 * RESOLVED: NO. The GL implementation might return a different
378 * virtual mapping of that memory, although the same physical
381 * So don't ever use staging buffers.
383 if (rbuffer
->b
.is_user_ptr
)
384 usage
|= PIPE_TRANSFER_PERSISTENT
;
386 /* See if the buffer range being mapped has never been initialized,
387 * in which case it can be mapped unsynchronized. */
388 if (!(usage
& (PIPE_TRANSFER_UNSYNCHRONIZED
|
389 TC_TRANSFER_MAP_NO_INFER_UNSYNCHRONIZED
)) &&
390 usage
& PIPE_TRANSFER_WRITE
&&
391 !rbuffer
->b
.is_shared
&&
392 !util_ranges_intersect(&rbuffer
->valid_buffer_range
, box
->x
, box
->x
+ box
->width
)) {
393 usage
|= PIPE_TRANSFER_UNSYNCHRONIZED
;
396 /* If discarding the entire range, discard the whole resource instead. */
397 if (usage
& PIPE_TRANSFER_DISCARD_RANGE
&&
398 box
->x
== 0 && box
->width
== resource
->width0
) {
399 usage
|= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
;
402 if (usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
&&
403 !(usage
& (PIPE_TRANSFER_UNSYNCHRONIZED
|
404 TC_TRANSFER_MAP_NO_INVALIDATE
))) {
405 assert(usage
& PIPE_TRANSFER_WRITE
);
407 if (r600_invalidate_buffer(rctx
, rbuffer
)) {
408 /* At this point, the buffer is always idle. */
409 usage
|= PIPE_TRANSFER_UNSYNCHRONIZED
;
411 /* Fall back to a temporary buffer. */
412 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
416 if ((usage
& PIPE_TRANSFER_DISCARD_RANGE
) &&
417 !(rscreen
->debug_flags
& DBG_NO_DISCARD_RANGE
) &&
418 ((!(usage
& (PIPE_TRANSFER_UNSYNCHRONIZED
|
419 PIPE_TRANSFER_PERSISTENT
)) &&
420 r600_can_dma_copy_buffer(rctx
, box
->x
, 0, box
->width
)) ||
421 (rbuffer
->flags
& RADEON_FLAG_SPARSE
))) {
422 assert(usage
& PIPE_TRANSFER_WRITE
);
424 /* Check if mapping this buffer would cause waiting for the GPU.
426 if (rbuffer
->flags
& RADEON_FLAG_SPARSE
||
427 si_rings_is_buffer_referenced(rctx
, rbuffer
->buf
, RADEON_USAGE_READWRITE
) ||
428 !rctx
->ws
->buffer_wait(rbuffer
->buf
, 0, RADEON_USAGE_READWRITE
)) {
429 /* Do a wait-free write-only transfer using a temporary buffer. */
431 struct r600_resource
*staging
= NULL
;
433 u_upload_alloc(ctx
->stream_uploader
, 0,
434 box
->width
+ (box
->x
% R600_MAP_BUFFER_ALIGNMENT
),
435 rctx
->screen
->info
.tcc_cache_line_size
,
436 &offset
, (struct pipe_resource
**)&staging
,
440 data
+= box
->x
% R600_MAP_BUFFER_ALIGNMENT
;
441 return r600_buffer_get_transfer(ctx
, resource
, usage
, box
,
442 ptransfer
, data
, staging
, offset
);
443 } else if (rbuffer
->flags
& RADEON_FLAG_SPARSE
) {
447 /* At this point, the buffer is always idle (we checked it above). */
448 usage
|= PIPE_TRANSFER_UNSYNCHRONIZED
;
451 /* Use a staging buffer in cached GTT for reads. */
452 else if (((usage
& PIPE_TRANSFER_READ
) &&
453 !(usage
& PIPE_TRANSFER_PERSISTENT
) &&
454 (rbuffer
->domains
& RADEON_DOMAIN_VRAM
||
455 rbuffer
->flags
& RADEON_FLAG_GTT_WC
) &&
456 r600_can_dma_copy_buffer(rctx
, 0, box
->x
, box
->width
)) ||
457 (rbuffer
->flags
& RADEON_FLAG_SPARSE
)) {
458 struct r600_resource
*staging
;
460 assert(!(usage
& TC_TRANSFER_MAP_THREADED_UNSYNC
));
461 staging
= (struct r600_resource
*) pipe_buffer_create(
462 ctx
->screen
, 0, PIPE_USAGE_STAGING
,
463 box
->width
+ (box
->x
% R600_MAP_BUFFER_ALIGNMENT
));
465 /* Copy the VRAM buffer to the staging buffer. */
466 rctx
->dma_copy(ctx
, &staging
->b
.b
, 0,
467 box
->x
% R600_MAP_BUFFER_ALIGNMENT
,
468 0, 0, resource
, 0, box
);
470 data
= si_buffer_map_sync_with_rings(rctx
, staging
,
471 usage
& ~PIPE_TRANSFER_UNSYNCHRONIZED
);
473 r600_resource_reference(&staging
, NULL
);
476 data
+= box
->x
% R600_MAP_BUFFER_ALIGNMENT
;
478 return r600_buffer_get_transfer(ctx
, resource
, usage
, box
,
479 ptransfer
, data
, staging
, 0);
480 } else if (rbuffer
->flags
& RADEON_FLAG_SPARSE
) {
485 data
= si_buffer_map_sync_with_rings(rctx
, rbuffer
, usage
);
491 return r600_buffer_get_transfer(ctx
, resource
, usage
, box
,
492 ptransfer
, data
, NULL
, 0);
495 static void r600_buffer_do_flush_region(struct pipe_context
*ctx
,
496 struct pipe_transfer
*transfer
,
497 const struct pipe_box
*box
)
499 struct r600_transfer
*rtransfer
= (struct r600_transfer
*)transfer
;
500 struct r600_resource
*rbuffer
= r600_resource(transfer
->resource
);
502 if (rtransfer
->staging
) {
503 struct pipe_resource
*dst
, *src
;
505 struct pipe_box dma_box
;
507 dst
= transfer
->resource
;
508 src
= &rtransfer
->staging
->b
.b
;
509 soffset
= rtransfer
->offset
+ box
->x
% R600_MAP_BUFFER_ALIGNMENT
;
511 u_box_1d(soffset
, box
->width
, &dma_box
);
513 /* Copy the staging buffer into the original one. */
514 ctx
->resource_copy_region(ctx
, dst
, 0, box
->x
, 0, 0, src
, 0, &dma_box
);
517 util_range_add(&rbuffer
->valid_buffer_range
, box
->x
,
518 box
->x
+ box
->width
);
521 static void r600_buffer_flush_region(struct pipe_context
*ctx
,
522 struct pipe_transfer
*transfer
,
523 const struct pipe_box
*rel_box
)
525 unsigned required_usage
= PIPE_TRANSFER_WRITE
|
526 PIPE_TRANSFER_FLUSH_EXPLICIT
;
528 if ((transfer
->usage
& required_usage
) == required_usage
) {
531 u_box_1d(transfer
->box
.x
+ rel_box
->x
, rel_box
->width
, &box
);
532 r600_buffer_do_flush_region(ctx
, transfer
, &box
);
536 static void r600_buffer_transfer_unmap(struct pipe_context
*ctx
,
537 struct pipe_transfer
*transfer
)
539 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
540 struct r600_transfer
*rtransfer
= (struct r600_transfer
*)transfer
;
542 if (transfer
->usage
& PIPE_TRANSFER_WRITE
&&
543 !(transfer
->usage
& PIPE_TRANSFER_FLUSH_EXPLICIT
))
544 r600_buffer_do_flush_region(ctx
, transfer
, &transfer
->box
);
546 r600_resource_reference(&rtransfer
->staging
, NULL
);
547 assert(rtransfer
->b
.staging
== NULL
); /* for threaded context only */
548 pipe_resource_reference(&transfer
->resource
, NULL
);
550 /* Don't use pool_transfers_unsync. We are always in the driver
552 slab_free(&rctx
->pool_transfers
, transfer
);
555 void si_buffer_subdata(struct pipe_context
*ctx
,
556 struct pipe_resource
*buffer
,
557 unsigned usage
, unsigned offset
,
558 unsigned size
, const void *data
)
560 struct pipe_transfer
*transfer
= NULL
;
564 u_box_1d(offset
, size
, &box
);
565 map
= r600_buffer_transfer_map(ctx
, buffer
, 0,
566 PIPE_TRANSFER_WRITE
|
567 PIPE_TRANSFER_DISCARD_RANGE
|
573 memcpy(map
, data
, size
);
574 r600_buffer_transfer_unmap(ctx
, transfer
);
577 static const struct u_resource_vtbl r600_buffer_vtbl
=
579 NULL
, /* get_handle */
580 r600_buffer_destroy
, /* resource_destroy */
581 r600_buffer_transfer_map
, /* transfer_map */
582 r600_buffer_flush_region
, /* transfer_flush_region */
583 r600_buffer_transfer_unmap
, /* transfer_unmap */
586 static struct r600_resource
*
587 r600_alloc_buffer_struct(struct pipe_screen
*screen
,
588 const struct pipe_resource
*templ
)
590 struct r600_resource
*rbuffer
;
592 rbuffer
= MALLOC_STRUCT(r600_resource
);
594 rbuffer
->b
.b
= *templ
;
595 rbuffer
->b
.b
.next
= NULL
;
596 pipe_reference_init(&rbuffer
->b
.b
.reference
, 1);
597 rbuffer
->b
.b
.screen
= screen
;
599 rbuffer
->b
.vtbl
= &r600_buffer_vtbl
;
600 threaded_resource_init(&rbuffer
->b
.b
);
603 rbuffer
->bind_history
= 0;
604 rbuffer
->TC_L2_dirty
= false;
605 util_range_init(&rbuffer
->valid_buffer_range
);
609 struct pipe_resource
*si_buffer_create(struct pipe_screen
*screen
,
610 const struct pipe_resource
*templ
,
613 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
614 struct r600_resource
*rbuffer
= r600_alloc_buffer_struct(screen
, templ
);
616 si_init_resource_fields(rscreen
, rbuffer
, templ
->width0
, alignment
);
618 if (templ
->flags
& PIPE_RESOURCE_FLAG_SPARSE
)
619 rbuffer
->flags
|= RADEON_FLAG_SPARSE
;
621 if (!si_alloc_resource(rscreen
, rbuffer
)) {
625 return &rbuffer
->b
.b
;
628 struct pipe_resource
*si_aligned_buffer_create(struct pipe_screen
*screen
,
634 struct pipe_resource buffer
;
636 memset(&buffer
, 0, sizeof buffer
);
637 buffer
.target
= PIPE_BUFFER
;
638 buffer
.format
= PIPE_FORMAT_R8_UNORM
;
640 buffer
.usage
= usage
;
641 buffer
.flags
= flags
;
642 buffer
.width0
= size
;
645 buffer
.array_size
= 1;
646 return si_buffer_create(screen
, &buffer
, alignment
);
649 struct pipe_resource
*
650 si_buffer_from_user_memory(struct pipe_screen
*screen
,
651 const struct pipe_resource
*templ
,
654 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
655 struct radeon_winsys
*ws
= rscreen
->ws
;
656 struct r600_resource
*rbuffer
= r600_alloc_buffer_struct(screen
, templ
);
658 rbuffer
->domains
= RADEON_DOMAIN_GTT
;
660 rbuffer
->b
.is_user_ptr
= true;
661 util_range_add(&rbuffer
->valid_buffer_range
, 0, templ
->width0
);
662 util_range_add(&rbuffer
->b
.valid_buffer_range
, 0, templ
->width0
);
664 /* Convert a user pointer to a buffer. */
665 rbuffer
->buf
= ws
->buffer_from_ptr(ws
, user_memory
, templ
->width0
);
671 if (rscreen
->info
.has_virtual_memory
)
672 rbuffer
->gpu_address
=
673 ws
->buffer_get_virtual_address(rbuffer
->buf
);
675 rbuffer
->gpu_address
= 0;
677 rbuffer
->vram_usage
= 0;
678 rbuffer
->gart_usage
= templ
->width0
;
680 return &rbuffer
->b
.b
;