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" 3187f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt#include "intel_mipmap_tree.h" 326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_regions.h" 33f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#include "intel_tris.h" 342c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt#include "intel_fbo.h" 35f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt#include "intel_buffers.h" 366cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt#include "tnl/tnl.h" 376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_context.h" 386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_vertex.h" 393541cc0d40f86d8ea63a876b7215831335ec677dEric Anholt#include "swrast_setup/swrast_setup.h" 40f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt#include "main/renderbuffer.h" 41f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt#include "main/framebuffer.h" 42c738ea1191cd1b5a0dc60b0e6d05fd918083e961Paul Berry#include "main/fbobject.h" 436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define FILE_DEBUG_FLAG DEBUG_STATE 456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 462e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkestatic bool i830_check_vertex_size(struct intel_context *intel, 472e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke GLuint expected); 486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define SZ_TO_HW(sz) ((sz-2)&0x3) 506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define EMIT_SZ(sz) (EMIT_1F + (sz) - 1) 516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define EMIT_ATTR( ATTR, STYLE, V0 ) \ 526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo { \ 536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attrs[intel->vertex_attr_count].attrib = (ATTR); \ 546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attrs[intel->vertex_attr_count].format = (STYLE); \ 556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attr_count++; \ 566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell v0 |= V0; \ 576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0) 586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define EMIT_PAD( N ) \ 606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo { \ 616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attrs[intel->vertex_attr_count].attrib = 0; \ 626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attrs[intel->vertex_attr_count].format = EMIT_PAD; \ 636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attrs[intel->vertex_attr_count].offset = (N); \ 646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attr_count++; \ 656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0) 666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VRTX_TEX_SET_FMT(n, x) ((x)<<((n)*2)) 696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TEXBIND_SET(n, x) ((x)<<((n)*4)) 706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 72a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheideggeri830_render_prevalidate(struct intel_context *intel) 73a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger{ 74a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger} 75a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger 76a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheideggerstatic void 776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_render_start(struct intel_context *intel) 786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 79f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &intel->ctx; 806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(ctx); 816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct vertex_buffer *VB = &tnl->vb; 83b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich GLbitfield64 index_bitset = tnl->render_inputs_bitset; 846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint v0 = _3DSTATE_VFT0_CMD; 856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint v2 = _3DSTATE_VFT1_CMD; 866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint mcsb1 = 0; 876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Important: 896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; 916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attr_count = 0; 926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* EMIT_ATTR's must be in order as they tell t_vertex.c how to 946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * build up a hardware vertex. 956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 96b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich if (index_bitset & BITFIELD64_RANGE(_TNL_ATTRIB_TEX0, _TNL_NUM_TEX)) { 976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VFT0_XYZW); 986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->coloroffset = 4; 996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else { 1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, VFT0_XYZ); 1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->coloroffset = 3; 1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 105b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_POINTSIZE)) { 1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_ATTR(_TNL_ATTRIB_POINTSIZE, EMIT_1F, VFT0_POINT_WIDTH); 1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_ATTR(_TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VFT0_DIFFUSE); 1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->specoffset = 0; 112b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich if (index_bitset & (BITFIELD64_BIT(_TNL_ATTRIB_COLOR1) | 113b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich BITFIELD64_BIT(_TNL_ATTRIB_FOG))) { 114b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_COLOR1)) { 1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->specoffset = intel->coloroffset + 1; 1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_ATTR(_TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VFT0_SPEC); 1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else 1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_PAD(3); 1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 121b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_FOG)) 1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_ATTR(_TNL_ATTRIB_FOG, EMIT_1UB_1F, VFT0_SPEC); 1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else 1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_PAD(1); 1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 127b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich if (index_bitset & BITFIELD64_RANGE(_TNL_ATTRIB_TEX0, _TNL_NUM_TEX)) { 1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int i, count = 0; 1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I830_TEX_UNITS; i++) { 131b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_TEX(i))) { 132df582ca767a38f185f9b4c449e7ed4266c414ae2Eric Anholt GLuint sz = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]->size; 1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint emit; 1346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint mcs = (i830->state.Tex[i][I830_TEXREG_MCS] & 1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ~TEXCOORDTYPE_MASK); 1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (sz) { 1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 1: 1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 2: 1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit = EMIT_2F; 1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 2; 1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mcs |= TEXCOORDTYPE_CARTESIAN; 1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 3: 1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit = EMIT_3F; 1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 3; 1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mcs |= TEXCOORDTYPE_VECTOR; 1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 4: 1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit = EMIT_3F_XYW; 1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 3; 1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mcs |= TEXCOORDTYPE_HOMOGENEOUS; 1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell continue; 1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell }; 1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell EMIT_ATTR(_TNL_ATTRIB_TEX0 + i, emit, 0); 1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell v2 |= VRTX_TEX_SET_FMT(count, SZ_TO_HW(sz)); 1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mcsb1 |= (count + 8) << (i * 4); 1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (mcs != i830->state.Tex[i][I830_TEXREG_MCS]) { 1646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I830_STATECHANGE(i830, I830_UPLOAD_TEX(i)); 1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.Tex[i][I830_TEXREG_MCS] = mcs; 1666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell count++; 1696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell v0 |= VFT0_TEX_COUNT(count); 1736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Only need to change the vertex emit code if there has been a 1766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * statechange to a new hardware vertex format: 1776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (v0 != i830->state.Ctx[I830_CTXREG_VF] || 1796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell v2 != i830->state.Ctx[I830_CTXREG_VF2] || 1806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mcsb1 != i830->state.Ctx[I830_CTXREG_MCSB1] || 181b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich index_bitset != i830->last_index_bitset) { 1826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int k; 1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I830_STATECHANGE(i830, I830_UPLOAD_CTX); 1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Must do this *after* statechange, so as not to affect 1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * buffered vertices reliant on the old state: 1886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_size = 1906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell _tnl_install_attrs(ctx, 1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attrs, 1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_attr_count, 1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->ViewportMatrix.m, 0); 1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel->vertex_size >>= 2; 1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.Ctx[I830_CTXREG_VF] = v0; 1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.Ctx[I830_CTXREG_VF2] = v2; 1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.Ctx[I830_CTXREG_MCSB1] = mcsb1; 200b49b1e46425b7ba475b9d78e418dd1fc177786d3Mathias Fröhlich i830->last_index_bitset = index_bitset; 2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell k = i830_check_vertex_size(intel, intel->vertex_size); 2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell assert(k); 2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_reduced_primitive_state(struct intel_context *intel, GLenum rprim) 2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint st1 = i830->state.Stipple[I830_STPREG_ST1]; 2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell st1 &= ~ST1_ENABLE; 2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (rprim) { 2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TRIANGLES: 2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple) 2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell st1 |= ST1_ENABLE; 2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_LINES: 2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_POINTS: 2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.reduced_primitive = rprim; 2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (st1 != i830->state.Stipple[I830_STPREG_ST1]) { 2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell INTEL_FIREVERTICES(intel); 2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I830_STATECHANGE(i830, I830_UPLOAD_STIPPLE); 2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.Stipple[I830_STPREG_ST1] = st1; 2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Pull apart the vertex format registers and figure out how large a 2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * vertex is supposed to be. 2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 2392e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkestatic bool 2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_check_vertex_size(struct intel_context *intel, GLuint expected) 2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 243c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt int vft0 = i830->state.Ctx[I830_CTXREG_VF]; 244c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt int vft1 = i830->state.Ctx[I830_CTXREG_VF2]; 2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int nrtex = (vft0 & VFT0_TEX_COUNT_MASK) >> VFT0_TEX_COUNT_SHIFT; 2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int i, sz = 0; 2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (vft0 & VFT0_XYZW_MASK) { 2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case VFT0_XY: 2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 2; 2516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case VFT0_XYZ: 2536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 3; 2546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case VFT0_XYW: 2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 3; 2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case VFT0_XYZW: 2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 4; 2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "no xyzw specified\n"); 2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return 0; 2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (vft0 & VFT0_SPEC) 2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (vft0 & VFT0_DIFFUSE) 2696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (vft0 & VFT0_DEPTH_OFFSET) 2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 2726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (vft0 & VFT0_POINT_WIDTH) 2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 2746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < nrtex; i++) { 2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (vft1 & VFT1_TEX0_MASK) { 2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_2D: 2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 2; 2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_3D: 2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 3; 2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_4D: 2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 4; 2856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_1D: 2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 1; 2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell vft1 >>= VFT1_TEX1_SHIFT; 2916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (sz != expected) 2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "vertex size mismatch %d/%d\n", sz, expected); 2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return sz == expected; 2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_emit_invarient_state(struct intel_context *intel) 3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell BATCH_LOCALS; 3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3045203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(29); 3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD); 3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD); 3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 3116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_DFLT_Z_CMD); 3136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 3146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_FOG_MODE_CMD); 3166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(FOGFUNC_ENABLE | 3176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell FOG_LINEAR_CONST | FOGSRC_INDEX_Z | ENABLE_FOG_DENSITY); 3186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 3196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 3206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | 3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell MAP_UNIT(0) | 3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DISABLE_TEX_STREAM_BUMP | 3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_COORD_SET | 3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEX_STREAM_COORD_SET(0) | 3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(0)); 3286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | 3296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell MAP_UNIT(1) | 3306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DISABLE_TEX_STREAM_BUMP | 3316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_COORD_SET | 3326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEX_STREAM_COORD_SET(1) | 3336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(1)); 3346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | 3356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell MAP_UNIT(2) | 3366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DISABLE_TEX_STREAM_BUMP | 3376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_COORD_SET | 3386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEX_STREAM_COORD_SET(2) | 3396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(2)); 3406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | 3416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell MAP_UNIT(3) | 3426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DISABLE_TEX_STREAM_BUMP | 3436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_COORD_SET | 3446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEX_STREAM_COORD_SET(3) | 3456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(3)); 3466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); 3486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(0)); 3496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); 3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(1)); 3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); 3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(2)); 3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM); 3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(3)); 3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_VERTEX_TRANSFORM); 3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(DISABLE_VIEWPORT_TRANSFORM | DISABLE_PERSPECTIVE_DIVIDE); 3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_W_STATE_CMD); 3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(MAGIC_W_STATE_DWORD1); 3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0x3f800000 /* 1.0 in IEEE float */ ); 3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_COLOR_FACTOR_CMD); 3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0x80808080); /* .5 required in alpha for GL_DOT3_RGBA_EXT */ 3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ADVANCE_BATCH(); 3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define emit( intel, state, size ) \ 3728d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson intel_batchbuffer_data(intel, state, size, false) 3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint 3752af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzerget_dirty(struct i830_hw_state *state) 3762af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer{ 3772af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer return state->active & ~state->emitted; 3782af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer} 3792af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer 3802af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzerstatic GLuint 3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellget_state_size(struct i830_hw_state *state) 3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 3832af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer GLuint dirty = get_dirty(state); 3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint sz = 0; 3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint i; 3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_INVARIENT) 3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 40 * sizeof(int); 3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 390de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt if (dirty & I830_UPLOAD_RASTER_RULES) 391de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt sz += sizeof(state->RasterRules); 392de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt 3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_CTX) 3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += sizeof(state->Ctx); 3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_BUFFERS) 3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += sizeof(state->Buffer); 3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_STIPPLE) 4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += sizeof(state->Stipple); 4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I830_TEX_UNITS; i++) { 4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if ((dirty & I830_UPLOAD_TEX(i))) 4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += sizeof(state->Tex[i]); 4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_TEXBLEND(i)) 4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += state->TexBlendWordsUsed[i] * 4; 4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return sz; 4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Push the state into the sarea and/or texture memory. 4156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 4166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 4178517079cbcbbf31291b05420f3b776df712dfd47Eric Anholti830_emit_state(struct intel_context *intel) 4186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 4196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 420c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt struct i830_hw_state *state = &i830->state; 421f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie int i, count; 4226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint dirty; 42334474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo *aper_array[3 + I830_TEX_UNITS]; 424f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie int aper_count; 4256b9c1446b35cb33d73bd8ea7aeed8d219d0a9989Brian Paul GET_CURRENT_CONTEXT(ctx); 4266b9c1446b35cb33d73bd8ea7aeed8d219d0a9989Brian Paul BATCH_LOCALS; 4276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* We don't hold the lock at this point, so want to make sure that 4298517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt * there won't be a buffer wrap between the state emits and the primitive 4308517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt * emit header. 4316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 4326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * It might be better to talk about explicit places where 4336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * scheduling is allowed, rather than assume that it is whenever a 4346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * batchbuffer fills up. 4352af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer */ 4368d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson intel_batchbuffer_require_space(intel, 437c27285610c9f9b50d06bf0f2725da195937cb48dEric Anholt get_state_size(state) + INTEL_PRIM_EMIT_SIZE, 438c27285610c9f9b50d06bf0f2725da195937cb48dEric Anholt false); 43996338dd1470bb088cbbe50d629cd30175245a784Dave Airlie count = 0; 44096338dd1470bb088cbbe50d629cd30175245a784Dave Airlie again: 441f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_count = 0; 44296338dd1470bb088cbbe50d629cd30175245a784Dave Airlie dirty = get_dirty(state); 44396338dd1470bb088cbbe50d629cd30175245a784Dave Airlie 4448d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson aper_array[aper_count++] = intel->batch.bo; 44596338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (dirty & I830_UPLOAD_BUFFERS) { 4468004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt aper_array[aper_count++] = state->draw_region->bo; 447b4bf9acc32ac8693b1fdf80f351523a468ba6bd1Xiang, Haihao if (state->depth_region) 4488004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt aper_array[aper_count++] = state->depth_region->bo; 44996338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 450f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie 45196338dd1470bb088cbbe50d629cd30175245a784Dave Airlie for (i = 0; i < I830_TEX_UNITS; i++) 45296338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (dirty & I830_UPLOAD_TEX(i)) { 45396338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (state->tex_buffer[i]) { 454f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_array[aper_count++] = state->tex_buffer[i]; 45596338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 45696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 45796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie 458f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie if (dri_bufmgr_check_aperture_space(aper_array, aper_count)) { 45996338dd1470bb088cbbe50d629cd30175245a784Dave Airlie if (count == 0) { 46096338dd1470bb088cbbe50d629cd30175245a784Dave Airlie count++; 4618d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson intel_batchbuffer_flush(intel); 46296338dd1470bb088cbbe50d629cd30175245a784Dave Airlie goto again; 46396338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } else { 46496338dd1470bb088cbbe50d629cd30175245a784Dave Airlie _mesa_error(ctx, GL_OUT_OF_MEMORY, "i830 emit state"); 46596338dd1470bb088cbbe50d629cd30175245a784Dave Airlie assert(0); 46696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 46796338dd1470bb088cbbe50d629cd30175245a784Dave Airlie } 46896338dd1470bb088cbbe50d629cd30175245a784Dave Airlie 4692af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer 4706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Do this here as we may have flushed the batchbuffer above, 4716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * causing more state to be dirty! 4726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 4732af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer dirty = get_dirty(state); 4742af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer state->emitted |= dirty; 4752af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer assert(get_dirty(state) == 0); 4762af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer 4776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_INVARIENT) { 4786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_INVARIENT:\n"); 4796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830_emit_invarient_state(intel); 4806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 482de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt if (dirty & I830_UPLOAD_RASTER_RULES) { 483de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt DBG("I830_UPLOAD_RASTER_RULES:\n"); 484de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt emit(intel, state->RasterRules, sizeof(state->RasterRules)); 485de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt } 486de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt 4876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_CTX) { 4886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_CTX:\n"); 489a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt emit(intel, state->Ctx, sizeof(state->Ctx)); 4906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_BUFFERS) { 4942861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg GLuint count = 15; 495df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 4966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_BUFFERS:\n"); 497df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 498df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao if (state->depth_region) 499df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao count += 3; 500df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 5015203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(count); 5026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR0]); 5036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_CBUFADDR1]); 5048004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt OUT_RELOC(state->draw_region->bo, 50541d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); 5066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (state->depth_region) { 5086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR0]); 5096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DBUFADDR1]); 5108004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt OUT_RELOC(state->depth_region->bo, 51141d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); 5126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DV0]); 5156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_DV1]); 5166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SENABLE]); 5176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SR0]); 5186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SR1]); 5196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I830_DESTREG_SR2]); 5200cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt 5212861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg assert(state->Buffer[I830_DESTREG_DRAWRECT0] != MI_NOOP); 5222861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT0]); 5232861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT1]); 5242861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT2]); 5252861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT3]); 5262861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT4]); 5272861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I830_DESTREG_DRAWRECT5]); 5286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ADVANCE_BATCH(); 5296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 53050b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie 5316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_STIPPLE) { 5326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_STIPPLE:\n"); 533a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt emit(intel, state->Stipple, sizeof(state->Stipple)); 5346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I830_TEX_UNITS; i++) { 5376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if ((dirty & I830_UPLOAD_TEX(i))) { 5386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_TEX(%d):\n", i); 5396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5405203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(I830_TEX_SETUP_SIZE + 1); 5416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0LI]); 5426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5435df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt OUT_RELOC(state->tex_buffer[i], 5445df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt I915_GEM_DOMAIN_SAMPLER, 0, 5455df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt state->tex_offset[i]); 5466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S1]); 5486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S2]); 5496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S3]); 5506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_TM0S4]); 5516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_MCS]); 5526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I830_TEXREG_CUBE]); 553df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 554df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao ADVANCE_BATCH(); 5556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I830_UPLOAD_TEXBLEND(i)) { 5586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DBG("I830_UPLOAD_TEXBLEND(%d): %d words\n", i, 5596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state->TexBlendWordsUsed[i]); 560a04b632350e5d0e9994fc667afc59407a39da0baEric Anholt emit(intel, state->TexBlend[i], state->TexBlendWordsUsed[i] * 4); 5616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5642af613e0b8e6f89cc7528ff5a969e18f077e61fcMichel Dänzer assert(get_dirty(state) == 0); 5656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 5666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 5686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_destroy_context(struct intel_context *intel) 5696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 5702193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer GLuint i; 5712193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer struct i830_context *i830 = i830_context(&intel->ctx); 5722193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer 5737d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt intel_region_release(&i830->state.draw_region); 5747d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt intel_region_release(&i830->state.depth_region); 5757d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt 5762193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer for (i = 0; i < I830_TEX_UNITS; i++) { 5772193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer if (i830->state.tex_buffer[i] != NULL) { 57834474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo_unreference(i830->state.tex_buffer[i]); 5792193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer i830->state.tex_buffer[i] = NULL; 5802193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer } 5812193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer } 5822193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer 5836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell _tnl_free_vertices(&intel->ctx); 5846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 5856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 586a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholtstatic uint32_t i830_render_target_format_for_mesa_format[MESA_FORMAT_COUNT] = 587a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt{ 588a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt [MESA_FORMAT_ARGB8888] = DV_PF_8888, 589a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt [MESA_FORMAT_XRGB8888] = DV_PF_8888, 590a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt [MESA_FORMAT_RGB565] = DV_PF_565, 591a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt [MESA_FORMAT_ARGB1555] = DV_PF_1555, 592a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt [MESA_FORMAT_ARGB4444] = DV_PF_4444, 593a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt}; 594a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt 595a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholtstatic bool 596796f44d77906342e5912e7da6bdba1ba86bab9f0Eric Anholti830_render_target_supported(struct intel_context *intel, 597796f44d77906342e5912e7da6bdba1ba86bab9f0Eric Anholt struct gl_renderbuffer *rb) 598a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt{ 599796f44d77906342e5912e7da6bdba1ba86bab9f0Eric Anholt gl_format format = rb->Format; 600796f44d77906342e5912e7da6bdba1ba86bab9f0Eric Anholt 601a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt if (format == MESA_FORMAT_S8_Z24 || 602a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt format == MESA_FORMAT_X8_Z24 || 603a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt format == MESA_FORMAT_Z16) { 604a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt return true; 605a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt } 606a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt 607a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt return i830_render_target_format_for_mesa_format[format] != 0; 608a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt} 609a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt 610f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholtstatic void 611f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholti830_set_draw_region(struct intel_context *intel, 612f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct intel_region *color_regions[], 613f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct intel_region *depth_region, 614f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt GLuint num_regions) 6156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 6166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 617f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &intel->ctx; 6182c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; 6192c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt struct intel_renderbuffer *irb = intel_renderbuffer(rb); 620b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt struct gl_renderbuffer *drb; 621b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt struct intel_renderbuffer *idrb = NULL; 622d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie GLuint value; 623f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct i830_hw_state *state = &i830->state; 62441d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt uint32_t draw_x, draw_y; 6256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 626f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt if (state->draw_region != color_regions[0]) { 627f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt intel_region_reference(&state->draw_region, color_regions[0]); 628d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie } 629d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie if (state->depth_region != depth_region) { 630d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie intel_region_reference(&state->depth_region, depth_region); 631d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie } 632d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie 633d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie /* 634d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie * Set stride/cpp values 635d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie */ 636165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt i915_set_buf_info_for_region(&state->Buffer[I830_DESTREG_CBUFADDR0], 637f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt color_regions[0], BUF_3D_ID_COLOR_BACK); 638d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie 639165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt i915_set_buf_info_for_region(&state->Buffer[I830_DESTREG_DBUFADDR0], 640165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt depth_region, BUF_3D_ID_DEPTH); 641d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie 642d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie /* 643d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie * Compute/set I830_DESTREG_DV1 value 644d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie */ 645d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie value = (DSTORG_HORT_BIAS(0x8) | /* .5 */ 646d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie DSTORG_VERT_BIAS(0x8) | DEPTH_IS_Z); /* .5 */ 6472c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt 6482c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt if (irb != NULL) { 649924de7dc96f4607cb3d833637b5f69f4b9e2a6d0Brian Paul value |= i830_render_target_format_for_mesa_format[intel_rb_format(irb)]; 650d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie } 6512c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt 652d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie if (depth_region && depth_region->cpp == 4) { 653d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie value |= DEPTH_FRMT_24_FIXED_8_OTHER; 654d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie } 655d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie else { 656d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie value |= DEPTH_FRMT_16_FIXED; 657d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie } 658d98e1f3761860ad453a9acb446efeee6af97f00aDave Airlie state->Buffer[I830_DESTREG_DV1] = value; 6596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 660b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt drb = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; 661b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt if (!drb) 662b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt drb = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; 663b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt 664b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt if (drb) 665b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt idrb = intel_renderbuffer(drb); 666b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt 66741d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt /* We set up the drawing rectangle to be offset into the color 66841d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * region's location in the miptree. If it doesn't match with 66941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * depth's offsets, we can't render to it. 67041d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * 67141d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * (Well, not actually true -- the hw grew a bit to let depth's 67241d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * offset get forced to 0,0. We may want to use that if people are 67341d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * hitting that case. Also, some configurations may be supportable 67441d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * by tweaking the start offset of the buffers around, which we 67541d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt * can't do in general due to tiling) 67641d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt */ 67741d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt FALLBACK(intel, I830_FALLBACK_DRAW_OFFSET, 678b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt idrb && irb && (idrb->draw_x != irb->draw_x || 679b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt idrb->draw_y != irb->draw_y)); 680b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt 681b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt if (irb) { 682b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_x = irb->draw_x; 683b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_y = irb->draw_y; 684b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt } else if (idrb) { 685b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_x = idrb->draw_x; 686b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_y = idrb->draw_y; 68741d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt } else { 68841d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt draw_x = 0; 68941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt draw_y = 0; 69041d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt } 69141d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt 6922861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg state->Buffer[I830_DESTREG_DRAWRECT0] = _3DSTATE_DRAWRECT_INFO; 6932861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg state->Buffer[I830_DESTREG_DRAWRECT1] = 0; 69441d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt state->Buffer[I830_DESTREG_DRAWRECT2] = (draw_y << 16) | draw_x; 6952861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg state->Buffer[I830_DESTREG_DRAWRECT3] = 6967d13a6e64bf88566875a8f68e0aac9b937e30febAlban Browaeys ((ctx->DrawBuffer->Width + draw_x - 1) & 0xffff) | 6977d13a6e64bf88566875a8f68e0aac9b937e30febAlban Browaeys ((ctx->DrawBuffer->Height + draw_y - 1) << 16); 69841d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt state->Buffer[I830_DESTREG_DRAWRECT4] = (draw_y << 16) | draw_x; 69941d3fdc380655b701fab2537bdc7e254b6155286Eric Anholt state->Buffer[I830_DESTREG_DRAWRECT5] = MI_NOOP; 7000cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt 7016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I830_STATECHANGE(i830, I830_UPLOAD_BUFFERS); 7026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 7036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 704f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt/** 705f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Update the hardware state for drawing into a window or framebuffer object. 706f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * 707f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Called by glDrawBuffer, glBindFramebufferEXT, MakeCurrent, and other 708f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * places within the driver. 709f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * 710f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Basically, this needs to be called any time the current framebuffer 711f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * changes, the renderbuffers change, or we need to draw into different 712f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * color buffers. 713f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 714f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholtstatic void 715f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholti830_update_draw_buffer(struct intel_context *intel) 716f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt{ 717f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct gl_context *ctx = &intel->ctx; 718f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct gl_framebuffer *fb = ctx->DrawBuffer; 719f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct intel_region *colorRegions[MAX_DRAW_BUFFERS], *depthRegion = NULL; 720f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct intel_renderbuffer *irbDepth = NULL, *irbStencil = NULL; 721f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 722f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (!fb) { 723f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this can happen during the initial context initialization */ 724f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt return; 725f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 726f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 727f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt irbDepth = intel_get_renderbuffer(fb, BUFFER_DEPTH); 728f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt irbStencil = intel_get_renderbuffer(fb, BUFFER_STENCIL); 729f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 730f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Do this here, not core Mesa, since this function is called from 731f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * many places within the driver. 732f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 733f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (ctx->NewState & _NEW_BUFFERS) { 734f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this updates the DrawBuffer->_NumColorDrawBuffers fields, etc */ 735f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt _mesa_update_framebuffer(ctx); 736f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this updates the DrawBuffer's Width/Height if it's a FBO */ 737f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt _mesa_update_draw_buffer_bounds(ctx); 738f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 739f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 740f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 741f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this may occur when we're called by glBindFrameBuffer() during 742f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * the process of someone setting up renderbuffers, etc. 743f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 744f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /*_mesa_debug(ctx, "DrawBuffer: incomplete user FBO\n");*/ 745f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt return; 746f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 747f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 748f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* How many color buffers are we drawing into? 749f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * 750f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * If there are zero buffers or the buffer is too big, don't configure any 751f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * regions for hardware drawing. We'll fallback to software below. Not 752f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * having regions set makes some of the software fallback paths faster. 753f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 754f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if ((fb->Width > ctx->Const.MaxRenderbufferSize) 755f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt || (fb->Height > ctx->Const.MaxRenderbufferSize) 756f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt || (fb->_NumColorDrawBuffers == 0)) { 757f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* writing to 0 */ 758f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt colorRegions[0] = NULL; 759f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 760f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt else if (fb->_NumColorDrawBuffers > 1) { 761f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt int i; 762f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct intel_renderbuffer *irb; 763f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 764f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt for (i = 0; i < fb->_NumColorDrawBuffers; i++) { 765f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt irb = intel_renderbuffer(fb->_ColorDrawBuffers[i]); 76687f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt colorRegions[i] = (irb && irb->mt) ? irb->mt->region : NULL; 767f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 768f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 769f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt else { 770f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Get the intel_renderbuffer for the single colorbuffer we're drawing 771f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * into. 772f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 773c738ea1191cd1b5a0dc60b0e6d05fd918083e961Paul Berry if (_mesa_is_winsys_fbo(fb)) { 774f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* drawing to window system buffer */ 775f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) 776f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt colorRegions[0] = intel_get_rb_region(fb, BUFFER_FRONT_LEFT); 777f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt else 778f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt colorRegions[0] = intel_get_rb_region(fb, BUFFER_BACK_LEFT); 779f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 780f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt else { 781f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* drawing to user-created FBO */ 782f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct intel_renderbuffer *irb; 783f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt irb = intel_renderbuffer(fb->_ColorDrawBuffers[0]); 78487f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt colorRegions[0] = (irb && irb->mt->region) ? irb->mt->region : NULL; 785f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 786f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 787f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 788f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (!colorRegions[0]) { 7892e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, true); 790f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 791f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt else { 7922e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, false); 793f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 794f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 795f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Check for depth fallback. */ 79687f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt if (irbDepth && irbDepth->mt) { 7972e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, false); 79887f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt depthRegion = irbDepth->mt->region; 79987f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt } else if (irbDepth && !irbDepth->mt) { 8002e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, true); 801f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt depthRegion = NULL; 802f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } else { /* !irbDepth */ 803f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* No fallback is needed because there is no depth buffer. */ 8042e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, false); 805f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt depthRegion = NULL; 806f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 807f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 808f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Check for stencil fallback. */ 80987f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt if (irbStencil && irbStencil->mt) { 810924de7dc96f4607cb3d833637b5f69f4b9e2a6d0Brian Paul assert(intel_rb_format(irbStencil) == MESA_FORMAT_S8_Z24); 8112e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false); 81287f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt } else if (irbStencil && !irbStencil->mt) { 8132e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, true); 814f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } else { /* !irbStencil */ 815f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* No fallback is needed because there is no stencil buffer. */ 8162e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false); 817f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 818f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 819f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* If we have a (packed) stencil buffer attached but no depth buffer, 820f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * we still need to set up the shared depth/stencil state so we can use it. 821f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 82287f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt if (depthRegion == NULL && irbStencil && irbStencil->mt 823924de7dc96f4607cb3d833637b5f69f4b9e2a6d0Brian Paul && intel_rb_format(irbStencil) == MESA_FORMAT_S8_Z24) { 82487f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt depthRegion = irbStencil->mt->region; 825f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 826f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 827f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* 828f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Update depth and stencil test state 829f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 8304d4f2daefabdc4ca1dd778a9265475c65ef52936Eric Anholt ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test); 8314c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt ctx->Driver.Enable(ctx, GL_STENCIL_TEST, 8324c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt (ctx->Stencil.Enabled && fb->Visual.stencilBits > 0)); 833f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 834f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt intel->vtbl.set_draw_region(intel, colorRegions, depthRegion, 835f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt fb->_NumColorDrawBuffers); 836f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt intel->NewGLState |= _NEW_BUFFERS; 837f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 838f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* update viewport since it depends on window size */ 839f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt intelCalcViewport(ctx); 8404c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt 841f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Set state we know depends on drawable parameters: 842f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 8434c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y, 8444c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt ctx->Scissor.Width, ctx->Scissor.Height); 845f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 8464c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt ctx->Driver.DepthRange(ctx, ctx->Viewport.Near, ctx->Viewport.Far); 847f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 848f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Update culling direction which changes depending on the 849f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * orientation of the buffer: 850f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 8514c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace); 852f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt} 853f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 8546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* This isn't really handled at the moment. 8556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 8566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 8575f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholti830_new_batch(struct intel_context *intel) 8586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 8596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 8606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.emitted = 0; 8616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 8626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 8636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 8646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_assert_not_dirty( struct intel_context *intel ) 8656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 8666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 867c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt assert(!get_dirty(&i830->state)); 8680f4984a0fb5a59efe8e3d954e9deb5ec83177e90Vinson Lee (void) i830; 8696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 8706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 871de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholtstatic void 872de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholti830_invalidate_state(struct intel_context *intel, GLuint new_state) 873de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt{ 8746cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt struct gl_context *ctx = &intel->ctx; 8756cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt 8763541cc0d40f86d8ea63a876b7215831335ec677dEric Anholt _swsetup_InvalidateState(ctx, new_state); 8776cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt _tnl_InvalidateState(ctx, new_state); 8786cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt _tnl_invalidate_vertex_state(ctx, new_state); 8796cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt 880de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt if (new_state & _NEW_LIGHT) 881de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt i830_update_provoking_vertex(&intel->ctx); 882de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt} 883de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt 88409eeb0ff27005c0ffccd5cdbe46862e181a4ee6cCarl Simonsonstatic bool 88509eeb0ff27005c0ffccd5cdbe46862e181a4ee6cCarl Simonsoni830_is_hiz_depth_format(struct intel_context *intel, gl_format format) 88609eeb0ff27005c0ffccd5cdbe46862e181a4ee6cCarl Simonson{ 88709eeb0ff27005c0ffccd5cdbe46862e181a4ee6cCarl Simonson return false; 88809eeb0ff27005c0ffccd5cdbe46862e181a4ee6cCarl Simonson} 88909eeb0ff27005c0ffccd5cdbe46862e181a4ee6cCarl Simonson 8907b0f748efa5af84668cc3609a0070163bfa22607Chad Versacevoid 8916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830InitVtbl(struct i830_context *i830) 8926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 8936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.check_vertex_size = i830_check_vertex_size; 8946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.destroy = i830_destroy_context; 8956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.emit_state = i830_emit_state; 8965f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt i830->intel.vtbl.new_batch = i830_new_batch; 8976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.reduced_primitive_state = i830_reduced_primitive_state; 8986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.set_draw_region = i830_set_draw_region; 899f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt i830->intel.vtbl.update_draw_buffer = i830_update_draw_buffer; 9006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.update_texture_state = i830UpdateTextureState; 9016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.render_start = i830_render_start; 902a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger i830->intel.vtbl.render_prevalidate = i830_render_prevalidate; 9036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->intel.vtbl.assert_not_dirty = i830_assert_not_dirty; 904f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie i830->intel.vtbl.finish_batch = intel_finish_vb; 905de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt i830->intel.vtbl.invalidate_state = i830_invalidate_state; 906a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt i830->intel.vtbl.render_target_supported = i830_render_target_supported; 90709eeb0ff27005c0ffccd5cdbe46862e181a4ee6cCarl Simonson i830->intel.vtbl.is_hiz_depth_format = i830_is_hiz_depth_format; 9086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 909