i830_vtbl.c revision 5df51c2bb00871b338ec8455bd4ce5feea163f63
16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved.
56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions:
136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the
156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software.
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_context.h"
296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_reg.h"
306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_batchbuffer.h"
316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_regions.h"
32f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#include "intel_tris.h"
332c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt#include "intel_fbo.h"
346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_context.h"
356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_vertex.h"
366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define FILE_DEBUG_FLAG DEBUG_STATE
386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLboolean i830_check_vertex_size(struct intel_context *intel,
406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                        GLuint expected);
416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define SZ_TO_HW(sz)  ((sz-2)&0x3)
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define EMIT_SZ(sz)   (EMIT_1F + (sz) - 1)
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define EMIT_ATTR( ATTR, STYLE, V0 )					\
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo {									\
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attrs[intel->vertex_attr_count].attrib = (ATTR);	\
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attrs[intel->vertex_attr_count].format = (STYLE);	\
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attr_count++;						\
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   v0 |= V0;								\
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define EMIT_PAD( N )							\
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo {									\
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attrs[intel->vertex_attr_count].attrib = 0;		\
556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attrs[intel->vertex_attr_count].format = EMIT_PAD;	\
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attrs[intel->vertex_attr_count].offset = (N);		\
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attr_count++;						\
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VRTX_TEX_SET_FMT(n, x)          ((x)<<((n)*2))
626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TEXBIND_SET(n, x) 		((x)<<((n)*4))
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
65a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheideggeri830_render_prevalidate(struct intel_context *intel)
66a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger{
67a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger}
68a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger
69a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheideggerstatic void
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_render_start(struct intel_context *intel)
716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
72f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct vertex_buffer *VB = &tnl->vb;
766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DECLARE_RENDERINPUTS(index_bitset);
776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint v0 = _3DSTATE_VFT0_CMD;
786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint v2 = _3DSTATE_VFT1_CMD;
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint mcsb1 = 0;
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   RENDERINPUTS_COPY(index_bitset, tnl->render_inputs_bitset);
826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Important:
846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vertex_attr_count = 0;
876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * build up a hardware vertex.
906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (RENDERINPUTS_TEST_RANGE(index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX)) {
926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VFT0_XYZW);
936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->coloroffset = 4;
946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, VFT0_XYZ);
976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->coloroffset = 3;
986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_POINTSIZE)) {
1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      EMIT_ATTR(_TNL_ATTRIB_POINTSIZE, EMIT_1F, VFT0_POINT_WIDTH);
1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   EMIT_ATTR(_TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VFT0_DIFFUSE);
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->specoffset = 0;
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_COLOR1) ||
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_FOG)) {
1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_COLOR1)) {
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->specoffset = intel->coloroffset + 1;
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         EMIT_ATTR(_TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VFT0_SPEC);
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         EMIT_PAD(3);
1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_FOG))
1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         EMIT_ATTR(_TNL_ATTRIB_FOG, EMIT_1UB_1F, VFT0_SPEC);
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         EMIT_PAD(1);
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (RENDERINPUTS_TEST_RANGE(index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX)) {
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      int i, count = 0;
1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      for (i = 0; i < I830_TEX_UNITS; i++) {
1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_TEX(i))) {
127df582ca767a38f185f9b4c449e7ed4266c414ae2Eric Anholt            GLuint sz = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]->size;
1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            GLuint emit;
1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            GLuint mcs = (i830->state.Tex[i][I830_TEXREG_MCS] &
1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                          ~TEXCOORDTYPE_MASK);
1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            switch (sz) {
1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            case 1:
1346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            case 2:
1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               emit = EMIT_2F;
1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               sz = 2;
1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               mcs |= TEXCOORDTYPE_CARTESIAN;
1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               break;
1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            case 3:
1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               emit = EMIT_3F;
1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               sz = 3;
1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               mcs |= TEXCOORDTYPE_VECTOR;
1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               break;
1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            case 4:
1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               emit = EMIT_3F_XYW;
1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               sz = 3;
1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               mcs |= TEXCOORDTYPE_HOMOGENEOUS;
1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               break;
1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            default:
1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               continue;
1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            };
1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            EMIT_ATTR(_TNL_ATTRIB_TEX0 + i, emit, 0);
1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            v2 |= VRTX_TEX_SET_FMT(count, SZ_TO_HW(sz));
1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            mcsb1 |= (count + 8) << (i * 4);
1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            if (mcs != i830->state.Tex[i][I830_TEXREG_MCS]) {
1596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               I830_STATECHANGE(i830, I830_UPLOAD_TEX(i));
1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->state.Tex[i][I830_TEXREG_MCS] = mcs;
1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            }
1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            count++;
1646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
1666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      v0 |= VFT0_TEX_COUNT(count);
1686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Only need to change the vertex emit code if there has been a
1716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * statechange to a new hardware vertex format:
1726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
1736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (v0 != i830->state.Ctx[I830_CTXREG_VF] ||
1746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       v2 != i830->state.Ctx[I830_CTXREG_VF2] ||
1756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       mcsb1 != i830->state.Ctx[I830_CTXREG_MCSB1] ||
1766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       !RENDERINPUTS_EQUAL(index_bitset, i830->last_index_bitset)) {
1776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      int k;
1786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
1806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Must do this *after* statechange, so as not to affect
1826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * buffered vertices reliant on the old state:
1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->vertex_size =
1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         _tnl_install_attrs(ctx,
1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                            intel->vertex_attrs,
1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                            intel->vertex_attr_count,
1886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                            intel->ViewportMatrix.m, 0);
1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->vertex_size >>= 2;
1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_VF] = v0;
1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_VF2] = v2;
1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_MCSB1] = mcsb1;
1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      RENDERINPUTS_COPY(i830->last_index_bitset, index_bitset);
1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      k = i830_check_vertex_size(intel, intel->vertex_size);
1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      assert(k);
1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_reduced_primitive_state(struct intel_context *intel, GLenum rprim)
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(&intel->ctx);
2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint st1 = i830->state.Stipple[I830_STPREG_ST1];
2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   st1 &= ~ST1_ENABLE;
2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (rprim) {
2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_TRIANGLES:
2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple)
2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         st1 |= ST1_ENABLE;
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_LINES:
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_POINTS:
2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.reduced_primitive = rprim;
2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (st1 != i830->state.Stipple[I830_STPREG_ST1]) {
2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      INTEL_FIREVERTICES(intel);
2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_STIPPLE);
2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Stipple[I830_STPREG_ST1] = st1;
2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Pull apart the vertex format registers and figure out how large a
2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * vertex is supposed to be.
2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLboolean
2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_check_vertex_size(struct intel_context *intel, GLuint expected)
2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(&intel->ctx);
238c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt   int vft0 = i830->state.Ctx[I830_CTXREG_VF];
239c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt   int vft1 = i830->state.Ctx[I830_CTXREG_VF2];
2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int nrtex = (vft0 & VFT0_TEX_COUNT_MASK) >> VFT0_TEX_COUNT_SHIFT;
2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int i, sz = 0;
2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (vft0 & VFT0_XYZW_MASK) {
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case VFT0_XY:
2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz = 2;
2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case VFT0_XYZ:
2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz = 3;
2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case VFT0_XYW:
2516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz = 3;
2526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
2536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case VFT0_XYZW:
2546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz = 4;
2556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fprintf(stderr, "no xyzw specified\n");
2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return 0;
2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (vft0 & VFT0_SPEC)
2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz++;
2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (vft0 & VFT0_DIFFUSE)
2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz++;
2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (vft0 & VFT0_DEPTH_OFFSET)
2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz++;
2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (vft0 & VFT0_POINT_WIDTH)
2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz++;
2696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < nrtex; i++) {
2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      switch (vft1 & VFT1_TEX0_MASK) {
2726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXCOORDFMT_2D:
2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         sz += 2;
2746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXCOORDFMT_3D:
2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         sz += 3;
2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXCOORDFMT_4D:
2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         sz += 4;
2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXCOORDFMT_1D:
2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         sz += 1;
2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      vft1 >>= VFT1_TEX1_SHIFT;
2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (sz != expected)
2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fprintf(stderr, "vertex size mismatch %d/%d\n", sz, expected);
2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return sz == expected;
2926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_emit_invarient_state(struct intel_context *intel)
2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   BATCH_LOCALS;
2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2995203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg   BEGIN_BATCH(29);
3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD);
3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(0);
3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD);
3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(0);
3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_DFLT_Z_CMD);
3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(0);
3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_FOG_MODE_CMD);
3116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(FOGFUNC_ENABLE |
3126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             FOG_LINEAR_CONST | FOGSRC_INDEX_Z | ENABLE_FOG_DENSITY);
3136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(0);
3146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(0);
3156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
3186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             MAP_UNIT(0) |
3196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             DISABLE_TEX_STREAM_BUMP |
3206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_COORD_SET |
3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             TEX_STREAM_COORD_SET(0) |
3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(0));
3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             MAP_UNIT(1) |
3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             DISABLE_TEX_STREAM_BUMP |
3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_COORD_SET |
3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             TEX_STREAM_COORD_SET(1) |
3286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(1));
3296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
3306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             MAP_UNIT(2) |
3316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             DISABLE_TEX_STREAM_BUMP |
3326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_COORD_SET |
3336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             TEX_STREAM_COORD_SET(2) |
3346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(2));
3356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
3366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             MAP_UNIT(3) |
3376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             DISABLE_TEX_STREAM_BUMP |
3386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_COORD_SET |
3396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             TEX_STREAM_COORD_SET(3) |
3406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(3));
3416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
3436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(0));
3446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
3456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(1));
3466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
3476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(2));
3486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
3496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(3));
3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_VERTEX_TRANSFORM);
3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(DISABLE_VIEWPORT_TRANSFORM | DISABLE_PERSPECTIVE_DIVIDE);
3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_W_STATE_CMD);
3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(MAGIC_W_STATE_DWORD1);
3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(0x3f800000 /* 1.0 in IEEE float */ );
3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(_3DSTATE_COLOR_FACTOR_CMD);
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   OUT_BATCH(0x80808080);       /* .5 required in alpha for GL_DOT3_RGBA_EXT */
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   ADVANCE_BATCH();
3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define emit( intel, state, size )			\
367c27285610c9f9b50d06bf0f2725da195937cb48dEric Anholt   intel_batchbuffer_data(intel->batch, state, size, false)
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint
3702af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzerget_dirty(struct i830_hw_state *state)
3712af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer{
3722af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   return state->active & ~state->emitted;
3732af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer}
3742af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer
3752af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzerstatic GLuint
3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellget_state_size(struct i830_hw_state *state)
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3782af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   GLuint dirty = get_dirty(state);
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint sz = 0;
3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint i;
3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_INVARIENT)
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz += 40 * sizeof(int);
3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
385de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt   if (dirty & I830_UPLOAD_RASTER_RULES)
386de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt      sz += sizeof(state->RasterRules);
387de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt
3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_CTX)
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz += sizeof(state->Ctx);
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_BUFFERS)
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz += sizeof(state->Buffer);
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_STIPPLE)
3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      sz += sizeof(state->Stipple);
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < I830_TEX_UNITS; i++) {
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if ((dirty & I830_UPLOAD_TEX(i)))
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         sz += sizeof(state->Tex[i]);
4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (dirty & I830_UPLOAD_TEXBLEND(i))
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         sz += state->TexBlendWordsUsed[i] * 4;
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return sz;
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Push the state into the sarea and/or texture memory.
4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4128517079cbcbbf31291b05420f3b776df712dfd47Eric Anholti830_emit_state(struct intel_context *intel)
4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(&intel->ctx);
415c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt   struct i830_hw_state *state = &i830->state;
416f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   int i, count;
4176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint dirty;
41834474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo *aper_array[3 + I830_TEX_UNITS];
419f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   int aper_count;
4206b9c1446b35cb33d73bd8ea7aeed8d219d0a9989Brian Paul   GET_CURRENT_CONTEXT(ctx);
4216b9c1446b35cb33d73bd8ea7aeed8d219d0a9989Brian Paul   BATCH_LOCALS;
4226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* We don't hold the lock at this point, so want to make sure that
4248517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt    * there won't be a buffer wrap between the state emits and the primitive
4258517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt    * emit header.
4266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    *
4276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * It might be better to talk about explicit places where
4286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * scheduling is allowed, rather than assume that it is whenever a
4296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * batchbuffer fills up.
4302af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer    */
431f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   intel_batchbuffer_require_space(intel->batch,
432c27285610c9f9b50d06bf0f2725da195937cb48dEric Anholt				   get_state_size(state) + INTEL_PRIM_EMIT_SIZE,
433c27285610c9f9b50d06bf0f2725da195937cb48dEric Anholt				   false);
43496338dd1470bb088cbbe50d629cd30175245a784Dave Airlie   count = 0;
43596338dd1470bb088cbbe50d629cd30175245a784Dave Airlie again:
436f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   aper_count = 0;
43796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie   dirty = get_dirty(state);
43896338dd1470bb088cbbe50d629cd30175245a784Dave Airlie
439f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   aper_array[aper_count++] = intel->batch->buf;
44096338dd1470bb088cbbe50d629cd30175245a784Dave Airlie   if (dirty & I830_UPLOAD_BUFFERS) {
441f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      aper_array[aper_count++] = state->draw_region->buffer;
442b4bf9acc32ac8693b1fdf80f351523a468ba6bd1Xiang, Haihao      if (state->depth_region)
443b4bf9acc32ac8693b1fdf80f351523a468ba6bd1Xiang, Haihao         aper_array[aper_count++] = state->depth_region->buffer;
44496338dd1470bb088cbbe50d629cd30175245a784Dave Airlie   }
445f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
44696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie   for (i = 0; i < I830_TEX_UNITS; i++)
44796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie     if (dirty & I830_UPLOAD_TEX(i)) {
44896338dd1470bb088cbbe50d629cd30175245a784Dave Airlie	if (state->tex_buffer[i]) {
449f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie	   aper_array[aper_count++] = state->tex_buffer[i];
45096338dd1470bb088cbbe50d629cd30175245a784Dave Airlie	}
45196338dd1470bb088cbbe50d629cd30175245a784Dave Airlie     }
45296338dd1470bb088cbbe50d629cd30175245a784Dave Airlie
453f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   if (dri_bufmgr_check_aperture_space(aper_array, aper_count)) {
45496338dd1470bb088cbbe50d629cd30175245a784Dave Airlie       if (count == 0) {
45596338dd1470bb088cbbe50d629cd30175245a784Dave Airlie	   count++;
45696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie	   intel_batchbuffer_flush(intel->batch);
45796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie	   goto again;
45896338dd1470bb088cbbe50d629cd30175245a784Dave Airlie       } else {
45996338dd1470bb088cbbe50d629cd30175245a784Dave Airlie	   _mesa_error(ctx, GL_OUT_OF_MEMORY, "i830 emit state");
46096338dd1470bb088cbbe50d629cd30175245a784Dave Airlie	   assert(0);
46196338dd1470bb088cbbe50d629cd30175245a784Dave Airlie       }
46296338dd1470bb088cbbe50d629cd30175245a784Dave Airlie   }
46396338dd1470bb088cbbe50d629cd30175245a784Dave Airlie
4642af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer
4656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Do this here as we may have flushed the batchbuffer above,
4666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * causing more state to be dirty!
4676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
4682af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   dirty = get_dirty(state);
4692af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   state->emitted |= dirty;
4702af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   assert(get_dirty(state) == 0);
4712af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer
4726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_INVARIENT) {
4736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      DBG("I830_UPLOAD_INVARIENT:\n");
4746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830_emit_invarient_state(intel);
4756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
477de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt   if (dirty & I830_UPLOAD_RASTER_RULES) {
478de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt      DBG("I830_UPLOAD_RASTER_RULES:\n");
479de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt      emit(intel, state->RasterRules, sizeof(state->RasterRules));
480de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt   }
481de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt
4826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_CTX) {
4836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      DBG("I830_UPLOAD_CTX:\n");
484a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt      emit(intel, state->Ctx, sizeof(state->Ctx));
4856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_BUFFERS) {
4892861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      GLuint count = 15;
490df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao
4916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      DBG("I830_UPLOAD_BUFFERS:\n");
492df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao
493df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao      if (state->depth_region)
494df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao          count += 3;
495df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao
4965203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg      BEGIN_BATCH(count);
4976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR0]);
4986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR1]);
4996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_RELOC(state->draw_region->buffer,
50041d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt		I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
5016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (state->depth_region) {
5036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR0]);
5046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR1]);
5056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_RELOC(state->depth_region->buffer,
50641d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt		   I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
5076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
5086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_DV0]);
5106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_DV1]);
5116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_SENABLE]);
5126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_SR0]);
5136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_SR1]);
5146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      OUT_BATCH(state->Buffer[I830_DESTREG_SR2]);
5150cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt
5162861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      assert(state->Buffer[I830_DESTREG_DRAWRECT0] != MI_NOOP);
5172861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT0]);
5182861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT1]);
5192861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT2]);
5202861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT3]);
5212861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT4]);
5222861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg      OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT5]);
5236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      ADVANCE_BATCH();
5246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
52550b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie
5266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (dirty & I830_UPLOAD_STIPPLE) {
5276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      DBG("I830_UPLOAD_STIPPLE:\n");
528a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt      emit(intel, state->Stipple, sizeof(state->Stipple));
5296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
5306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < I830_TEX_UNITS; i++) {
5326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if ((dirty & I830_UPLOAD_TEX(i))) {
5336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         DBG("I830_UPLOAD_TEX(%d):\n", i);
5346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5355203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg         BEGIN_BATCH(I830_TEX_SETUP_SIZE + 1);
5366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Tex[i][I830_TEXREG_TM0LI]);
5376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5385df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt	 OUT_RELOC(state->tex_buffer[i],
5395df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt		   I915_GEM_DOMAIN_SAMPLER, 0,
5405df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt		   state->tex_offset[i]);
5416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S1]);
5436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S2]);
5446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S3]);
5456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S4]);
5466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Tex[i][I830_TEXREG_MCS]);
5476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         OUT_BATCH(state->Tex[i][I830_TEXREG_CUBE]);
548df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao
549df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao         ADVANCE_BATCH();
5506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
5516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (dirty & I830_UPLOAD_TEXBLEND(i)) {
5536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         DBG("I830_UPLOAD_TEXBLEND(%d): %d words\n", i,
5546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell             state->TexBlendWordsUsed[i]);
555a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt         emit(intel, state->TexBlend[i], state->TexBlendWordsUsed[i] * 4);
5566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
5576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
5586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5592af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   intel->batch->dirty_state &= ~dirty;
5602af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   assert(get_dirty(state) == 0);
5612af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer   assert((intel->batch->dirty_state & (1<<1)) == 0);
5626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_destroy_context(struct intel_context *intel)
5666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
5672193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer   GLuint i;
5682193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer   struct i830_context *i830 = i830_context(&intel->ctx);
5692193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer
5707d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt   intel_region_release(&i830->state.draw_region);
5717d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt   intel_region_release(&i830->state.depth_region);
5727d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt
5732193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer   for (i = 0; i < I830_TEX_UNITS; i++) {
5742193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer      if (i830->state.tex_buffer[i] != NULL) {
57534474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt	 drm_intel_bo_unreference(i830->state.tex_buffer[i]);
5762193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer	 i830->state.tex_buffer[i] = NULL;
5772193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer      }
5782193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer   }
5792193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer
5806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _tnl_free_vertices(&intel->ctx);
5816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
583a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholtstatic uint32_t i830_render_target_format_for_mesa_format[MESA_FORMAT_COUNT] =
584a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt{
585a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   [MESA_FORMAT_ARGB8888] = DV_PF_8888,
586a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   [MESA_FORMAT_XRGB8888] = DV_PF_8888,
587a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   [MESA_FORMAT_RGB565] = DV_PF_565,
588a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   [MESA_FORMAT_ARGB1555] = DV_PF_1555,
589a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   [MESA_FORMAT_ARGB4444] = DV_PF_4444,
590a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt};
591a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt
592a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholtstatic bool
593a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholti830_render_target_supported(gl_format format)
594a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt{
595a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   if (format == MESA_FORMAT_S8_Z24 ||
596a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt       format == MESA_FORMAT_X8_Z24 ||
597a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt       format == MESA_FORMAT_Z16) {
598a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt      return true;
599a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   }
600a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt
601a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   return i830_render_target_format_for_mesa_format[format] != 0;
602a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt}
603a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt
604f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholtstatic void
605f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholti830_set_draw_region(struct intel_context *intel,
606f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt                     struct intel_region *color_regions[],
607f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt                     struct intel_region *depth_region,
608f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt		     GLuint num_regions)
6096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
6106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(&intel->ctx);
611f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
6122c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
6132c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
614d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   GLuint value;
615f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt   struct i830_hw_state *state = &i830->state;
61641d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   uint32_t draw_x, draw_y;
6176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
618f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt   if (state->draw_region != color_regions[0]) {
619d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie      intel_region_release(&state->draw_region);
620f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt      intel_region_reference(&state->draw_region, color_regions[0]);
621d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   }
622d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   if (state->depth_region != depth_region) {
623d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie      intel_region_release(&state->depth_region);
624d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie      intel_region_reference(&state->depth_region, depth_region);
625d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   }
626d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie
627d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   /*
628d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie    * Set stride/cpp values
629d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie    */
630165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   i915_set_buf_info_for_region(&state->Buffer[I830_DESTREG_CBUFADDR0],
631f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt				color_regions[0], BUF_3D_ID_COLOR_BACK);
632d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie
633165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   i915_set_buf_info_for_region(&state->Buffer[I830_DESTREG_DBUFADDR0],
634165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt				depth_region, BUF_3D_ID_DEPTH);
635d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie
636d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   /*
637d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie    * Compute/set I830_DESTREG_DV1 value
638d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie    */
639d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   value = (DSTORG_HORT_BIAS(0x8) |     /* .5 */
640d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie            DSTORG_VERT_BIAS(0x8) | DEPTH_IS_Z);    /* .5 */
6412c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt
6422c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt   if (irb != NULL) {
643a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt      value |= i830_render_target_format_for_mesa_format[irb->Base.Format];
644d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   }
6452c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt
646d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   if (depth_region && depth_region->cpp == 4) {
647d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie      value |= DEPTH_FRMT_24_FIXED_8_OTHER;
648d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   }
649d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   else {
650d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie      value |= DEPTH_FRMT_16_FIXED;
651d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   }
652d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie   state->Buffer[I830_DESTREG_DV1] = value;
6536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
65441d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   /* We set up the drawing rectangle to be offset into the color
65541d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    * region's location in the miptree.  If it doesn't match with
65641d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    * depth's offsets, we can't render to it.
65741d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    *
65841d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    * (Well, not actually true -- the hw grew a bit to let depth's
65941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    * offset get forced to 0,0.  We may want to use that if people are
66041d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    * hitting that case.  Also, some configurations may be supportable
66141d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    * by tweaking the start offset of the buffers around, which we
66241d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    * can't do in general due to tiling)
66341d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt    */
66441d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   FALLBACK(intel, I830_FALLBACK_DRAW_OFFSET,
66541d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt	    (depth_region && color_regions[0]) &&
66641d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt	    (depth_region->draw_x != color_regions[0]->draw_x ||
66741d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt	     depth_region->draw_y != color_regions[0]->draw_y));
66841d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt
66941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   if (color_regions[0]) {
67041d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      draw_x = color_regions[0]->draw_x;
67141d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      draw_y = color_regions[0]->draw_y;
67241d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   } else if (depth_region) {
67341d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      draw_x = depth_region->draw_x;
67441d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      draw_y = depth_region->draw_y;
67541d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   } else {
67641d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      draw_x = 0;
67741d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      draw_y = 0;
67841d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   }
67941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt
6802861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg   state->Buffer[I830_DESTREG_DRAWRECT0] = _3DSTATE_DRAWRECT_INFO;
6812861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg   state->Buffer[I830_DESTREG_DRAWRECT1] = 0;
68241d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   state->Buffer[I830_DESTREG_DRAWRECT2] = (draw_y << 16) | draw_x;
6832861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg   state->Buffer[I830_DESTREG_DRAWRECT3] =
68441d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      ((ctx->DrawBuffer->Width + draw_x) & 0xffff) |
68541d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt      ((ctx->DrawBuffer->Height + draw_y) << 16);
68641d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   state->Buffer[I830_DESTREG_DRAWRECT4] = (draw_y << 16) | draw_x;
68741d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt   state->Buffer[I830_DESTREG_DRAWRECT5] = MI_NOOP;
6880cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt
6896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_BUFFERS);
6906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
6916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* This isn't really handled at the moment.
6936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
6946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
6955f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholti830_new_batch(struct intel_context *intel)
6966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
6976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(&intel->ctx);
6986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.emitted = 0;
6996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
7006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
7026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_assert_not_dirty( struct intel_context *intel )
7036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
7046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(&intel->ctx);
705c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt   assert(!get_dirty(&i830->state));
7060f4984a0fb5a59efe8e3d954e9deb5ec83177e90Vinson Lee   (void) i830;
7076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
7086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
709de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholtstatic void
710de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholti830_invalidate_state(struct intel_context *intel, GLuint new_state)
711de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt{
712de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt   if (new_state & _NEW_LIGHT)
713de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt      i830_update_provoking_vertex(&intel->ctx);
714de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt}
715de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt
7166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
7176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830InitVtbl(struct i830_context *i830)
7186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
7196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.check_vertex_size = i830_check_vertex_size;
7206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.destroy = i830_destroy_context;
7216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.emit_state = i830_emit_state;
7225f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt   i830->intel.vtbl.new_batch = i830_new_batch;
7236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.reduced_primitive_state = i830_reduced_primitive_state;
7246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.set_draw_region = i830_set_draw_region;
7256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.update_texture_state = i830UpdateTextureState;
7266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.render_start = i830_render_start;
727a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger   i830->intel.vtbl.render_prevalidate = i830_render_prevalidate;
7286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.vtbl.assert_not_dirty = i830_assert_not_dirty;
729f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   i830->intel.vtbl.finish_batch = intel_finish_vb;
730de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt   i830->intel.vtbl.invalidate_state = i830_invalidate_state;
731a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt   i830->intel.vtbl.render_target_supported = i830_render_target_supported;
7326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
733