blob: 85ec34f3145bb5c0354c1fdeeb367344069c678e [file] [log] [blame]
Jakob Bornecrantz31926332009-11-16 19:56:18 +01001/**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
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:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
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
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26#include "pipe/p_defines.h"
Brian Paulc84a8912016-02-08 09:29:38 -070027#include "util/u_debug_image.h"
Brian Paule40252d2011-01-31 14:41:36 -070028#include "util/u_string.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010029#include "svga_screen.h"
Keith Whitwell287c94e2010-04-10 16:05:54 +010030#include "svga_surface.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010031#include "svga_context.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010032#include "svga_debug.h"
33
Jakob Bornecrantz31926332009-11-16 19:56:18 +010034
35static void svga_flush( struct pipe_context *pipe,
Marek Olšák598cc1f2012-12-21 17:03:22 +010036 struct pipe_fence_handle **fence,
Chia-I Wu8c347d42013-05-02 16:25:15 +080037 unsigned flags)
Jakob Bornecrantz31926332009-11-16 19:56:18 +010038{
39 struct svga_context *svga = svga_context(pipe);
Jakob Bornecrantz31926332009-11-16 19:56:18 +010040
José Fonseca0ced7892011-02-18 14:33:55 +000041 /* Emit buffered drawing commands, and any back copies.
Jakob Bornecrantz31926332009-11-16 19:56:18 +010042 */
José Fonseca0ced7892011-02-18 14:33:55 +000043 svga_surfaces_flush( svga );
Jakob Bornecrantz31926332009-11-16 19:56:18 +010044
Sinclair Yeh56a6e892017-05-15 16:22:53 -070045 if (flags & PIPE_FLUSH_FENCE_FD)
46 svga->swc->hints |= SVGA_HINT_FLAG_EXPORT_FENCE_FD;
47
Jakob Bornecrantz31926332009-11-16 19:56:18 +010048 /* Flush command queue.
49 */
50 svga_context_flush(svga, fence);
Keith Whitwellb9116882009-11-27 12:18:22 +000051
Marek Olšák7e023032011-03-08 00:57:48 +010052 SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n",
53 __FUNCTION__, fence ? *fence : 0x0);
Brian Paule40252d2011-01-31 14:41:36 -070054
55 /* Enable to dump BMPs of the color/depth buffers each frame */
56 if (0) {
Marek Olšák7e023032011-03-08 00:57:48 +010057 struct pipe_framebuffer_state *fb = &svga->curr.framebuffer;
58 static unsigned frame_no = 1;
59 char filename[256];
60 unsigned i;
Brian Paule40252d2011-01-31 14:41:36 -070061
Marek Olšák7e023032011-03-08 00:57:48 +010062 for (i = 0; i < fb->nr_cbufs; i++) {
Brian Paulb54ce372013-03-28 17:17:26 -060063 util_snprintf(filename, sizeof(filename), "cbuf%u_%04u.bmp", i, frame_no);
Marek Olšák7e023032011-03-08 00:57:48 +010064 debug_dump_surface_bmp(&svga->pipe, filename, fb->cbufs[i]);
Brian Paule40252d2011-01-31 14:41:36 -070065 }
Marek Olšák7e023032011-03-08 00:57:48 +010066
67 if (0 && fb->zsbuf) {
Brian Paulb54ce372013-03-28 17:17:26 -060068 util_snprintf(filename, sizeof(filename), "zsbuf_%04u.bmp", frame_no);
Marek Olšák7e023032011-03-08 00:57:48 +010069 debug_dump_surface_bmp(&svga->pipe, filename, fb->zsbuf);
70 }
71
72 ++frame_no;
Brian Paule40252d2011-01-31 14:41:36 -070073 }
Jakob Bornecrantz31926332009-11-16 19:56:18 +010074}
75
76
Sinclair Yeh56a6e892017-05-15 16:22:53 -070077/**
78 * svga_create_fence_fd
79 *
80 * Wraps a SVGA fence around an imported file descriptor. This
81 * fd represents a fence from another process/device. The fence created
82 * here can then be fed into fence_server_sync() so SVGA can synchronize
83 * with an external process
84 */
85static void
86svga_create_fence_fd(struct pipe_context *pipe,
87 struct pipe_fence_handle **fence,
88 int fd)
89{
90 struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);
91
92 sws->fence_create_fd(sws, fence, fd);
93}
94
95
96/**
97 * svga_fence_server_sync
98 *
99 * This function imports a fence from another process/device into the current
100 * software context so that SVGA can synchronize with it.
101 */
102static void
103svga_fence_server_sync(struct pipe_context *pipe,
104 struct pipe_fence_handle *fence)
105{
106 struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);
107 struct svga_context *svga = svga_context(pipe);
108
109 sws->fence_server_sync(sws, &svga->swc->imported_fence_fd, fence);
110}
111
112
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100113void svga_init_flush_functions( struct svga_context *svga )
114{
115 svga->pipe.flush = svga_flush;
Sinclair Yeh56a6e892017-05-15 16:22:53 -0700116 svga->pipe.create_fence_fd = svga_create_fence_fd;
117 svga->pipe.fence_server_sync = svga_fence_server_sync;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100118}