i915_flush.c revision b9baad2aff6ddc5145d91cbfb81d083a21990a80
193d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell/**************************************************************************
293d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell *
393d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
493d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * All Rights Reserved.
593d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell *
693d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
793d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * copy of this software and associated documentation files (the
893d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * "Software"), to deal in the Software without restriction, including
993d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
1093d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
1193d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
1293d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * the following conditions:
1393d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell *
1493d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * The above copyright notice and this permission notice (including the
1593d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
1693d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * of the Software.
1793d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell *
1893d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1993d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2093d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2193d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
2293d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2393d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2493d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2593d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell *
2693d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell **************************************************************************/
2793d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
2893d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell/* Author:
2993d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell *    Keith Whitwell <keith@tungstengraphics.com>
3093d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell */
3193d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
3293d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
3393d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell#include "pipe/p_defines.h"
34b53110c78941e7fcaa41921cce07ca00ec117a97Brian#include "draw/draw_context.h"
3593d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell#include "i915_context.h"
3693d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell#include "i915_reg.h"
3793d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell#include "i915_batch.h"
38abbb1bde06990cb15c82ebcdb9ac07b00cb0ab4fJakob Bornecrantz#include "i915_debug.h"
3993d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
4074df1f4adbbc4fe6027265625cd248c3add154f5Brian
4157fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantzstatic void i915_flush_pipe( struct pipe_context *pipe,
4257fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz                             unsigned flags,
4357fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz                             struct pipe_fence_handle **fence )
4493d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell{
4593d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell   struct i915_context *i915 = i915_context(pipe);
4693d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
47b53110c78941e7fcaa41921cce07ca00ec117a97Brian   draw_flush(i915->draw);
48b53110c78941e7fcaa41921cce07ca00ec117a97Brian
4987a4fa56ae473946b84233fda59d40dd479a4d64Jakob Bornecrantz#if 0
5093d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell   /* Do we need to emit an MI_FLUSH command to flush the hardware
5193d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell    * caches?
5293d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell    */
53ae44a81d1bd40852a7cea9b8025dfa3821adc785Brian   if (flags & (PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_TEXTURE_CACHE)) {
5493d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell      unsigned flush = MI_FLUSH;
5593d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
5693d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell      if (!(flags & PIPE_FLUSH_RENDER_CACHE))
5793d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell	 flush |= INHIBIT_FLUSH_RENDER_CACHE;
5893d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
5993d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell      if (flags & PIPE_FLUSH_TEXTURE_CACHE)
6093d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell	 flush |= FLUSH_MAP_CACHE;
6193d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
625fa6ea68586e906a984291dd4c20f664924157ebJosé Fonseca      if (!BEGIN_BATCH(1, 0)) {
634abe1eb980ed76d2b2d3383eaab520d0aa2ae6f4Michel Dänzer	 FLUSH_BATCH(NULL);
645fa6ea68586e906a984291dd4c20f664924157ebJosé Fonseca	 assert(BEGIN_BATCH(1, 0));
655fa6ea68586e906a984291dd4c20f664924157ebJosé Fonseca      }
6693d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell      OUT_BATCH( flush );
6793d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell   }
6887a4fa56ae473946b84233fda59d40dd479a4d64Jakob Bornecrantz#endif
6987a4fa56ae473946b84233fda59d40dd479a4d64Jakob Bornecrantz
7087a4fa56ae473946b84233fda59d40dd479a4d64Jakob Bornecrantz   if (i915->batch->map == i915->batch->ptr) {
7187a4fa56ae473946b84233fda59d40dd479a4d64Jakob Bornecrantz      return;
7287a4fa56ae473946b84233fda59d40dd479a4d64Jakob Bornecrantz   }
7393d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
7493d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell   /* If there are no flags, just flush pending commands to hardware:
7593d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell    */
764abe1eb980ed76d2b2d3383eaab520d0aa2ae6f4Michel Dänzer   FLUSH_BATCH(fence);
7793d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
78abbb1bde06990cb15c82ebcdb9ac07b00cb0ab4fJakob Bornecrantz   I915_DBG(DBG_FLUSH, "%s: #####\n", __FUNCTION__);
79abbb1bde06990cb15c82ebcdb9ac07b00cb0ab4fJakob Bornecrantz}
8093d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell
8193d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwellvoid i915_init_flush_functions( struct i915_context *i915 )
8293d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell{
8357fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz   i915->base.flush = i915_flush_pipe;
8457fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz}
8557fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz
8657fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz/**
8757fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz * Here we handle all the notifications that needs to go out on a flush.
8857fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz * XXX might move above function to i915_pipe_flush.c and leave this here.
8957fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz */
9057fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantzvoid i915_flush(struct i915_context *i915, struct pipe_fence_handle **fence)
9157fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz{
9257fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz   struct i915_winsys_batchbuffer *batch = i915->batch;
9357fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz
9457fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz   batch->iws->batchbuffer_flush(batch, fence);
954407e5078f6083e4e56ba5970d0fa10d504ed45bJakob Bornecrantz   i915->vbo_flushed = 1;
9657fc2ad7a165bd969de5d1943e325db52f702eb8Jakob Bornecrantz   i915->hardware_dirty = ~0;
97b9baad2aff6ddc5145d91cbfb81d083a21990a80Jakob Bornecrantz   i915->immediate_dirty = ~0;
9893d5cfd8b7c641c5656aed38ad2f9559e09502f0Keith Whitwell}
99