Path: blob/21.2-virgl/src/gallium/drivers/svga/svga_pipe_flush.c
4570 views
/**********************************************************1* Copyright 2008-2009 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**********************************************************/2425#include "pipe/p_defines.h"26#include "util/u_debug_image.h"27#include "util/u_string.h"28#include "svga_screen.h"29#include "svga_surface.h"30#include "svga_context.h"31#include "svga_debug.h"323334static void svga_flush( struct pipe_context *pipe,35struct pipe_fence_handle **fence,36unsigned flags)37{38struct svga_context *svga = svga_context(pipe);3940/* Emit buffered drawing commands, and any back copies.41*/42svga_surfaces_flush( svga );4344if (flags & PIPE_FLUSH_FENCE_FD)45svga->swc->hints |= SVGA_HINT_FLAG_EXPORT_FENCE_FD;4647/* Flush command queue.48*/49svga_context_flush(svga, fence);5051SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n",52__FUNCTION__, fence ? *fence : 0x0);5354/* Enable to dump BMPs of the color/depth buffers each frame */55if (0) {56struct pipe_framebuffer_state *fb = &svga->curr.framebuffer;57static unsigned frame_no = 1;58char filename[256];59unsigned i;6061for (i = 0; i < fb->nr_cbufs; i++) {62snprintf(filename, sizeof(filename), "cbuf%u_%04u.bmp", i, frame_no);63debug_dump_surface_bmp(&svga->pipe, filename, fb->cbufs[i]);64}6566if (0 && fb->zsbuf) {67snprintf(filename, sizeof(filename), "zsbuf_%04u.bmp", frame_no);68debug_dump_surface_bmp(&svga->pipe, filename, fb->zsbuf);69}7071++frame_no;72}73}747576/**77* svga_create_fence_fd78*79* Wraps a SVGA fence around an imported file descriptor. This80* fd represents a fence from another process/device. The fence created81* here can then be fed into fence_server_sync() so SVGA can synchronize82* with an external process83*/84static void85svga_create_fence_fd(struct pipe_context *pipe,86struct pipe_fence_handle **fence,87int fd,88enum pipe_fd_type type)89{90struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);9192assert(type == PIPE_FD_TYPE_NATIVE_SYNC);93sws->fence_create_fd(sws, fence, fd);94}959697/**98* svga_fence_server_sync99*100* This function imports a fence from another process/device into the current101* software context so that SVGA can synchronize with it.102*/103static void104svga_fence_server_sync(struct pipe_context *pipe,105struct pipe_fence_handle *fence)106{107struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);108struct svga_context *svga = svga_context(pipe);109110sws->fence_server_sync(sws, &svga->swc->imported_fence_fd, fence);111}112113114void svga_init_flush_functions( struct svga_context *svga )115{116svga->pipe.flush = svga_flush;117svga->pipe.create_fence_fd = svga_create_fence_fd;118svga->pipe.fence_server_sync = svga_fence_server_sync;119}120121122