i830_vtbl.c revision f9995b30756140724f41daf963fa06167912be7f
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 ) \ 3675203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg intel_batchbuffer_data(intel->batch, state, size ) 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, 4325203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg get_state_size(state) + INTEL_PRIM_EMIT_SIZE); 43396338dd1470bb088cbbe50d629cd30175245a784Dave Airlie count = 0; 43496338dd1470bb088cbbe50d629cd30175245a784Dave Airlie again: 435f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_count = 0; 43696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie dirty = get_dirty(state); 43796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie 438f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_array[aper_count++] = intel->batch->buf; 43996338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (dirty & I830_UPLOAD_BUFFERS) { 440f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_array[aper_count++] = state->draw_region->buffer; 441b4bf9acc32ac8693b1fdf80f351523a468ba6bd1Xiang, Haihao if (state->depth_region) 442b4bf9acc32ac8693b1fdf80f351523a468ba6bd1Xiang, Haihao aper_array[aper_count++] = state->depth_region->buffer; 44396338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 444f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie 44596338dd1470bb088cbbe50d629cd30175245a784Dave Airlie for (i = 0; i < I830_TEX_UNITS; i++) 44696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (dirty & I830_UPLOAD_TEX(i)) { 44796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (state->tex_buffer[i]) { 448f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_array[aper_count++] = state->tex_buffer[i]; 44996338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 45096338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 45196338dd1470bb088cbbe50d629cd30175245a784Dave Airlie 452f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie if (dri_bufmgr_check_aperture_space(aper_array, aper_count)) { 45396338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (count == 0) { 45496338dd1470bb088cbbe50d629cd30175245a784Dave Airlie count++; 45596338dd1470bb088cbbe50d629cd30175245a784Dave Airlie intel_batchbuffer_flush(intel->batch); 45696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie goto again; 45796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } else { 45896338dd1470bb088cbbe50d629cd30175245a784Dave Airlie _mesa_error(ctx, GL_OUT_OF_MEMORY, "i830 emit state"); 45996338dd1470bb088cbbe50d629cd30175245a784Dave Airlie assert(0); 46096338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 46196338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 46296338dd1470bb088cbbe50d629cd30175245a784Dave Airlie 4632af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer 4646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Do this here as we may have flushed the batchbuffer above, 4656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * causing more state to be dirty! 4666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 4672af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer dirty = get_dirty(state); 4682af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer state->emitted |= dirty; 4692af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer assert(get_dirty(state) == 0); 4702af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer 4716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_INVARIENT) { 4726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_INVARIENT:\n"); 4736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830_emit_invarient_state(intel); 4746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 476de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt if (dirty & I830_UPLOAD_RASTER_RULES) { 477de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt DBG("I830_UPLOAD_RASTER_RULES:\n"); 478de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt emit(intel, state->RasterRules, sizeof(state->RasterRules)); 479de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt } 480de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt 4816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_CTX) { 4826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_CTX:\n"); 483a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt emit(intel, state->Ctx, sizeof(state->Ctx)); 4846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_BUFFERS) { 4882861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg GLuint count = 15; 489df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 4906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_BUFFERS:\n"); 491df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 492df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao if (state->depth_region) 493df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao count += 3; 494df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 4955203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(count); 4966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR0]); 4976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR1]); 4986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_RELOC(state->draw_region->buffer, 49941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); 5006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (state->depth_region) { 5026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR0]); 5036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR1]); 5046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_RELOC(state->depth_region->buffer, 50541d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); 5066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DV0]); 5096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DV1]); 5106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SENABLE]); 5116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SR0]); 5126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SR1]); 5136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SR2]); 5140cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt 5152861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg assert(state->Buffer[I830_DESTREG_DRAWRECT0] != MI_NOOP); 5162861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT0]); 5172861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT1]); 5182861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT2]); 5192861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT3]); 5202861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT4]); 5212861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT5]); 5226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ADVANCE_BATCH(); 5236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 52450b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie 5256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_STIPPLE) { 5266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_STIPPLE:\n"); 527a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt emit(intel, state->Stipple, sizeof(state->Stipple)); 5286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I830_TEX_UNITS; i++) { 5316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if ((dirty & I830_UPLOAD_TEX(i))) { 5326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_TEX(%d):\n", i); 5336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5345203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(I830_TEX_SETUP_SIZE + 1); 5356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0LI]); 5366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (state->tex_buffer[i]) { 5386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_RELOC(state->tex_buffer[i], 539f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie I915_GEM_DOMAIN_SAMPLER, 0, 540165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt state->tex_offset[i]); 5416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5429cde7fb61dd26cd98a26dcb0a54197e8d28ac3beMichel Dänzer else { 5439cde7fb61dd26cd98a26dcb0a54197e8d28ac3beMichel Dänzer OUT_BATCH(state->tex_offset[i]); 5449cde7fb61dd26cd98a26dcb0a54197e8d28ac3beMichel Dänzer } 5456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S1]); 5476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S2]); 5486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S3]); 5496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S4]); 5506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_MCS]); 5516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_CUBE]); 552df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 553df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao ADVANCE_BATCH(); 5546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_TEXBLEND(i)) { 5576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_TEXBLEND(%d): %d words\n", i, 5586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state->TexBlendWordsUsed[i]); 559a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt emit(intel, state->TexBlend[i], state->TexBlendWordsUsed[i] * 4); 5606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5632af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer intel->batch->dirty_state &= ~dirty; 5642af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer assert(get_dirty(state) == 0); 5652af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer assert((intel->batch->dirty_state & (1<<1)) == 0); 5666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 5676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 5696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_destroy_context(struct intel_context *intel) 5706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 5712193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer GLuint i; 5722193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer struct i830_context *i830 = i830_context(&intel->ctx); 5732193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer 5747d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt intel_region_release(&i830->state.draw_region); 5757d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt intel_region_release(&i830->state.depth_region); 5767d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt 5772193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer for (i = 0; i < I830_TEX_UNITS; i++) { 5782193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer if (i830->state.tex_buffer[i] != NULL) { 57934474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo_unreference(i830->state.tex_buffer[i]); 5802193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer i830->state.tex_buffer[i] = NULL; 5812193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer } 5822193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer } 5832193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer 5846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell _tnl_free_vertices(&intel->ctx); 5856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 5866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 587f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholtstatic void 588f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholti830_set_draw_region(struct intel_context *intel, 589f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct intel_region *color_regions[], 590f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct intel_region *depth_region, 591f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt GLuint num_regions) 5926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 5936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 594f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &intel->ctx; 5952c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; 5962c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt struct intel_renderbuffer *irb = intel_renderbuffer(rb); 597d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie GLuint value; 598f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct i830_hw_state *state = &i830->state; 59941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt uint32_t draw_x, draw_y; 6006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 601f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt if (state->draw_region != color_regions[0]) { 602d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie intel_region_release(&state->draw_region); 603f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt intel_region_reference(&state->draw_region, color_regions[0]); 604d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie } 605d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie if (state->depth_region != depth_region) { 606d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie intel_region_release(&state->depth_region); 607d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie intel_region_reference(&state->depth_region, depth_region); 608d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie } 609d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie 610d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie /* 611d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie * Set stride/cpp values 612d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie */ 613165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt i915_set_buf_info_for_region(&state->Buffer[I830_DESTREG_CBUFADDR0], 614f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt color_regions[0], BUF_3D_ID_COLOR_BACK); 615d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie 616165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt i915_set_buf_info_for_region(&state->Buffer[I830_DESTREG_DBUFADDR0], 617165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt depth_region, BUF_3D_ID_DEPTH); 618d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie 619d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie /* 620d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie * Compute/set I830_DESTREG_DV1 value 621d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie */ 622d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie value = (DSTORG_HORT_BIAS(0x8) | /* .5 */ 623d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie DSTORG_VERT_BIAS(0x8) | DEPTH_IS_Z); /* .5 */ 6242c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt 6252c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt if (irb != NULL) { 6263078bd136d6ee1d9ad16b4c834cad23b005304a4Ian Romanick switch (irb->Base.Format) { 6272c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt case MESA_FORMAT_ARGB8888: 6284a253431abf43a0638afb43605b44a8742b72a60Brian Paul case MESA_FORMAT_XRGB8888: 6292c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt value |= DV_PF_8888; 6302c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt break; 6312c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt case MESA_FORMAT_RGB565: 6322c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt value |= DV_PF_565; 6332c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt break; 6342c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt case MESA_FORMAT_ARGB1555: 6352c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt value |= DV_PF_1555; 6362c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt break; 6372c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt case MESA_FORMAT_ARGB4444: 6382c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt value |= DV_PF_4444; 6392c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt break; 6402c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt default: 6412c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt _mesa_problem(ctx, "Bad renderbuffer format: %d\n", 6423078bd136d6ee1d9ad16b4c834cad23b005304a4Ian Romanick irb->Base.Format); 6432c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt } 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; 7316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 732