1bf215546Sopenharmony_ci/********************************************************** 2bf215546Sopenharmony_ci * Copyright 2008-2009 VMware, Inc. All rights reserved. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person 5bf215546Sopenharmony_ci * obtaining a copy of this software and associated documentation 6bf215546Sopenharmony_ci * files (the "Software"), to deal in the Software without 7bf215546Sopenharmony_ci * restriction, including without limitation the rights to use, copy, 8bf215546Sopenharmony_ci * modify, merge, publish, distribute, sublicense, and/or sell copies 9bf215546Sopenharmony_ci * of the Software, and to permit persons to whom the Software is 10bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be 13bf215546Sopenharmony_ci * included in all copies or substantial portions of the Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18bf215546Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19bf215546Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20bf215546Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21bf215546Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22bf215546Sopenharmony_ci * SOFTWARE. 23bf215546Sopenharmony_ci * 24bf215546Sopenharmony_ci **********************************************************/ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "pipe/p_defines.h" 27bf215546Sopenharmony_ci#include "util/u_debug_image.h" 28bf215546Sopenharmony_ci#include "util/u_string.h" 29bf215546Sopenharmony_ci#include "svga_screen.h" 30bf215546Sopenharmony_ci#include "svga_surface.h" 31bf215546Sopenharmony_ci#include "svga_context.h" 32bf215546Sopenharmony_ci#include "svga_debug.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_cistatic void svga_flush( struct pipe_context *pipe, 36bf215546Sopenharmony_ci struct pipe_fence_handle **fence, 37bf215546Sopenharmony_ci unsigned flags) 38bf215546Sopenharmony_ci{ 39bf215546Sopenharmony_ci struct svga_context *svga = svga_context(pipe); 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci /* Emit buffered drawing commands, and any back copies. 42bf215546Sopenharmony_ci */ 43bf215546Sopenharmony_ci svga_surfaces_flush( svga ); 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci if (flags & PIPE_FLUSH_FENCE_FD) 46bf215546Sopenharmony_ci svga->swc->hints |= SVGA_HINT_FLAG_EXPORT_FENCE_FD; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci /* Flush command queue. 49bf215546Sopenharmony_ci */ 50bf215546Sopenharmony_ci svga_context_flush(svga, fence); 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n", 53bf215546Sopenharmony_ci __FUNCTION__, fence ? *fence : NULL); 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci /* Enable to dump BMPs of the color/depth buffers each frame */ 56bf215546Sopenharmony_ci if (0) { 57bf215546Sopenharmony_ci struct pipe_framebuffer_state *fb = &svga->curr.framebuffer; 58bf215546Sopenharmony_ci static unsigned frame_no = 1; 59bf215546Sopenharmony_ci char filename[256]; 60bf215546Sopenharmony_ci unsigned i; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci for (i = 0; i < fb->nr_cbufs; i++) { 63bf215546Sopenharmony_ci snprintf(filename, sizeof(filename), "cbuf%u_%04u.bmp", i, frame_no); 64bf215546Sopenharmony_ci debug_dump_surface_bmp(&svga->pipe, filename, fb->cbufs[i]); 65bf215546Sopenharmony_ci } 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci if (0 && fb->zsbuf) { 68bf215546Sopenharmony_ci snprintf(filename, sizeof(filename), "zsbuf_%04u.bmp", frame_no); 69bf215546Sopenharmony_ci debug_dump_surface_bmp(&svga->pipe, filename, fb->zsbuf); 70bf215546Sopenharmony_ci } 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci ++frame_no; 73bf215546Sopenharmony_ci } 74bf215546Sopenharmony_ci} 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci/** 78bf215546Sopenharmony_ci * svga_create_fence_fd 79bf215546Sopenharmony_ci * 80bf215546Sopenharmony_ci * Wraps a SVGA fence around an imported file descriptor. This 81bf215546Sopenharmony_ci * fd represents a fence from another process/device. The fence created 82bf215546Sopenharmony_ci * here can then be fed into fence_server_sync() so SVGA can synchronize 83bf215546Sopenharmony_ci * with an external process 84bf215546Sopenharmony_ci */ 85bf215546Sopenharmony_cistatic void 86bf215546Sopenharmony_cisvga_create_fence_fd(struct pipe_context *pipe, 87bf215546Sopenharmony_ci struct pipe_fence_handle **fence, 88bf215546Sopenharmony_ci int fd, 89bf215546Sopenharmony_ci enum pipe_fd_type type) 90bf215546Sopenharmony_ci{ 91bf215546Sopenharmony_ci struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen); 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci assert(type == PIPE_FD_TYPE_NATIVE_SYNC); 94bf215546Sopenharmony_ci sws->fence_create_fd(sws, fence, fd); 95bf215546Sopenharmony_ci} 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci/** 99bf215546Sopenharmony_ci * svga_fence_server_sync 100bf215546Sopenharmony_ci * 101bf215546Sopenharmony_ci * This function imports a fence from another process/device into the current 102bf215546Sopenharmony_ci * software context so that SVGA can synchronize with it. 103bf215546Sopenharmony_ci */ 104bf215546Sopenharmony_cistatic void 105bf215546Sopenharmony_cisvga_fence_server_sync(struct pipe_context *pipe, 106bf215546Sopenharmony_ci struct pipe_fence_handle *fence) 107bf215546Sopenharmony_ci{ 108bf215546Sopenharmony_ci struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen); 109bf215546Sopenharmony_ci struct svga_context *svga = svga_context(pipe); 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci sws->fence_server_sync(sws, &svga->swc->imported_fence_fd, fence); 112bf215546Sopenharmony_ci} 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_civoid svga_init_flush_functions( struct svga_context *svga ) 116bf215546Sopenharmony_ci{ 117bf215546Sopenharmony_ci svga->pipe.flush = svga_flush; 118bf215546Sopenharmony_ci svga->pipe.create_fence_fd = svga_create_fence_fd; 119bf215546Sopenharmony_ci svga->pipe.fence_server_sync = svga_fence_server_sync; 120bf215546Sopenharmony_ci} 121