14a49301eSmrg/**************************************************************************
27ec681f3Smrg *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
57ec681f3Smrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
137ec681f3Smrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
177ec681f3Smrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
257ec681f3Smrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
284a49301eSmrg/* Author:
29af69d88dSmrg *    Keith Whitwell <keithw@vmware.com>
304a49301eSmrg */
314a49301eSmrg
324a49301eSmrg#include "draw/draw_context.h"
337ec681f3Smrg#include "pipe/p_defines.h"
344a49301eSmrg#include "i915_batch.h"
357ec681f3Smrg#include "i915_context.h"
363464ebd5Sriastradh#include "i915_debug.h"
37af69d88dSmrg#include "i915_reg.h"
384a49301eSmrg
397ec681f3Smrgstatic void
407ec681f3Smrgi915_flush_pipe(struct pipe_context *pipe, struct pipe_fence_handle **fence,
417ec681f3Smrg                unsigned flags)
424a49301eSmrg{
434a49301eSmrg   struct i915_context *i915 = i915_context(pipe);
44af69d88dSmrg   enum i915_winsys_flush_flags winsys_flags = I915_FLUSH_ASYNC;
454a49301eSmrg
46af69d88dSmrg   if (!i915->batch)
47af69d88dSmrg      return;
484a49301eSmrg
49af69d88dSmrg   /* Only shortcut this if we have no fence, otherwise we must flush the
50af69d88dSmrg    * empty batchbuffer to get our fence back.
51af69d88dSmrg    */
52af69d88dSmrg   if (!fence && (i915->batch->map == i915->batch->ptr)) {
534a49301eSmrg      return;
544a49301eSmrg   }
554a49301eSmrg
56af69d88dSmrg   if (flags == PIPE_FLUSH_END_OF_FRAME)
57af69d88dSmrg      winsys_flags = I915_FLUSH_END_OF_FRAME;
58af69d88dSmrg
59af69d88dSmrg   FLUSH_BATCH(fence, winsys_flags);
604a49301eSmrg
613464ebd5Sriastradh   I915_DBG(DBG_FLUSH, "%s: #####\n", __FUNCTION__);
623464ebd5Sriastradh}
634a49301eSmrg
647ec681f3Smrgvoid
657ec681f3Smrgi915_init_flush_functions(struct i915_context *i915)
664a49301eSmrg{
673464ebd5Sriastradh   i915->base.flush = i915_flush_pipe;
683464ebd5Sriastradh}
693464ebd5Sriastradh
703464ebd5Sriastradh/**
713464ebd5Sriastradh * Here we handle all the notifications that needs to go out on a flush.
723464ebd5Sriastradh * XXX might move above function to i915_pipe_flush.c and leave this here.
733464ebd5Sriastradh */
747ec681f3Smrgvoid
757ec681f3Smrgi915_flush(struct i915_context *i915, struct pipe_fence_handle **fence,
767ec681f3Smrg           unsigned flags)
773464ebd5Sriastradh{
783464ebd5Sriastradh   struct i915_winsys_batchbuffer *batch = i915->batch;
793464ebd5Sriastradh
80af69d88dSmrg   batch->iws->batchbuffer_flush(batch, fence, flags);
813464ebd5Sriastradh   i915->vbo_flushed = 1;
823464ebd5Sriastradh   i915->hardware_dirty = ~0;
833464ebd5Sriastradh   i915->immediate_dirty = ~0;
843464ebd5Sriastradh   i915->dynamic_dirty = ~0;
853464ebd5Sriastradh   i915->static_dirty = ~0;
863464ebd5Sriastradh   /* kernel emits flushes in between batchbuffers */
873464ebd5Sriastradh   i915->flush_dirty = 0;
88af69d88dSmrg   i915->fired_vertices += i915->queued_vertices;
89af69d88dSmrg   i915->queued_vertices = 0;
904a49301eSmrg}
91