1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
27 #include "os/os_thread.h"
28 #include "pipe/p_state.h"
29 #include "pipe/p_defines.h"
30 #include "util/u_inlines.h"
31 #include "util/u_math.h"
32 #include "util/u_memory.h"
35 #include "svga_context.h"
36 #include "svga_debug.h"
37 #include "svga_resource_buffer.h"
38 #include "svga_resource_buffer_upload.h"
39 #include "svga_screen.h"
40 #include "svga_winsys.h"
43 * Describes a complete SVGA_3D_CMD_UPDATE_GB_IMAGE command
46 struct svga_3d_update_gb_image
{
47 SVGA3dCmdHeader header
;
48 SVGA3dCmdUpdateGBImage body
;
51 struct svga_3d_invalidate_gb_image
{
52 SVGA3dCmdHeader header
;
53 SVGA3dCmdInvalidateGBImage body
;
58 * Allocate a winsys_buffer (ie. DMA, aka GMR memory).
60 * It will flush and retry in case the first attempt to create a DMA buffer
61 * fails, so it should not be called from any function involved in flushing
64 struct svga_winsys_buffer
*
65 svga_winsys_buffer_create( struct svga_context
*svga
,
70 struct svga_screen
*svgascreen
= svga_screen(svga
->pipe
.screen
);
71 struct svga_winsys_screen
*sws
= svgascreen
->sws
;
72 struct svga_winsys_buffer
*buf
;
75 buf
= sws
->buffer_create(sws
, alignment
, usage
, size
);
77 SVGA_DBG(DEBUG_DMA
|DEBUG_PERF
, "flushing context to find %d bytes GMR\n",
80 /* Try flushing all pending DMAs */
81 svga_context_flush(svga
, NULL
);
82 buf
= sws
->buffer_create(sws
, alignment
, usage
, size
);
90 * Destroy HW storage if separate from the host surface.
91 * In the GB case, the HW storage is associated with the host surface
92 * and is therefore a No-op.
95 svga_buffer_destroy_hw_storage(struct svga_screen
*ss
, struct svga_buffer
*sbuf
)
97 struct svga_winsys_screen
*sws
= ss
->sws
;
99 assert(!sbuf
->map
.count
);
102 sws
->buffer_destroy(sws
, sbuf
->hwbuf
);
110 * Allocate DMA'ble or Updatable storage for the buffer.
112 * Called before mapping a buffer.
115 svga_buffer_create_hw_storage(struct svga_screen
*ss
,
116 struct svga_buffer
*sbuf
)
120 if (ss
->sws
->have_gb_objects
) {
121 assert(sbuf
->handle
|| !sbuf
->dma
.pending
);
122 return svga_buffer_create_host_surface(ss
, sbuf
);
125 struct svga_winsys_screen
*sws
= ss
->sws
;
126 unsigned alignment
= 16;
128 unsigned size
= sbuf
->b
.b
.width0
;
130 sbuf
->hwbuf
= sws
->buffer_create(sws
, alignment
, usage
, size
);
132 return PIPE_ERROR_OUT_OF_MEMORY
;
134 assert(!sbuf
->dma
.pending
);
143 svga_buffer_create_host_surface(struct svga_screen
*ss
,
144 struct svga_buffer
*sbuf
)
151 sbuf
->key
.format
= SVGA3D_BUFFER
;
152 if (sbuf
->b
.b
.bind
& PIPE_BIND_VERTEX_BUFFER
)
153 sbuf
->key
.flags
|= SVGA3D_SURFACE_HINT_VERTEXBUFFER
;
154 if (sbuf
->b
.b
.bind
& PIPE_BIND_INDEX_BUFFER
)
155 sbuf
->key
.flags
|= SVGA3D_SURFACE_HINT_INDEXBUFFER
;
157 sbuf
->key
.size
.width
= sbuf
->b
.b
.width0
;
158 sbuf
->key
.size
.height
= 1;
159 sbuf
->key
.size
.depth
= 1;
161 sbuf
->key
.numFaces
= 1;
162 sbuf
->key
.numMipLevels
= 1;
163 sbuf
->key
.cachable
= 1;
165 SVGA_DBG(DEBUG_DMA
, "surface_create for buffer sz %d\n", sbuf
->b
.b
.width0
);
167 sbuf
->handle
= svga_screen_surface_create(ss
, &sbuf
->key
);
169 return PIPE_ERROR_OUT_OF_MEMORY
;
171 /* Always set the discard flag on the first time the buffer is written
172 * as svga_screen_surface_create might have passed a recycled host
175 sbuf
->dma
.flags
.discard
= TRUE
;
177 SVGA_DBG(DEBUG_DMA
, " --> got sid %p sz %d (buffer)\n", sbuf
->handle
, sbuf
->b
.b
.width0
);
185 svga_buffer_destroy_host_surface(struct svga_screen
*ss
,
186 struct svga_buffer
*sbuf
)
189 SVGA_DBG(DEBUG_DMA
, " ungrab sid %p sz %d\n", sbuf
->handle
, sbuf
->b
.b
.width0
);
190 svga_screen_surface_destroy(ss
, &sbuf
->key
, &sbuf
->handle
);
196 * Insert a number of preliminary UPDATE_GB_IMAGE commands in the
197 * command buffer, equal to the current number of mapped ranges.
198 * The UPDATE_GB_IMAGE commands will be patched with the
199 * actual ranges just before flush.
201 static enum pipe_error
202 svga_buffer_upload_gb_command(struct svga_context
*svga
,
203 struct svga_buffer
*sbuf
)
205 struct svga_winsys_context
*swc
= svga
->swc
;
206 SVGA3dCmdUpdateGBImage
*cmd
;
207 struct svga_3d_update_gb_image
*ccmd
= NULL
;
208 uint32 numBoxes
= sbuf
->map
.num_ranges
;
209 struct pipe_resource
*dummy
;
213 assert(sbuf
->dma
.updates
== NULL
);
215 if (sbuf
->dma
.flags
.discard
) {
216 struct svga_3d_invalidate_gb_image
*cicmd
= NULL
;
217 SVGA3dCmdInvalidateGBImage
*icmd
;
219 /* Allocate FIFO space for one INVALIDATE_GB_IMAGE command followed by
220 * 'numBoxes' UPDATE_GB_IMAGE commands. Allocate all at once rather
221 * than with separate commands because we need to properly deal with
222 * filling the command buffer.
224 icmd
= SVGA3D_FIFOReserve(swc
,
225 SVGA_3D_CMD_INVALIDATE_GB_IMAGE
,
226 sizeof *icmd
+ numBoxes
* sizeof *ccmd
,
229 return PIPE_ERROR_OUT_OF_MEMORY
;
231 cicmd
= container_of(icmd
, cicmd
, body
);
232 cicmd
->header
.size
= sizeof *icmd
;
233 swc
->surface_relocation(swc
, &icmd
->image
.sid
, NULL
, sbuf
->handle
,
235 SVGA_RELOC_INTERNAL
|
237 icmd
->image
.face
= 0;
238 icmd
->image
.mipmap
= 0;
240 /* initialize the first UPDATE_GB_IMAGE command */
241 ccmd
= (struct svga_3d_update_gb_image
*) &icmd
[1];
242 ccmd
->header
.id
= SVGA_3D_CMD_UPDATE_GB_IMAGE
;
246 /* Allocate FIFO space for 'numBoxes' UPDATE_GB_IMAGE commands */
247 cmd
= SVGA3D_FIFOReserve(swc
,
248 SVGA_3D_CMD_UPDATE_GB_IMAGE
,
249 sizeof *cmd
+ (numBoxes
- 1) * sizeof *ccmd
,
252 return PIPE_ERROR_OUT_OF_MEMORY
;
254 ccmd
= container_of(cmd
, ccmd
, body
);
257 /* Init the first UPDATE_GB_IMAGE command */
258 ccmd
->header
.size
= sizeof *cmd
;
259 swc
->surface_relocation(swc
, &cmd
->image
.sid
, NULL
, sbuf
->handle
,
260 SVGA_RELOC_WRITE
| SVGA_RELOC_INTERNAL
);
262 cmd
->image
.mipmap
= 0;
264 /* Save pointer to the first UPDATE_GB_IMAGE command so that we can
265 * fill in the box info below.
267 sbuf
->dma
.updates
= ccmd
;
270 * Copy the relocation info, face and mipmap to all
271 * subsequent commands. NOTE: For winsyses that actually
272 * patch the image.sid member at flush time, this will fail
273 * miserably. For those we need to add as many relocations
274 * as there are copy boxes.
277 for (i
= 1; i
< numBoxes
; ++i
) {
278 memcpy(++ccmd
, sbuf
->dma
.updates
, sizeof *ccmd
);
281 /* Increment reference count */
282 sbuf
->dma
.svga
= svga
;
284 pipe_resource_reference(&dummy
, &sbuf
->b
.b
);
285 SVGA_FIFOCommitAll(swc
);
287 sbuf
->dma
.flags
.discard
= FALSE
;
294 * Variant of SVGA3D_BufferDMA which leaves the copy box temporarily in blank.
296 static enum pipe_error
297 svga_buffer_upload_command(struct svga_context
*svga
,
298 struct svga_buffer
*sbuf
)
300 struct svga_winsys_context
*swc
= svga
->swc
;
301 struct svga_winsys_buffer
*guest
= sbuf
->hwbuf
;
302 struct svga_winsys_surface
*host
= sbuf
->handle
;
303 SVGA3dTransferType transfer
= SVGA3D_WRITE_HOST_VRAM
;
304 SVGA3dCmdSurfaceDMA
*cmd
;
305 uint32 numBoxes
= sbuf
->map
.num_ranges
;
306 SVGA3dCopyBox
*boxes
;
307 SVGA3dCmdSurfaceDMASuffix
*pSuffix
;
308 unsigned region_flags
;
309 unsigned surface_flags
;
310 struct pipe_resource
*dummy
;
312 if (svga_have_gb_objects(svga
))
313 return svga_buffer_upload_gb_command(svga
, sbuf
);
315 if (transfer
== SVGA3D_WRITE_HOST_VRAM
) {
316 region_flags
= SVGA_RELOC_READ
;
317 surface_flags
= SVGA_RELOC_WRITE
;
319 else if (transfer
== SVGA3D_READ_HOST_VRAM
) {
320 region_flags
= SVGA_RELOC_WRITE
;
321 surface_flags
= SVGA_RELOC_READ
;
325 return PIPE_ERROR_BAD_INPUT
;
330 cmd
= SVGA3D_FIFOReserve(swc
,
331 SVGA_3D_CMD_SURFACE_DMA
,
332 sizeof *cmd
+ numBoxes
* sizeof *boxes
+ sizeof *pSuffix
,
335 return PIPE_ERROR_OUT_OF_MEMORY
;
337 swc
->region_relocation(swc
, &cmd
->guest
.ptr
, guest
, 0, region_flags
);
338 cmd
->guest
.pitch
= 0;
340 swc
->surface_relocation(swc
, &cmd
->host
.sid
, NULL
, host
, surface_flags
);
342 cmd
->host
.mipmap
= 0;
344 cmd
->transfer
= transfer
;
346 sbuf
->dma
.boxes
= (SVGA3dCopyBox
*)&cmd
[1];
347 sbuf
->dma
.svga
= svga
;
349 /* Increment reference count */
351 pipe_resource_reference(&dummy
, &sbuf
->b
.b
);
353 pSuffix
= (SVGA3dCmdSurfaceDMASuffix
*)((uint8_t*)cmd
+ sizeof *cmd
+ numBoxes
* sizeof *boxes
);
354 pSuffix
->suffixSize
= sizeof *pSuffix
;
355 pSuffix
->maximumOffset
= sbuf
->b
.b
.width0
;
356 pSuffix
->flags
= sbuf
->dma
.flags
;
358 SVGA_FIFOCommitAll(swc
);
360 sbuf
->dma
.flags
.discard
= FALSE
;
367 * Patch up the upload DMA command reserved by svga_buffer_upload_command
368 * with the final ranges.
371 svga_buffer_upload_flush(struct svga_context
*svga
,
372 struct svga_buffer
*sbuf
)
375 struct pipe_resource
*dummy
;
377 if (!sbuf
->dma
.pending
) {
378 //debug_printf("no dma pending on buffer\n");
382 assert(sbuf
->handle
);
383 assert(sbuf
->map
.num_ranges
);
384 assert(sbuf
->dma
.svga
== svga
);
387 * Patch the DMA/update command with the final copy box.
389 if (svga_have_gb_objects(svga
)) {
390 struct svga_3d_update_gb_image
*update
= sbuf
->dma
.updates
;
393 for (i
= 0; i
< sbuf
->map
.num_ranges
; ++i
, ++update
) {
394 SVGA3dBox
*box
= &update
->body
.box
;
396 SVGA_DBG(DEBUG_DMA
, " bytes %u - %u\n",
397 sbuf
->map
.ranges
[i
].start
, sbuf
->map
.ranges
[i
].end
);
399 box
->x
= sbuf
->map
.ranges
[i
].start
;
402 box
->w
= sbuf
->map
.ranges
[i
].end
- sbuf
->map
.ranges
[i
].start
;
406 assert(box
->x
<= sbuf
->b
.b
.width0
);
407 assert(box
->x
+ box
->w
<= sbuf
->b
.b
.width0
);
412 assert(sbuf
->dma
.boxes
);
413 SVGA_DBG(DEBUG_DMA
, "dma to sid %p\n", sbuf
->handle
);
415 for (i
= 0; i
< sbuf
->map
.num_ranges
; ++i
) {
416 SVGA3dCopyBox
*box
= sbuf
->dma
.boxes
+ i
;
418 SVGA_DBG(DEBUG_DMA
, " bytes %u - %u\n",
419 sbuf
->map
.ranges
[i
].start
, sbuf
->map
.ranges
[i
].end
);
421 box
->x
= sbuf
->map
.ranges
[i
].start
;
424 box
->w
= sbuf
->map
.ranges
[i
].end
- sbuf
->map
.ranges
[i
].start
;
427 box
->srcx
= sbuf
->map
.ranges
[i
].start
;
431 assert(box
->x
<= sbuf
->b
.b
.width0
);
432 assert(box
->x
+ box
->w
<= sbuf
->b
.b
.width0
);
436 /* Reset sbuf for next use/upload */
438 sbuf
->map
.num_ranges
= 0;
440 assert(sbuf
->head
.prev
&& sbuf
->head
.next
);
441 LIST_DEL(&sbuf
->head
); /* remove from svga->dirty_buffers list */
443 sbuf
->head
.next
= sbuf
->head
.prev
= NULL
;
445 sbuf
->dma
.pending
= FALSE
;
446 sbuf
->dma
.flags
.discard
= FALSE
;
447 sbuf
->dma
.flags
.unsynchronized
= FALSE
;
449 sbuf
->dma
.svga
= NULL
;
450 sbuf
->dma
.boxes
= NULL
;
451 sbuf
->dma
.updates
= NULL
;
453 /* Decrement reference count (and potentially destroy) */
455 pipe_resource_reference(&dummy
, NULL
);
460 * Note a dirty range.
462 * This function only notes the range down. It doesn't actually emit a DMA
463 * upload command. That only happens when a context tries to refer to this
464 * buffer, and the DMA upload command is added to that context's command
467 * We try to lump as many contiguous DMA transfers together as possible.
470 svga_buffer_add_range(struct svga_buffer
*sbuf
,
475 unsigned nearest_range
;
476 unsigned nearest_dist
;
480 if (sbuf
->map
.num_ranges
< SVGA_BUFFER_MAX_RANGES
) {
481 nearest_range
= sbuf
->map
.num_ranges
;
484 nearest_range
= SVGA_BUFFER_MAX_RANGES
- 1;
489 * Try to grow one of the ranges.
492 for (i
= 0; i
< sbuf
->map
.num_ranges
; ++i
) {
497 left_dist
= start
- sbuf
->map
.ranges
[i
].end
;
498 right_dist
= sbuf
->map
.ranges
[i
].start
- end
;
499 dist
= MAX2(left_dist
, right_dist
);
503 * Ranges are contiguous or overlapping -- extend this one and return.
505 * Note that it is not this function's task to prevent overlapping
506 * ranges, as the GMR was already given so it is too late to do
507 * anything. If the ranges overlap here it must surely be because
508 * PIPE_TRANSFER_UNSYNCHRONIZED was set.
511 sbuf
->map
.ranges
[i
].start
= MIN2(sbuf
->map
.ranges
[i
].start
, start
);
512 sbuf
->map
.ranges
[i
].end
= MAX2(sbuf
->map
.ranges
[i
].end
, end
);
517 * Discontiguous ranges -- keep track of the nearest range.
520 if (dist
< nearest_dist
) {
528 * We cannot add a new range to an existing DMA command, so patch-up the
529 * pending DMA upload and start clean.
532 svga_buffer_upload_flush(sbuf
->dma
.svga
, sbuf
);
534 assert(!sbuf
->dma
.pending
);
535 assert(!sbuf
->dma
.svga
);
536 assert(!sbuf
->dma
.boxes
);
538 if (sbuf
->map
.num_ranges
< SVGA_BUFFER_MAX_RANGES
) {
543 sbuf
->map
.ranges
[sbuf
->map
.num_ranges
].start
= start
;
544 sbuf
->map
.ranges
[sbuf
->map
.num_ranges
].end
= end
;
545 ++sbuf
->map
.num_ranges
;
548 * Everything else failed, so just extend the nearest range.
550 * It is OK to do this because we always keep a local copy of the
551 * host buffer data, for SW TNL, and the host never modifies the buffer.
554 assert(nearest_range
< SVGA_BUFFER_MAX_RANGES
);
555 assert(nearest_range
< sbuf
->map
.num_ranges
);
556 sbuf
->map
.ranges
[nearest_range
].start
= MIN2(sbuf
->map
.ranges
[nearest_range
].start
, start
);
557 sbuf
->map
.ranges
[nearest_range
].end
= MAX2(sbuf
->map
.ranges
[nearest_range
].end
, end
);
564 * Copy the contents of the malloc buffer to a hardware buffer.
566 static enum pipe_error
567 svga_buffer_update_hw(struct svga_context
*svga
, struct svga_buffer
*sbuf
)
570 if (!svga_buffer_has_hw_storage(sbuf
)) {
571 struct svga_screen
*ss
= svga_screen(sbuf
->b
.b
.screen
);
580 ret
= svga_buffer_create_hw_storage(svga_screen(sbuf
->b
.b
.screen
),
585 pipe_mutex_lock(ss
->swc_mutex
);
586 map
= svga_buffer_hw_storage_map(svga
, sbuf
, PIPE_TRANSFER_WRITE
, &retry
);
590 pipe_mutex_unlock(ss
->swc_mutex
);
591 svga_buffer_destroy_hw_storage(ss
, sbuf
);
595 memcpy(map
, sbuf
->swbuf
, sbuf
->b
.b
.width0
);
596 svga_buffer_hw_storage_unmap(svga
, sbuf
);
598 /* This user/malloc buffer is now indistinguishable from a gpu buffer */
599 assert(!sbuf
->map
.count
);
600 if (!sbuf
->map
.count
) {
604 align_free(sbuf
->swbuf
);
608 pipe_mutex_unlock(ss
->swc_mutex
);
616 * Upload the buffer to the host in a piecewise fashion.
618 * Used when the buffer is too big to fit in the GMR aperture.
619 * This function should never get called in the guest-backed case
620 * since we always have a full-sized hardware storage backing the
623 static enum pipe_error
624 svga_buffer_upload_piecewise(struct svga_screen
*ss
,
625 struct svga_context
*svga
,
626 struct svga_buffer
*sbuf
)
628 struct svga_winsys_screen
*sws
= ss
->sws
;
629 const unsigned alignment
= sizeof(void *);
630 const unsigned usage
= 0;
633 assert(sbuf
->map
.num_ranges
);
634 assert(!sbuf
->dma
.pending
);
635 assert(!svga_have_gb_objects(svga
));
637 SVGA_DBG(DEBUG_DMA
, "dma to sid %p\n", sbuf
->handle
);
639 for (i
= 0; i
< sbuf
->map
.num_ranges
; ++i
) {
640 struct svga_buffer_range
*range
= &sbuf
->map
.ranges
[i
];
641 unsigned offset
= range
->start
;
642 unsigned size
= range
->end
- range
->start
;
644 while (offset
< range
->end
) {
645 struct svga_winsys_buffer
*hwbuf
;
649 if (offset
+ size
> range
->end
)
650 size
= range
->end
- offset
;
652 hwbuf
= sws
->buffer_create(sws
, alignment
, usage
, size
);
656 return PIPE_ERROR_OUT_OF_MEMORY
;
657 hwbuf
= sws
->buffer_create(sws
, alignment
, usage
, size
);
660 SVGA_DBG(DEBUG_DMA
, " bytes %u - %u\n",
661 offset
, offset
+ size
);
663 map
= sws
->buffer_map(sws
, hwbuf
,
664 PIPE_TRANSFER_WRITE
|
665 PIPE_TRANSFER_DISCARD_RANGE
);
668 memcpy(map
, (const char *) sbuf
->swbuf
+ offset
, size
);
669 sws
->buffer_unmap(sws
, hwbuf
);
672 ret
= SVGA3D_BufferDMA(svga
->swc
,
674 SVGA3D_WRITE_HOST_VRAM
,
675 size
, 0, offset
, sbuf
->dma
.flags
);
676 if (ret
!= PIPE_OK
) {
677 svga_context_flush(svga
, NULL
);
678 ret
= SVGA3D_BufferDMA(svga
->swc
,
680 SVGA3D_WRITE_HOST_VRAM
,
681 size
, 0, offset
, sbuf
->dma
.flags
);
682 assert(ret
== PIPE_OK
);
685 sbuf
->dma
.flags
.discard
= FALSE
;
687 sws
->buffer_destroy(sws
, hwbuf
);
693 sbuf
->map
.num_ranges
= 0;
700 * Get (or create/upload) the winsys surface handle so that we can
701 * refer to this buffer in fifo commands.
702 * This function will create the host surface, and in the GB case also the
703 * hardware storage. In the non-GB case, the hardware storage will be created
704 * if there are mapped ranges and the data is currently in a malloc'ed buffer.
706 struct svga_winsys_surface
*
707 svga_buffer_handle(struct svga_context
*svga
,
708 struct pipe_resource
*buf
)
710 struct pipe_screen
*screen
= svga
->pipe
.screen
;
711 struct svga_screen
*ss
= svga_screen(screen
);
712 struct svga_buffer
*sbuf
;
718 sbuf
= svga_buffer(buf
);
723 /* This call will set sbuf->handle */
724 if (svga_have_gb_objects(svga
)) {
725 ret
= svga_buffer_update_hw(svga
, sbuf
);
727 ret
= svga_buffer_create_host_surface(ss
, sbuf
);
733 assert(sbuf
->handle
);
735 if (sbuf
->map
.num_ranges
) {
736 if (!sbuf
->dma
.pending
) {
738 * No pending DMA upload yet, so insert a DMA upload command now.
742 * Migrate the data from swbuf -> hwbuf if necessary.
744 ret
= svga_buffer_update_hw(svga
, sbuf
);
745 if (ret
== PIPE_OK
) {
747 * Queue a dma command.
750 ret
= svga_buffer_upload_command(svga
, sbuf
);
751 if (ret
== PIPE_ERROR_OUT_OF_MEMORY
) {
752 svga_context_flush(svga
, NULL
);
753 ret
= svga_buffer_upload_command(svga
, sbuf
);
754 assert(ret
== PIPE_OK
);
756 if (ret
== PIPE_OK
) {
757 sbuf
->dma
.pending
= TRUE
;
758 assert(!sbuf
->head
.prev
&& !sbuf
->head
.next
);
759 LIST_ADDTAIL(&sbuf
->head
, &svga
->dirty_buffers
);
762 else if (ret
== PIPE_ERROR_OUT_OF_MEMORY
) {
764 * The buffer is too big to fit in the GMR aperture, so break it in
767 ret
= svga_buffer_upload_piecewise(ss
, svga
, sbuf
);
770 if (ret
!= PIPE_OK
) {
772 * Something unexpected happened above. There is very little that
773 * we can do other than proceeding while ignoring the dirty ranges.
776 sbuf
->map
.num_ranges
= 0;
781 * There a pending dma already. Make sure it is from this context.
783 assert(sbuf
->dma
.svga
== svga
);
787 assert(!sbuf
->map
.num_ranges
|| sbuf
->dma
.pending
);
795 svga_context_flush_buffers(struct svga_context
*svga
)
797 struct list_head
*curr
, *next
;
798 struct svga_buffer
*sbuf
;
800 curr
= svga
->dirty_buffers
.next
;
802 while(curr
!= &svga
->dirty_buffers
) {
803 sbuf
= LIST_ENTRY(struct svga_buffer
, curr
, head
);
805 assert(p_atomic_read(&sbuf
->b
.b
.reference
.count
) != 0);
806 assert(sbuf
->dma
.pending
);
808 svga_buffer_upload_flush(svga
, sbuf
);