Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 1 | /********************************************************** |
| 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 Paul | c84a891 | 2016-02-08 09:29:38 -0700 | [diff] [blame] | 27 | #include "util/u_debug_image.h" |
Brian Paul | e40252d | 2011-01-31 14:41:36 -0700 | [diff] [blame] | 28 | #include "util/u_string.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 29 | #include "svga_screen.h" |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 30 | #include "svga_surface.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 31 | #include "svga_context.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 32 | #include "svga_debug.h" |
| 33 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 34 | |
| 35 | static void svga_flush( struct pipe_context *pipe, |
Marek Olšák | 598cc1f | 2012-12-21 17:03:22 +0100 | [diff] [blame] | 36 | struct pipe_fence_handle **fence, |
Chia-I Wu | 8c347d4 | 2013-05-02 16:25:15 +0800 | [diff] [blame] | 37 | unsigned flags) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 38 | { |
| 39 | struct svga_context *svga = svga_context(pipe); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 40 | |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 41 | /* Emit buffered drawing commands, and any back copies. |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 42 | */ |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 43 | svga_surfaces_flush( svga ); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 44 | |
Sinclair Yeh | 56a6e89 | 2017-05-15 16:22:53 -0700 | [diff] [blame] | 45 | if (flags & PIPE_FLUSH_FENCE_FD) |
| 46 | svga->swc->hints |= SVGA_HINT_FLAG_EXPORT_FENCE_FD; |
| 47 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 48 | /* Flush command queue. |
| 49 | */ |
| 50 | svga_context_flush(svga, fence); |
Keith Whitwell | b911688 | 2009-11-27 12:18:22 +0000 | [diff] [blame] | 51 | |
Marek Olšák | 7e02303 | 2011-03-08 00:57:48 +0100 | [diff] [blame] | 52 | SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n", |
| 53 | __FUNCTION__, fence ? *fence : 0x0); |
Brian Paul | e40252d | 2011-01-31 14:41:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* Enable to dump BMPs of the color/depth buffers each frame */ |
| 56 | if (0) { |
Marek Olšák | 7e02303 | 2011-03-08 00:57:48 +0100 | [diff] [blame] | 57 | struct pipe_framebuffer_state *fb = &svga->curr.framebuffer; |
| 58 | static unsigned frame_no = 1; |
| 59 | char filename[256]; |
| 60 | unsigned i; |
Brian Paul | e40252d | 2011-01-31 14:41:36 -0700 | [diff] [blame] | 61 | |
Marek Olšák | 7e02303 | 2011-03-08 00:57:48 +0100 | [diff] [blame] | 62 | for (i = 0; i < fb->nr_cbufs; i++) { |
Brian Paul | b54ce37 | 2013-03-28 17:17:26 -0600 | [diff] [blame] | 63 | util_snprintf(filename, sizeof(filename), "cbuf%u_%04u.bmp", i, frame_no); |
Marek Olšák | 7e02303 | 2011-03-08 00:57:48 +0100 | [diff] [blame] | 64 | debug_dump_surface_bmp(&svga->pipe, filename, fb->cbufs[i]); |
Brian Paul | e40252d | 2011-01-31 14:41:36 -0700 | [diff] [blame] | 65 | } |
Marek Olšák | 7e02303 | 2011-03-08 00:57:48 +0100 | [diff] [blame] | 66 | |
| 67 | if (0 && fb->zsbuf) { |
Brian Paul | b54ce37 | 2013-03-28 17:17:26 -0600 | [diff] [blame] | 68 | util_snprintf(filename, sizeof(filename), "zsbuf_%04u.bmp", frame_no); |
Marek Olšák | 7e02303 | 2011-03-08 00:57:48 +0100 | [diff] [blame] | 69 | debug_dump_surface_bmp(&svga->pipe, filename, fb->zsbuf); |
| 70 | } |
| 71 | |
| 72 | ++frame_no; |
Brian Paul | e40252d | 2011-01-31 14:41:36 -0700 | [diff] [blame] | 73 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
Sinclair Yeh | 56a6e89 | 2017-05-15 16:22:53 -0700 | [diff] [blame] | 77 | /** |
| 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 | */ |
| 85 | static void |
| 86 | svga_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 | */ |
| 102 | static void |
| 103 | svga_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 Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 113 | void svga_init_flush_functions( struct svga_context *svga ) |
| 114 | { |
| 115 | svga->pipe.flush = svga_flush; |
Sinclair Yeh | 56a6e89 | 2017-05-15 16:22:53 -0700 | [diff] [blame] | 116 | svga->pipe.create_fence_fd = svga_create_fence_fd; |
| 117 | svga->pipe.fence_server_sync = svga_fence_server_sync; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 118 | } |