16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/************************************************************************** 26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2003 VMware, Inc. 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. 21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE 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 296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 30ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/glheader.h" 31ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/mtypes.h" 32ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/imports.h" 33ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/macros.h" 34f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt#include "main/renderbuffer.h" 35f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt#include "main/framebuffer.h" 366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 376cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt#include "tnl/tnl.h" 386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_context.h" 396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_vertex.h" 403541cc0d40f86d8ea63a876b7215831335ec677dEric Anholt#include "swrast_setup/swrast_setup.h" 416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_batchbuffer.h" 4387f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt#include "intel_mipmap_tree.h" 446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_regions.h" 45f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#include "intel_tris.h" 462c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt#include "intel_fbo.h" 47f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt#include "intel_buffers.h" 486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_reg.h" 506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_context.h" 516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 53a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheideggeri915_render_prevalidate(struct intel_context *intel) 546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i915_context *i915 = i915_context(&intel->ctx); 566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 57d6fbf87575a59e24c5d47b8b6b8700ee4583709bEric Anholt i915ValidateFragmentProgram(i915); 586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 60a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheideggerstatic void 61a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheideggeri915_render_start(struct intel_context *intel) 62a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger{ 630032525242950bae197b267794193cdcb611c376Jesse Barnes intel_prepare_render(intel); 64a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger} 65a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger 666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_reduced_primitive_state(struct intel_context *intel, GLenum rprim) 696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i915_context *i915 = i915_context(&intel->ctx); 716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint st1 = i915->state.Stipple[I915_STPREG_ST1]; 726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell st1 &= ~ST1_ENABLE; 746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (rprim) { 760bf2479aef5def4d01bfc55b08992f41664f1431Brian Paul case GL_QUADS: /* from RASTERIZE(GL_QUADS) in t_dd_tritemp.h */ 776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TRIANGLES: 786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple) 796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell st1 |= ST1_ENABLE; 806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_LINES: 826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_POINTS: 836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.reduced_primitive = rprim; 886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (st1 != i915->state.Stipple[I915_STPREG_ST1]) { 906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell INTEL_FIREVERTICES(intel); 916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); 936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->state.Stipple[I915_STPREG_ST1] = st1; 946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Pull apart the vertex format registers and figure out how large a 996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * vertex is supposed to be. 1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1012e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkestatic bool 1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_check_vertex_size(struct intel_context *intel, GLuint expected) 1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i915_context *i915 = i915_context(&intel->ctx); 105c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt int lis2 = i915->state.Ctx[I915_CTXREG_LIS2]; 106c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt int lis4 = i915->state.Ctx[I915_CTXREG_LIS4]; 1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int i, sz = 0; 1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (lis4 & S4_VFMT_XYZW_MASK) { 1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case S4_VFMT_XY: 1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 2; 1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case S4_VFMT_XYZ: 1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 3; 1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case S4_VFMT_XYW: 1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 3; 1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case S4_VFMT_XYZW: 1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz = 4; 1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "no xyzw specified\n"); 1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return 0; 1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (lis4 & S4_VFMT_SPEC_FOG) 1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (lis4 & S4_VFMT_COLOR) 1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (lis4 & S4_VFMT_DEPTH_OFFSET) 1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (lis4 & S4_VFMT_POINT_WIDTH) 1346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (lis4 & S4_VFMT_FOG_PARAM) 1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz++; 1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < 8; i++) { 1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (lis2 & S2_TEXCOORD_FMT0_MASK) { 1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_2D: 1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 2; 1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_3D: 1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 3; 1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_4D: 1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 4; 1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_1D: 1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 1; 1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_2D_16: 1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 1; 1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_4D_16: 1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += 2; 1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXCOORDFMT_NOT_PRESENT: 1596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "bad texcoord fmt %d\n", i); 1622e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return false; 1636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell lis2 >>= S2_TEXCOORD_FMT1_SHIFT; 1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (sz != expected) 1686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "vertex size mismatch %d/%d\n", sz, expected); 1696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return sz == expected; 1716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 1726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 1756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_emit_invarient_state(struct intel_context *intel) 1766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 1776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell BATCH_LOCALS; 1786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1795203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(17); 1806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_AA_CMD | 1826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell AA_LINE_ECAAR_WIDTH_ENABLE | 1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell AA_LINE_ECAAR_WIDTH_1_0 | 1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell AA_LINE_REGION_WIDTH_ENABLE | AA_LINE_REGION_WIDTH_1_0); 1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD); 1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 1886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD); 1906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_DFLT_Z_CMD); 1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Don't support texture crossbar yet */ 1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_COORD_SET_BINDINGS | 1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CSB_TCB(0, 0) | 1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CSB_TCB(1, 1) | 1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CSB_TCB(2, 2) | 2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CSB_TCB(3, 3) | 2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CSB_TCB(4, 4) | CSB_TCB(5, 5) | CSB_TCB(6, 6) | CSB_TCB(7, 7)); 2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Need to initialize this to zero. 2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 2054a789e408dbba7891f1436b2f42e7c0824e5ba7aKeith Whitwell OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | (0)); 2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_SCISSOR_RECT_0_CMD); 2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2120d924738d9d86a19b9bffa01ba9f29f2f697bb27Ville Syrjälä /* XXX: Use this */ 2130d924738d9d86a19b9bffa01ba9f29f2f697bb27Ville Syrjälä OUT_BATCH(_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT); 2140d924738d9d86a19b9bffa01ba9f29f2f697bb27Ville Syrjälä 2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_DEPTH_SUBRECT_DISABLE); 2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_LOAD_INDIRECT | 0); /* disable indirect state */ 2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(0); 2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ADVANCE_BATCH(); 2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define emit(intel, state, size ) \ 225f6426509dcbe6ff1332f30f74d9cf2ec3c00908fEric Anholt intel_batchbuffer_data(intel, state, size) 2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint 2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellget_dirty(struct i915_hw_state *state) 2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint dirty; 2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Workaround the multitex hang - if one texture unit state is 2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * modified, emit all texture units. 2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell dirty = state->active & ~state->emitted; 2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_TEX_ALL) 2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state->emitted &= ~I915_UPLOAD_TEX_ALL; 2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell dirty = state->active & ~state->emitted; 2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return dirty; 2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint 2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellget_state_size(struct i915_hw_state *state) 2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint dirty = get_dirty(state); 2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint i; 2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint sz = 0; 2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2504a789e408dbba7891f1436b2f42e7c0824e5ba7aKeith Whitwell if (dirty & I915_UPLOAD_INVARIENT) 2514a789e408dbba7891f1436b2f42e7c0824e5ba7aKeith Whitwell sz += 30 * 4; 2524a789e408dbba7891f1436b2f42e7c0824e5ba7aKeith Whitwell 253de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt if (dirty & I915_UPLOAD_RASTER_RULES) 254de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt sz += sizeof(state->RasterRules); 255de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt 2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_CTX) 2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += sizeof(state->Ctx); 2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2597c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson if (dirty & I915_UPLOAD_BLEND) 2607c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson sz += sizeof(state->Blend); 2617c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson 2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_BUFFERS) 2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += sizeof(state->Buffer); 2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_STIPPLE) 2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += sizeof(state->Stipple); 2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_TEX_ALL) { 2696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int nr = 0; 2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I915_TEX_UNITS; i++) 2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_TEX(i)) 2726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell nr++; 2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += (2 + nr * 3) * sizeof(GLuint) * 2; 2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_CONSTANTS) 2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += state->ConstantSize * sizeof(GLuint); 2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_PROGRAM) 2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell sz += state->ProgramSize * sizeof(GLuint); 2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return sz; 2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 2856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Push the state into the sarea and/or texture memory. 2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 2898517079cbcbbf31291b05420f3b776df712dfd47Eric Anholti915_emit_state(struct intel_context *intel) 2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 2916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i915_context *i915 = i915_context(&intel->ctx); 292c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt struct i915_hw_state *state = &i915->state; 293f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie int i, count, aper_count; 2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint dirty; 29534474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo *aper_array[3 + I915_TEX_UNITS]; 29696338dd1470bb088cbbe50d629cd30175245a784Dave Airlie GET_CURRENT_CONTEXT(ctx); 2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell BATCH_LOCALS; 2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* We don't hold the lock at this point, so want to make sure that 3008517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt * there won't be a buffer wrap between the state emits and the primitive 3018517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt * emit header. 3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * It might be better to talk about explicit places where 3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * scheduling is allowed, rather than assume that it is whenever a 3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * batchbuffer fills up. 306a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell */ 3078d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson intel_batchbuffer_require_space(intel, 308f6426509dcbe6ff1332f30f74d9cf2ec3c00908fEric Anholt get_state_size(state) + 309f6426509dcbe6ff1332f30f74d9cf2ec3c00908fEric Anholt INTEL_PRIM_EMIT_SIZE); 3107cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie count = 0; 3117cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie again: 312b094dff50a05e56f5415d31daa5e4542f321c858Chris Wilson if (intel->batch.bo == NULL) { 313b094dff50a05e56f5415d31daa5e4542f321c858Chris Wilson _mesa_error(ctx, GL_OUT_OF_MEMORY, "i915 emit state"); 314b094dff50a05e56f5415d31daa5e4542f321c858Chris Wilson assert(0); 315b094dff50a05e56f5415d31daa5e4542f321c858Chris Wilson } 316f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_count = 0; 3177cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie dirty = get_dirty(state); 3187cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie 3198d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson aper_array[aper_count++] = intel->batch.bo; 3207cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie if (dirty & I915_UPLOAD_BUFFERS) { 321af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt if (state->draw_region) 3228004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt aper_array[aper_count++] = state->draw_region->bo; 323f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie if (state->depth_region) 3248004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt aper_array[aper_count++] = state->depth_region->bo; 3257cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie } 3267cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie 3277cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie if (dirty & I915_UPLOAD_TEX_ALL) { 328f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie for (i = 0; i < I915_TEX_UNITS; i++) { 329f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie if (dirty & I915_UPLOAD_TEX(i)) { 330f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie if (state->tex_buffer[i]) { 331f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie aper_array[aper_count++] = state->tex_buffer[i]; 332f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie } 333f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie } 334f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie } 3357cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie } 336f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie 337f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie if (dri_bufmgr_check_aperture_space(aper_array, aper_count)) { 3387cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie if (count == 0) { 3397cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie count++; 3408d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson intel_batchbuffer_flush(intel); 3417cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie goto again; 3427cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie } else { 3437cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie _mesa_error(ctx, GL_OUT_OF_MEMORY, "i915 emit state"); 3447cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie assert(0); 3457cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie } 3467cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie } 347a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell 3487cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie /* work out list of buffers to emit */ 3497cc7ff7051d427ff45b4d7d3664e2eecd13d0e13Dave Airlie 3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Do this here as we may have flushed the batchbuffer above, 3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * causing more state to be dirty! 3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell dirty = get_dirty(state); 3544a789e408dbba7891f1436b2f42e7c0824e5ba7aKeith Whitwell state->emitted |= dirty; 355a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell assert(get_dirty(state) == 0); 356a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell 3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (INTEL_DEBUG & DEBUG_STATE) 358139e6c7c4a9c59be5f4b3f431ac393cc097326acMarius Predut fprintf(stderr, "%s dirty: %x\n", __func__, dirty); 3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_INVARIENT) { 3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (INTEL_DEBUG & DEBUG_STATE) 3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "I915_UPLOAD_INVARIENT:\n"); 3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915_emit_invarient_state(intel); 3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 366de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt if (dirty & I915_UPLOAD_RASTER_RULES) { 367de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt if (INTEL_DEBUG & DEBUG_STATE) 368de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt fprintf(stderr, "I915_UPLOAD_RASTER_RULES:\n"); 369de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt emit(intel, state->RasterRules, sizeof(state->RasterRules)); 370de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt } 371de80eeea0eebf00ee678b1a0fbd5fe67b00a8636Eric Anholt 3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_CTX) { 3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (INTEL_DEBUG & DEBUG_STATE) 3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "I915_UPLOAD_CTX:\n"); 3757a9c7c1133d5cf17d032c8568e8f040a7c171a72Brian Paul 3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit(intel, state->Ctx, sizeof(state->Ctx)); 3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3797c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson if (dirty & I915_UPLOAD_BLEND) { 3807c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson if (INTEL_DEBUG & DEBUG_STATE) 3817c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson fprintf(stderr, "I915_UPLOAD_BLEND:\n"); 3827c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson 3837c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson emit(intel, state->Blend, sizeof(state->Blend)); 3847c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson } 3857c97e288fb6a105ea60c377aef4472cc33ca01bcChris Wilson 3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_BUFFERS) { 3876d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson GLuint count; 388df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (INTEL_DEBUG & DEBUG_STATE) 3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "I915_UPLOAD_BUFFERS:\n"); 391df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 392af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt count = 17; 3936d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson if (state->Buffer[I915_DESTREG_DRAWRECT0] != MI_NOOP) 3946d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson count++; 395df73363ed1aa34cc0dc5feefb3933309591fa015Xiang, Haihao 3965203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(count); 3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I915_DESTREG_CBUFADDR0]); 3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I915_DESTREG_CBUFADDR1]); 399af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt if (state->draw_region) { 4008004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt OUT_RELOC(state->draw_region->bo, 401af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); 402af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } else { 403af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt OUT_BATCH(0); 404af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } 4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 406af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt OUT_BATCH(state->Buffer[I915_DESTREG_DBUFADDR0]); 407af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt OUT_BATCH(state->Buffer[I915_DESTREG_DBUFADDR1]); 4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (state->depth_region) { 4098004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt OUT_RELOC(state->depth_region->bo, 410b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); 411af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } else { 412af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt OUT_BATCH(0); 4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I915_DESTREG_DV0]); 4166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I915_DESTREG_DV1]); 4176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I915_DESTREG_SR0]); 4186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I915_DESTREG_SR1]); 4196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Buffer[I915_DESTREG_SR2]); 4200d924738d9d86a19b9bffa01ba9f29f2f697bb27Ville Syrjälä OUT_BATCH(state->Buffer[I915_DESTREG_SENABLE]); 4210cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt 4226d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson if (state->Buffer[I915_DESTREG_DRAWRECT0] != MI_NOOP) 4236d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT0]); 4242861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT1]); 4252861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT2]); 4262861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT3]); 4272861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT4]); 4282861d9200be15cc44e8825387d3bd79086523c67Kristian Høgsberg OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT5]); 4290cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt 4306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ADVANCE_BATCH(); 4316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_STIPPLE) { 4346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (INTEL_DEBUG & DEBUG_STATE) 4356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "I915_UPLOAD_STIPPLE:\n"); 4366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit(intel, state->Stipple, sizeof(state->Stipple)); 4376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Combine all the dirty texture state into a single command to 4406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * avoid lockups on I915 hardware. 4416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 4426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_TEX_ALL) { 4436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int nr = 0; 4440b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson GLuint unwind; 4456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I915_TEX_UNITS; i++) 4476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_TEX(i)) 4486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell nr++; 4496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4505203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(2 + nr * 3); 4516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_MAP_STATE | (3 * nr)); 4526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH((dirty & I915_UPLOAD_TEX_ALL) >> I915_UPLOAD_TEX_0_SHIFT); 4536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I915_TEX_UNITS; i++) 4546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_TEX(i)) { 4555df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt OUT_RELOC(state->tex_buffer[i], 4565df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt I915_GEM_DOMAIN_SAMPLER, 0, 4575df51c2bb00871b338ec8455bd4ce5feea163f63Eric Anholt state->tex_offset[i]); 4586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I915_TEXREG_MS3]); 4606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I915_TEXREG_MS4]); 4616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ADVANCE_BATCH(); 4636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4640b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson unwind = intel->batch.used; 4655203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg BEGIN_BATCH(2 + nr * 3); 4666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(_3DSTATE_SAMPLER_STATE | (3 * nr)); 4676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH((dirty & I915_UPLOAD_TEX_ALL) >> I915_UPLOAD_TEX_0_SHIFT); 4686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I915_TEX_UNITS; i++) 4696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_TEX(i)) { 4706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I915_TEXREG_SS2]); 4716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I915_TEXREG_SS3]); 4726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell OUT_BATCH(state->Tex[i][I915_TEXREG_SS4]); 4736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ADVANCE_BATCH(); 4750b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson if (i915->last_sampler && 4760b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson memcmp(intel->batch.map + i915->last_sampler, 4770b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson intel->batch.map + unwind, 4780b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson (2 + nr*3)*sizeof(int)) == 0) 4790b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson intel->batch.used = unwind; 4800b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson else 4810b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson i915->last_sampler = unwind; 4826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_CONSTANTS) { 4856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (INTEL_DEBUG & DEBUG_STATE) 4866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "I915_UPLOAD_CONSTANTS:\n"); 4876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit(intel, state->Constant, state->ConstantSize * sizeof(GLuint)); 4886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (dirty & I915_UPLOAD_PROGRAM) { 491e2ca788ae700aae75bf8d024c1374c38cc5574f9Xiang, Haihao if (state->ProgramSize) { 492c1a3ac0e45d6b69d5567f80b76815b2e6997128dXiang, Haihao if (INTEL_DEBUG & DEBUG_STATE) 493c1a3ac0e45d6b69d5567f80b76815b2e6997128dXiang, Haihao fprintf(stderr, "I915_UPLOAD_PROGRAM:\n"); 4946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 495c1a3ac0e45d6b69d5567f80b76815b2e6997128dXiang, Haihao assert((state->Program[0] & 0x1ff) + 2 == state->ProgramSize); 4966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 497c1a3ac0e45d6b69d5567f80b76815b2e6997128dXiang, Haihao emit(intel, state->Program, state->ProgramSize * sizeof(GLuint)); 498c1a3ac0e45d6b69d5567f80b76815b2e6997128dXiang, Haihao if (INTEL_DEBUG & DEBUG_STATE) 499c1a3ac0e45d6b69d5567f80b76815b2e6997128dXiang, Haihao i915_disassemble_program(state->Program, state->ProgramSize); 500c1a3ac0e45d6b69d5567f80b76815b2e6997128dXiang, Haihao } 5016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5034a789e408dbba7891f1436b2f42e7c0824e5ba7aKeith Whitwell assert(get_dirty(state) == 0); 504a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell} 505a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell 506a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwellstatic void 5076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_destroy_context(struct intel_context *intel) 5086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 5092193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer GLuint i; 5102193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer struct i915_context *i915 = i915_context(&intel->ctx); 5112193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer 5127d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt intel_region_release(&i915->state.draw_region); 5137d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt intel_region_release(&i915->state.depth_region); 5147d99ddcb2bb09f1f54d91e6e20e42d217a5bccdfEric Anholt 5152193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer for (i = 0; i < I915_TEX_UNITS; i++) { 5162193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer if (i915->state.tex_buffer[i] != NULL) { 51734474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo_unreference(i915->state.tex_buffer[i]); 5182193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer i915->state.tex_buffer[i] = NULL; 5192193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer } 5202193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer } 5212193c4de83acfc3268ccca7b54b00543307e0baaMichel Dänzer 5226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell _tnl_free_vertices(&intel->ctx); 5236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 5246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 525165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholtvoid 526165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholti915_set_buf_info_for_region(uint32_t *state, struct intel_region *region, 527165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt uint32_t buffer_id) 528165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt{ 529165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt state[0] = _3DSTATE_BUF_INFO_CMD; 530165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt state[1] = buffer_id; 531165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt 532165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt if (region != NULL) { 53360894edeef973e86a73067276f658b72f84271b6Eric Anholt state[1] |= BUF_3D_PITCH(region->pitch); 534165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt 535165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt if (region->tiling != I915_TILING_NONE) { 536165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt state[1] |= BUF_3D_TILED_SURFACE; 537165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt if (region->tiling == I915_TILING_Y) 538165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt state[1] |= BUF_3D_TILE_WALK_Y; 539165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt } 540af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } else { 541af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt /* Fill in a default pitch, since 0 is invalid. We'll be 542af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt * setting the buffer offset to 0 and not referencing the 543af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt * buffer, so the pitch could really be any valid value. 544af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt */ 545af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt state[1] |= BUF_3D_PITCH(4096); 546165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt } 547165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt} 5486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 549a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholtstatic uint32_t i915_render_target_format_for_mesa_format[MESA_FORMAT_COUNT] = 550a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt{ 551ef145ba4ded6aafb28e3bda02fb348e6b8bff12aMark Mueller [MESA_FORMAT_B8G8R8A8_UNORM] = DV_PF_8888, 552ef145ba4ded6aafb28e3bda02fb348e6b8bff12aMark Mueller [MESA_FORMAT_B8G8R8X8_UNORM] = DV_PF_8888, 553eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller [MESA_FORMAT_B5G6R5_UNORM] = DV_PF_565 | DITHER_FULL_ALWAYS, 554eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller [MESA_FORMAT_B5G5R5A1_UNORM] = DV_PF_1555 | DITHER_FULL_ALWAYS, 555eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller [MESA_FORMAT_B4G4R4A4_UNORM] = DV_PF_4444 | DITHER_FULL_ALWAYS, 556a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt}; 557a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt 558a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholtstatic bool 559796f44d77906342e5912e7da6bdba1ba86bab9f0Eric Anholti915_render_target_supported(struct intel_context *intel, 560796f44d77906342e5912e7da6bdba1ba86bab9f0Eric Anholt struct gl_renderbuffer *rb) 561a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt{ 56271fe9437169cfdafda8814aa814bb85429fb6cfcMark Mueller mesa_format format = rb->Format; 563796f44d77906342e5912e7da6bdba1ba86bab9f0Eric Anholt 564a487ef87fe4aa8c4b8e5c0d888bfb18727c8e570Kenneth Graunke if (format == MESA_FORMAT_Z24_UNORM_S8_UINT || 565a487ef87fe4aa8c4b8e5c0d888bfb18727c8e570Kenneth Graunke format == MESA_FORMAT_Z24_UNORM_X8_UINT || 56650a01d2acafb2a937e62b24258e2e777c0cd1489Mark Mueller format == MESA_FORMAT_Z_UNORM16) { 567a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt return true; 568a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt } 569a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt 570a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt return i915_render_target_format_for_mesa_format[format] != 0; 571a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt} 572a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt 573f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholtstatic void 574f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholti915_set_draw_region(struct intel_context *intel, 575f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct intel_region *color_regions[], 576f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct intel_region *depth_region, 577f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt GLuint num_regions) 5786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 5796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i915_context *i915 = i915_context(&intel->ctx); 580f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &intel->ctx; 5812c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; 5822c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt struct intel_renderbuffer *irb = intel_renderbuffer(rb); 583b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt struct gl_renderbuffer *drb; 584b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt struct intel_renderbuffer *idrb = NULL; 5856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint value; 586f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt struct i915_hw_state *state = &i915->state; 5876d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson uint32_t draw_x, draw_y, draw_offset; 5886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 589f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt if (state->draw_region != color_regions[0]) { 590f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt intel_region_reference(&state->draw_region, color_regions[0]); 5916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (state->depth_region != depth_region) { 5936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel_region_reference(&state->depth_region, depth_region); 5946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 5956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 5966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* 5976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Set stride/cpp values 5986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 599165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt i915_set_buf_info_for_region(&state->Buffer[I915_DESTREG_CBUFADDR0], 600f9439e4a4696b8bc5fcdf3ac664f5e8d446f6621Eric Anholt color_regions[0], BUF_3D_ID_COLOR_BACK); 6016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 602165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt i915_set_buf_info_for_region(&state->Buffer[I915_DESTREG_DBUFADDR0], 603165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt depth_region, BUF_3D_ID_DEPTH); 6046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 6056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* 6066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Compute/set I915_DESTREG_DV1 value 6076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 6086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell value = (DSTORG_HORT_BIAS(0x8) | /* .5 */ 6096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DSTORG_VERT_BIAS(0x8) | /* .5 */ 6106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell LOD_PRECLAMP_OGL | TEX_DEFAULT_COLOR_OGL); 6112c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt if (irb != NULL) { 612924de7dc96f4607cb3d833637b5f69f4b9e2a6d0Brian Paul value |= i915_render_target_format_for_mesa_format[intel_rb_format(irb)]; 613af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } else { 614af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt value |= DV_PF_8888; 6156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 6162c30fd84dfa052949a117c78d932b58c1f88b446Eric Anholt 617b30dc2c66aeaad6661eef515a08a3da89aa07cb2Eric Anholt /* This isn't quite safe, thus being hidden behind an option. When changing 618b30dc2c66aeaad6661eef515a08a3da89aa07cb2Eric Anholt * the value of this bit, the pipeline needs to be MI_FLUSHed. And it 619b30dc2c66aeaad6661eef515a08a3da89aa07cb2Eric Anholt * can only be set when a depth buffer is already defined. 620b30dc2c66aeaad6661eef515a08a3da89aa07cb2Eric Anholt */ 621f67748038935e609aa85450b20d550b4813c9429Eric Anholt if (intel->is_945 && intel->use_early_z && 622b30dc2c66aeaad6661eef515a08a3da89aa07cb2Eric Anholt depth_region->tiling != I915_TILING_NONE) 623b30dc2c66aeaad6661eef515a08a3da89aa07cb2Eric Anholt value |= CLASSIC_EARLY_DEPTH; 624b30dc2c66aeaad6661eef515a08a3da89aa07cb2Eric Anholt 6256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (depth_region && depth_region->cpp == 4) { 6266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell value |= DEPTH_FRMT_24_FIXED_8_OTHER; 6276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 6286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else { 6296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell value |= DEPTH_FRMT_16_FIXED; 6306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 6316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state->Buffer[I915_DESTREG_DV1] = value; 6326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 633b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt drb = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; 634b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt if (!drb) 635b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt drb = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; 636b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt 637b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt if (drb) 638b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt idrb = intel_renderbuffer(drb); 639b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt 640b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt /* We set up the drawing rectangle to be offset into the color 641b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * region's location in the miptree. If it doesn't match with 642b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * depth's offsets, we can't render to it. 643b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * 644b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * (Well, not actually true -- the hw grew a bit to let depth's 645b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * offset get forced to 0,0. We may want to use that if people are 646b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * hitting that case. Also, some configurations may be supportable 647b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * by tweaking the start offset of the buffers around, which we 648b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt * can't do in general due to tiling) 649b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt */ 650b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt FALLBACK(intel, I915_FALLBACK_DRAW_OFFSET, 651b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt idrb && irb && (idrb->draw_x != irb->draw_x || 652b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt idrb->draw_y != irb->draw_y)); 653b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt 654b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt if (irb) { 655b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_x = irb->draw_x; 656b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_y = irb->draw_y; 657b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt } else if (idrb) { 658b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_x = idrb->draw_x; 659b17aab5753a6d14c9e757bedb186963b2dae8823Eric Anholt draw_y = idrb->draw_y; 660b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt } else { 661b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt draw_x = 0; 662b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt draw_y = 0; 663b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt } 664b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt 6656d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson draw_offset = (draw_y << 16) | draw_x; 6666d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson 667cf2f9ef015c312ecaa6656519602ae535f7ce9d7Yuanhan Liu FALLBACK(intel, I915_FALLBACK_DRAW_OFFSET, 668cf2f9ef015c312ecaa6656519602ae535f7ce9d7Yuanhan Liu (ctx->DrawBuffer->Width + draw_x > 2048) || 669cf2f9ef015c312ecaa6656519602ae535f7ce9d7Yuanhan Liu (ctx->DrawBuffer->Height + draw_y > 2048)); 670b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt /* When changing drawing rectangle offset, an MI_FLUSH is first required. */ 6716d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson if (draw_offset != i915->last_draw_offset) { 6726d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson state->Buffer[I915_DESTREG_DRAWRECT0] = MI_FLUSH | INHIBIT_FLUSH_RENDER_CACHE; 6736d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson i915->last_draw_offset = draw_offset; 6746d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson } else 6756d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson state->Buffer[I915_DESTREG_DRAWRECT0] = MI_NOOP; 6766d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson 677b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt state->Buffer[I915_DESTREG_DRAWRECT1] = _3DSTATE_DRAWRECT_INFO; 678b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt state->Buffer[I915_DESTREG_DRAWRECT2] = 0; 6796d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson state->Buffer[I915_DESTREG_DRAWRECT3] = draw_offset; 680b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt state->Buffer[I915_DESTREG_DRAWRECT4] = 681add3260157368458501709d08a3f913ed448234fChris Wilson ((ctx->DrawBuffer->Width + draw_x - 1) & 0xffff) | 682add3260157368458501709d08a3f913ed448234fChris Wilson ((ctx->DrawBuffer->Height + draw_y - 1) << 16); 6836d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson state->Buffer[I915_DESTREG_DRAWRECT5] = draw_offset; 6840cade4de4f74f6b0e86fb6622e2fc370c73fd840Eric Anholt 6856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS); 6866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 6876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 688af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholtstatic void 689af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholti915_update_color_write_enable(struct i915_context *i915, bool enable) 690af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt{ 691af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt uint32_t dw = i915->state.Ctx[I915_CTXREG_LIS6]; 692af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt if (enable) 693af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt dw |= S6_COLOR_WRITE_ENABLE; 694af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt else 695af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt dw &= ~S6_COLOR_WRITE_ENABLE; 696af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) { 697af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt I915_STATECHANGE(i915, I915_UPLOAD_CTX); 698af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt i915->state.Ctx[I915_CTXREG_LIS6] = dw; 699af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } 700af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt} 701af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt 702f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt/** 703f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Update the hardware state for drawing into a window or framebuffer object. 704f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * 705f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Called by glDrawBuffer, glBindFramebufferEXT, MakeCurrent, and other 706f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * places within the driver. 707f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * 708f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Basically, this needs to be called any time the current framebuffer 709f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * changes, the renderbuffers change, or we need to draw into different 710f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * color buffers. 711f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 712f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholtstatic void 713f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholti915_update_draw_buffer(struct intel_context *intel) 714f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt{ 715af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt struct i915_context *i915 = (struct i915_context *)intel; 716f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct gl_context *ctx = &intel->ctx; 717f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct gl_framebuffer *fb = ctx->DrawBuffer; 718af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt struct intel_region *colorRegion = NULL, *depthRegion = NULL; 719f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt struct intel_renderbuffer *irbDepth = NULL, *irbStencil = NULL; 720f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 721f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (!fb) { 722f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this can happen during the initial context initialization */ 723f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt return; 724f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 725f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 726f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt irbDepth = intel_get_renderbuffer(fb, BUFFER_DEPTH); 727f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt irbStencil = intel_get_renderbuffer(fb, BUFFER_STENCIL); 728f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 729f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Do this here, not core Mesa, since this function is called from 730f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * many places within the driver. 731f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 732f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (ctx->NewState & _NEW_BUFFERS) { 733f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this updates the DrawBuffer->_NumColorDrawBuffers fields, etc */ 7349036a6c0aa0637a1cd756836006dc8565b15a478Laura Ekstrand _mesa_update_framebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer); 735f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this updates the DrawBuffer's Width/Height if it's a FBO */ 736b590c617256720e82fff0428a5e0e4a64115fac2Laura Ekstrand _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer); 737f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 738f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 739f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { 740f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* this may occur when we're called by glBindFrameBuffer() during 741f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * the process of someone setting up renderbuffers, etc. 742f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 743f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /*_mesa_debug(ctx, "DrawBuffer: incomplete user FBO\n");*/ 744f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt return; 745f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 746f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 747f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* How many color buffers are we drawing into? 748f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * 749af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt * If there is more than one drawbuffer (GL_FRONT_AND_BACK), or the 750af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt * drawbuffers are too big, we have to fallback to software. 751f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 752f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt if ((fb->Width > ctx->Const.MaxRenderbufferSize) 753af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt || (fb->Height > ctx->Const.MaxRenderbufferSize)) { 754af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, true); 755af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } else if (fb->_NumColorDrawBuffers > 1) { 756af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, true); 757af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt } else { 758af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt struct intel_renderbuffer *irb; 759af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt irb = intel_renderbuffer(fb->_ColorDrawBuffers[0]); 76087f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt colorRegion = (irb && irb->mt) ? irb->mt->region : NULL; 761af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt FALLBACK(intel, INTEL_FALLBACK_DRAW_BUFFER, false); 762f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 763f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 764f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Check for depth fallback. */ 76587f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt if (irbDepth && irbDepth->mt) { 7662e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, false); 76787f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt depthRegion = irbDepth->mt->region; 76887f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt } else if (irbDepth && !irbDepth->mt) { 7692e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, true); 770f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt depthRegion = NULL; 771f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } else { /* !irbDepth */ 772f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* No fallback is needed because there is no depth buffer. */ 7732e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_DEPTH_BUFFER, false); 774f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt depthRegion = NULL; 775f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 776f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 777f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Check for stencil fallback. */ 77887f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt if (irbStencil && irbStencil->mt) { 779a487ef87fe4aa8c4b8e5c0d888bfb18727c8e570Kenneth Graunke assert(intel_rb_format(irbStencil) == MESA_FORMAT_Z24_UNORM_S8_UINT); 7802e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false); 78187f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt } else if (irbStencil && !irbStencil->mt) { 7822e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, true); 783f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } else { /* !irbStencil */ 784f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* No fallback is needed because there is no stencil buffer. */ 7852e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false); 786f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 7876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 788f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* If we have a (packed) stencil buffer attached but no depth buffer, 789f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * we still need to set up the shared depth/stencil state so we can use it. 790f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 79187f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt if (depthRegion == NULL && irbStencil && irbStencil->mt 792a487ef87fe4aa8c4b8e5c0d888bfb18727c8e570Kenneth Graunke && intel_rb_format(irbStencil) == MESA_FORMAT_Z24_UNORM_S8_UINT) { 79387f12bb2d95236c7b025d1a8be56b5ab1683d702Eric Anholt depthRegion = irbStencil->mt->region; 794f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt } 795f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 796f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* 797f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * Update depth and stencil test state 798f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 799fc4fba52cf7e9616c70dd76b4d6bdba6582e157bEric Anholt ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test); 80079fee3a76b7f4f63d01266fc3a3cd6ca44d1e513Eric Anholt ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled); 801f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 802af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt i915_update_color_write_enable(i915, colorRegion != NULL); 803af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt 804af9548d3358884b408fb4c3cc69028befc5abe1dEric Anholt intel->vtbl.set_draw_region(intel, &colorRegion, depthRegion, 805f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt fb->_NumColorDrawBuffers); 806f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt intel->NewGLState |= _NEW_BUFFERS; 807f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 808f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Set state we know depends on drawable parameters: 809f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 8104fcdb75268fe844c60d9c53f0dfd38d7460dea00Ian Romanick intelCalcViewport(ctx); 811a05c596a00916ce6a9c9d35ff36cd1e401fddd43Ian Romanick ctx->Driver.Scissor(ctx); 812f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt 813f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt /* Update culling direction which changes depending on the 814f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt * orientation of the buffer: 815f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt */ 8164c47fce92e381cb182b51ce6d0727c0a1365e8b0Eric Anholt ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace); 817f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt} 8186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 8196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 8205f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholti915_new_batch(struct intel_context *intel) 8216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 8226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i915_context *i915 = i915_context(&intel->ctx); 8235f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt 8245f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt /* Mark all state as needing to be emitted when starting a new batchbuffer. 8255f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt * Using hardware contexts would be an alternative, but they have some 8265f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt * difficulties associated with them (physical address requirements). 8275f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt */ 8286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->state.emitted = 0; 8296d741627b00677d269537ad36e5f2ecd31fd98b5Chris Wilson i915->last_draw_offset = 0; 8300b0cad38c57fbe59710cb4058866b2e68f6d471aChris Wilson i915->last_sampler = 0; 8312c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson 8322c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson i915->current_vb_bo = NULL; 8332c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson i915->current_vertex_size = 0; 8346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 8356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 8366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 8376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_assert_not_dirty( struct intel_context *intel ) 8386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 8396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i915_context *i915 = i915_context(&intel->ctx); 840c9886d535e4ac5ae108b1015a9682f4ddd297536Eric Anholt GLuint dirty = get_dirty(&i915->state); 8416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell assert(!dirty); 842220c0834a45d1dfa71f192b17d9a9b959a5a807eVinson Lee (void) dirty; 8436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 8446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 845483ea0a76fd2cde8fd5d4c303f1576ae15c21de5Brian Paulstatic void 8466cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholti915_invalidate_state(struct intel_context *intel, GLuint new_state) 8476cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt{ 8486cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt struct gl_context *ctx = &intel->ctx; 8496cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt 8503541cc0d40f86d8ea63a876b7215831335ec677dEric Anholt _swsetup_InvalidateState(ctx, new_state); 8516cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt _tnl_InvalidateState(ctx, new_state); 8526cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt _tnl_invalidate_vertex_state(ctx, new_state); 8536cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt} 8546cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt 8556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid 8566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915InitVtbl(struct i915_context *i915) 8576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 8586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.check_vertex_size = i915_check_vertex_size; 8596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.destroy = i915_destroy_context; 8606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.emit_state = i915_emit_state; 8615f86ae057a645c03dc1e0c51c2fb1b2628a50e0aEric Anholt i915->intel.vtbl.new_batch = i915_new_batch; 8626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.reduced_primitive_state = i915_reduced_primitive_state; 8636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.render_start = i915_render_start; 864a188ba4bf9364df24842d8727f4c7ddb2f894a2cRoland Scheidegger i915->intel.vtbl.render_prevalidate = i915_render_prevalidate; 8656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.set_draw_region = i915_set_draw_region; 866f34ec6169dc8b96e3958a42b51c9048c5f42ed80Eric Anholt i915->intel.vtbl.update_draw_buffer = i915_update_draw_buffer; 8676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.update_texture_state = i915UpdateTextureState; 8686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i915->intel.vtbl.assert_not_dirty = i915_assert_not_dirty; 869f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie i915->intel.vtbl.finish_batch = intel_finish_vb; 8706cf3d1cace770a3b4a0bff0d44db3b9e1da4cb09Eric Anholt i915->intel.vtbl.invalidate_state = i915_invalidate_state; 871a7bf7230564ac282cc957207224d16f322fa73d8Eric Anholt i915->intel.vtbl.render_target_supported = i915_render_target_supported; 8726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 873