1 /*
2 * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
3 * The term “Broadcom” refers to Broadcom Inc.
4 * and/or its subsidiaries.
5 * SPDX-License-Identifier: MIT
6 */
7
8 #include "pipe/p_defines.h"
9 #include "util/u_debug_image.h"
10 #include "util/u_string.h"
11 #include "svga_screen.h"
12 #include "svga_surface.h"
13 #include "svga_context.h"
14 #include "svga_debug.h"
15
16
svga_flush(struct pipe_context * pipe,struct pipe_fence_handle ** fence,unsigned flags)17 static void svga_flush( struct pipe_context *pipe,
18 struct pipe_fence_handle **fence,
19 unsigned flags)
20 {
21 struct svga_context *svga = svga_context(pipe);
22
23 /* Emit buffered drawing commands, and any back copies.
24 */
25 svga_surfaces_flush( svga );
26
27 if (flags & PIPE_FLUSH_FENCE_FD)
28 svga->swc->hints |= SVGA_HINT_FLAG_EXPORT_FENCE_FD;
29
30 /* Flush command queue.
31 */
32 svga_context_flush(svga, fence);
33
34 SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n",
35 __func__, fence ? *fence : NULL);
36
37 /* Enable to dump BMPs of the color/depth buffers each frame */
38 if (0) {
39 struct pipe_framebuffer_state *fb = &svga->curr.framebuffer;
40 static unsigned frame_no = 1;
41 char filename[256];
42 unsigned i;
43
44 for (i = 0; i < fb->nr_cbufs; i++) {
45 snprintf(filename, sizeof(filename), "cbuf%u_%04u.bmp", i, frame_no);
46 debug_dump_surface_bmp(&svga->pipe, filename, fb->cbufs[i]);
47 }
48
49 if (0 && fb->zsbuf) {
50 snprintf(filename, sizeof(filename), "zsbuf_%04u.bmp", frame_no);
51 debug_dump_surface_bmp(&svga->pipe, filename, fb->zsbuf);
52 }
53
54 ++frame_no;
55 }
56 }
57
58
59 /**
60 * svga_create_fence_fd
61 *
62 * Wraps a SVGA fence around an imported file descriptor. This
63 * fd represents a fence from another process/device. The fence created
64 * here can then be fed into fence_server_sync() so SVGA can synchronize
65 * with an external process
66 */
67 static void
svga_create_fence_fd(struct pipe_context * pipe,struct pipe_fence_handle ** fence,int fd,enum pipe_fd_type type)68 svga_create_fence_fd(struct pipe_context *pipe,
69 struct pipe_fence_handle **fence,
70 int fd,
71 enum pipe_fd_type type)
72 {
73 struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);
74
75 assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
76 sws->fence_create_fd(sws, fence, fd);
77 }
78
79
80 /**
81 * svga_fence_server_sync
82 *
83 * This function imports a fence from another process/device into the current
84 * software context so that SVGA can synchronize with it.
85 */
86 static void
svga_fence_server_sync(struct pipe_context * pipe,struct pipe_fence_handle * fence)87 svga_fence_server_sync(struct pipe_context *pipe,
88 struct pipe_fence_handle *fence)
89 {
90 struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);
91 struct svga_context *svga = svga_context(pipe);
92
93 sws->fence_server_sync(sws, &svga->swc->imported_fence_fd, fence);
94 }
95
96
svga_init_flush_functions(struct svga_context * svga)97 void svga_init_flush_functions( struct svga_context *svga )
98 {
99 svga->pipe.flush = svga_flush;
100 svga->pipe.create_fence_fd = svga_create_fence_fd;
101 svga->pipe.fence_server_sync = svga_fence_server_sync;
102 }
103